def get_random_params(self): """create random parameters for portinfo test""" tenant = utils.str_uuid() network = utils.str_uuid() port = utils.str_uuid() _filter = utils.str_uuid() none = utils.str_uuid() return tenant, network, port, _filter, none
def get_portinfo_random_params(self): """create random parameters for portinfo test""" port_id = utils.str_uuid() datapath_id = hex(random.randint(0, 0xffffffff)) port_no = random.randint(1, 100) vlan_id = random.randint(0, 4095) mac = ':'.join(["%02x" % random.randint(0, 0xff) for x in range(6)]) none = utils.str_uuid() return port_id, datapath_id, port_no, vlan_id, mac, none
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" tenant_id = utils.str_uuid() network_id = utils.str_uuid() port_id = utils.str_uuid() portinfo = nmodels.PortInfo( id=port_id, datapath_id="0x123456789", port_no=1234, vlan_id=321, mac="11:22:33:44:55:66" ) return tenant_id, network_id, portinfo
def create_security_group(self, context, security_group, default_sg=False): """Create security group. If default_sg is true that means we are a default security group for a given tenant if it does not exist. """ s = security_group['security_group'] if (cfg.CONF.SECURITYGROUP.proxy_mode and not context.is_admin): raise ext_sg.SecurityGroupProxyModeNotAdmin() if (cfg.CONF.SECURITYGROUP.proxy_mode and not s.get('external_id')): raise ext_sg.SecurityGroupProxyMode() if not cfg.CONF.SECURITYGROUP.proxy_mode and s.get('external_id'): raise ext_sg.SecurityGroupNotProxyMode() tenant_id = self._get_tenant_id_for_create(context, s) # if in proxy mode a default security group will be created by source if not default_sg and not cfg.CONF.SECURITYGROUP.proxy_mode: self._ensure_default_security_group(context, tenant_id, security_group) if s.get('external_id'): try: # Check if security group already exists sg = self.get_security_group(context, s.get('external_id')) if sg: raise ext_sg.SecurityGroupAlreadyExists( name=sg.get('name', ''), external_id=s.get('external_id')) except ext_sg.SecurityGroupNotFound: pass with context.session.begin(subtransactions=True): security_group_db = SecurityGroup(id=s.get('id') or ( utils.str_uuid()), description=s['description'], tenant_id=tenant_id, name=s['name'], external_id=s.get('external_id')) context.session.add(security_group_db) if s.get('name') == 'default': for ethertype in self.sg_supported_ethertypes: # Allow all egress traffic db = SecurityGroupRule( id=utils.str_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='egress', ethertype=ethertype) context.session.add(db) # Allow intercommunication db = SecurityGroupRule( id=utils.str_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='ingress', source_group=security_group_db, ethertype=ethertype) context.session.add(db) return self._make_security_group_dict(security_group_db)
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" tenant_id = utils.str_uuid() network_id = utils.str_uuid() port_id = utils.str_uuid() portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789", port_no=1234, vlan_id=321, mac="11:22:33:44:55:66") return tenant_id, network_id, portinfo
def create_security_group(self, context, security_group, default_sg=False): """Create security group. If default_sg is true that means we are a default security group for a given tenant if it does not exist. """ s = security_group['security_group'] if (cfg.CONF.SECURITYGROUP.proxy_mode and not context.is_admin): raise ext_sg.SecurityGroupProxyModeNotAdmin() if (cfg.CONF.SECURITYGROUP.proxy_mode and not s.get('external_id')): raise ext_sg.SecurityGroupProxyMode() if not cfg.CONF.SECURITYGROUP.proxy_mode and s.get('external_id'): raise ext_sg.SecurityGroupNotProxyMode() tenant_id = self._get_tenant_id_for_create(context, s) # if in proxy mode a default security group will be created by source if not default_sg and not cfg.CONF.SECURITYGROUP.proxy_mode: self._ensure_default_security_group(context, tenant_id, security_group) if s.get('external_id'): try: # Check if security group already exists sg = self.get_security_group(context, s.get('external_id')) if sg: raise ext_sg.SecurityGroupAlreadyExists( name=sg.get('name', ''), external_id=s.get('external_id')) except ext_sg.SecurityGroupNotFound: pass with context.session.begin(subtransactions=True): security_group_db = SecurityGroup(id=s.get('id') or (utils.str_uuid()), description=s['description'], tenant_id=tenant_id, name=s['name'], external_id=s.get('external_id')) context.session.add(security_group_db) if s.get('name') == 'default': for ethertype in self.sg_supported_ethertypes: # Allow all egress traffic db = SecurityGroupRule(id=utils.str_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='egress', ethertype=ethertype) context.session.add(db) # Allow intercommunication db = SecurityGroupRule(id=utils.str_uuid(), tenant_id=tenant_id, security_group=security_group_db, direction='ingress', source_group=security_group_db, ethertype=ethertype) context.session.add(db) return self._make_security_group_dict(security_group_db)
def create_security_group_rule_bulk_native(self, context, security_group_rule): r = security_group_rule['security_group_rules'] scoped_session(context.session) security_group_id = self._validate_security_group_rules( context, security_group_rule) with context.session.begin(subtransactions=True): if not self.get_security_group(context, security_group_id): raise ext_sg.SecurityGroupNotFound(id=security_group_id) self._check_for_duplicate_rules(context, r) ret = [] for rule_dict in r: rule = rule_dict['security_group_rule'] tenant_id = self._get_tenant_id_for_create(context, rule) db = SecurityGroupRule( id=utils.str_uuid(), tenant_id=tenant_id, security_group_id=rule['security_group_id'], direction=rule['direction'], external_id=rule.get('external_id'), source_group_id=rule.get('source_group_id'), ethertype=rule['ethertype'], protocol=rule['protocol'], port_range_min=rule['port_range_min'], port_range_max=rule['port_range_max'], source_ip_prefix=rule.get('source_ip_prefix')) context.session.add(db) ret.append(self._make_security_group_rule_dict(db)) return ret
def create_subnet(self, context, subnet): s = subnet['subnet'] net = netaddr.IPNetwork(s['cidr']) if s['gateway_ip'] == attributes.ATTR_NOT_SPECIFIED: s['gateway_ip'] = str(netaddr.IPAddress(net.first + 1)) tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(): network = self._get_network(context, s["network_id"]) self._validate_subnet_cidr(network, s['cidr']) subnet = models_v2.Subnet(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], network_id=s['network_id'], ip_version=s['ip_version'], cidr=s['cidr'], gateway_ip=s['gateway_ip'], enable_dhcp=s['enable_dhcp']) context.session.add(subnet) pools = self._allocate_pools_for_subnet(context, s) for pool in pools: ip_pool = models_v2.IPAllocationPool(subnet=subnet, first_ip=pool['start'], last_ip=pool['end']) context.session.add(ip_pool) ip_range = models_v2.IPAvailabilityRange( ipallocationpool=ip_pool, first_ip=pool['start'], last_ip=pool['end']) context.session.add(ip_range) return self._make_subnet_dict(subnet)
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" t, n, p = (super(TremaFilterDriverTest, self).get_ofc_item_random_params()) filter_id = utils.str_uuid() filter_dict = { 'tenant_id': t, 'id': filter_id, 'network_id': n, 'priority': 123, 'action': "ACCEPT", 'in_port': p.id, 'src_mac': p.mac, 'dst_mac': "", 'eth_type': 0, 'src_cidr': "", 'dst_cidr': "", 'src_port': 0, 'dst_port': 0, 'protocol': "TCP", 'admin_state_up': True, 'status': "ACTIVE" } filter_item = nmodels.PacketFilter(**filter_dict) return t, n, p, filter_item
def create_floatingip(self, context, floatingip): fip = floatingip['floatingip'] tenant_id = self._get_tenant_id_for_create(context, fip) fip_id = utils.str_uuid() f_net_id = fip['floating_network_id'] if not self._network_is_external(context, f_net_id): msg = "Network %s is not a valid external network" % f_net_id raise q_exc.BadRequest(resource='floatingip', msg=msg) # This external port is never exposed to the tenant. # it is used purely for internal system and admin use when # managing floating IPs. external_port = self.create_port(context.elevated(), { 'port': {'tenant_id': '', # tenant intentionally not set 'network_id': f_net_id, 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'device_id': fip_id, 'device_owner': DEVICE_OWNER_FLOATINGIP, 'name': ''}}) # Ensure IP addresses are allocated on external port if not external_port['fixed_ips']: msg = "Unable to find any IP address on external network" # remove the external port self.delete_port(context.elevated(), external_port['id'], l3_port_check=False) raise q_exc.BadRequest(resource='floatingip', msg=msg) floating_ip_address = external_port['fixed_ips'][0]['ip_address'] try: with context.session.begin(subtransactions=True): floatingip_db = FloatingIP( id=fip_id, tenant_id=tenant_id, floating_network_id=fip['floating_network_id'], floating_ip_address=floating_ip_address, floating_port_id=external_port['id']) fip['tenant_id'] = tenant_id # Update association with internal port # and define external IP address self._update_fip_assoc(context, fip, floatingip_db, external_port) context.session.add(floatingip_db) # TODO(salvatore-orlando): Avoid broad catch # Maybe by introducing base class for L3 exceptions except q_exc.BadRequest: LOG.exception("Unable to create Floating ip due to a " "malformed request") raise except Exception: LOG.exception("Floating IP association failed") # Remove the port created for internal purposes self.delete_port(context.elevated(), external_port['id'], l3_port_check=False) raise return self._make_floatingip_dict(floatingip_db)
def create_category_networkfunction(self, context, category_networkfunction): n = category_networkfunction['category_networkfunction'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): category_networkfunction = ns_category_networkfunction(id=n.get('id') or utils.str_uuid(), category_id=n['category_id'], networkfunction_id=n['networkfunction_id']) context.session.add(category_networkfunction) return self._make_category_networkfunction_dict(category_networkfunction)
def create_floatingip(self, context, floatingip): fip = floatingip['floatingip'] tenant_id = self._get_tenant_id_for_create(context, fip) fip_id = utils.str_uuid() f_net_id = fip['floating_network_id'] if not self._network_is_external(context, f_net_id): msg = "Network %s is not a valid external network" % f_net_id raise q_exc.BadRequest(resource='floatingip', msg=msg) # This external port is never exposed to the tenant. # it is used purely for internal system and admin use when # managing floating IPs. external_port = self.create_port( context, { 'port': { 'network_id': f_net_id, 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'admin_state_up': True, 'device_id': fip_id, 'device_owner': DEVICE_OWNER_FLOATINGIP, 'name': '' } }) # Ensure IP addresses are allocated on external port if not external_port['fixed_ips']: msg = "Unable to find any IP address on external network" # remove the external port self.delete_port(context, external_port['id'], l3_port_check=False) raise q_exc.BadRequest(resource='floatingip', msg=msg) floating_ip_address = external_port['fixed_ips'][0]['ip_address'] try: with context.session.begin(subtransactions=True): floatingip_db = FloatingIP( id=fip_id, tenant_id=tenant_id, floating_network_id=fip['floating_network_id'], floating_ip_address=floating_ip_address, floating_port_id=external_port['id']) fip['tenant_id'] = tenant_id # Update association with internal port # and define external IP address self._update_fip_assoc(context, fip, floatingip_db, external_port) context.session.add(floatingip_db) # TODO(salvatore-orlando): Avoid broad catch # Maybe by introducing base class for L3 exceptions except Exception: LOG.exception("Floating IP association failed") # Remove the port created for internal purposes self.delete_port(context, external_port['id'], l3_port_check=False) raise return self._make_floatingip_dict(floatingip_db)
def create_metadata(self, context, metadata): n = metadata['metadata'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): metadata = ns_metadata(id=n.get('id') or utils.str_uuid(), name=n['name'], value=n['value'], image_map_id=n['image_map_id']) context.session.add(metadata) return self._make_metadata_dict(metadata)
def create_personality(self, context, personality): n = personality['personality'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): personality = ns_personalitie(id=n.get('id') or utils.str_uuid(), file_path=n['file_path'], file_content=n['file_content'], image_map_id=n['image_map_id']) context.session.add(personality) return self._make_personality_dict(personality)
def create_networkfunction(self, context, networkfunction): n = networkfunction['networkfunction'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): networkfunction = ns_networkfunction(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], description=n['description'], shared=n['shared']) context.session.add(networkfunction) return self._make_networkfunction_dict(networkfunction)
def create_vendor(self, context, vendor): n = vendor['vendor'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): vendor = ns_vendor(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], description=n['description'], shared=n['shared']) context.session.add(vendor) return self._make_vendor_dict(vendor)
def create_category(self, context, category): n = category['category'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): category = ns_categorie(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], description=n['description'], shared=n['shared']) context.session.add(category) return self._make_category_dict(category)
def create_chain(self, context, chain): n = chain['chain'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): chain = ns_chain(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], type=n['type'], auto_boot=n['auto_boot']) context.session.add(chain) return self._make_chain_dict(chain)
def create_chain_image(self, context, chain_image): n = chain_image['chain_image'] with context.session.begin(subtransactions=True): chain_image = ns_chain_image_map(id=n.get('id') or utils.str_uuid(), name=n['name'], chain_id=n['chain_id'], image_map_id=n['image_map_id'], sequence_number=n['sequence_number'], instance_id =n['instance_id'], instance_uuid =n['instance_uuid']) context.session.add(chain_image) return self._make_chain_image_dict(chain_image)
def create_chain_image_network(self, context, chain_image_network): n = chain_image_network['chain_image_network'] with context.session.begin(subtransactions=True): chain_image = self._get_chain_image(context, n["chain_map_id"]) self._validate_chain_image_network_id(context, chain_image, n['network_id']) chain_image_network = ns_chain_network_associate(id=n.get('id') or utils.str_uuid(), chain_map_id=n['chain_map_id'], network_id=n['network_id']) context.session.add(chain_image_network) return self._make_chain_image_network_dict(chain_image_network)
def create_config_handle(self, context, config_handle): n = config_handle['config_handle'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): config_handle = ns_config_handle(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], networkfunction_id=n['networkfunction_id'], status=n['status'], slug=n['slug']) context.session.add(config_handle) return self._make_config_handle_dict(config_handle)
def create_port(self, context, port): p = port['port'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, p) with context.session.begin(subtransactions=True): network = self._get_network(context, p["network_id"]) # Ensure that a MAC address is defined and it is unique on the # network if p['mac_address'] == attributes.ATTR_NOT_SPECIFIED: p['mac_address'] = QuantumDbPluginV2._generate_mac( context, p["network_id"]) else: # Ensure that the mac on the network is unique if not QuantumDbPluginV2._check_unique_mac(context, p["network_id"], p['mac_address']): raise q_exc.MacAddressInUse(net_id=p["network_id"], mac=p['mac_address']) # Returns the IP's for the port ips = self._allocate_ips_for_port(context, network, port) port = models_v2.Port(tenant_id=tenant_id, name=p['name'], id=p.get('id') or utils.str_uuid(), network_id=p['network_id'], mac_address=p['mac_address'], admin_state_up=p['admin_state_up'], status=constants.PORT_STATUS_ACTIVE, device_id=p['device_id'], device_owner=p['device_owner']) context.session.add(port) # Update the allocated IP's if ips: with context.session.begin(subtransactions=True): for ip in ips: LOG.debug("Allocated IP %s (%s/%s/%s)", ip['ip_address'], port['network_id'], ip['subnet_id'], port.id) allocated = models_v2.IPAllocation( network_id=port['network_id'], port_id=port.id, ip_address=ip['ip_address'], subnet_id=ip['subnet_id'], expiration=self._default_allocation_expiration() ) context.session.add(allocated) return self._make_port_dict(port)
def create_subnet(self, context, subnet): s = subnet['subnet'] self._validate_subnet(s) net = netaddr.IPNetwork(s['cidr']) if s['gateway_ip'] == attributes.ATTR_NOT_SPECIFIED: s['gateway_ip'] = str(netaddr.IPAddress(net.first + 1)) tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): network = self._get_network(context, s["network_id"]) self._validate_subnet_cidr(network, s['cidr']) # The 'shared' attribute for subnets is for internal plugin # use only. It is not exposed through the API subnet = models_v2.Subnet(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], network_id=s['network_id'], ip_version=s['ip_version'], cidr=s['cidr'], enable_dhcp=s['enable_dhcp'], gateway_ip=s['gateway_ip'], shared=network.shared) # perform allocate pools first, since it might raise an error pools = self._allocate_pools_for_subnet(context, s) context.session.add(subnet) if s['dns_nameservers'] != attributes.ATTR_NOT_SPECIFIED: for addr in s['dns_nameservers']: ns = models_v2.DNSNameServer(address=addr, subnet_id=subnet.id) context.session.add(ns) if s['host_routes'] != attributes.ATTR_NOT_SPECIFIED: for rt in s['host_routes']: route = models_v2.Route(subnet_id=subnet.id, destination=rt['destination'], nexthop=rt['nexthop']) context.session.add(route) for pool in pools: ip_pool = models_v2.IPAllocationPool(subnet=subnet, first_ip=pool['start'], last_ip=pool['end']) context.session.add(ip_pool) ip_range = models_v2.IPAvailabilityRange( ipallocationpool=ip_pool, first_ip=pool['start'], last_ip=pool['end']) context.session.add(ip_range) return self._make_subnet_dict(subnet)
def create_network(self, context, network): n = network['network'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(): network = models_v2.Network(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], admin_state_up=n['admin_state_up'], status="ACTIVE") context.session.add(network) return self._make_network_dict(network)
def create_chain_image_conf(self, context, chain_image_conf): n = chain_image_conf['chain_image_conf'] with context.session.begin(subtransactions=True): chain_image = self._get_chain_image(context, n["chain_map_id"]) #self._validate_chain_image_conf_id(context, chain_image, n['networkfunction_id']) chain_image_conf = ns_chain_configuration_associate(id=n.get('id') or utils.str_uuid(), chain_map_id=n['chain_map_id'], networkfunction_id=n['networkfunction_id'], config_handle_id=n['config_handle_id']) context.session.add(chain_image_conf) return self._make_chain_image_conf_dict(chain_image_conf)
def create_session(self, context, session): """ handle creation of a single session """ # single request processing s = session['session'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): session = LB_Session_Persistance(id=s.get('id') or utils.str_uuid(), type=s['type'], cookie_name=s['cookie_name']) context.session.add(session) return self._make_session_dict(session)
def create_image(self, context, image): n = image['image'] tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): image = ns_image_map(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], category_id=n['category_id'], vendor_id=n['vendor_id'], flavor_id=n['flavor_id'], security_group_id=n['security_group_id'], image_id=n['image_id'], shared=n['shared']) context.session.add(image) return self._make_image_dict(image)
def create_configuration(self, context, configuration): """ handle creation of a single configuration """ # single request processing s = configuration['configuration'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): configuration = LB_Logical_app(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], status='In-Active', category_id=s['category_id']) context.session.add(configuration) return self._make_configuration_dict(configuration)
def create_network(self, context, network): """ handle creation of a single network """ # single request processing n = network['network'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, n) with context.session.begin(subtransactions=True): network = models_v2.Network(tenant_id=tenant_id, id=n.get('id') or utils.str_uuid(), name=n['name'], admin_state_up=n['admin_state_up'], shared=n['shared'], status=constants.NET_STATUS_ACTIVE) context.session.add(network) return self._make_network_dict(network)
def create_member(self, context, member): """ handle creation of a single member """ # single request processing s = member['member'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): member = LB_Pool_Member(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], ip_address=s['ip_address'], pool_id=s['pool_id'], port_no=s['port_no'], weight=s['weight'], status=1, admin_status=1) context.session.add(member) return self._make_member_dict(member)
def create_pool(self, context, pool): """ handle creation of a single pool """ # single request processing s = pool['pool'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): pool = LB_Pool(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], description=s['description'], protocol=s['protocol'], lb_method=s['lb_method'], status=1, admin_status=1, subnet_id=s['subnet_id']) context.session.add(pool) return self._make_pool_dict(pool)
def create_router(self, context, router): r = router['router'] has_gw_info = False if 'external_gateway_info' in r: has_gw_info = True gw_info = r['external_gateway_info'] del r['external_gateway_info'] tenant_id = self._get_tenant_id_for_create(context, r) with context.session.begin(subtransactions=True): # pre-generate id so it will be available when # configuring external gw port router_db = Router(id=utils.str_uuid(), tenant_id=tenant_id, name=r['name'], admin_state_up=r['admin_state_up'], status="ACTIVE") context.session.add(router_db) if has_gw_info: self._update_router_gw_info(context, router_db['id'], gw_info) return self._make_router_dict(router_db)
def create_packet_filter(self, context, packet_filter): pf = packet_filter['packet_filter'] tenant_id = self._get_tenant_id_for_create(context, pf) # validate network ownership super(NECPluginV2Base, self).get_network(context, pf['network_id']) if pf.get('in_port') != attributes.ATTR_NOT_SPECIFIED: # validate port ownership super(NECPluginV2Base, self).get_port(context, pf['in_port']) params = { 'tenant_id': tenant_id, 'id': pf.get('id') or utils.str_uuid(), 'network_id': pf['network_id'], 'priority': pf['priority'], 'action': pf['action'], 'admin_state_up': pf.get('admin_state_up', True), 'status': "ACTIVE" } conditions = { 'in_port': '', 'src_mac': '', 'dst_mac': '', 'eth_type': 0, 'src_cidr': '', 'dst_cidr': '', 'src_port': 0, 'dst_port': 0, 'protocol': '' } for key, default in conditions.items(): if pf.get(key) == attributes.ATTR_NOT_SPECIFIED: params.update({key: default}) else: params.update({key: pf.get(key)}) with context.session.begin(): pf_entry = nmodels.PacketFilter(**params) context.session.add(pf_entry) return self._make_packet_filter_dict(pf_entry)
def create_vip(self, context, vip): """ handle creation of a single vip """ # single request processing s = vip['vip'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): vip = LB_Virtual_IP(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], description=s['description'], port_no=s['port_no'], protocol=s['protocol'], connection_limit=s['connection_limit'], status=1, admin_status=1, session_persistance_id=s['session_persistance_id'], config_handle_id=s['config_handle_id'], pool_id=s['pool_id']) context.session.add(vip) return self._make_vip_dict(vip)
def create_monitor(self, context, monitor): """ handle creation of a single monitor """ # single request processing s = monitor['monitor'] # NOTE(jkoelker) Get the tenant_id outside of the session to avoid # unneeded db action if the operation raises tenant_id = self._get_tenant_id_for_create(context, s) with context.session.begin(subtransactions=True): monitor = LB_Health_Monitor(tenant_id=tenant_id, id=s.get('id') or utils.str_uuid(), name=s['name'], pool_id=s['pool_id'], type=s['type'], delay=s['delay'], timeout=s['timeout'], max_retries=s['max_retries'], http_method=s['http_method'], url_path=s['url_path'], expected_codes=s['expected_codes'], status=1, admin_status=1) context.session.add(monitor) return self._make_monitor_dict(monitor)
def test_create_floatingip_invalid_fixed_ip_address_returns_400(self): # API-level test - no need to create all objects for l3 plugin res = self._create_floatingip('json', utils.str_uuid(), utils.str_uuid(), 'iamnotnanip') self.assertEqual(res.status_int, 400)
def get_ofc_item_random_params(self): """create random parameters for ofc_item test""" ofc_id = utils.str_uuid() quantum_id = utils.str_uuid() none = utils.str_uuid() return ofc_id, quantum_id, none
def test_create_floatingip_invalid_floating_port_id_returns_400(self): # API-level test - no need to create all objects for l3 plugin res = self._create_floatingip('json', utils.str_uuid(), 'iamnotanuuid', '192.168.0.1') self.assertEqual(res.status_int, 400)