Ejemplo n.º 1
0
    def _update_share_network_net_data(self, context, share_network_subnet):
        upd = dict()

        if not share_network_subnet.get('neutron_net_id') == self.net:
            if share_network_subnet.get('neutron_net_id') is not None:
                raise exception.NetworkBadConfigurationException(
                    "Using neutron net id different from None or value "
                    "specified in the config is forbidden for "
                    "NeutronSingleNetworkPlugin. Allowed values: (%(net)s, "
                    "None), received value: %(err)s" % {
                        "net": self.net,
                        "err": share_network_subnet.get('neutron_net_id')
                    })
            upd['neutron_net_id'] = self.net
        if not share_network_subnet.get('neutron_subnet_id') == self.subnet:
            if share_network_subnet.get('neutron_subnet_id') is not None:
                raise exception.NetworkBadConfigurationException(
                    "Using neutron subnet id different from None or value "
                    "specified in the config is forbidden for "
                    "NeutronSingleNetworkPlugin. Allowed values: (%(snet)s, "
                    "None), received value: %(err)s" % {
                        "snet": self.subnet,
                        "err": share_network_subnet.get('neutron_subnet_id')
                    })
            upd['neutron_subnet_id'] = self.subnet
        if upd:
            share_network_subnet = self.db.share_network_subnet_update(
                context, share_network_subnet['id'], upd)
        return share_network_subnet
Ejemplo n.º 2
0
 def _verify_net_and_subnet(self):
     data = dict(net=self.net, subnet=self.subnet)
     if self.net and self.subnet:
         net = self.neutron_api.get_network(self.net)
         if not (net.get('subnets') and data['subnet'] in net['subnets']):
             raise exception.NetworkBadConfigurationException(
                 "Subnet '%(subnet)s' does not belong to "
                 "network '%(net)s'." % data)
     else:
         raise exception.NetworkBadConfigurationException(
             "Neutron net and subnet are expected to be both set. "
             "Got: net=%(net)s and subnet=%(subnet)s." % data)
 def _get_network(self):
     """Returns IPNetwork object calculated from gateway and netmask."""
     if not isinstance(self.gateway, six.string_types):
         raise exception.NetworkBadConfigurationException(
             _("Configuration option 'standalone_network_plugin_gateway' "
               "is required and has improper value '%s'.") % self.gateway)
     if not isinstance(self.mask, six.string_types):
         raise exception.NetworkBadConfigurationException(
             _("Configuration option 'standalone_network_plugin_mask' is "
               "required and has improper value '%s'.") % self.mask)
     try:
         return netaddr.IPNetwork(self.gateway + '/' + self.mask)
     except netaddr.AddrFormatError as e:
         raise exception.NetworkBadConfigurationException(reason=e)
Ejemplo n.º 4
0
 def _validate_network_type(self, network_info):
     """Raises exception if the segmentation type is incorrect."""
     if network_info['network_type'] not in SUPPORTED_NETWORK_TYPES:
         msg = _('The specified network type %s is unsupported by the '
                 'NetApp clustered Data ONTAP driver')
         raise exception.NetworkBadConfigurationException(
             reason=msg % network_info['network_type'])
Ejemplo n.º 5
0
    def allocate_network(self, context, share_server, share_network=None,
                         **kwargs):
        """Allocate network resources using given network information.

        Create neutron ports for a given neutron network and subnet,
        create manila db records for allocated neutron ports.

        :param context: RequestContext object
        :param share_network: share network data
        :param kwargs: allocations parameters given by the back-end
                       driver. Supported params:
                       'count' - how many allocations should be created
                       'device_owner' - set owner for network allocations
        :rtype: list of :class: 'dict'
        """
        if not self._has_provider_network_extension():
            msg = "%s extension required" % neutron_constants.PROVIDER_NW_EXT
            raise exception.NetworkBadConfigurationException(reason=msg)

        self._verify_share_network(share_server['id'], share_network)
        self._store_neutron_net_info(context, share_network)

        allocation_count = kwargs.get('count', 1)
        device_owner = kwargs.get('device_owner', 'share')

        ports = []
        for __ in range(0, allocation_count):
            ports.append(self._create_port(context, share_server,
                                           share_network, device_owner))

        return ports
    def _get_available_ips(self, context, amount):
        """Returns IP addresses from allowed IP range if there are unused IPs.

        :returns: IP addresses as list of text types
        :raises: exception.NetworkBadConfigurationException
        """
        ips = []
        if amount < 1:
            return ips
        iterator = netaddr.iter_unique_ips(*self.allowed_cidrs)
        for ip in iterator:
            ip = six.text_type(ip)
            if (ip in self.reserved_addresses
                    or self.db.network_allocations_get_by_ip_address(
                        context, ip)):
                continue
            else:
                ips.append(ip)
            if len(ips) == amount:
                return ips
        msg = _("No available IP addresses left in CIDRs %(cidrs)s. "
                "Requested amount of IPs to be provided '%(amount)s', "
                "available only '%(available)s'.") % {
                    'cidrs': self.allowed_cidrs,
                    'amount': amount,
                    'available': len(ips)
                }
        raise exception.NetworkBadConfigurationException(reason=msg)
Ejemplo n.º 7
0
 def _verify_share_network_subnet(self, share_server_id,
                                  share_network_subnet):
     if share_network_subnet is None:
         msg = _("'Share network subnet' is not provided for setting up "
                 "network interfaces for 'Share server' "
                 "'%s'.") % share_server_id
         raise exception.NetworkBadConfigurationException(reason=msg)
Ejemplo n.º 8
0
 def validate_network(network_info):
     network = network_info['network_allocations'][0]
     if network['network_type'] not in SUPPORTED_NETWORK_TYPES:
         msg = _('The specified network type %s is unsupported by '
                 'the EMC Unity driver')
         raise exception.NetworkBadConfigurationException(
             reason=msg % network['network_type'])
     return network
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     super(NovaSingleNetworkPlugin, self).__init__(*args, **kwargs)
     CONF.register_opts(nova_single_network_plugin_opts,
                        group=self.config_group_name)
     self.net_id = getattr(CONF, self.config_group_name,
                           CONF).nova_single_network_plugin_net_id
     if not self.net_id:
         msg = _("Nova network is not set")
         LOG.error(msg)
         raise exception.NetworkBadConfigurationException(reason=msg)
Ejemplo n.º 10
0
 def enabled_ip_version(self):
     if not hasattr(self, '_enabled_ip_version'):
         if self.configuration.network_plugin_ipv6_enabled:
             self._enabled_ip_version = 6
         elif self.configuration.network_plugin_ipv4_enabled:
             self._enabled_ip_version = 4
         else:
             msg = _("Either 'network_plugin_ipv4_enabled' or "
                     "'network_plugin_ipv6_enabled' "
                     "should be configured to 'True'.")
             raise exception.NetworkBadConfigurationException(reason=msg)
     return self._enabled_ip_version
Ejemplo n.º 11
0
    def _save_neutron_network_data(self, context, share_network_subnet):
        net_info = self.neutron_api.get_network(
            share_network_subnet['neutron_net_id'])
        segmentation_id = None
        network_type = None

        if self._is_neutron_multi_segment(share_network_subnet, net_info):
            # we have a multi segment network and need to identify the
            # lowest segment used for binding
            phy_nets = []
            phy = self.neutron_api.configuration.neutron_physical_net_name
            if not phy:
                msg = "Cannot identify segment used for binding. Please add "
                "neutron_physical_net_name in configuration."
                raise exception.NetworkBadConfigurationException(reason=msg)
            for segment in net_info['segments']:
                phy_nets.append(segment['provider:physical_network'])
                if segment['provider:physical_network'] == phy:
                    segmentation_id = segment['provider:segmentation_id']
                    network_type = segment['provider:network_type']
            if not (segmentation_id and network_type):
                msg = ("No matching neutron_physical_net_name found for %s "
                       "(found: %s)." % (phy, phy_nets))
                raise exception.NetworkBadConfigurationException(reason=msg)
        else:
            network_type = net_info['provider:network_type']
            segmentation_id = net_info['provider:segmentation_id']

        provider_nw_dict = {
            'network_type': network_type,
            'segmentation_id': segmentation_id,
            'mtu': net_info['mtu'],
        }
        share_network_subnet.update(provider_nw_dict)

        if self.label != 'admin':
            self.db.share_network_subnet_update(context,
                                                share_network_subnet['id'],
                                                provider_nw_dict)
Ejemplo n.º 12
0
 def _update_share_network_net_data(self, context, share_network):
     neutron_data = share_network.get(
         'neutron_net_id', share_network.get('neutron_subnet_id'))
     if neutron_data:
         msg = _("'share-network' with id '%s' should not contain Neutron "
                 "data. Either remove it or use another "
                 "'share-network'") % share_network['id']
         LOG.error(msg)
         raise exception.NetworkBadConfigurationException(reason=msg)
     nova_net_id = share_network.get('nova_net_id')
     if nova_net_id and nova_net_id != self.net_id:
         msg = _("'share-network' with id '%(sn_id)s' already contains "
                 "Nova network id '%(provided)s' that is different from "
                 "what is defined in config '%(allowed)s'. Either remove "
                 "incorrect network id or set it the same") % dict(
                     sn_id=share_network['id'], provided=nova_net_id,
                     allowed=self.net_id)
         LOG.error(msg)
         raise exception.NetworkBadConfigurationException(reason=msg)
     elif not nova_net_id:
         share_network = self.db.share_network_update(
             context, share_network['id'], dict(nova_net_id=self.net_id))
     return share_network
Ejemplo n.º 13
0
 def _validate_segmentation_id(self, network_info):
     """Raises exception if the segmentation type is incorrect."""
     if (network_info['network_type'] in (None, 'flat') and
             network_info['segmentation_id']):
         msg = _('A segmentation ID %(vlan_id)s was specified but can not '
                 'be used with a network of type %(seg_type)s; the '
                 'segmentation ID option must be omitted or set to 0')
         raise exception.NetworkBadConfigurationException(
             reason=msg % {'vlan_id': network_info['segmentation_id'],
                           'seg_type': network_info['network_type']})
     elif (network_info['network_type'] == 'vlan'
           and (network_info['segmentation_id'] is None
                or int(network_info['segmentation_id']) > 4094
                or int(network_info['segmentation_id'] < 1))):
         msg = _('A segmentation ID %s was specified but is not valid for '
                 'a VLAN network type; the segmentation ID must be an '
                 'integer value in the range of [1,4094]')
         raise exception.NetworkBadConfigurationException(
             reason=msg % network_info['segmentation_id'])
     elif (network_info['network_type'] == 'vxlan'
           and (network_info['segmentation_id'] is None
                or int(network_info['segmentation_id']) > 16777215
                or int(network_info['segmentation_id'] < 1))):
         msg = _('A segmentation ID %s was specified but is not valid for '
                 'a VXLAN network type; the segmentation ID must be an '
                 'integer value in the range of [1,16777215]')
         raise exception.NetworkBadConfigurationException(
             reason=msg % network_info['segmentation_id'])
     elif (network_info['network_type'] == 'gre'
           and (network_info['segmentation_id'] is None
                or int(network_info['segmentation_id']) > 4294967295
                or int(network_info['segmentation_id'] < 1))):
         msg = _('A segmentation ID %s was specified but is not valid for '
                 'a GRE network type; the segmentation ID must be an '
                 'integer value in the range of [1, 4294967295]')
         raise exception.NetworkBadConfigurationException(
             reason=msg % network_info['segmentation_id'])
Ejemplo n.º 14
0
    def _get_available_ips(self, context, nova_net, amount):
        """Returns unused IP addresses from provided Nova network.

        :param context: RequestContext instance
        :param nova_net: dict -- dictionary with data of nova network
        :param amount: int - amount of IP addresses to return
        :returns: IP addresses as list of text types
        :raises: exception.NetworkBadConfigurationException
        """
        cidr = nova_net['cidr'] or nova_net['cidr_v6']
        reserved = (
            six.text_type(netaddr.IPNetwork(cidr).network),
            nova_net['gateway'],
            nova_net['gateway_v6'],
            nova_net['dhcp_server'],
            nova_net['broadcast'],
            nova_net['vpn_private_address'],
            nova_net['vpn_public_address'],
            nova_net['dns1'],
            nova_net['dns2'])

        ips = []
        iterator = netaddr.iter_unique_ips(cidr)

        for ip in iterator:
            ip = six.text_type(ip)

            if ip in reserved:
                # This IP address is reserved for service needs
                continue
            elif self.db.network_allocations_get_by_ip_address(context, ip):
                # Some existing share server already uses this IP address
                continue
            fixed_ip = self.nova_api.fixed_ip_get(self.admin_context, ip)
            if fixed_ip.get('host') or fixed_ip.get('hostname'):
                # Some Nova VM already uses this IP address
                continue

            ips.append(ip)
            if len(ips) == amount:
                return ips
        msg = _("No available IP addresses left in network '%(net_id)s' with "
                "CIDR %(cidr)s. Requested amount of IPs to be provided "
                "'%(amount)s', available only '%(available)s'") % dict(
                    net_id=nova_net['id'], cidr=cidr, amount=amount,
                    available=len(ips))
        LOG.error(msg)
        raise exception.NetworkBadConfigurationException(reason=msg)
Ejemplo n.º 15
0
    def _get_matched_ip_address(self, fixed_ips, ip_version):
        """Get first ip address which matches the specified ip_version."""

        for ip in fixed_ips:
            try:
                address = ipaddress.ip_address(str(ip['ip_address']))
                if address.version == ip_version:
                    return ip['ip_address']
            except ValueError:
                LOG.error("%(address)s isn't a valid ip "
                          "address, omitted.", {'address': ip['ip_address']})
        msg = _("Can not find any IP address with configured IP "
                "version %(version)s in share-network.") % {
                    'version': ip_version
                }
        raise exception.NetworkBadConfigurationException(reason=msg)
Ejemplo n.º 16
0
    def _create_network_interface(self, nas_server, network):
        ip_addr = network['ip_address']
        netmask = utils.cidr_to_netmask(network['cidr'])
        gateway = network['gateway']
        vlan_id = network['segmentation_id']
        if network['network_type'] not in SUPPORTED_NETWORK_TYPES:
            msg = _('The specified network type %s is unsupported by '
                    'the EMC Unity driver')
            raise exception.NetworkBadConfigurationException(
                reason=msg % network['network_type'])

        # Create the interfaces on NAS server
        self.client.create_interface(nas_server,
                                     ip_addr,
                                     netmask,
                                     gateway,
                                     ports=self.port_set,
                                     vlan_id=vlan_id)
Ejemplo n.º 17
0
 def _validate_network_type(network_type):
     if network_type not in ('flat', 'vlan', None):
         reason = _('Invalid network type. %s is not supported by the '
                    '3PAR driver.')
         raise exception.NetworkBadConfigurationException(reason=reason %
                                                          network_type)
Ejemplo n.º 18
0
    def _get_list_of_allowed_addresses(self):
        """Returns list of CIDRs that can be used for getting IP addresses.

        Reads information provided via configuration, such as gateway,
        netmask, segmentation ID and allowed IP ranges, then performs
        validation of provided data.

        :returns: list of CIDRs as text types.
        :raises: exception.NetworkBadConfigurationException
        """
        cidrs = []
        if self.allowed_ip_ranges:
            for ip_range in self.allowed_ip_ranges:
                ip_range_start = ip_range_end = None
                if utils.is_valid_ip_address(ip_range, self.ip_version):
                    ip_range_start = ip_range_end = ip_range
                elif '-' in ip_range:
                    ip_range_list = ip_range.split('-')
                    if len(ip_range_list) == 2:
                        ip_range_start = ip_range_list[0]
                        ip_range_end = ip_range_list[1]
                        for ip in ip_range_list:
                            utils.is_valid_ip_address(ip, self.ip_version)
                    else:
                        msg = _("Wrong value for IP range "
                                "'%s' was provided.") % ip_range
                        raise exception.NetworkBadConfigurationException(
                            reason=msg)
                else:
                    msg = _("Config option "
                            "'standalone_network_plugin_allowed_ip_ranges' "
                            "has incorrect value "
                            "'%s'.") % self.allowed_ip_ranges
                    raise exception.NetworkBadConfigurationException(
                        reason=msg)

                range_instance = netaddr.IPRange(ip_range_start, ip_range_end)

                if range_instance not in self.net:
                    data = dict(range=six.text_type(range_instance),
                                net=six.text_type(self.net),
                                gateway=self.gateway,
                                netmask=self.net.netmask)
                    msg = _("One of provided allowed IP ranges ('%(range)s') "
                            "does not fit network '%(net)s' combined from "
                            "gateway '%(gateway)s' and netmask "
                            "'%(netmask)s'.") % data
                    raise exception.NetworkBadConfigurationException(
                        reason=msg)

                cidrs.extend(
                    six.text_type(cidr) for cidr in range_instance.cidrs())
        else:
            if self.net.version != self.ip_version:
                msg = _("Configured invalid IP version '%(conf_v)s', network "
                        "has version "
                        "'%(net_v)s'") % dict(conf_v=self.ip_version,
                                              net_v=self.net.version)
                raise exception.NetworkBadConfigurationException(reason=msg)
            cidrs.append(six.text_type(self.net))

        return cidrs