def run(self, id): peer = self.datastore.get_by_id('peers', id) if not peer: raise TaskException(errno.ENOENT, 'Peer entry {0} does not exist'.format(id)) remote = q.get(peer, 'credentials.address') remote_client = None hostid = self.dispatcher.call_sync('system.info.host_uuid') try: try: remote_client = get_freenas_peer_client(self, remote) call_task_and_check_state(remote_client, 'peer.freenas.delete_local', hostid, False) except RpcException as e: self.add_warning( TaskWarning( e.code, 'Remote {0} is unreachable. Delete operation is performed at local side only.' .format(remote))) except ValueError as e: self.add_warning(TaskWarning(errno.EINVAL, str(e))) self.join_subtasks( self.run_subtask('peer.freenas.delete_local', id, True)) finally: if remote_client: remote_client.disconnect()
def run(self, id): peer = self.datastore.get_by_id('peers', id) hostid = self.dispatcher.call_sync('system.info.host_uuid') remote_client = None if not peer: raise TaskException( errno.ENOENT, 'FreeNAS peer entry {0} does not exist'.format(id)) try: remote_client = get_freenas_peer_client( self, peer['credentials']['address']) remote_peer = remote_client.call_sync('peer.query', [('id', '=', hostid)], {'single': True}) if not remote_peer: raise TaskException( errno.ENOENT, 'Remote side of peer {0} does not exist'.format( peer['name'])) ip_at_remote_side = remote_client.local_address[0] hostname = self.dispatcher.call_sync( 'system.general.get_config')['hostname'] port = self.dispatcher.call_sync('service.sshd.get_config')['port'] remote_peer['name'] = hostname remote_peer['credentials']['port'] = port remote_peer['credentials']['address'] = hostname call_task_and_check_state(remote_client, 'peer.freenas.delete_local', hostid) remote_peer = exclude(remote_peer, 'created_at', 'updated_at') call_task_and_check_state(remote_client, 'peer.freenas.create_local', remote_peer, ip_at_remote_side) finally: if remote_client: remote_client.disconnect()
def run(self, id): peer = self.datastore.get_by_id('peers', id) hostid = self.dispatcher.call_sync('system.info.host_uuid') remote_client = None if not peer: raise TaskException(errno.ENOENT, 'FreeNAS peer entry {0} does not exist'.format(id)) try: remote_client = get_freenas_peer_client(self, peer['credentials']['address']) remote_peer = remote_client.call_sync('peer.query', [('id', '=', hostid)], {'single': True}) if not remote_peer: raise TaskException(errno.ENOENT, 'Remote side of peer {0} does not exist'.format(peer['name'])) ip_at_remote_side = remote_client.local_address[0] hostname = self.dispatcher.call_sync('system.general.get_config')['hostname'] port = self.dispatcher.call_sync('service.sshd.get_config')['port'] remote_peer['name'] = hostname remote_peer['credentials']['port'] = port remote_peer['credentials']['address'] = hostname call_task_and_check_state( remote_client, 'peer.freenas.delete_local', hostid ) remote_peer = exclude(remote_peer, 'created_at', 'updated_at') call_task_and_check_state( remote_client, 'peer.freenas.create_local', remote_peer, ip_at_remote_side ) finally: if remote_client: remote_client.disconnect()
def run(self, id): peer = self.datastore.get_by_id('peers', id) if not peer: raise TaskException(errno.ENOENT, 'Peer entry {0} does not exist'.format(id)) remote = q.get(peer, 'credentials.address') remote_client = None hostid = self.dispatcher.call_sync('system.info.host_uuid') try: try: remote_client = get_freenas_peer_client(self, remote) call_task_and_check_state( remote_client, 'peer.freenas.delete_local', hostid, False ) except RpcException as e: self.add_warning(TaskWarning( e.code, 'Remote {0} is unreachable. Delete operation is performed at local side only.'.format(remote) )) except ValueError as e: self.add_warning(TaskWarning( errno.EINVAL, str(e) )) self.run_subtask_sync( 'peer.freenas.delete_local', id, True ) finally: if remote_client: remote_client.disconnect()