def create_port_precommit(self, context): """Remember the infromation about a VM and its ports A VM information, along with the physical host information is saved. """ port = context.current device_id = port['device_id'] device_owner = port['device_owner'] host = context.host # device_id and device_owner are set on VM boot is_vm_boot = device_id and device_owner if host and is_vm_boot: port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] if not tenant_id: tenant_id = context._plugin_context.tenant_id with self.eos_sync_lock: # If network does not exist under this tenant, # it may be a shared network. Get shared network owner Id net_provisioned = ( db_lib.is_network_provisioned(tenant_id, network_id) or self.ndb.get_shared_network_owner_id(network_id) ) if not net_provisioned: # Ignore this request if network is not provisioned return db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id)
def create_port_precommit(self, context): """Remember the infromation about a VM and its ports A VM information, along with the physical host information is saved. """ port = context.current device_id = port["device_id"] device_owner = port["device_owner"] host = context.host # device_id and device_owner are set on VM boot is_vm_boot = device_id and device_owner if host and is_vm_boot: port_id = port["id"] network_id = port["network_id"] tenant_id = port["tenant_id"] if not tenant_id: tenant_id = context._plugin_context.tenant_id with self.eos_sync_lock: if not db_lib.is_network_provisioned(tenant_id, network_id): # Ignore this request if network is not provisioned return db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id)
def create_port_precommit(self, context): """Remember the infromation about a VM and its ports A VM information, along with the physical host information is saved. """ port = context.current device_id = port['device_id'] device_owner = port['device_owner'] host = context.host # device_id and device_owner are set on VM boot is_vm_boot = device_id and device_owner if host and is_vm_boot: port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] if not tenant_id: tenant_id = context._plugin_context.tenant_id with self.eos_sync_lock: # If network does not exist under this tenant, # it may be a shared network. Get shared network owner Id net_provisioned = ( db_lib.is_network_provisioned(tenant_id, network_id) or self.ndb.get_shared_network_owner_id(network_id)) if not net_provisioned: # Ignore this request if network is not provisioned return db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_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']) new_port = context.current device_id = new_port['device_id'] host = context.host # 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 with self.eos_sync_lock: port_provisioned = db_lib.is_port_provisioned(port_id) if not port_provisioned: # 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: # Port exists in the DB. Update it db_lib.update_port(device_id, host, port_id, network_id, tenant_id)
def create_port_precommit(self, context): """Remember the information about a VM and its ports A VM information, along with the physical host information is saved. """ port = context.current device_id = port['device_id'] device_owner = port['device_owner'] host = context.host pretty_log("create_port_precommit:", port) if device_owner == 'compute:probe': return # device_id and device_owner are set on VM boot is_vm_boot = device_id and device_owner if host and is_vm_boot: port_id = port['id'] network_id = port['network_id'] tenant_id = 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) with self.eos_sync_lock: # If network does not exist under this tenant, # it may be a shared network. Get shared network owner Id if not self._network_provisioned(tenant_id, network_id): # Ignore this request if network is not provisioned return db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id)
def test_vm_is_remembered(self): vm_id = 'VM-1' tenant_id = 'test' network_id = '123' port_id = 456 host_id = 'ubuntu1' db_lib.remember_vm(vm_id, host_id, port_id, network_id, tenant_id) vm_provisioned = db_lib.is_vm_provisioned(vm_id, host_id, port_id, network_id, tenant_id) self.assertTrue(vm_provisioned, 'VM must be provisioned')
def test_vm_is_removed(self): vm_id = 'VM-1' tenant_id = 'test' network_id = '123' port_id = 456 host_id = 'ubuntu1' db_lib.remember_vm(vm_id, host_id, port_id, network_id, tenant_id) db_lib.forget_vm(vm_id, host_id, port_id, network_id, tenant_id) vm_provisioned = db_lib.is_vm_provisioned(vm_id, host_id, port_id, network_id, tenant_id) self.assertFalse(vm_provisioned, 'The vm should be deleted')
def create_port_precommit(self, context): """Remember the infromation about a VM and its ports A VM information, along with the physical host information is saved. """ port = context.current device_id = port['device_id'] device_owner = port['device_owner'] host = context.host # device_id and device_owner are set on VM boot is_vm_boot = device_id and device_owner if host and is_vm_boot: port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] with self.eos_sync_lock: db_lib.remember_tenant(tenant_id) db_lib.remember_vm(device_id, host, port_id, network_id, tenant_id)
def test_num_vm_is_valid(self): tenant_id = 'test' network_id = '123' port_id = 456 host_id = 'ubuntu1' vm_to_remember = ['vm1', 'vm2', 'vm3'] vm_to_forget = ['vm2', 'vm1'] for vm in vm_to_remember: db_lib.remember_vm(vm, host_id, port_id, network_id, tenant_id) for vm in vm_to_forget: db_lib.forget_vm(vm, host_id, port_id, network_id, tenant_id) num_vms = len(db_lib.get_vms(tenant_id)) expected = len(vm_to_remember) - len(vm_to_forget) self.assertEqual(expected, num_vms, 'There should be %d records, ' 'got %d records' % (expected, num_vms)) # clean up afterwards db_lib.forget_vm('vm3', host_id, port_id, network_id, tenant_id)
def test_num_vm_is_valid(self): tenant_id = 'test' network_id = '123' port_id = 456 host_id = 'ubuntu1' vm_to_remember = ['vm1', 'vm2', 'vm3'] vm_to_forget = ['vm2', 'vm1'] for vm in vm_to_remember: db_lib.remember_vm(vm, host_id, port_id, network_id, tenant_id) for vm in vm_to_forget: db_lib.forget_vm(vm, host_id, port_id, network_id, tenant_id) num_vms = len(db_lib.get_vms(tenant_id)) expected = len(vm_to_remember) - len(vm_to_forget) self.assertEqual( expected, num_vms, 'There should be %d records, ' 'got %d records' % (expected, num_vms)) # clean up afterwards db_lib.forget_vm('vm3', host_id, port_id, network_id, tenant_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)