def create_trunk(self, context, trunk): """Create a trunk.""" trunk = self.validate(context, trunk['trunk']) sub_ports = [ trunk_objects.SubPort(context=context, port_id=p['port_id'], segmentation_id=p['segmentation_id'], segmentation_type=p['segmentation_type']) for p in trunk['sub_ports'] ] admin_state_up = trunk.get('admin_state_up', True) # NOTE(status_police): a trunk is created in DOWN status. Depending # on the nature of the create request, a driver may set the status # immediately to ACTIVE if no physical provisioning is required. # Otherwise a transition to BUILD (or ERROR) should be expected # depending on how the driver reacts. PRECOMMIT failures prevent the # trunk from being created altogether. trunk_description = trunk.get('description', "") trunk_obj = trunk_objects.Trunk(context=context, admin_state_up=admin_state_up, id=uuidutils.generate_uuid(), name=trunk.get('name', ""), description=trunk_description, project_id=trunk['tenant_id'], port_id=trunk['port_id'], status=constants.DOWN_STATUS, sub_ports=sub_ports) with db_api.autonested_transaction(context.session): trunk_obj.create() payload = callbacks.TrunkPayload(context, trunk_obj.id, current_trunk=trunk_obj) registry.notify(constants.TRUNK, events.PRECOMMIT_CREATE, self, payload=payload) registry.notify(constants.TRUNK, events.AFTER_CREATE, self, payload=payload) return trunk_obj
def create_trunk(self, context, trunk): """Create a trunk object.""" LOG.debug("Creating trunk %s", trunk) trunk = self.validate_trunk(context, trunk['trunk']) sub_ports = [ trunk_objects.SubPort(context=context, port_id=p['port_id'], segmentation_id=p['segmentation_id'], segmentation_type=p['segmentation_type']) for p in trunk['sub_ports'] ] trunk_obj = trunk_objects.Trunk( context=context, admin_state_up=trunk.get('admin_state_up', True), id=uuidutils.generate_uuid(), name=trunk.get('name', ""), description=trunk.get('description', ""), project_id=trunk['tenant_id'], port_id=trunk['port_id'], # Trunk will turn active only after it has been bound on a host status=trunk_const.DOWN_STATUS, sub_ports=sub_ports) with db_context_writer.using(context): trunk_obj.create() payload = callbacks.TrunkPayload(context, trunk_obj.id, current_trunk=trunk_obj) registry.notify(trunk_const.TRUNK, events.PRECOMMIT_CREATE, self, payload=payload) registry.notify(trunk_const.TRUNK, events.AFTER_CREATE, self, payload=payload) return trunk_obj
def _mock_get_trunk_details(self, context, parent_port_id): if parent_port_id == self.trunk_dict['port_id']: return trunk_obj.Trunk(**self.trunk_dict)
def _create_ml2_ovs_test_resources(self, vif_details_list): self.subport_profiles = {} ctx = n_context.get_admin_context() for sid in range(1, 6): net_arg = {pnet.NETWORK_TYPE: 'vxlan', pnet.SEGMENTATION_ID: sid} network_id = self._make_network(self.fmt, 'net%d' % sid, True, arg_list=( pnet.NETWORK_TYPE, pnet.SEGMENTATION_ID, ), **net_arg)['network']['id'] for vif_details in vif_details_list: port = self._make_port(self.fmt, network_id)['port'] port_o = port_obj.PortBinding.get_object(ctx, port_id=port['id'], host='') port_o.vif_type = 'ovs' port_o.vif_details = vif_details port_o.update() for i in range(1, 4): port = self._make_port(self.fmt, network_id)['port'] subport1 = self._make_port(self.fmt, network_id)['port'] subport2 = self._make_port(self.fmt, network_id)['port'] trunk_id = uuidutils.generate_uuid() subports = [ trunk_obj.SubPort(ctx, port_id=subport1['id'], trunk_id=trunk_id, segmentation_type="vlan", segmentation_id=i * 10 + j) for j in range(2) ] trunk = trunk_obj.Trunk(ctx, id=trunk_id, port_id=port['id'], project_id='foo', subports=subports) trunk.create() subport_pb = port_obj.PortBinding.get_object( ctx, port_id=subport1['id'], host='') self.assertFalse(subport_pb.profile) self.subport_profiles[subport1['id']] = { "parent_name": port['id'], "tag": i * 10 } self.subport_profiles[subport2['id']] = { "parent_name": port['id'], "tag": i * 10 + 1 } # set something to the last subport port binding subport_pb = port_obj.PortBinding.get_object(ctx, port_id=subport2['id'], host='') # need to generate new id subport_pb.profile = subport_pb.profile.copy() subport_pb.profile['foo'] = 'bar' subport_pb.update() self.subport_profiles[subport2['id']]["foo"] = "bar"
def _create_trunk(self, trunk_id): port_id = uuidutils.generate_uuid() self._create_port(id=port_id, network_id=self._network['id']) trunk = t_obj.Trunk(self.context, id=trunk_id, port_id=port_id) trunk.create()
def _create_trunk(self, trunk_id): port_id = self._create_test_port_id(network_id=self._network_id) trunk = t_obj.Trunk(self.context, id=trunk_id, port_id=port_id) trunk.create()