def test_device_resource_provider_uuid(self): try: # assertNotRaises place_utils.device_resource_provider_uuid( namespace=self._uuid_ns, host='some host', device='some device') except Exception: self.fail('could not generate device resource provider uuid')
def test_device_resource_provider_uuid_stable(self): uuid_a = place_utils.device_resource_provider_uuid( namespace=self._uuid_ns, host='somehost', device='some-device') uuid_b = place_utils.device_resource_provider_uuid( namespace=self._uuid_ns, host='somehost', device='some-device') self.assertEqual(uuid_a, uuid_b)
def deferred_update_resource_provider_traits(self): rp_traits = [] physnet_trait_mappings = {} for physnet, devices in self._device_mappings.items(): for device in devices: physnet_trait_mappings[device] = place_utils.physnet_trait( physnet) vnic_type_traits = [ place_utils.vnic_type_trait(vnic_type) for vnic_type in self._supported_vnic_types ] for device in self._rp_bandwidths: rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._hypervisor_rps[device]['name'], device) traits = [] traits.append(physnet_trait_mappings[device]) traits.extend(vnic_type_traits) rp_traits.append( DeferredCall(self._client.update_resource_provider_traits, resource_provider_uuid=rp_uuid, traits=traits)) return rp_traits
def deferred_update_resource_provider_inventories(self): rp_inventories = [] for device, bw_values in self._rp_bandwidths.items(): rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._hypervisor_rps[device]['name'], device) inventories = {} for direction, rp_class in ((nlib_const.EGRESS_DIRECTION, orc.NET_BW_EGR_KILOBIT_PER_SEC), (nlib_const.INGRESS_DIRECTION, orc.NET_BW_IGR_KILOBIT_PER_SEC)): if bw_values[direction] is not None: inventory = dict(self._rp_inventory_defaults) inventory['total'] = bw_values[direction] inventories[rp_class] = inventory if inventories: rp_inventories.append( DeferredCall( self._client.update_resource_provider_inventories, resource_provider_uuid=rp_uuid, inventories=inventories)) return rp_inventories
def deferred_update_resource_provider_traits(self): rp_traits = [] physnet_trait_mappings = {} for physnet, devices in self._device_mappings.items(): for device in devices: physnet_trait_mappings[device] = place_utils.physnet_trait( physnet) vnic_type_traits = [place_utils.vnic_type_trait(vnic_type) for vnic_type in self._supported_vnic_types] for device in self._rp_bandwidths: rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._agent_host, device) traits = [] traits.append(physnet_trait_mappings[device]) traits.extend(vnic_type_traits) rp_traits.append( DeferredCall( self._client.update_resource_provider_traits, resource_provider_uuid=rp_uuid, traits=traits)) return rp_traits
def deferred_update_resource_provider_inventories(self): rp_inventories = [] for device, bw_values in self._rp_bandwidths.items(): rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._agent_host, device) inventories = {} for direction, rp_class in ( (nlib_const.EGRESS_DIRECTION, place_const.CLASS_NET_BW_EGRESS_KBPS), (nlib_const.INGRESS_DIRECTION, place_const.CLASS_NET_BW_INGRESS_KBPS)): if bw_values[direction] is not None: inventory = dict(self._rp_inventory_defaults) inventory['total'] = bw_values[direction] inventories[rp_class] = inventory if inventories: rp_inventories.append( DeferredCall( self._client.update_resource_provider_inventories, resource_provider_uuid=rp_uuid, inventories=inventories)) return rp_inventories
def responsible_for_ports_allocation(self, context): """Report if an agent is responsible for a resource provider. :param context: PortContext instance describing the port :returns: True for responsible, False for not responsible An agent based mechanism driver is reponsible for a resource provider if an agent of it is responsible for that resource provider. An agent reports responsibility by including the resource provider in the configurations field of the agent heartbeat. """ uuid_ns = self.resource_provider_uuid5_namespace if uuid_ns is None: return False if 'allocation' not in context.current['binding:profile']: return False rp = uuid.UUID(context.current['binding:profile']['allocation']) host_agents = self._possible_agents_for_port(context) reported = {} for agent in host_agents: if 'resource_provider_bandwidths' in agent['configurations']: for device in agent['configurations'][ 'resource_provider_bandwidths'].keys(): device_rp_uuid = place_utils.device_resource_provider_uuid( namespace=uuid_ns, host=agent['host'], device=device) if device_rp_uuid == rp: reported[agent['id']] = agent if len(reported) == 1: agent = list(reported.values())[0] LOG.debug( "Agent %(agent)s of type %(agent_type)s reports to be " "responsible for resource provider %(rsc_provider)s", { 'agent': agent['id'], 'agent_type': agent['agent_type'], 'rsc_provider': rp }) return True elif len(reported) > 1: LOG.error( "Agent misconfiguration, multiple agents on the same " "host %(host)s reports being responsible for resource " "provider %(rsc_provider)s: %(agents)s", { 'host': context.current['binding:host_id'], 'rsc_provider': rp, 'agents': reported.keys() }) return False else: # not responsible, must be somebody else return False
def responsible_for_ports_allocation(self, context): """Report if an agent is responsible for a resource provider. :param context: PortContext instance describing the port :returns: True for responsible, False for not responsible An agent based mechanism driver is reponsible for a resource provider if an agent of it is responsible for that resource provider. An agent reports responsibility by including the resource provider in the configurations field of the agent heartbeat. """ uuid_ns = self.resource_provider_uuid5_namespace if uuid_ns is None: return False if 'allocation' not in context.current['binding:profile']: return False rp = uuid.UUID(context.current['binding:profile']['allocation']) host_agents = self._possible_agents_for_port(context) reported = {} for agent in host_agents: if 'resource_provider_bandwidths' in agent['configurations']: for device in agent['configurations'][ 'resource_provider_bandwidths'].keys(): device_rp_uuid = place_utils.device_resource_provider_uuid( namespace=uuid_ns, host=agent['host'], device=device) if device_rp_uuid == rp: reported[agent['id']] = agent if len(reported) == 1: agent = list(reported.values())[0] LOG.debug("Agent %(agent)s of type %(agent_type)s reports to be " "responsible for resource provider %(rsc_provider)s", {'agent': agent['id'], 'agent_type': agent['agent_type'], 'rsc_provider': rp}) return True elif len(reported) > 1: LOG.error("Agent misconfiguration, multiple agents on the same " "host %(host)s reports being responsible for resource " "provider %(rsc_provider)s: %(agents)s", {'host': context.current['binding:host_id'], 'rsc_provider': rp, 'agents': reported.keys()}) return False else: # not responsible, must be somebody else return False
def _deferred_create_device_rps(self, agent_rp): rps = [] for device in self._rp_bandwidths: rp_name = '%s:%s' % (agent_rp['resource_provider']['name'], device) rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._agent_host, device) rps.append( DeferredCall( self._client.ensure_resource_provider, {'name': rp_name, 'uuid': rp_uuid, 'parent_provider_uuid': agent_rp[ 'resource_provider']['uuid']})) return rps
def _deferred_create_device_rps(self): rps = [] for device in self._rp_bandwidths: hypervisor = self._hypervisor_rps[device] rp_name = '%s:%s:%s' % (hypervisor['name'], self._agent_type, device) rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, hypervisor['name'], device) rps.append( DeferredCall( self._client.ensure_resource_provider, { 'name': rp_name, 'uuid': rp_uuid, 'parent_provider_uuid': hypervisor['uuid'] })) return rps
def _deferred_create_device_rps(self, agent_rp): rps = [] for device in self._rp_bandwidths: rp_name = '%s:%s' % (agent_rp['resource_provider']['name'], device) rp_uuid = place_utils.device_resource_provider_uuid( self._driver_uuid_namespace, self._agent_host, device) rps.append( DeferredCall( self._client.ensure_resource_provider, { 'name': rp_name, 'uuid': rp_uuid, 'parent_provider_uuid': agent_rp['resource_provider']['uuid'] })) return rps
def responsible_for_ports_allocation(self, context): """Report if an agent is responsible for a resource provider. :param context: PortContext instance describing the port :returns: True for responsible, False for not responsible An agent based mechanism driver is reponsible for a resource provider if an agent of it is responsible for that resource provider. An agent reports responsibility by including the resource provider in the configurations field of the agent heartbeat. """ uuid_ns = self.resource_provider_uuid5_namespace if uuid_ns is None: return False if 'allocation' not in context.current['binding:profile']: return False allocation = context.current['binding:profile']['allocation'] host_agents = self._possible_agents_for_port(context) reported = {} for agent in host_agents: if const.RP_BANDWIDTHS in agent['configurations']: for device in agent['configurations'][ const.RP_BANDWIDTHS].keys(): device_rp_uuid = place_utils.device_resource_provider_uuid( namespace=uuid_ns, host=agent['host'], device=device) for group, rp in allocation.items(): if device_rp_uuid == uuid.UUID(rp): reported[group] = reported.get(group, []) + [agent] if (const.RP_PP_WITHOUT_DIRECTION in agent['configurations'] or const.RP_PP_WITH_DIRECTION in agent['configurations']): for group, rp in allocation.items(): agent_rp_uuid = place_utils.agent_resource_provider_uuid( namespace=uuid_ns, host=agent['host']) if agent_rp_uuid == uuid.UUID(rp): reported[group] = reported.get(group, []) + [agent] for group, agents in reported.items(): if len(agents) == 1: agent = agents[0] LOG.debug( "Agent %(agent)s of type %(agent_type)s reports to be " "responsible for resource provider %(rsc_provider)s", { 'agent': agent['id'], 'agent_type': agent['agent_type'], 'rsc_provider': allocation[group] }) elif len(agents) > 1: LOG.error( "Agent misconfiguration, multiple agents on the same " "host %(host)s reports being responsible for resource " "provider %(rsc_provider)s: %(agents)s", { 'host': context.current['binding:host_id'], 'rsc_provider': allocation[group], 'agents': [agent['id'] for agent in agents] }) return False else: # not responsible, must be somebody else return False return (len(reported) >= 1 and (len(reported) == len(allocation)))