Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        node = kwargs.pop('node', {})
        addr_relay = str(node['pm_address']).split(',')

        if len(addr_relay) > 1:
            try:
                self.relay_id = int(addr_relay[1])
            except ValueError:
                msg = _("iboot PDU relay ID must be an integer.")
                raise exception.InvalidParameterValue(msg)
        else:
            self.relay_id = 1

        addr_port = addr_relay[0].split(':')
        self.address = addr_port[0]
        if len(addr_port) > 1:
            try:
                self.port = int(addr_port[1])
            except ValueError:
                msg = _("iboot PDU port must be an integer.")
                raise exception.InvalidParameterValue(msg)
        else:
            self.port = 9100

        self.user = str(node['pm_user'])
        self.password = str(node['pm_password'])
        instance = kwargs.pop('instance', {})
        self.node_name = instance.get('hostname', "")
        self.state = None
        self.conn = None
Ejemplo n.º 2
0
    def __init__(self, node, **kwargs):
        self.state = None
        self.retries = None
        self.node_id = node['id']
        self.address = node['pm_address']
        self.user = node['pm_user']
        self.password = node['pm_password']
        self.port = node['terminal_port']

        if self.node_id is None:
            raise exception.InvalidParameterValue(
                _("Node id not supplied "
                  "to IPMI"))
        if self.address is None:
            raise exception.InvalidParameterValue(
                _("Address not supplied "
                  "to IPMI"))
        if self.user is None:
            raise exception.InvalidParameterValue(
                _("User not supplied "
                  "to IPMI"))
        if self.password is None:
            raise exception.InvalidParameterValue(
                _("Password not supplied "
                  "to IPMI"))
Ejemplo n.º 3
0
    def _poll_for_lpar_status(self, instance_name, status, operation,
                            timeout=constants.POWERVM_LPAR_OPERATION_TIMEOUT):
        """Polls until the LPAR with the given name reaches the given status.

        :param instance_name: LPAR instance name
        :param status: Poll until the given LPAR status is reached
        :param operation: The operation being performed, e.g. 'stop_lpar'
        :param timeout: The number of seconds to wait.
        :raises: PowerVMLPARInstanceNotFound
        :raises: PowerVMLPAROperationTimeout
        :raises: InvalidParameterValue
        """
        # make sure it's a valid status
        if (status == constants.POWERVM_NOSTATE or
                not status in constants.POWERVM_POWER_STATE):
            msg = _("Invalid LPAR state: %s") % status
            raise n_exc.InvalidParameterValue(err=msg)

        # raise the given timeout exception if the loop call doesn't complete
        # in the specified timeout
        timeout_exception = exception.PowerVMLPAROperationTimeout(
                                                operation=operation,
                                                instance_name=instance_name)
        with eventlet_timeout.Timeout(timeout, timeout_exception):
            def _wait_for_lpar_status(instance_name, status):
                """Called at an interval until the status is reached."""
                lpar_obj = self.get_lpar(instance_name)
                if lpar_obj['state'] == status:
                    raise loopingcall.LoopingCallDone()

            timer = loopingcall.FixedIntervalLoopingCall(_wait_for_lpar_status,
                                                         instance_name, status)
            timer.start(interval=1).wait()
Ejemplo n.º 4
0
    def create(self, req, body):
        """Creates a new snapshot."""
        context = req.environ['nova.context']
        authorize(context)

        if not self.is_valid_body(body, 'snapshot'):
            raise exc.HTTPUnprocessableEntity()

        snapshot = body['snapshot']
        volume_id = snapshot['volume_id']
        volume = self.volume_api.get(context, volume_id)

        force = snapshot.get('force', False)
        LOG.audit(_("Create snapshot from volume %s"), volume_id,
                context=context)

        if not utils.is_valid_boolstr(force):
            msg = _("Invalid value '%s' for force. ") % force
            raise exception.InvalidParameterValue(err=msg)

        if utils.bool_from_str(force):
            new_snapshot = self.volume_api.create_snapshot_force(context,
                                        volume,
                                        snapshot.get('display_name'),
                                        snapshot.get('display_description'))
        else:
            new_snapshot = self.volume_api.create_snapshot(context,
                                        volume,
                                        snapshot.get('display_name'),
                                        snapshot.get('display_description'))

        retval = _translate_snapshot_detail_view(context, new_snapshot)

        return {'snapshot': retval}
Ejemplo n.º 5
0
    def show_target(self, tid, iqn=None, **kwargs):
        if iqn is None:
            raise exception.InvalidParameterValue(
                err=_('valid iqn needed for show_target'))

        tid = self._get_target(iqn)
        if tid is None:
            raise exception.NotFound()
Ejemplo n.º 6
0
 def _get_kernel_ramdisk_id(self, flavor):
     values = []
     extra_specs = flavor['extra_specs']
     for key in ['baremetal:deploy_kernel_id',
                 'baremetal:deploy_ramdisk_id']:
         try:
             values.append(extra_specs[key])
         except KeyError:
             msg = (_("'%s' not found in flavor's extra_specs") % key)
             LOG.error(msg)
             raise exception.InvalidParameterValue(message=msg)
     return values
Ejemplo n.º 7
0
    def test_nwfilter_parameters(self,
                                 mock_define,
                                 mock_lookup):
        fakefilter = NWFilterFakes()
        mock_lookup.side_effect = fakefilter.nwfilterLookupByName
        mock_define.side_effect = fakefilter.filterDefineXMLMock

        instance_ref = self._create_instance()
        self._create_security_group(instance_ref)

        network_info = _fake_network_info(self.stubs, 1)
        self.fw.setup_basic_filtering(instance_ref, network_info)

        vif = network_info[0]
        nic_id = vif['address'].replace(':', '')
        instance_filter_name = self.fw._instance_filter_name(instance_ref,
                                                             nic_id)
        f = fakefilter.nwfilterLookupByName(instance_filter_name)
        tree = etree.fromstring(f.xml)

        for fref in tree.findall('filterref'):
            parameters = fref.findall('./parameter')
            for parameter in parameters:
                subnet_v4, subnet_v6 = vif['network']['subnets']
                if parameter.get('name') == 'IP':
                    self.assertTrue(_ipv4_like(parameter.get('value'),
                                                             '192.168'))
                elif parameter.get('name') == 'DHCPSERVER':
                    dhcp_server = subnet_v4.get('dhcp_server')
                    self.assertEqual(parameter.get('value'), dhcp_server)
                elif parameter.get('name') == 'RASERVER':
                    ra_server = subnet_v6['gateway']['address'] + "/128"
                    self.assertEqual(parameter.get('value'), ra_server)
                elif parameter.get('name') == 'PROJNET':
                    ipv4_cidr = subnet_v4['cidr']
                    net, mask = netutils.get_net_and_mask(ipv4_cidr)
                    self.assertEqual(parameter.get('value'), net)
                elif parameter.get('name') == 'PROJMASK':
                    ipv4_cidr = subnet_v4['cidr']
                    net, mask = netutils.get_net_and_mask(ipv4_cidr)
                    self.assertEqual(parameter.get('value'), mask)
                elif parameter.get('name') == 'PROJNET6':
                    ipv6_cidr = subnet_v6['cidr']
                    net, prefix = netutils.get_net_and_prefixlen(ipv6_cidr)
                    self.assertEqual(parameter.get('value'), net)
                elif parameter.get('name') == 'PROJMASK6':
                    ipv6_cidr = subnet_v6['cidr']
                    net, prefix = netutils.get_net_and_prefixlen(ipv6_cidr)
                    self.assertEqual(parameter.get('value'), prefix)
                else:
                    raise exception.InvalidParameterValue('unknown parameter '
                                                          'in filter')
Ejemplo n.º 8
0
    def _build_complex_type(self, key, attrs, flavor):
        """If a key does not directly map, this method derives the right value.

        Some types are complex, in that the flavor may have one key that maps
        to several different attributes in the lpar builder.  This method
        handles the complex types.

        :param key: The flavor's key.
        :param attrs: The attribute map to put the value into.
        :param flavor: The Nova instance flavor.
        :return: The value to put in for the key.
        """
        # Map uncapped to sharing mode
        if key == self._PVM_UNCAPPED:
            attrs[lpar_bldr.SHARING_MODE] = (
                pvm_bp.SharingMode.UNCAPPED
                if stru.bool_from_string(flavor.extra_specs[key], strict=True)
                else pvm_bp.SharingMode.CAPPED)
        elif key == self._PVM_DED_SHAR_MODE:
            # Dedicated sharing modes...map directly
            shr_mode_key = flavor.extra_specs[key]
            mode = self._DED_SHARING_MODES_MAP.get(shr_mode_key)
            if mode is None:
                raise exc.InvalidParameterValue(
                    err=_("Invalid dedicated sharing mode '%s'!") %
                    shr_mode_key)
            attrs[lpar_bldr.SHARING_MODE] = mode
        elif key == self._PVM_SHAR_PROC_POOL:
            pool_name = flavor.extra_specs[key]
            attrs[lpar_bldr.SPP] = self._spp_pool_id(pool_name)
        elif key == self._PVM_PROC_COMPAT:
            # Handle variants of the supported values
            attrs[lpar_bldr.PROC_COMPAT] = re.sub(r'\+', '_Plus',
                                                  flavor.extra_specs[key])
        elif key == self._PVM_SRR_CAPABILITY:
            attrs[lpar_bldr.SRR_CAPABLE] = stru.bool_from_string(
                flavor.extra_specs[key], strict=True)
        else:
            # There was no mapping or we didn't handle it.  This is a BUG!
            raise KeyError(
                _("Unhandled PowerVM key '%s'!  Please report this bug.") %
                key)
Ejemplo n.º 9
0
    def test_nwfilter_parameters(self):
        admin_ctxt = context.get_admin_context()

        fakefilter = NWFilterFakes()
        self.fw._conn.nwfilterDefineXML = fakefilter.filterDefineXMLMock
        self.fw._conn.nwfilterLookupByName = fakefilter.nwfilterLookupByName

        instance_ref = self._create_instance()
        inst_id = instance_ref['id']
        inst_uuid = instance_ref['uuid']

        self.security_group = self.setup_and_return_security_group()

        db.instance_add_security_group(self.context, inst_uuid,
                                       self.security_group['id'])

        instance = db.instance_get(self.context, inst_id)

        network_info = _fake_network_info(self.stubs, 1)
        self.fw.setup_basic_filtering(instance, network_info)

        vif = network_info[0]
        nic_id = vif['address'].replace(':', '')
        instance_filter_name = self.fw._instance_filter_name(instance, nic_id)
        f = fakefilter.nwfilterLookupByName(instance_filter_name)
        tree = etree.fromstring(f.xml)

        for fref in tree.findall('filterref'):
            parameters = fref.findall('./parameter')
            for parameter in parameters:
                subnet_v4, subnet_v6 = vif['network']['subnets']
                if parameter.get('name') == 'IP':
                    self.assertTrue(
                        _ipv4_like(parameter.get('value'), '192.168'))
                elif parameter.get('name') == 'DHCPSERVER':
                    dhcp_server = subnet_v4.get('dhcp_server')
                    self.assertEqual(parameter.get('value'), dhcp_server)
                elif parameter.get('name') == 'RASERVER':
                    ra_server = subnet_v6['gateway']['address'] + "/128"
                    self.assertEqual(parameter.get('value'), ra_server)
                elif parameter.get('name') == 'PROJNET':
                    ipv4_cidr = subnet_v4['cidr']
                    net, mask = netutils.get_net_and_mask(ipv4_cidr)
                    self.assertEqual(parameter.get('value'), net)
                elif parameter.get('name') == 'PROJMASK':
                    ipv4_cidr = subnet_v4['cidr']
                    net, mask = netutils.get_net_and_mask(ipv4_cidr)
                    self.assertEqual(parameter.get('value'), mask)
                elif parameter.get('name') == 'PROJNET6':
                    ipv6_cidr = subnet_v6['cidr']
                    net, prefix = netutils.get_net_and_prefixlen(ipv6_cidr)
                    self.assertEqual(parameter.get('value'), net)
                elif parameter.get('name') == 'PROJMASK6':
                    ipv6_cidr = subnet_v6['cidr']
                    net, prefix = netutils.get_net_and_prefixlen(ipv6_cidr)
                    self.assertEqual(parameter.get('value'), prefix)
                else:
                    raise exception.InvalidParameterValue('unknown parameter '
                                                          'in filter')

        db.instance_destroy(admin_ctxt, instance_ref['uuid'])