def _parse_source_ssh_conn_info(self, conn_info): # if we get valid SSH connection info we can # use it to copy the binary, and potentially # create a SSH tunnel through which we will # connect to the coriolis replicator required = ('ip', 'username') port = conn_info.get('port', 22) password = conn_info.get('password', None) pkey = conn_info.get('pkey', None) missing = [field for field in required if field not in conn_info] if missing: raise exception.CoriolisException( "Missing some required fields from source replication " "worker VM connection info: %s" % missing) if any([password, pkey]) is False: raise exception.CoriolisException( "Either 'password' or 'pkey' for source worker VM is required " "to initialize the Coriolis replicator.") if pkey: if type(pkey) is str: pkey = utils.deserialize_key( pkey, CONF.serialization.temp_keypair_password) args = { "hostname": conn_info["ip"], "username": conn_info["username"], "password": password, "pkey": pkey, "port": port, } return args
def _parse_source_ssh_conn_info(self, conn_info): # if we get valid SSH connection info we can # use it to copy the binary, and potentially # create a SSH tunnel through which we will # connect to the coriolis replicator required = ('ip', 'username') port = conn_info.get('port', 22) password = conn_info.get('password', None) pkey = conn_info.get('pkey', None) for i in required: if conn_info.get(i) is None: raise exception.CoriolisException( "missing required field: %s" % i) if any([password, pkey]) is False: raise exception.CoriolisException( "Either password or pkey is required") if pkey: if type(pkey) is str: pkey = utils.deserialize_key( pkey, CONF.serialization.temp_keypair_password) args = { "hostname": conn_info["ip"], "username": conn_info["username"], "password": password, "pkey": pkey, "port": port, } return args
def unmarshal_migr_conn_info(migr_connection_info): if migr_connection_info and "pkey" in migr_connection_info: migr_connection_info = migr_connection_info.copy() pkey_str = migr_connection_info["pkey"] migr_connection_info["pkey"] = utils.deserialize_key( pkey_str, CONF.serialization.temp_keypair_password) return migr_connection_info
def unmarshal_migr_conn_info(migr_connection_info): if migr_connection_info and "pkey" in migr_connection_info: migr_connection_info = migr_connection_info.copy() pkey_str = migr_connection_info["pkey"] if isinstance(pkey_str, paramiko.rsakey.RSAKey) is False: migr_connection_info["pkey"] = utils.deserialize_key( pkey_str, CONF.serialization.temp_keypair_password) return migr_connection_info
def unmarshal_migr_conn_info( migr_connection_info, private_key_field_name="pkey"): if migr_connection_info and ( private_key_field_name in migr_connection_info): migr_connection_info = migr_connection_info.copy() pkey_str = migr_connection_info[private_key_field_name] if isinstance(pkey_str, paramiko.rsakey.RSAKey) is False: migr_connection_info[private_key_field_name] = ( utils.deserialize_key( pkey_str, CONF.serialization.temp_keypair_password)) return migr_connection_info
def _check_deserialize_key(key): res = None if isinstance(key, paramiko.RSAKey): LOG.trace("Key is already in the proper format.") res = key elif type(key) is str: LOG.trace("Deserializing PEM-encoded private key.") res = utils.deserialize_key(key, CONF.serialization.temp_keypair_password) else: raise exception.CoriolisException( "Private key must be either a PEM-encoded string or " "a paramiko.RSAKey instance. Got type '%s'." % (type(key))) return res
def __init__(self, ssh_conn_info, writer_port): self._lock = threading.Lock() self._writer_cmd = os.path.join( "/usr/bin", _CORIOLIS_HTTP_WRITER_CMD) self._writer_port = writer_port self._ip = ssh_conn_info.get("ip") self._port = ssh_conn_info.get("port", 22) self._username = ssh_conn_info.get("username") self._password = ssh_conn_info.get("password") self._pkey = ssh_conn_info.get("pkey") if not all([self._ip, self._port, self._username]): raise exception.CoriolisException( "Invalid SSH connection info. IP, port and" " username are mandatory") if self._password is None and self._pkey is None: raise exception.CoriolisException( "Either password or pkey are required") if self._pkey: self._pkey = utils.deserialize_key( self._pkey, CONF.serialization.temp_keypair_password) self._ssh = self._connect_ssh()
def from_connection_info(cls, info, volumes_info): required = ["ip", "port", "username"] ip = info.get("ip") port = info.get("port") username = info.get("username") pkey = info.get("pkey") password = info.get("password") if not all([ip, port, username]): raise exception.CoriolisException( "Connection info is invalid for SSHBackupWriter. " "The following fields are required: %s" % ", ".join(required)) if pkey is None and password is None: raise exception.CoriolisException( "Either pkey or password are required") if pkey: if type(pkey) is not str: raise exception.CoriolisException( "pkey must be a PEM encoded RSA private key") pkey = utils.deserialize_key( pkey, CONF.serialization.temp_keypair_password) return cls(ip, port, username, pkey, password, volumes_info)