Пример #1
0
def _parse_physical_port_id(port_id):

    message = ('Physical port ID should follow the format: '
               '<card-type><slot-idx>-<port-idx> like CNA1-1. '
               '<card-type> must be chosen from CNA, FC, or LAN. '
               '<slot-idx> should be 0 for onboard slot or 1-9 for addon '
               'slot. <port-idx> should be 1-9.')

    m = re.match('^([a-zA-Z]+)([0-9])-([1-9])$', port_id)
    if not m:
        raise scci.SCCIInvalidInputError(message)

    card_type = m.group(1).upper()
    if card_type not in _POSSIBLE_CARD_TYPE:
        raise scci.SCCIInvalidInputError(message)

    slot_idx = 0
    if int(m.group(2)) == 0:
        slot_type = ONBOARD
        card_idx = 1
    else:
        slot_type = ADDON
        card_idx = int(m.group(2))
    port_idx = int(m.group(3))

    return _PORT_HANDLERS[card_type](slot_type, card_type, slot_idx, card_idx,
                                     port_idx)
Пример #2
0
def _convert_netmask(mask):
    """Convert netmask from CIDR format(integer) to doted decimal string."""
    if mask not in range(0, 33):
        raise scci.SCCIInvalidInputError('Netmask value is invalid.')

    return socket.inet_ntoa(
        struct.pack('!L', int('1' * mask + '0' * (32 - mask), 2)))
Пример #3
0
    def _process_bios_config():
        try:
            if isinstance(bios_config, dict):
                input_data = bios_config
            else:
                input_data = jsonutils.loads(bios_config)

            # The input data must contain flag "@Processing":"execute" in the
            # equivalent section.
            bios_cfg = input_data['Server']['SystemConfig']['BiosConfig']
            bios_cfg['@Processing'] = 'execute'

            return input_data
        except (TypeError, ValueError, KeyError):
            raise scci.SCCIInvalidInputError(
                ('Invalid input bios config "%s".' % bios_config))
Пример #4
0
    def _process_bios_config():
        try:
            if isinstance(bios_config, dict):
                input_data = bios_config
            else:
                input_data = jsonutils.loads(bios_config)

            # The input data must contain flag "@Processing":"execute" in the
            # equivalent section.
            bios_cfg = input_data['Server']['SystemConfig']['BiosConfig']
            bios_cfg['@Processing'] = 'execute'

            # NOTE: It seems without 2 sub profiles IrmcConfig and
            # OSInstallation present in the input_data, the process will fail.
            # The info for this error can be found in the session log.
            # Work-around: add 2 sub profiles with empty content.
            input_data['Server']['SystemConfig']['IrmcConfig'] = {}
            input_data['Server']['SystemConfig']['OSInstallation'] = {}

            return input_data
        except (TypeError, ValueError, KeyError):
            raise scci.SCCIInvalidInputError(
                ('Invalid input bios config "%s".' % bios_config))
Пример #5
0
def elcm_request(irmc_info, method, path, **kwargs):
    """send an eLCM request to the server

    :param irmc_info: dict of iRMC params to access the server node
        {
          'irmc_address': host,
          'irmc_username': user_id,
          'irmc_password': password,
          'irmc_port': 80 or 443, default is 443,
          'irmc_auth_method': 'basic' or 'digest', default is 'basic',
          'irmc_client_timeout': timeout, default is 60,
          ...
        }
    :param method: request method such as 'GET', 'POST'
    :param path: url path for eLCM request
    :returns: requests.Response from SCCI server
    :raises SCCIInvalidInputError: if port and/or auth_method params
             are invalid
    :raises SCCIClientError: if SCCI failed
    """
    host = irmc_info['irmc_address']
    port = irmc_info.get('irmc_port', 443)
    auth_method = irmc_info.get('irmc_auth_method', 'basic')
    userid = irmc_info['irmc_username']
    password = irmc_info['irmc_password']
    client_timeout = irmc_info.get('irmc_client_timeout', 60)

    # Request headers, params, and data
    headers = kwargs.get('headers', {'Accept': 'application/json'})
    params = kwargs.get('params')
    data = kwargs.get('data')

    auth_obj = None
    try:
        protocol = {80: 'http', 443: 'https'}[port]
        auth_obj = {
            'basic': requests.auth.HTTPBasicAuth(userid, password),
            'digest': requests.auth.HTTPDigestAuth(userid, password)
        }[auth_method.lower()]

    except KeyError:
        raise scci.SCCIInvalidInputError(
            ("Invalid port %(port)d or " +
             "auth_method for method %(auth_method)s") % {
                 'port': port,
                 'auth_method': auth_method
             })

    try:
        r = requests.request(method,
                             protocol + '://' + host + path,
                             headers=headers,
                             params=params,
                             data=data,
                             verify=False,
                             timeout=client_timeout,
                             allow_redirects=False,
                             auth=auth_obj)
    except requests.exceptions.RequestException as requests_exception:
        raise scci.SCCIClientError(requests_exception)

    # Process status_code 401
    if r.status_code == 401:
        raise scci.SCCIClientError('UNAUTHORIZED')

    return r