def test_device_attahed_to_network_standard(self): self.assertFalse(VNicService.device_is_attached_to_network(None, None)) network_name = "TEST" device = Mock() device.backing = Mock() device.backing.network = Mock() device.backing.network.name = network_name self.assertTrue(VNicService.device_is_attached_to_network(device, network_name)) network = Mock(spec=vim.Network) network.name = "xnet" nicspec = Mock() nicspec.device = device res = VNicService.vnic_attach_to_network_standard(nicspec, network) self.assertEquals(res.device.backing.network.name, "xnet")
def test_is_device_match_network_not_found(self): # arrange device = Mock() device.backing = Mock(spec=[]) virtual_switch_to_machine_connector = VirtualSwitchToMachineDisconnectCommand(Mock(), Mock(), 'anetwork') # act # res = virtual_switch_to_machine_connector.is_device_match_network(device, 'Fake name') res = VNicService.device_is_attached_to_network(device, 'Fake name') # assert self.assertFalse(res)
def test_is_device_match_network_not_found(self): # arrange device = Mock() device.backing = Mock(spec=[]) virtual_switch_to_machine_connector = VirtualSwitchToMachineDisconnectCommand( Mock(), Mock(), 'anetwork') # act # res = virtual_switch_to_machine_connector.is_device_match_network(device, 'Fake name') res = VNicService.device_is_attached_to_network(device, 'Fake name') # assert self.assertFalse(res)
def test_is_device_match_network_other_type(self): # arrange backing = Mock(spec=[]) device = Mock() nerwork = Mock() device.backing = backing backing.network = nerwork nerwork.name = 'vln name or network name' # act res = VNicService.device_is_attached_to_network(device, nerwork.name) # assert self.assertTrue(res)
def remove_vnic(self, si, vm_uuid, network_name=None): """ disconnect all of the network adapter of the vm :param <str> si: :param <str> vm_uuid: the uuid of the vm :param <str> network_name: the name of the specific network to disconnect & vNic remove :return: """ _logger.debug(u"Revoking ALL Interfaces from VM '{}'...".format(vm_uuid)) vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid) condition = lambda device: \ VNicService.device_is_attached_to_network(device, network_name) if network_name else lambda x: True return self.remove_interfaces_from_vm_task(vm, condition)
def test_is_device_match_network_port_type(self): # arrange backing = Mock(spec=[]) device = Mock() port = Mock() device.backing = backing backing.port = port port.portgroupKey = 'port key' # act res = VNicService.device_is_attached_to_network(device, port.portgroupKey) # assert self.assertTrue(res)
def remove_vnic(self, si, vm_uuid, network_name=None): """ disconnect all of the network adapter of the vm :param <str> si: :param <str> vm_uuid: the uuid of the vm :param <str> network_name: the name of the specific network to disconnect & vNic remove :return: """ _logger.debug( u"Revoking ALL Interfaces from VM '{}'...".format(vm_uuid)) vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid) condition = lambda device: \ VNicService.device_is_attached_to_network(device, network_name) if network_name else lambda x: True return self.remove_interfaces_from_vm_task(vm, condition)
def test_is_device_match_network_port_type(self): # arrange backing = Mock(spec=[]) device = Mock() port = Mock() device.backing = backing backing.port = port port.portgroupKey = 'port key' # act res = VNicService.device_is_attached_to_network( device, port.portgroupKey) # assert self.assertTrue(res)
def test_device_attahed_to_network_distributed(self): network_name = "PORT-GROUP" device = Mock() device.backing = MagicMock() device.backing.port = Mock() hasattr(device.backing, "network") del device.backing.network device.backing.port.portgroupKey = network_name self.assertTrue(VNicService.device_is_attached_to_network(device, network_name)) port_group = Mock(spec=vim.dvs.DistributedVirtualPortgroup) port_group.key = "group_net" port_group.config.distributedVirtualSwitch.uuid = "6686" nicspec = Mock() nicspec.device = device res = VNicService.vnic_attach_to_network_distributed(nicspec, port_group) self.assertEquals(res.device.backing.port.portgroupKey, "group_net")