Пример #1
0
class ServiceUnavailable(HttpServerError):
    """HTTP 503 - Service Unavailable.

    The server is currently unavailable.
    """
    http_status = http_client.SERVICE_UNAVAILABLE
    message = _("Service Unavailable")
Пример #2
0
class HTTPClientError(HttpError):
    """Client-side HTTP error.

    Exception for cases in which the client seems to have erred.
    """
    message = _("HTTP Client Error")

    def __init__(self,
                 message=None,
                 details=None,
                 response=None,
                 request_id=None,
                 url=None,
                 method=None,
                 http_status=None):
        if method:
            error_json = _extract_error_json(method)
            message = error_json.get('faultstring')
        super(HTTPClientError, self).__init__(message=message,
                                              details=details,
                                              response=response,
                                              request_id=request_id,
                                              url=url,
                                              method=method,
                                              http_status=http_status)
Пример #3
0
class HttpServerError(HttpError):
    """Server-side HTTP error.

    Exception for cases in which the server is aware that it has
    erred or is incapable of performing the request.
    """
    message = _("HTTP Server Error")

    def __init__(self,
                 message=None,
                 details=None,
                 response=None,
                 request_id=None,
                 url=None,
                 method=None,
                 http_status=None):
        if method:
            error_json = _extract_error_json(method)
            message = error_json.get('faultstring')
        super(HttpServerError, self).__init__(message=message,
                                              details=details,
                                              response=response,
                                              request_id=request_id,
                                              url=url,
                                              method=method,
                                              http_status=http_status)
Пример #4
0
    def __init__(self, endpoint=None, session=None, **kwargs):
        """Initialize a new client for the INVENTORY v1 API."""
        if not session:
            if kwargs.get('os_inventory_api_version'):
                kwargs['api_version_select_state'] = "user"
            else:
                if not endpoint:
                    raise exc.EndpointException(
                        _("Must provide 'endpoint' "
                          "if os_inventory_api_version isn't specified"))

            # If the user didn't specify a version, use a default version
            kwargs['api_version_select_state'] = "default"
            kwargs['os_inventory_api_version'] = DEFAULT_VERSION

        self.http_client = http.get_http_client(endpoint, session, **kwargs)
        self.host = host.HostManager(self.http_client)
        self.cpu = cpu.CpuManager(self.http_client)
        self.ethernetport = ethernetport.EthernetPortManager(self.http_client)
        self.lldp_agent = lldp_agent.LldpAgentManager(self.http_client)
        self.lldp_neighbour = lldp_neighbour.LldpNeighbourManager(
            self.http_client)
        self.memory = memory.MemoryManager(self.http_client)
        self.node = node.NodeManager(self.http_client)
        self.pci_device = pci_device.PciDeviceManager(self.http_client)
        self.port = port.PortManager(self.http_client)
Пример #5
0
def do_host_bulk_export(cc, args):
    """Export host bulk configurations."""
    result = cc.host.bulk_export()

    xml_content = result['content']
    config_filename = './hosts.xml'
    if hasattr(args, 'filename') and args.filename:
        config_filename = args.filename
    try:
        with open(config_filename, 'wb') as fw:
            fw.write(xml_content)
        print(_('Export successfully to %s') % config_filename)
    except IOError:
        print(_('Cannot write to file: %s') % config_filename)

    return
Пример #6
0
class Conflict(ClientException):
    """HTTP 409 - Conflict.

    Indicates that the request could not be processed because of conflict
    in the request, such as an edit conflict.
    """
    http_status = http_client.CONFLICT
    message = _("Conflict")
Пример #7
0
class HttpError(ClientException):
    """The base exception class for all HTTP exceptions."""
    http_status = 0
    message = _("HTTP Error")

    def __init__(self,
                 message=None,
                 details=None,
                 response=None,
                 request_id=None,
                 url=None,
                 method=None,
                 http_status=None):
        self.http_status = http_status or self.http_status
        self.message = message or self.message
        self.details = details
        self.request_id = request_id
        self.response = response
        self.url = url
        self.method = method
        formatted_string = "%s (HTTP %s)" % (self.message, self.http_status)
        if request_id:
            formatted_string += " (Request-ID: %s)" % request_id
        super(HttpError, self).__init__(formatted_string)
Пример #8
0
    'num_cores_on_processor0', 'num_cores_on_processor1',
    'num_cores_on_processor2', 'num_cores_on_processor3'
]

PLATFORM_CPU_TYPE = "Platform"
VSWITCH_CPU_TYPE = "Vswitch"
SHARED_CPU_TYPE = "Shared"
VMS_CPU_TYPE = "VMs"
NONE_CPU_TYPE = "None"

CPU_TYPE_LIST = [
    PLATFORM_CPU_TYPE, VSWITCH_CPU_TYPE, SHARED_CPU_TYPE, VMS_CPU_TYPE,
    NONE_CPU_TYPE
]

PLATFORM_CPU_TYPE_FORMAT = _("Platform")
VSWITCH_CPU_TYPE_FORMAT = _("vSwitch")
SHARED_CPU_TYPE_FORMAT = _("Shared")
VMS_CPU_TYPE_FORMAT = _("VMs")
NONE_CPU_TYPE_FORMAT = _("None")

CPU_TYPE_FORMATS = {
    PLATFORM_CPU_TYPE: PLATFORM_CPU_TYPE_FORMAT,
    VSWITCH_CPU_TYPE: VSWITCH_CPU_TYPE_FORMAT,
    SHARED_CPU_TYPE: SHARED_CPU_TYPE_FORMAT,
    VMS_CPU_TYPE: VMS_CPU_TYPE_FORMAT,
    NONE_CPU_TYPE: NONE_CPU_TYPE_FORMAT
}


def _cpu_function_formatter(allocated_function):
Пример #9
0
class HTTPRedirection(HttpError):
    """HTTP Redirection."""
    message = _("HTTP Redirection")
Пример #10
0
def get_client(version,
               endpoint=None,
               session=None,
               auth_token=None,
               inventory_url=None,
               username=None,
               password=None,
               auth_url=None,
               project_id=None,
               project_name=None,
               region_name=None,
               timeout=None,
               user_domain_id=None,
               user_domain_name=None,
               project_domain_id=None,
               project_domain_name=None,
               service_type=SERVICE_TYPE,
               endpoint_type=None,
               **ignored_kwargs):
    """Get an authenticated client, based on the credentials."""
    kwargs = {}
    interface = endpoint_type or 'publicURL'
    endpoint = endpoint or inventory_url
    if auth_token and endpoint:
        kwargs.update({
            'token': auth_token,
        })
        if timeout:
            kwargs.update({
                'timeout': timeout,
            })
    elif auth_url:
        auth_kwargs = {}
        auth_type = 'password'
        auth_kwargs.update({
            'auth_url': auth_url,
            'project_id': project_id,
            'project_name': project_name,
            'user_domain_id': user_domain_id,
            'user_domain_name': user_domain_name,
            'project_domain_id': project_domain_id,
            'project_domain_name': project_domain_name,
        })
        if username and password:
            auth_kwargs.update({'username': username, 'password': password})
        elif auth_token:
            auth_type = 'token'
            auth_kwargs.update({
                'token': auth_token,
            })

        # Create new session only if it was not passed in
        if not session:
            loader = loading.get_plugin_loader(auth_type)
            auth_plugin = loader.load_from_options(**auth_kwargs)
            session = loading.session.Session().load_from_options(
                auth=auth_plugin, timeout=timeout)

    exception_msg = _('Must provide Keystone credentials or user-defined '
                      'endpoint and token')
    if not endpoint:
        if session:
            try:
                endpoint = session.get_endpoint(service_type=service_type,
                                                interface=interface,
                                                region_name=region_name)
            except Exception as e:
                raise exc.AuthSystem(
                    _('%(message)s, error was: %(error)s') % {
                        'message': exception_msg,
                        'error': e
                    })
        else:
            # Neither session, nor valid auth parameters provided
            raise exc.AuthSystem(exception_msg)

    kwargs['endpoint_override'] = endpoint
    kwargs['service_type'] = service_type
    kwargs['interface'] = interface
    kwargs['version'] = version

    inventory_module = importutils.import_versioned_module(
        'inventoryclient', version, 'client')
    client_class = getattr(inventory_module, 'Client')
    return client_class(endpoint, session=session, **kwargs)