From 045260ff0603c67654845ac90bc9292ef01acd80 Mon Sep 17 00:00:00 2001 From: fuyi Date: Thu, 26 Oct 2023 11:34:42 +0800 Subject: [PATCH 1/7] migrate_vm --- kvmagent/kvmagent/plugins/vm_plugin.py | 43 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index 5b86f36f6..ee0cccdeb 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6389,23 +6389,32 @@ class VmPlugin(kvmagent.KvmAgent): for nic in cmd.nics: if nic.type != 'TFVNIC': continue - vrouter_cmd = [ - 'vrouter-port-control', - '--oper=add', - '--vm_project_uuid=%s' % transform_to_tf_uuid(cmd.accountUuid), - '--instance_uuid=%s' % transform_to_tf_uuid(cmd.vmInstanceUuid), - '--vm_name=', - '--uuid=%s' % transform_to_tf_uuid(nic.uuid), - '--vn_uuid=%s' % transform_to_tf_uuid(nic.l2NetworkUuid), - '--port_type=NovaVMPort', - '--tap_name=%s' % nic.nicInternalName, - '--mac=%s' % nic.mac, - '--ip_address=%s' % nic.ipForTf, - '--ipv6_address=', - '--tx_vlan_id=-1', - '--rx_vlan_id=-1', - ] - notify_vrouter(vrouter_cmd) + if "add" == cmd.sugonSdnAction: + vrouter_cmd = [ + 'vrouter-port-control', + '--oper=add', + '--vm_project_uuid=%s' % transform_to_tf_uuid(cmd.accountUuid), + '--instance_uuid=%s' % transform_to_tf_uuid(cmd.vmInstanceUuid), + '--vm_name=', + '--uuid=%s' % transform_to_tf_uuid(nic.uuid), + '--vn_uuid=%s' % transform_to_tf_uuid(nic.l2NetworkUuid), + '--port_type=NovaVMPort', + '--tap_name=%s' % nic.nicInternalName, + '--mac=%s' % nic.mac, + '--ip_address=%s' % nic.ips[0], + '--ipv6_address=', + '--tx_vlan_id=-1', + '--rx_vlan_id=-1', + ] + notify_vrouter(vrouter_cmd) + elif "delete" == cmd.sugonSdnAction: + # notify vrouter agent nic removed from dest host when migrate failed + vrouter_cmd = [ + 'vrouter-port-control', + '--oper=delete', + '--uuid=%s' % transform_to_tf_uuid(nic.uuid) + ] + notify_vrouter(vrouter_cmd) return jsonobject.dumps(rsp) vm = get_vm_by_uuid(cmd.vmInstanceUuid) vm.update_nic(cmd) -- Gitee From 5545d03d90365599d28610881411a8deab7d4c41 Mon Sep 17 00:00:00 2001 From: fuyi Date: Thu, 26 Oct 2023 19:13:33 +0800 Subject: [PATCH 2/7] review fix --- kvmagent/kvmagent/plugins/vm_plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index ee0cccdeb..163cd5a93 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6385,11 +6385,11 @@ class VmPlugin(kvmagent.KvmAgent): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = kvmagent.AgentResponse() # Deal with update nic request form migration - if cmd.notifySugonSdn: + if cmd.sugonNicCfg.notifySugonSdn: for nic in cmd.nics: if nic.type != 'TFVNIC': continue - if "add" == cmd.sugonSdnAction: + if "add" == cmd.sugonNicCfg.sugonSdnAction: vrouter_cmd = [ 'vrouter-port-control', '--oper=add', @@ -6407,7 +6407,7 @@ class VmPlugin(kvmagent.KvmAgent): '--rx_vlan_id=-1', ] notify_vrouter(vrouter_cmd) - elif "delete" == cmd.sugonSdnAction: + elif "delete" == cmd.sugonNicCfg.sugonSdnAction: # notify vrouter agent nic removed from dest host when migrate failed vrouter_cmd = [ 'vrouter-port-control', -- Gitee From 01d34ecb59f5fc6e694aad9fdec8715dfee9a701 Mon Sep 17 00:00:00 2001 From: fuyi Date: Fri, 27 Oct 2023 19:56:59 +0800 Subject: [PATCH 3/7] revirw update --- kvmagent/kvmagent/plugins/vm_plugin.py | 71 ++++++++++++++------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index 163cd5a93..b81476a20 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6118,7 +6118,7 @@ class VmPlugin(kvmagent.KvmAgent): KVM_SYNC_VM_DEVICEINFO_PATH = "/sync/vm/deviceinfo" CLEAN_FIRMWARE_FLASH = "/clean/firmware/flash" APPLY_MEMORY_BALLOON_PATH = "/vm/apply/memory/balloon" - + KVM_NOTIFY_TF_NIC_PATH = "/vm/nodifytfnic" VM_CONSOLE_LOGROTATE_PATH = "/etc/logrotate.d/vm-console-log" SET_VM_IOTHREADPIN_PATH = "/vm/setiothreadpin" @@ -6381,41 +6381,44 @@ class VmPlugin(kvmagent.KvmAgent): return jsonobject.dumps(rsp) @kvmagent.replyerror - def update_nic(self, req): + def notify_tf_nic(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = kvmagent.AgentResponse() # Deal with update nic request form migration - if cmd.sugonNicCfg.notifySugonSdn: - for nic in cmd.nics: - if nic.type != 'TFVNIC': - continue - if "add" == cmd.sugonNicCfg.sugonSdnAction: - vrouter_cmd = [ - 'vrouter-port-control', - '--oper=add', - '--vm_project_uuid=%s' % transform_to_tf_uuid(cmd.accountUuid), - '--instance_uuid=%s' % transform_to_tf_uuid(cmd.vmInstanceUuid), - '--vm_name=', - '--uuid=%s' % transform_to_tf_uuid(nic.uuid), - '--vn_uuid=%s' % transform_to_tf_uuid(nic.l2NetworkUuid), - '--port_type=NovaVMPort', - '--tap_name=%s' % nic.nicInternalName, - '--mac=%s' % nic.mac, - '--ip_address=%s' % nic.ips[0], - '--ipv6_address=', - '--tx_vlan_id=-1', - '--rx_vlan_id=-1', - ] - notify_vrouter(vrouter_cmd) - elif "delete" == cmd.sugonNicCfg.sugonSdnAction: - # notify vrouter agent nic removed from dest host when migrate failed - vrouter_cmd = [ - 'vrouter-port-control', - '--oper=delete', - '--uuid=%s' % transform_to_tf_uuid(nic.uuid) - ] - notify_vrouter(vrouter_cmd) - return jsonobject.dumps(rsp) + for nic in cmd.nics: + if nic.type != 'TFVNIC': + continue + if "add" == cmd.sugonSdnAction: + vrouter_cmd = [ + 'vrouter-port-control', + '--oper=add', + '--vm_project_uuid=%s' % transform_to_tf_uuid(cmd.accountUuid), + '--instance_uuid=%s' % transform_to_tf_uuid(cmd.vmInstanceUuid), + '--vm_name=', + '--uuid=%s' % transform_to_tf_uuid(nic.uuid), + '--vn_uuid=%s' % transform_to_tf_uuid(nic.l2NetworkUuid), + '--port_type=NovaVMPort', + '--tap_name=%s' % nic.nicInternalName, + '--mac=%s' % nic.mac, + '--ip_address=%s' % nic.ipForTf, + '--ipv6_address=', + '--tx_vlan_id=-1', + '--rx_vlan_id=-1', + ] + notify_vrouter(vrouter_cmd) + elif "delete" == cmd.sugonNicCfg.sugonSdnAction: + # notify vrouter agent nic removed from dest host when migrate failed + vrouter_cmd = [ + 'vrouter-port-control', + '--oper=delete', + '--uuid=%s' % transform_to_tf_uuid(nic.uuid) + ] + notify_vrouter(vrouter_cmd) + return jsonobject.dumps(rsp) + @kvmagent.replyerror + def update_nic(self, req): + cmd = jsonobject.loads(req[http.REQUEST_BODY]) + rsp = kvmagent.AgentResponse() vm = get_vm_by_uuid(cmd.vmInstanceUuid) vm.update_nic(cmd) @@ -9887,7 +9890,7 @@ host side snapshot files chian: http_server.register_async_uri(self.SSH_KEY_PAIR_ATTACH_TO_VM, self.attach_ssh_key_pair) http_server.register_async_uri(self.SSH_KEY_PAIR_DETACH_FROM_VM, self.detach_ssh_key_pair) http_server.register_async_uri(self.APPLY_MEMORY_BALLOON_PATH, self.apply_memory_balloon) - + http_server.register_async_uri(self.KVM_NOTIFY_TF_NIC_PATH, self.notify_tf_nic) self.clean_old_sshfs_mount_points() self.register_libvirt_event() self.register_qemu_log_cleaner() -- Gitee From fd19dec478a26e8d464655495c2737448c9ab072 Mon Sep 17 00:00:00 2001 From: fuyi Date: Tue, 31 Oct 2023 15:27:28 +0800 Subject: [PATCH 4/7] update --- kvmagent/kvmagent/plugins/vm_plugin.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index b81476a20..2b14eb08b 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6408,6 +6408,7 @@ class VmPlugin(kvmagent.KvmAgent): notify_vrouter(vrouter_cmd) elif "delete" == cmd.sugonNicCfg.sugonSdnAction: # notify vrouter agent nic removed from dest host when migrate failed + # when migrate success, notify vrouter agent removed src host. vrouter_cmd = [ 'vrouter-port-control', '--oper=delete', @@ -7140,15 +7141,6 @@ class VmPlugin(kvmagent.KvmAgent): vm = get_vm_by_uuid(cmd.vmUuid) vm.migrate(cmd) - # notify vrouter agent nic removed from source host - for nic in cmd.nics: - if nic.type == 'TFVNIC': - vrouter_cmd = [ - 'vrouter-port-control', - '--oper=delete', - '--uuid=%s' % transform_to_tf_uuid(nic.uuid) - ] - notify_vrouter(vrouter_cmd) except kvmagent.KvmError as e: logger.warn(linux.get_exception_stacktrace()) -- Gitee From 5ffe05ea83b1eb78e91e24ad43b5836c7a1e5780 Mon Sep 17 00:00:00 2001 From: fuyi Date: Tue, 31 Oct 2023 15:32:18 +0800 Subject: [PATCH 5/7] update --- kvmagent/kvmagent/plugins/vm_plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index 2b14eb08b..626bc245e 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6416,6 +6416,7 @@ class VmPlugin(kvmagent.KvmAgent): ] notify_vrouter(vrouter_cmd) return jsonobject.dumps(rsp) + @kvmagent.replyerror def update_nic(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) -- Gitee From 04bc87daa42f086c8e29d7688a69bdbad179ddd3 Mon Sep 17 00:00:00 2001 From: fuyi Date: Mon, 6 Nov 2023 17:38:48 +0800 Subject: [PATCH 6/7] bugfix --- kvmagent/kvmagent/plugins/vm_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index 626bc245e..b08d38975 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6406,7 +6406,7 @@ class VmPlugin(kvmagent.KvmAgent): '--rx_vlan_id=-1', ] notify_vrouter(vrouter_cmd) - elif "delete" == cmd.sugonNicCfg.sugonSdnAction: + elif "delete" == cmd.sugonSdnAction: # notify vrouter agent nic removed from dest host when migrate failed # when migrate success, notify vrouter agent removed src host. vrouter_cmd = [ @@ -6416,7 +6416,7 @@ class VmPlugin(kvmagent.KvmAgent): ] notify_vrouter(vrouter_cmd) return jsonobject.dumps(rsp) - + @kvmagent.replyerror def update_nic(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) -- Gitee From fe966c0c6e688004237a46dcc1d2d072fa60f093 Mon Sep 17 00:00:00 2001 From: fuyi Date: Mon, 6 Nov 2023 19:30:47 +0800 Subject: [PATCH 7/7] update --- kvmagent/kvmagent/plugins/vm_plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kvmagent/kvmagent/plugins/vm_plugin.py b/kvmagent/kvmagent/plugins/vm_plugin.py index b08d38975..cd0b86905 100644 --- a/kvmagent/kvmagent/plugins/vm_plugin.py +++ b/kvmagent/kvmagent/plugins/vm_plugin.py @@ -6406,6 +6406,7 @@ class VmPlugin(kvmagent.KvmAgent): '--rx_vlan_id=-1', ] notify_vrouter(vrouter_cmd) + elif "delete" == cmd.sugonSdnAction: # notify vrouter agent nic removed from dest host when migrate failed # when migrate success, notify vrouter agent removed src host. -- Gitee