def delete_port_precommit(self, context): """Delete information about a VM and host from the DB.""" port = context.current pretty_log("delete_port_precommit:", port) port_id = port['id'] host_id = context.host with self.eos_sync_lock: if db_lib.is_port_provisioned(port_id): db_lib.forget_port(port_id, host_id)
def update_port_precommit(self, context): """Update the name of a given port. At the moment we only support port name change. Any other change to port is not supported at this time. We do not store the port names, therefore, no DB store action is performed here. """ new_port = context.current orig_port = context.original if new_port['name'] != orig_port['name']: LOG.info(_LI('Port name changed to %s'), new_port['name']) device_id = new_port['device_id'] host = context.host pretty_log("update_port_precommit: new", new_port) pretty_log("update_port_precommit: orig", orig_port) if new_port['device_owner'] == 'compute:probe': return # Check if it is port migration case if self._handle_port_migration_precommit(context): return # Check if the port is part of managed physical network seg_info = self._bound_segments(context) if not seg_info: # Ignoring the update as the port is not managed by # arista mechanism driver. return # device_id and device_owner are set on VM boot port_id = new_port['id'] network_id = new_port['network_id'] tenant_id = new_port['tenant_id'] or INTERNAL_TENANT_ID # Ensure that we use tenant Id for the network owner tenant_id = self._network_owner_tenant(context, network_id, tenant_id) if not self._network_provisioned(tenant_id, network_id, seg_info[driver_api.SEGMENTATION_ID], seg_info[driver_api.ID]): if not self.rpc.hpb_supported(): LOG.info( _LI("Ignoring port %(port)s conntected to " "%(net_id)s"), { 'port': port_id, 'net_id': network_id }) return LOG.info(_LI("Adding %s to provisioned network database"), seg_info) with self.eos_sync_lock: db_lib.remember_tenant(tenant_id) db_lib.remember_network_segment( tenant_id, network_id, seg_info[driver_api.SEGMENTATION_ID], seg_info[driver_api.ID]) with self.eos_sync_lock: port_down = False if (new_port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE ): # We care about port status only for DVR ports because # for DVR, a single port exists on multiple hosts. If a port # is no longer needed on a host then the driver gets a # port_update notification for that <port, host> with the # port status as PORT_STATUS_DOWN. port_down = context.status == n_const.PORT_STATUS_DOWN if host and not port_down: port_host_filter = None if (new_port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE): # <port, host> uniquely identifies a DVR port. Other # ports are identified by just the port id port_host_filter = host port_provisioned = db_lib.is_port_provisioned( port_id, port_host_filter) if not port_provisioned: LOG.info("Remembering the port") # Create a new port in the DB db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id) else: if (new_port['device_id'] != orig_port['device_id'] or context.host != context.original_host or new_port['network_id'] != orig_port['network_id'] or new_port['tenant_id'] != orig_port['tenant_id']): LOG.info("Updating the port") # Port exists in the DB. Update it db_lib.update_port(device_id, host, port_id, network_id, tenant_id) else: # Unbound or down port does not concern us orig_host = context.original_host LOG.info("Forgetting the port on %s" % str(orig_host)) db_lib.forget_port(port_id, orig_host)
def update_port_precommit(self, context): """Update the name of a given port. At the moment we only support port name change. Any other change to port is not supported at this time. We do not store the port names, therefore, no DB store action is performed here. """ new_port = context.current orig_port = context.original if new_port['name'] != orig_port['name']: LOG.info(_LI('Port name changed to %s'), new_port['name']) new_port = context.current device_id = new_port['device_id'] host = context.host pretty_log("update_port_precommit: new", new_port) pretty_log("update_port_precommit: orig", orig_port) if new_port['device_owner'] == 'compute:probe': return # device_id and device_owner are set on VM boot port_id = new_port['id'] network_id = new_port['network_id'] tenant_id = new_port['tenant_id'] or INTERNAL_TENANT_ID # Ensure that we use tenant Id for the network owner tenant_id = self._network_owner_tenant(context, network_id, tenant_id) if not self._network_provisioned(tenant_id, network_id): # If the Arista driver does not know about the network, ignore the # port. LOG.info(_LI("Ignoring port connected to %s"), network_id) return with self.eos_sync_lock: port_down = False if(new_port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE): # We care about port status only for DVR ports because # for DVR, a single port exists on multiple hosts. If a port # is no longer needed on a host then the driver gets a # port_update notification for that <port, host> with the # port status as PORT_STATUS_DOWN. port_down = context.status == n_const.PORT_STATUS_DOWN if host and not port_down: port_host_filter = None if(new_port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE): # <port, host> uniquely identifies a DVR port. Other # ports are identified by just the port id port_host_filter = host port_provisioned = db_lib.is_port_provisioned( port_id, port_host_filter) if not port_provisioned: LOG.info("Remembering the port") # Create a new port in the DB db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id) else: if(new_port['device_id'] != orig_port['device_id'] or context.host != context.original_host or new_port['network_id'] != orig_port['network_id'] or new_port['tenant_id'] != orig_port['tenant_id']): LOG.info("Updating the port") # Port exists in the DB. Update it db_lib.update_port(device_id, host, port_id, network_id, tenant_id) else: # Unbound or down port does not concern us orig_host = context.original_host LOG.info("Forgetting the port on %s" % str(orig_host)) db_lib.forget_port(port_id, orig_host)