<commit_before>diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py
index 3d228d7..d513a74 100644
--- a/nova/virt/vmwareapi/vif.py
+++ b/nova/virt/vmwareapi/vif.py
@@ -146,6 +146,10 @@
 def get_network_ref(session, cluster, vif, is_neutron):
     if is_neutron:
         network_ref = _get_neutron_network(session, cluster, vif)
+        try:
+            network_ref['dvs_port_key'] = vif['details']['dvs_port_key']
+        except KeyError:
+            pass
     else:
         create_vlan = vif['network'].get_meta('should_create_vlan', False)
         network_ref = ensure_vlan_bridge(session, vif, cluster=cluster,
diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py
index bbf2835..be68010 100644
--- a/nova/virt/vmwareapi/vm_util.py
+++ b/nova/virt/vmwareapi/vm_util.py
@@ -339,6 +339,10 @@ def _create_vif_spec(client_factory, vif_info):
                     'ns0:DistributedVirtualSwitchPortConnection')
         portgroup.switchUuid = network_ref['dvsw']
         portgroup.portgroupKey = network_ref['dvpg']
+        try:
+            portgroup.portKey = network_ref['dvs_port_key']
+        except KeyError:
+            pass
         backing.port = portgroup
     else:
         backing = client_factory.create(
<commit_msg>Nova.patch update for support DVS/PG IDs for VIFs<commit_after>--- a/nova/virt/vmwareapi/vif.py
+++ b/nova/virt/vmwareapi/vif.py
@@ -145,7 +145,16 @@
 
 def get_network_ref(session, cluster, vif, is_neutron):
     if is_neutron:
-        network_ref = _get_neutron_network(session, cluster, vif)
+        try:
+            network_ref = {'dvsw': vif['details']['dvs_id'],
+                           'dvpg': vif['details']['pg_id'],
+                           'type': 'DistributedVirtualPortgroup'}
+        except KeyError:
+            network_ref = _get_neutron_network(session, cluster, vif)
+        try:
+            network_ref['dvs_port_key'] = vif['details']['dvs_port_key']
+        except KeyError:
+            pass
     else:
         create_vlan = vif['network'].get_meta('should_create_vlan', False)
         network_ref = ensure_vlan_bridge(session, vif, cluster=cluster,
diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py
--- a/nova/virt/vmwareapi/vm_util.py
+++ b/nova/virt/vmwareapi/vm_util.py
@@ -453,6 +453,10 @@
                     'ns0:DistributedVirtualSwitchPortConnection')
         portgroup.switchUuid = network_ref['dvsw']
         portgroup.portgroupKey = network_ref['dvpg']
+        try:
+            portgroup.portKey = network_ref['dvs_port_key']
+        except KeyError:
+            pass
         backing.port = portgroup
     else:
         backing = client_factory.create(

{'fraction_non_alphanumeric': 0.13245033112582782, 'fraction_numerical': 0.025386313465783666, 'mean_word_length': 2.6594885598923286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010643', 'n_tokens_mistral': 999, 'n_tokens_neox': 952, 'n_words': 141}