text stringlengths 0 828 |
|---|
:raises: `KeypairError` if key is not a valid RSA or DSA key, |
the key could not be uploaded or the fingerprint does not |
match to the one uploaded to the cloud. |
"""""" |
# Read key. We do it as first thing because we need it either |
# way, to check the fingerprint of the remote keypair if it |
# exists already, or to create a new keypair. |
pkey = None |
try: |
pkey = DSSKey.from_private_key_file(private_key_path) |
except PasswordRequiredException: |
warn(""Unable to check key file `{0}` because it is encrypted with a "" |
""password. Please, ensure that you added it to the SSH agent "" |
""with `ssh-add {1}`"" |
.format(private_key_path, private_key_path)) |
except SSHException: |
try: |
pkey = RSAKey.from_private_key_file(private_key_path) |
except PasswordRequiredException: |
warn(""Unable to check key file `{0}` because it is encrypted with a "" |
""password. Please, ensure that you added it to the SSH agent "" |
""with `ssh-add {1}`"" |
.format(private_key_path, private_key_path)) |
except SSHException: |
raise KeypairError('File `%s` is neither a valid DSA key ' |
'or RSA key.' % private_key_path) |
try: |
# Check if a keypair `name` exists on the cloud. |
keypair = self.nova_client.keypairs.get(name) |
# Check if it has the correct keypair, but only if we can read the local key |
if pkey: |
fingerprint = str.join( |
':', (i.encode('hex') for i in pkey.get_fingerprint())) |
if fingerprint != keypair.fingerprint: |
raise KeypairError( |
""Keypair `%s` is present but has "" |
""different fingerprint. Aborting!"" % name) |
else: |
warn(""Unable to check if the keypair is using the correct key."") |
except NotFound: |
log.warning( |
""Keypair `%s` not found on resource `%s`, Creating a new one"", |
name, self._os_auth_url) |
# Create a new keypair |
with open(os.path.expanduser(public_key_path)) as f: |
key_material = f.read() |
try: |
self.nova_client.keypairs.create(name, key_material) |
except Exception as ex: |
log.error( |
""Could not import key `%s` with name `%s` to `%s`"", |
name, public_key_path, self._os_auth_url) |
raise KeypairError( |
""could not create keypair `%s`: %s"" % (name, ex))" |
4293,"def _load_instance(self, instance_id, force_reload=True): |
"""""" |
Return instance with the given id. |
For performance reasons, the instance ID is first searched for in the |
collection of VM instances started by ElastiCluster |
(`self._instances`), then in the list of all instances known to the |
cloud provider at the time of the last update |
(`self._cached_instances`), and finally the cloud provider is directly |
queried. |
:param str instance_id: instance identifier |
:param bool force_reload: |
if ``True``, skip searching caches and reload instance from server |
and immediately reload instance data from cloud provider |
:return: py:class:`novaclient.v1_1.servers.Server` - instance |
:raises: `InstanceError` is returned if the instance can't |
be found in the local cache or in the cloud. |
"""""" |
if force_reload: |
try: |
# Remove from cache and get from server again |
vm = self.nova_client.servers.get(instance_id) |
except NotFound: |
raise InstanceNotFoundError( |
""Instance `{instance_id}` not found"" |
.format(instance_id=instance_id)) |
# update caches |
self._instances[instance_id] = vm |
self._cached_instances[instance_id] = vm |
# if instance is known, return it |
if instance_id in self._instances: |
return self._instances[instance_id] |
# else, check (cached) list from provider |
if instance_id not in self._cached_instances: |
# Refresh the cache, just in case |
self._cached_instances = dict( |
(vm.id, vm) for vm in self.nova_client.servers.list()) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.