def create_network_spec(client_factory, vif_info):
 network_spec = client_factory.create('ns0:VirtualDeviceConfigSpec')
 network_spec.operation = 'add'
 net_device = client_factory.create('ns0:VirtualPCNet32')
 network_ref = vif_info['network_ref']
 network_name = vif_info['network_name']
 mac_address = vif_info['mac_address']
 backing = None
 if (network_ref and (network_ref['type'] == 'DistributedVirtualPortgroup')):
  backing_name = ''.join(['ns0:VirtualEthernetCardDistributed', 'VirtualPortBackingInfo'])
  backing = client_factory.create(backing_name)
  portgroup = client_factory.create('ns0:DistributedVirtualSwitchPortConnection')
  portgroup.switchUuid = network_ref['dvsw']
  portgroup.portgroupKey = network_ref['dvpg']
  backing.port = portgroup
 else:
  backing = client_factory.create('ns0:VirtualEthernetCardNetworkBackingInfo')
  backing.deviceName = network_name
 connectable_spec = client_factory.create('ns0:VirtualDeviceConnectInfo')
 connectable_spec.startConnected = True
 connectable_spec.allowGuestControl = True
 connectable_spec.connected = True
 net_device.connectable = connectable_spec
 net_device.backing = backing
 net_device.key = (-47)
 net_device.addressType = 'manual'
 net_device.macAddress = mac_address
 net_device.wakeOnLanEnabled = True
 network_spec.device = net_device
 return network_spec

def create_network_spec ( client_factory , vif_info ) : network_spec = client_factory . create ( 'ns0:VirtualDeviceConfigSpec' ) network_spec . operation = 'add' net_device = client_factory . create ( 'ns0:VirtualPCNet32' ) network_ref = vif_info [ 'network_ref' ] network_name = vif_info [ 'network_name' ] mac_address = vif_info [ 'mac_address' ] backing = None if ( network_ref and ( network_ref [ 'type' ] == 'DistributedVirtualPortgroup' ) ) : backing_name = '' . join ( [ 'ns0:VirtualEthernetCardDistributed' , 'VirtualPortBackingInfo' ] ) backing = client_factory . create ( backing_name ) portgroup = client_factory . create ( 'ns0:DistributedVirtualSwitchPortConnection' ) portgroup . switchUuid = network_ref [ 'dvsw' ] portgroup . portgroupKey = network_ref [ 'dvpg' ] backing . port = portgroup else : backing = client_factory . create ( 'ns0:VirtualEthernetCardNetworkBackingInfo' ) backing . deviceName = network_name connectable_spec = client_factory . create ( 'ns0:VirtualDeviceConnectInfo' ) connectable_spec . startConnected = True connectable_spec . allowGuestControl = True connectable_spec . connected = True net_device . connectable = connectable_spec net_device . backing = backing net_device . key = ( - 47 ) net_device . addressType = 'manual' net_device . macAddress = mac_address net_device . wakeOnLanEnabled = True network_spec . device = net_device return network_spec
builds a config spec for the addition of a new network adapter to the vm .