def process_create_network(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     prov_net_type = data.get(providernet.NETWORK_TYPE)
     net_prof_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id
     if not bc_attr.is_attr_set(net_prof_attr):
         if not bc_attr.is_attr_set(prov_net_type):
             network_type = cfg.CONF.ml2.tenant_network_types[0]
         else:
             network_type = prov_net_type
         if network_type == p_const.TYPE_VLAN:
             net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME
         elif network_type == p_const.TYPE_VXLAN:
             net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME
         else:
             # This network type is not supported with network profiles
             return
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(net_prof_attr):
                 net_prof_attr = n1kv_db.get_network_profile_by_name(
                     net_prof_attr, context.session)
             else:
                 net_prof_attr = n1kv_db.get_network_profile_by_uuid(
                     net_prof_attr, context.session)
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=net_prof_attr.id)
         except n1kv_exc.NetworkProfileNotFound:
             LOG.error(_LE("Network Profile %s does "
                           "not exist.") % net_prof_attr)
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and
                     net_prof_attr.name not in [
                         constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME,
                         constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]):
                 LOG.error(_LE("Network Profile %s is "
                               "not owned by this tenant.") %
                           net_prof_attr.name)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         segment_type = net_prof_attr.segment_type
         n1kv_db.add_network_binding(net_id, segment_type,
                                     0,
                                     net_prof_attr.id,
                                     context.session)
         data[providernet.NETWORK_TYPE] = segment_type
     result[constants.N1KV_PROFILE] = net_prof_attr.id
 def process_create_network(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     net_id = result.get('id')
     prov_net_type = data.get(bc.providernet.NETWORK_TYPE)
     net_prof_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id
     if not bc.is_attr_set(net_prof_attr):
         if not bc.is_attr_set(prov_net_type):
             network_type = cfg.CONF.ml2.tenant_network_types[0]
         else:
             network_type = prov_net_type
         if network_type == p_const.TYPE_VLAN:
             net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME
         elif network_type == p_const.TYPE_VXLAN:
             net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME
         else:
             # This network type is not supported with network profiles
             return
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(net_prof_attr):
                 net_prof_attr = n1kv_db.get_network_profile_by_name(
                     net_prof_attr, context.session)
             else:
                 net_prof_attr = n1kv_db.get_network_profile_by_uuid(
                     net_prof_attr, context.session)
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=net_prof_attr.id)
         except n1kv_exc.NetworkProfileNotFound:
             LOG.error("Network Profile %s does "
                       "not exist." % net_prof_attr)
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and
                     net_prof_attr.name not in [
                         constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME,
                         constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]):
                 LOG.error("Network Profile %s is "
                           "not owned by this tenant." %
                           net_prof_attr.name)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         segment_type = net_prof_attr.segment_type
         n1kv_db.add_network_binding(net_id, segment_type,
                                     0,
                                     net_prof_attr.id,
                                     context.session)
         data[bc.providernet.NETWORK_TYPE] = segment_type
     result[constants.N1KV_PROFILE] = net_prof_attr.id
 def process_create_port(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     port_id = result.get('id')
     policy_profile_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id or data.get('tenant_id')
     default_policy_profile_name = (cfg.CONF.ml2_cisco_n1kv.
                                    default_policy_profile)
     if not bc_attr.is_attr_set(policy_profile_attr):
         policy_profile_attr = default_policy_profile_name
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(policy_profile_attr):
                 policy_profile = n1kv_db.get_policy_profile_by_name(
                     policy_profile_attr,
                     context.session)
             else:
                 policy_profile = (n1kv_db.get_policy_profile_by_uuid(
                     context.session,
                     policy_profile_attr))
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=policy_profile.id)
         except n1kv_exc.PolicyProfileNotFound:
             LOG.error(_LE("Policy Profile %(profile)s does "
                           "not exist."), {"profile": policy_profile_attr})
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if context.is_admin:
                 session = context.session
                 n1kv_db.update_policy_profile_binding_with_tenant_id(
                     policy_profile.id, tenant_id, session)
             elif (cfg.CONF.ml2_cisco_n1kv.restrict_policy_profiles and
                     policy_profile.name != default_policy_profile_name):
                 LOG.error(_LE("Policy Profile %s is "
                               "not owned by this tenant.") %
                           policy_profile_attr)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         n1kv_db.add_policy_binding(port_id,
                                    policy_profile.id,
                                    context.session)
     result[constants.N1KV_PROFILE] = policy_profile.id
 def process_create_port(self, context, data, result):
     """Implementation of abstract method from ExtensionDriver class."""
     port_id = result.get('id')
     policy_profile_attr = data.get(constants.N1KV_PROFILE)
     tenant_id = context.tenant_id or data.get('tenant_id')
     default_policy_profile_name = (cfg.CONF.ml2_cisco_n1kv.
                                    default_policy_profile)
     if not bc.is_attr_set(policy_profile_attr):
         policy_profile_attr = default_policy_profile_name
     with context.session.begin(subtransactions=True):
         try:
             if not uuidutils.is_uuid_like(policy_profile_attr):
                 policy_profile = n1kv_db.get_policy_profile_by_name(
                     policy_profile_attr,
                     context.session)
             else:
                 policy_profile = (n1kv_db.get_policy_profile_by_uuid(
                     context.session,
                     policy_profile_attr))
             n1kv_db.get_profile_binding(db_session=context.session,
                                         tenant_id=tenant_id,
                                         profile_id=policy_profile.id)
         except n1kv_exc.PolicyProfileNotFound:
             LOG.error("Policy Profile %(profile)s does "
                       "not exist.", {"profile": policy_profile_attr})
             raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         except n1kv_exc.ProfileTenantBindingNotFound:
             if context.is_admin:
                 session = context.session
                 n1kv_db.update_policy_profile_binding_with_tenant_id(
                     policy_profile.id, tenant_id, session)
             elif (cfg.CONF.ml2_cisco_n1kv.restrict_policy_profiles and
                     policy_profile.name != default_policy_profile_name):
                 LOG.error("Policy Profile %s is "
                           "not owned by this tenant." %
                           policy_profile_attr)
                 raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2')
         n1kv_db.add_policy_binding(port_id,
                                    policy_profile.id,
                                    context.session)
     result[constants.N1KV_PROFILE] = policy_profile.id
Exemple #5
0
    def _validate_network_profile(self, net_p):
        """
        Validate completeness of a network profile arguments.

        :param net_p: network profile object
        """
        if self._is_reserved_name(net_p["name"]):
            msg = _LE("Reserved name used for network profile name")
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        if net_p["segment_type"] == "":
            msg = _LE("Arguments segment_type missing"
                      " for network profile %s") % net_p["name"]
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        segment_type = net_p["segment_type"].lower()
        if segment_type == n1kv_const.CLI_SEG_TYPE_OVERLAY:
            # Convert from CLI to internal type
            segment_type = p_const.TYPE_VXLAN
            net_p["segment_type"] = p_const.TYPE_VXLAN
        if segment_type not in [
                p_const.TYPE_VLAN, p_const.TYPE_VXLAN, n1kv_const.TYPE_TRUNK
        ]:
            msg = _LE("Segment_type should either be vlan, vxlan, " "or trunk")
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        if segment_type == p_const.TYPE_VLAN:
            if "physical_network" not in net_p:
                msg = _LE("Argument physical_network missing "
                          "for network profile %s") % net_p["name"]
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
        if segment_type in [n1kv_const.TYPE_TRUNK, p_const.TYPE_VXLAN]:
            if not bc.is_attr_set(net_p.get("sub_type")):
                msg = _LE("Argument sub_type missing "
                          "for network profile %s") % net_p["name"]
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
        if segment_type == p_const.TYPE_VXLAN:
            sub_type = net_p['sub_type']
            # Validate sub-type
            allowed_sub_types = [
                n1kv_const.CLI_VXLAN_MODE_NATIVE,
                n1kv_const.CLI_VXLAN_MODE_ENHANCED
            ]
            if sub_type not in allowed_sub_types:
                msg = _LE("Sub_type should be either 'native' or 'enhanced'")
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
            if sub_type != n1kv_const.CLI_VXLAN_MODE_NATIVE:
                net_p['multicast_ip_range'] = '0.0.0.0'
            else:
                group_ip = cfg.CONF.ml2_type_vxlan.vxlan_group
                multicast_ip_range = net_p.get("multicast_ip_range")
                if not bc.is_attr_set(multicast_ip_range):
                    if not group_ip:
                        msg = (_LE("Argument multicast_ip_range missing"
                                   " for VXLAN multicast network profile %s") %
                               net_p["name"])
                        LOG.error(msg)
                        raise n_exc.InvalidInput(error_message=msg)
                    else:
                        # Use the global value from conf
                        net_p['multicast_ip_range'] = "-".join(
                            [group_ip, group_ip])
                self._validate_multicast_ip_range(net_p)
        else:
            net_p['multicast_ip_range'] = '0.0.0.0'
    def _validate_network_profile(self, net_p):
        """
        Validate completeness of a network profile arguments.

        :param net_p: network profile object
        """
        if self._is_reserved_name(net_p["name"]):
            msg = _LE("Reserved name used for network profile name")
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        if net_p["segment_type"] == "":
            msg = _LE("Arguments segment_type missing"
                      " for network profile %s") % net_p["name"]
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        segment_type = net_p["segment_type"].lower()
        if segment_type == n1kv_const.CLI_SEG_TYPE_OVERLAY:
            # Convert from CLI to internal type
            segment_type = p_const.TYPE_VXLAN
            net_p["segment_type"] = p_const.TYPE_VXLAN
        if segment_type not in [p_const.TYPE_VLAN,
                                p_const.TYPE_VXLAN,
                                n1kv_const.TYPE_TRUNK]:
            msg = _LE("Segment_type should either be vlan, vxlan, "
                      "or trunk")
            LOG.error(msg)
            raise n_exc.InvalidInput(error_message=msg)
        if segment_type == p_const.TYPE_VLAN:
            if "physical_network" not in net_p:
                msg = _LE("Argument physical_network missing "
                          "for network profile %s") % net_p["name"]
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
        if segment_type in [n1kv_const.TYPE_TRUNK,
                            p_const.TYPE_VXLAN]:
            if not bc_attr.is_attr_set(net_p.get("sub_type")):
                msg = _LE("Argument sub_type missing "
                          "for network profile %s") % net_p["name"]
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
        if segment_type == p_const.TYPE_VXLAN:
            sub_type = net_p['sub_type']
            # Validate sub-type
            allowed_sub_types = [n1kv_const.CLI_VXLAN_MODE_NATIVE,
                                 n1kv_const.CLI_VXLAN_MODE_ENHANCED]
            if sub_type not in allowed_sub_types:
                msg = _LE("Sub_type should be either 'native' or 'enhanced'")
                LOG.error(msg)
                raise n_exc.InvalidInput(error_message=msg)
            if sub_type != n1kv_const.CLI_VXLAN_MODE_NATIVE:
                net_p['multicast_ip_range'] = '0.0.0.0'
            else:
                group_ip = cfg.CONF.ml2_type_vxlan.vxlan_group
                multicast_ip_range = net_p.get("multicast_ip_range")
                if not bc_attr.is_attr_set(multicast_ip_range):
                    if not group_ip:
                        msg = (_LE("Argument multicast_ip_range missing"
                                   " for VXLAN multicast network profile %s")
                               % net_p["name"])
                        LOG.error(msg)
                        raise n_exc.InvalidInput(error_message=msg)
                    else:
                        # Use the global value from conf
                        net_p['multicast_ip_range'] = "-".join(
                            [group_ip, group_ip])
                self._validate_multicast_ip_range(net_p)
        else:
            net_p['multicast_ip_range'] = '0.0.0.0'