def update_port(self, network=None, port=None, virtual_nic=None): device_id = port.vm_id mac_address = port.mac_address vm_mor = resource_util.get_vm_mor_for_uuid(self.session, device_id) if not vm_mor: LOG.warn(_("VM %(vm)s with mac address %(mac)s for port %(uuid)s " "not found on this node"), {'vm': device_id, 'mac': mac_address, 'uuid': port.uuid}) return False if port.port_status == model.PortStatus.UP: enabled = True elif port.port_status == model.PortStatus.DOWN: enabled = False else: raise error.NeutronAgentError("Invalid port status %s " "in update for port %s" % (port.port_status, port.uuid)) action = "Enabling" if enabled else "Disabling" LOG.debug("%s port used by VM " "%s for VNIC with macaddress %s" % (action, device_id, mac_address)) done = network_util.enable_disable_port_of_vm(self.session, vm_mor, mac_address, enabled) return done
def post_create_port(self, port): if port.port_status == model.PortStatus.UP: device_id = port.vm_id _clu_mor, _clu_path, vds_name = self.\ _find_cluster_switch_for_vm(device_id) pg_mor = network_util.get_portgroup_mor_by_name( self.session, vds_name, port.network_uuid) if pg_mor is None: raise error_util.RunTimeError("Port group %s not created " "on virtual switch %s" % (port.network_uuid, vds_name)) vm_mor = resource_util.get_vm_mor_for_uuid(self.session, device_id) if vm_mor is None: raise error_util.RunTimeError("Virtual machine %s with port " " %s not created " % (device_id, port.uuid)) (pg_key, port_key, swuuid) = self.\ _wait_for_port_update_on_vm(vm_mor, pg_mor) if None not in (pg_key, port_key, swuuid): # enable the port on virtual switch network_util.enable_disable_port(self.session, swuuid, pg_key, port_key, True)
def port_block_status_on_vm(session, vm_id, mac_address): block_status = True vm_mor = resource_util.get_vm_mor_for_uuid(session, vm_id) props = session._call_method(vim_util, "get_dynamic_properties", vm_mor, ["config.hardware.device"]) devices = props["config.hardware.device"] LOG.debug("Found %s devices on VM %s" % (len(devices.VirtualDevice), vm_mor.value)) vnics = get_vnics_from_devices(devices) for device in vnics: if (hasattr(device, "macAddress") and device.macAddress == mac_address): port = device.backing.port pgkey = port.portgroupKey portkey = port.portKey swuuid = port.switchUuid block_status = port_block_status(session, swuuid, pgkey, portkey) LOG.info(_("Block status of port %(pkey)s on port group %(pgkey)s" "on dvs %(uuid)s is %(status)s"), {'pkey': portkey, 'pgkey': pgkey, 'uuid': swuuid, 'status': str(block_status)}) break return block_status