Exemplo n.º 1
0
Arquivo: node.py Projeto: xe1gyq/metal
class Node(base.APIBase):
    """API representation of a host node.

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of
    an node.
    """

    uuid = types.uuid
    "Unique UUID for this node"

    numa_node = int
    "numa node zone for this node"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "This node's meta data"

    host_id = int
    "The hostid that this node belongs to"

    host_uuid = types.uuid
    "The UUID of the host this node belongs to"

    links = [link.Link]
    "A list containing a self link and associated node links"

    icpus = [link.Link]
    "Links to the collection of cpus on this node"

    imemorys = [link.Link]
    "Links to the collection of memorys on this node"

    ports = [link.Link]
    "Links to the collection of ports on this node"

    def __init__(self, **kwargs):
        self.fields = objects.Node.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

    @classmethod
    def convert_with_links(cls, rpc_node, expand=True):
        minimum_fields = [
            'uuid', 'numa_node', 'capabilities', 'host_uuid', 'host_id',
            'created_at'
        ] if not expand else None
        fields = minimum_fields if not expand else None

        node = Node.from_rpc_object(rpc_node, fields)

        # never expose the host_id attribute
        node.host_id = wtypes.Unset

        node.links = [
            link.Link.make_link('self', pecan.request.host_url, 'nodes',
                                node.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'nodes',
                                node.uuid,
                                bookmark=True)
        ]
        if expand:
            node.icpus = [
                link.Link.make_link('self', pecan.request.host_url, 'nodes',
                                    node.uuid + "/cpus"),
                link.Link.make_link('bookmark',
                                    pecan.request.host_url,
                                    'nodes',
                                    node.uuid + "/cpus",
                                    bookmark=True)
            ]

            node.imemorys = [
                link.Link.make_link('self', pecan.request.host_url, 'nodes',
                                    node.uuid + "/memorys"),
                link.Link.make_link('bookmark',
                                    pecan.request.host_url,
                                    'nodes',
                                    node.uuid + "/memorys",
                                    bookmark=True)
            ]

            node.ports = [
                link.Link.make_link('self', pecan.request.host_url, 'nodes',
                                    node.uuid + "/ports"),
                link.Link.make_link('bookmark',
                                    pecan.request.host_url,
                                    'nodes',
                                    node.uuid + "/ports",
                                    bookmark=True)
            ]

        return node
Exemplo n.º 2
0
class CPU(base.APIBase):
    """API representation of a host CPU.

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of a cpu.
    """

    uuid = types.uuid
    "Unique UUID for this cpu"

    cpu = int
    "Represent the cpu id cpu"

    core = int
    "Represent the core id cpu"

    thread = int
    "Represent the thread id cpu"

    cpu_family = wtypes.text
    "Represent the cpu family of the cpu"

    cpu_model = wtypes.text
    "Represent the cpu model of the cpu"

    function = wtypes.text
    "Represent the function of the cpu"

    num_cores_on_processor0 = wtypes.text
    "The number of cores on processors 0"

    num_cores_on_processor1 = wtypes.text
    "The number of cores on processors 1"

    num_cores_on_processor2 = wtypes.text
    "The number of cores on processors 2"

    num_cores_on_processor3 = wtypes.text
    "The number of cores on processors 3"

    numa_node = int
    "The numa node or zone the cpu. API only attribute"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "This cpu's meta data"

    host_id = int
    "The hostid that this cpu belongs to"

    node_id = int
    "The nodeId that this cpu belongs to"

    host_uuid = types.uuid
    "The UUID of the host this cpu belongs to"

    node_uuid = types.uuid
    "The UUID of the node this cpu belongs to"

    links = [link.Link]
    "A list containing a self link and associated cpu links"

    def __init__(self, **kwargs):
        self.fields = objects.CPU.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

        # API only attributes
        self.fields.append('function')
        setattr(self, 'function', kwargs.get('function', None))
        self.fields.append('num_cores_on_processor0')
        setattr(self, 'num_cores_on_processor0',
                kwargs.get('num_cores_on_processor0', None))
        self.fields.append('num_cores_on_processor1')
        setattr(self, 'num_cores_on_processor1',
                kwargs.get('num_cores_on_processor1', None))
        self.fields.append('num_cores_on_processor2')
        setattr(self, 'num_cores_on_processor2',
                kwargs.get('num_cores_on_processor2', None))
        self.fields.append('num_cores_on_processor3')
        setattr(self, 'num_cores_on_processor3',
                kwargs.get('num_cores_on_processor3', None))

    @classmethod
    def convert_with_links(cls, rpc_port, expand=True):
        cpu = CPU(**rpc_port.as_dict())
        if not expand:
            cpu.unset_fields_except([
                'uuid', 'cpu', 'core', 'thread', 'cpu_family', 'cpu_model',
                'numa_node', 'host_uuid', 'node_uuid', 'host_id', 'node_id',
                'capabilities', 'created_at', 'updated_at'
            ])

        # never expose the id attribute
        cpu.host_id = wtypes.Unset
        cpu.node_id = wtypes.Unset

        cpu.links = [
            link.Link.make_link('self', pecan.request.host_url, 'cpus',
                                cpu.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'cpus',
                                cpu.uuid,
                                bookmark=True)
        ]
        return cpu
Exemplo n.º 3
0
class EthernetPort(base.APIBase):
    """API representation of an Ethernet port

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of an
    Ethernet port.
    """

    uuid = types.uuid
    "Unique UUID for this port"

    type = wtypes.text
    "Represent the type of port"

    name = wtypes.text
    "Represent the name of the port. Unique per host"

    namedisplay = wtypes.text
    "Represent the display name of the port. Unique per host"

    pciaddr = wtypes.text
    "Represent the pci address of the port"

    dev_id = int
    "The unique identifier of PCI device"

    pclass = wtypes.text
    "Represent the pci class of the port"

    pvendor = wtypes.text
    "Represent the pci vendor of the port"

    pdevice = wtypes.text
    "Represent the pci device of the port"

    psvendor = wtypes.text
    "Represent the pci svendor of the port"

    psdevice = wtypes.text
    "Represent the pci sdevice of the port"

    numa_node = int
    "Represent the numa node or zone sdevice of the port"

    sriov_totalvfs = int
    "The total number of available SR-IOV VFs"

    sriov_numvfs = int
    "The number of configured SR-IOV VFs"

    sriov_vfs_pci_address = wtypes.text
    "The PCI Addresses of the VFs"

    driver = wtypes.text
    "The kernel driver for this device"

    mac = wsme.wsattr(types.macaddress, mandatory=False)
    "Represent the MAC Address of the port"

    mtu = int
    "Represent the MTU size (bytes) of the port"

    speed = int
    "Represent the speed (MBytes/sec) of the port"

    link_mode = int
    "Represent the link mode of the port"

    duplex = wtypes.text
    "Represent the duplex mode of the port"

    autoneg = wtypes.text
    "Represent the auto-negotiation mode of the port"

    bootp = wtypes.text
    "Represent the bootp port of the host"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "Represent meta data of the port"

    host_id = int
    "Represent the host_id the port belongs to"

    bootif = wtypes.text
    "Represent whether the port is a boot port"

    dpdksupport = bool
    "Represent whether or not the port supports DPDK acceleration"

    host_uuid = types.uuid
    "Represent the UUID of the host the port belongs to"

    node_uuid = types.uuid
    "Represent the UUID of the node the port belongs to"

    links = [link.Link]
    "Represent a list containing a self link and associated port links"

    def __init__(self, **kwargs):
        self.fields = objects.EthernetPort.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

    @classmethod
    def convert_with_links(cls, rpc_port, expand=True):
        port = EthernetPort(**rpc_port.as_dict())
        if not expand:
            port.unset_fields_except([
                'uuid', 'host_id', 'node_id', 'type', 'name', 'namedisplay',
                'pciaddr', 'dev_id', 'pclass', 'pvendor', 'pdevice',
                'psvendor', 'psdevice', 'numa_node', 'mac', 'sriov_totalvfs',
                'sriov_numvfs', 'sriov_vfs_pci_address', 'driver', 'mtu',
                'speed', 'link_mode', 'duplex', 'autoneg', 'bootp',
                'capabilities', 'host_uuid', 'node_uuid', 'dpdksupport',
                'created_at', 'updated_at'
            ])

        # never expose the id attribute
        port.host_id = wtypes.Unset
        port.node_id = wtypes.Unset

        port.links = [
            link.Link.make_link('self', pecan.request.host_url,
                                'ethernet_ports', port.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'ethernet_ports',
                                port.uuid,
                                bookmark=True)
        ]
        return port
Exemplo n.º 4
0
Arquivo: port.py Projeto: xe1gyq/metal
class Port(base.APIBase):
    """API representation of a host port

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of an
    port.
    """
    uuid = types.uuid
    "Unique UUID for this port"

    type = wtypes.text
    "Represent the type of port"

    name = wtypes.text
    "Represent the name of the port. Unique per host"

    namedisplay = wtypes.text
    "Represent the display name of the port. Unique per host"

    pciaddr = wtypes.text
    "Represent the pci address of the port"

    dev_id = int
    "The unique identifier of PCI device"

    pclass = wtypes.text
    "Represent the pci class of the port"

    pvendor = wtypes.text
    "Represent the pci vendor of the port"

    pdevice = wtypes.text
    "Represent the pci device of the port"

    psvendor = wtypes.text
    "Represent the pci svendor of the port"

    psdevice = wtypes.text
    "Represent the pci sdevice of the port"

    numa_node = int
    "Represent the numa node or zone sdevice of the port"

    sriov_totalvfs = int
    "The total number of available SR-IOV VFs"

    sriov_numvfs = int
    "The number of configured SR-IOV VFs"

    sriov_vfs_pci_address = wtypes.text
    "The PCI Addresses of the VFs"

    driver = wtypes.text
    "The kernel driver for this device"

    capabilities = {wtypes.text: utils.ValidTypes(wtypes.text,
                    six.integer_types)}
    "Represent meta data of the port"

    host_id = int
    "Represent the host_id the port belongs to"

    interface_id = int
    "Represent the interface_id the port belongs to"

    dpdksupport = bool
    "Represent whether or not the port supports DPDK acceleration"

    host_uuid = types.uuid
    "Represent the UUID of the host the port belongs to"

    interface_uuid = types.uuid
    "Represent the UUID of the interface the port belongs to"

    node_uuid = types.uuid
    "Represent the UUID of the node the port belongs to"

    links = [link.Link]
    "Represent a list containing a self link and associated port links"

    lldp_agents = [link.Link]
    "Links to the collection of LldpAgents on this port"

    lldp_neighbours = [link.Link]
    "Links to the collection of LldpNeighbours on this port"

    def __init__(self, **kwargs):
        self.fields = objects.Port.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

    @classmethod
    def convert_with_links(cls, rpc_port, expand=True):
        port = Port(**rpc_port.as_dict())
        if not expand:
            port.unset_fields_except(['uuid', 'host_id', 'node_id',
                                      'interface_id', 'type', 'name',
                                      'namedisplay', 'pciaddr', 'dev_id',
                                      'pclass', 'pvendor', 'pdevice',
                                      'psvendor', 'psdevice', 'numa_node',
                                      'sriov_totalvfs', 'sriov_numvfs',
                                      'sriov_vfs_pci_address', 'driver',
                                      'capabilities',
                                      'host_uuid', 'interface_uuid',
                                      'node_uuid', 'dpdksupport',
                                      'created_at', 'updated_at'])

        # never expose the id attribute
        port.host_id = wtypes.Unset
        port.interface_id = wtypes.Unset
        port.node_id = wtypes.Unset

        port.links = [link.Link.make_link('self', pecan.request.host_url,
                                          'ports', port.uuid),
                      link.Link.make_link('bookmark',
                                          pecan.request.host_url,
                                          'ports', port.uuid,
                                          bookmark=True)
                      ]

        port.lldp_agents = [link.Link.make_link('self',
                                                pecan.request.host_url,
                                                'ports',
                                                port.uuid + "/lldp_agents"),
                            link.Link.make_link('bookmark',
                                                pecan.request.host_url,
                                                'ports',
                                                port.uuid + "/lldp_agents",
                                                bookmark=True)
                            ]

        port.lldp_neighbours = [
            link.Link.make_link('self',
                                pecan.request.host_url,
                                'ports',
                                port.uuid + "/lldp_neighbors"),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'ports',
                                port.uuid + "/lldp_neighbors",
                                bookmark=True)
        ]

        return port
Exemplo n.º 5
0
class SensorGroup(base.APIBase):
    """API representation of an Sensor Group

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of an
    sensorgroup.
    """

    uuid = types.uuid
    "Unique UUID for this sensorgroup"

    sensorgroupname = wtypes.text
    "Represent the name of the sensorgroup. Unique with path per host"

    path = wtypes.text
    "Represent the path of the sensor. Unique with sensorname per host"

    sensortype = wtypes.text
    "Represent the sensortype . e.g. Temperature, WatchDog"

    datatype = wtypes.text
    "Represent the datatype e.g. discrete or analog,"

    state = wtypes.text
    "Represent the state of the sensorgroup"

    possible_states = wtypes.text
    "Represent the possible states of the sensorgroup"

    algorithm = wtypes.text
    "Represent the algorithm of the sensorgroup."

    audit_interval_group = int
    "Represent the audit interval of the sensorgroup."

    actions_critical_choices = wtypes.text
    "Represent the configurable critical severity actions of the sensorgroup."

    actions_major_choices = wtypes.text
    "Represent the configurable major severity actions of the sensorgroup."

    actions_minor_choices = wtypes.text
    "Represent the configurable minor severity actions of the sensorgroup."

    actions_minor_group = wtypes.text
    "Represent the minor configured actions of the sensorgroup. CSV."

    actions_major_group = wtypes.text
    "Represent the major configured actions of the sensorgroup. CSV."

    actions_critical_group = wtypes.text
    "Represent the critical configured actions of the sensorgroup. CSV."

    unit_base_group = wtypes.text
    "Represent the unit base of the analog sensorgroup e.g. revolutions"

    unit_modifier_group = wtypes.text
    "Represent the unit modifier of the analog sensorgroup e.g. 10**2"

    unit_rate_group = wtypes.text
    "Represent the unit rate of the sensorgroup e.g. /minute"

    t_minor_lower_group = wtypes.text
    "Represent the minor lower threshold of the analog sensorgroup"

    t_minor_upper_group = wtypes.text
    "Represent the minor upper threshold of the analog sensorgroup"

    t_major_lower_group = wtypes.text
    "Represent the major lower threshold of the analog sensorgroup"

    t_major_upper_group = wtypes.text
    "Represent the major upper threshold of the analog sensorgroup"

    t_critical_lower_group = wtypes.text
    "Represent the critical lower threshold of the analog sensorgroup"

    t_critical_upper_group = wtypes.text
    "Represent the critical upper threshold of the analog sensorgroup"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "Represent meta data of the sensorgroup"

    suppress = wtypes.text
    "Represent supress sensor if True, otherwise not suppress sensor"

    sensors = wtypes.text
    "Represent the sensors of the sensorgroup"

    host_id = int
    "Represent the host_id the sensorgroup belongs to"

    host_uuid = types.uuid
    "Represent the UUID of the host the sensorgroup belongs to"

    links = [link.Link]
    "Represent a list containing a self link and associated sensorgroup links"

    sensors = [link.Link]
    "Links to the collection of sensors on this sensorgroup"

    def __init__(self, **kwargs):
        self.fields = objects.SensorGroup.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

        # 'sensors' is not part of objects.SenorGroups.fields (it's an
        # API-only attribute)
        self.fields.append('sensors')
        setattr(self, 'sensors', kwargs.get('sensors', None))

    @classmethod
    def convert_with_links(cls, rsensorgroup, expand=True):

        sensorgroup = SensorGroup(**rsensorgroup.as_dict())

        sensorgroup_fields_common = [
            'uuid',
            'host_id',
            'host_uuid',
            'sensortype',
            'datatype',
            'sensorgroupname',
            'path',
            'state',
            'possible_states',
            'audit_interval_group',
            'algorithm',
            'actions_critical_choices',
            'actions_major_choices',
            'actions_minor_choices',
            'actions_minor_group',
            'actions_major_group',
            'actions_critical_group',
            'sensors',
            'suppress',
            'capabilities',
            'created_at',
            'updated_at',
        ]

        sensorgroup_fields_analog = [
            'unit_base_group',
            'unit_modifier_group',
            'unit_rate_group',
            't_minor_lower_group',
            't_minor_upper_group',
            't_major_lower_group',
            't_major_upper_group',
            't_critical_lower_group',
            't_critical_upper_group',
        ]

        if rsensorgroup.datatype == 'discrete':
            sensorgroup_fields = sensorgroup_fields_common
        elif rsensorgroup.datatype == 'analog':
            sensorgroup_fields = \
                sensorgroup_fields_common + sensorgroup_fields_analog
        else:
            LOG.error(_("Invalid datatype={}").format(rsensorgroup.datatype))

        if not expand:
            sensorgroup.unset_fields_except(sensorgroup_fields)

        if sensorgroup.host_id and not sensorgroup.host_uuid:
            host = objects.Host.get_by_uuid(pecan.request.context,
                                            sensorgroup.host_id)
            sensorgroup.host_uuid = host.uuid

        # never expose the id attribute
        sensorgroup.host_id = wtypes.Unset
        sensorgroup.id = wtypes.Unset

        sensorgroup.links = [
            link.Link.make_link('self', pecan.request.host_url, 'sensorgroups',
                                sensorgroup.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'sensorgroups',
                                sensorgroup.uuid,
                                bookmark=True)
        ]

        sensorgroup.sensors = [
            link.Link.make_link('self', pecan.request.host_url, 'sensorgroups',
                                sensorgroup.uuid + "/sensors"),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'sensorgroups',
                                sensorgroup.uuid + "/sensors",
                                bookmark=True)
        ]

        return sensorgroup
Exemplo n.º 6
0
class System(base.APIBase):
    """API representation of a system.

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of
    a system.
    """

    uuid = types.uuid
    "The UUID of the system"

    name = wtypes.text
    "The name of the system"

    system_type = wtypes.text
    "The type of the system"

    system_mode = wtypes.text
    "The mode of the system"

    description = wtypes.text
    "The name of the system"

    contact = wtypes.text
    "The contact of the system"

    location = wtypes.text
    "The location of the system"

    services = int
    "The services of the system"

    software_version = wtypes.text
    "A textual description of the entity"

    timezone = wtypes.text
    "The timezone of the system"

    links = [link.Link]
    "A list containing a self link and associated system links"

    hosts = [link.Link]
    "Links to the collection of hosts contained in this system"

    capabilities = {
        wtypes.text: api_utils.ValidTypes(wtypes.text, bool, six.integer_types)
    }
    "System defined capabilities"

    region_name = wtypes.text
    "The region name of the system"

    distributed_cloud_role = wtypes.text
    "The distributed cloud role of the system"

    service_project_name = wtypes.text
    "The service project name of the system"

    security_feature = wtypes.text
    "Kernel arguments associated with enabled spectre/meltdown fix features"

    def __init__(self, **kwargs):
        self.fields = objects.System.fields.keys()

        for k in self.fields:
            # Translate any special internal representation of data to its
            # customer facing form
            if k == 'security_feature':
                # look up which customer-facing-security-feature-string goes
                # with the kernel arguments tracked in sysinv
                kernel_args = kwargs.get(k)
                translated_string = kernel_args

                for user_string, args_string in \
                        constants.SYSTEM_SECURITY_FEATURE_SPECTRE_MELTDOWN_OPTS.iteritems():  # noqa
                    if args_string == kernel_args:
                        translated_string = user_string
                        break
                setattr(self, k, translated_string)
            else:
                # No translation required
                setattr(self, k, kwargs.get(k))

    @classmethod
    def convert_with_links(cls, rpc_system, expand=True):
        minimum_fields = [
            'id', 'uuid', 'name', 'system_type', 'system_mode', 'description',
            'capabilities', 'contact', 'location', 'software_version',
            'created_at', 'updated_at', 'timezone', 'region_name',
            'service_project_name', 'distributed_cloud_role',
            'security_feature'
        ]

        fields = minimum_fields if not expand else None

        iSystem = System.from_rpc_object(rpc_system, fields)

        iSystem.links = [
            link.Link.make_link('self', pecan.request.host_url, 'systems',
                                iSystem.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'systems',
                                iSystem.uuid,
                                bookmark=True)
        ]

        if expand:
            iSystem.hosts = [
                link.Link.make_link('self', pecan.request.host_url, 'systems',
                                    iSystem.uuid + "/hosts"),
                link.Link.make_link('bookmark',
                                    pecan.request.host_url,
                                    'systems',
                                    iSystem.uuid + "/hosts",
                                    bookmark=True)
            ]

        return iSystem
Exemplo n.º 7
0
class Memory(base.APIBase):
    """API representation of host memory.

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of a memory.
    """

    _minimum_platform_reserved_mib = None

    def _get_minimum_platform_reserved_mib(self):
        return self._minimum_platform_reserved_mib

    def _set_minimum_platform_reserved_mib(self, value):
        if self._minimum_platform_reserved_mib is None:
            try:
                ihost = objects.Host.get_by_uuid(pecan.request.context, value)
                self._minimum_platform_reserved_mib = \
                    cutils.get_minimum_platform_reserved_memory(ihost,
                                                                self.numa_node)
            except exception.HostNotFound as e:
                # Change error code because 404 (NotFound) is inappropriate
                # response for a POST request to create
                e.code = 400  # BadRequest
                raise e
        elif value == wtypes.Unset:
            self._minimum_platform_reserved_mib = wtypes.Unset

    uuid = types.uuid
    "Unique UUID for this memory"

    memtotal_mib = int
    "Represent the imemory total in MiB"

    memavail_mib = int
    "Represent the imemory available in MiB"

    platform_reserved_mib = int
    "Represent the imemory platform reserved in MiB"

    hugepages_configured = wtypes.text
    "Represent whether huge pages are configured"

    vswitch_hugepages_size_mib = int
    "Represent the imemory vswitch huge pages size in MiB"

    vswitch_hugepages_reqd = int
    "Represent the imemory vswitch required number of hugepages"

    vswitch_hugepages_nr = int
    "Represent the imemory vswitch number of hugepages"

    vswitch_hugepages_avail = int
    "Represent the imemory vswitch number of hugepages available"

    vm_hugepages_nr_2M_pending = int
    "Represent the imemory vm number of hugepages pending (2M pages)"

    vm_hugepages_nr_2M = int
    "Represent the imemory vm number of hugepages (2M pages)"

    vm_hugepages_avail_2M = int
    "Represent the imemory vm number of hugepages available (2M pages)"

    vm_hugepages_nr_1G_pending = int
    "Represent the imemory vm number of hugepages pending (1G pages)"

    vm_hugepages_nr_1G = int
    "Represent the imemory vm number of hugepages (1G pages)"

    vm_hugepages_nr_4K = int
    "Represent the imemory vm number of hugepages (4K pages)"

    vm_hugepages_use_1G = wtypes.text
    "1G hugepage is supported 'True' or not 'False' "

    vm_hugepages_avail_1G = int
    "Represent the imemory vm number of hugepages available (1G pages)"

    vm_hugepages_possible_2M = int
    "Represent the total possible number of vm hugepages available (2M pages)"

    vm_hugepages_possible_1G = int
    "Represent the total possible number of vm hugepages available (1G pages)"

    minimum_platform_reserved_mib = wsme.wsproperty(
        int,
        _get_minimum_platform_reserved_mib,
        _set_minimum_platform_reserved_mib,
        mandatory=True)
    "Represent the default platform reserved memory in MiB. API only attribute"

    numa_node = int
    "The numa node or zone the imemory. API only attribute"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "This memory's meta data"

    host_id = int
    "The ihostid that this imemory belongs to"

    node_id = int
    "The nodeId that this imemory belongs to"

    ihost_uuid = types.uuid
    "The UUID of the ihost this memory belongs to"

    node_uuid = types.uuid
    "The UUID of the node this memory belongs to"

    links = [link.Link]
    "A list containing a self link and associated memory links"

    def __init__(self, **kwargs):
        self.fields = objects.Memory.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

        # API only attributes
        self.fields.append('minimum_platform_reserved_mib')
        setattr(self, 'minimum_platform_reserved_mib',
                kwargs.get('host_id', None))

    @classmethod
    def convert_with_links(cls, rpc_mem, expand=True):
        # fields = ['uuid', 'address'] if not expand else None
        # memory = imemory.from_rpc_object(rpc_mem, fields)

        memory = Memory(**rpc_mem.as_dict())
        if not expand:
            memory.unset_fields_except([
                'uuid', 'memtotal_mib', 'memavail_mib',
                'platform_reserved_mib', 'hugepages_configured',
                'vswitch_hugepages_size_mib', 'vswitch_hugepages_nr',
                'vswitch_hugepages_reqd', 'vswitch_hugepages_avail',
                'vm_hugepages_nr_2M', 'vm_hugepages_nr_1G',
                'vm_hugepages_use_1G', 'vm_hugepages_nr_2M_pending',
                'vm_hugepages_avail_2M', 'vm_hugepages_nr_1G_pending',
                'vm_hugepages_avail_1G', 'vm_hugepages_nr_4K',
                'vm_hugepages_possible_2M', 'vm_hugepages_possible_1G',
                'numa_node', 'ihost_uuid', 'node_uuid', 'host_id', 'node_id',
                'capabilities', 'created_at', 'updated_at',
                'minimum_platform_reserved_mib'
            ])

        # never expose the id attribute
        memory.host_id = wtypes.Unset
        memory.node_id = wtypes.Unset

        memory.links = [
            link.Link.make_link('self', pecan.request.host_url, 'memorys',
                                memory.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'memorys',
                                memory.uuid,
                                bookmark=True)
        ]
        return memory
Exemplo n.º 8
0
class Sensor(base.APIBase):
    """API representation of an Sensor

    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of an
    sensor.
    """

    uuid = types.uuid
    "Unique UUID for this sensor"

    sensorname = wtypes.text
    "Represent the name of the sensor. Unique with path per host"

    path = wtypes.text
    "Represent the path of the sensor. Unique with sensorname per host"

    sensortype = wtypes.text
    "Represent the type of sensor. e.g. Temperature, WatchDog"

    datatype = wtypes.text
    "Represent the entity monitored. e.g. discrete, analog"

    status = wtypes.text
    "Represent current sensor status: ok, minor, major, critical, disabled"

    state = wtypes.text
    "Represent the current state of the sensor"

    state_requested = wtypes.text
    "Represent the requested state of the sensor"

    audit_interval = int
    "Represent the audit_interval of the sensor."

    algorithm = wtypes.text
    "Represent the algorithm of the sensor."

    actions_minor = wtypes.text
    "Represent the minor configured actions of the sensor. CSV."

    actions_major = wtypes.text
    "Represent the major configured actions of the sensor. CSV."

    actions_critical = wtypes.text
    "Represent the critical configured actions of the sensor. CSV."

    suppress = wtypes.text
    "Represent supress sensor if True, otherwise not suppress sensor"

    value = wtypes.text
    "Represent current value of the discrete sensor"

    unit_base = wtypes.text
    "Represent the unit base of the analog sensor e.g. revolutions"

    unit_modifier = wtypes.text
    "Represent the unit modifier of the analog sensor e.g. 10**2"

    unit_rate = wtypes.text
    "Represent the unit rate of the sensor e.g. /minute"

    t_minor_lower = wtypes.text
    "Represent the minor lower threshold of the analog sensor"

    t_minor_upper = wtypes.text
    "Represent the minor upper threshold of the analog sensor"

    t_major_lower = wtypes.text
    "Represent the major lower threshold of the analog sensor"

    t_major_upper = wtypes.text
    "Represent the major upper threshold of the analog sensor"

    t_critical_lower = wtypes.text
    "Represent the critical lower threshold of the analog sensor"

    t_critical_upper = wtypes.text
    "Represent the critical upper threshold of the analog sensor"

    capabilities = {
        wtypes.text: utils.ValidTypes(wtypes.text, six.integer_types)
    }
    "Represent meta data of the sensor"

    host_id = int
    "Represent the host_id the sensor belongs to"

    sensorgroup_id = int
    "Represent the sensorgroup_id the sensor belongs to"

    host_uuid = types.uuid
    "Represent the UUID of the host the sensor belongs to"

    sensorgroup_uuid = types.uuid
    "Represent the UUID of the sensorgroup the sensor belongs to"

    links = [link.Link]
    "Represent a list containing a self link and associated sensor links"

    def __init__(self, **kwargs):
        self.fields = objects.Sensor.fields.keys()
        for k in self.fields:
            setattr(self, k, kwargs.get(k))

    @classmethod
    def convert_with_links(cls, rpc_sensor, expand=True):

        sensor = Sensor(**rpc_sensor.as_dict())

        sensor_fields_common = [
            'uuid',
            'host_id',
            'sensorgroup_id',
            'sensortype',
            'datatype',
            'sensorname',
            'path',
            'status',
            'state',
            'state_requested',
            'sensor_action_requested',
            'actions_minor',
            'actions_major',
            'actions_critical',
            'suppress',
            'audit_interval',
            'algorithm',
            'capabilities',
            'host_uuid',
            'sensorgroup_uuid',
            'created_at',
            'updated_at',
        ]

        sensor_fields_analog = [
            'unit_base',
            'unit_modifier',
            'unit_rate',
            't_minor_lower',
            't_minor_upper',
            't_major_lower',
            't_major_upper',
            't_critical_lower',
            't_critical_upper',
        ]

        if rpc_sensor.datatype == 'discrete':
            sensor_fields = sensor_fields_common
        elif rpc_sensor.datatype == 'analog':
            sensor_fields = sensor_fields_common + sensor_fields_analog
        else:
            LOG.error(_("Invalid datatype={}").format(rpc_sensor.datatype))

        if not expand:
            sensor.unset_fields_except(sensor_fields)

        # never expose the id attribute
        sensor.host_id = wtypes.Unset
        sensor.sensorgroup_id = wtypes.Unset

        sensor.links = [
            link.Link.make_link('self', pecan.request.host_url, 'sensors',
                                sensor.uuid),
            link.Link.make_link('bookmark',
                                pecan.request.host_url,
                                'sensors',
                                sensor.uuid,
                                bookmark=True)
        ]
        return sensor