ironic_inspector.common package

Submodules

ironic_inspector.common.context module

class ironic_inspector.common.context.RequestContext(is_public_api=False, **kwargs)[source]

Bases: oslo_context.context.RequestContext

Extends security contexts from the oslo.context library.

classmethod from_dict(values, **kwargs)[source]

Construct a context object from a provided dictionary.

classmethod from_environ(environ, **kwargs)[source]

Load a context object from a request environment.

If keyword arguments are provided then they override the values in the request environment.

Parameters

environ (dict) – The environment dictionary associated with a request.

to_policy_values()[source]

A dictionary of context attributes to enforce policy with.

oslo.policy enforcement requires a dictionary of attributes representing the current logged in user on which it applies policy enforcement. This dictionary defines a standard list of attributes that should be available for enforcement across services.

It is expected that services will often have to override this method with either deprecated values or additional attributes used by that service specific policy.

ironic_inspector.common.coordination module

class ironic_inspector.common.coordination.Coordinator(prefix=None)[source]

Bases: object

Tooz coordination wrapper.

get_lock(uuid)[source]

Get lock for node uuid.

get_members()[source]

Get members in the service group.

group_name = b'ironic_inspector.service_group'
join_group()[source]

Join service group.

leave_group()[source]

Leave service group

lock_prefix = 'ironic_inspector.'
run_elect_coordinator()[source]

Trigger a new leader election.

start(heartbeat=True)[source]

Start coordinator.

Parameters

heartbeat – Whether spawns a new thread to keep heartbeating with the tooz backend. Unless there is periodic task to do heartbeat manually, it should be always set to True.

stop()[source]

Disconnect from coordination backend and stop heartbeat.

ironic_inspector.common.coordination.get_coordinator(prefix=None)[source]

ironic_inspector.common.ironic module

exception ironic_inspector.common.ironic.NotFound(node_ident, code=404, *args, **kwargs)[source]

Bases: ironic_inspector.utils.Error

Node not found in Ironic.

ironic_inspector.common.ironic.call_with_retries(func, *args, **kwargs)[source]

Call an ironic client function retrying all errors.

If an ironic client exception is raised, try calling the func again, at most 5 times, waiting 1 sec between each call. If on the 5th attempt the func raises again, the exception is propagated to the caller.

ironic_inspector.common.ironic.capabilities_to_dict(caps)[source]

Convert the Node’s capabilities into a dictionary.

ironic_inspector.common.ironic.check_provision_state(node)[source]

Sanity checks the provision state of the node.

Parameters

node – An API client returned node object describing the baremetal node according to ironic’s node data model.

Returns

None if no action is to be taken, True if the power node state should not be modified.

Raises

Error on an invalid state being detected.

ironic_inspector.common.ironic.dict_to_capabilities(caps_dict)[source]

Convert a dictionary into a string with the capabilities syntax.

ironic_inspector.common.ironic.get_client(token=None)[source]

Get an ironic client connection.

ironic_inspector.common.ironic.get_ipmi_address(node)[source]

Get the BMC address defined in node.driver_info dictionary

Possible names of BMC address value examined in order of list [‘ipmi_address’] + CONF.ipmi_address_fields. The value could be an IP address or a hostname. DNS lookup performed for the first non empty value.

The first valid BMC address value returned along with it’s v4 and v6 IP addresses.

Parameters

node – Node object with defined driver_info dictionary

Returns

tuple (ipmi_address, ipv4_address, ipv6_address)

ironic_inspector.common.ironic.get_node(node_id, ironic=None, **kwargs)[source]

Get a node from Ironic.

Parameters
  • node_id – node UUID or name.

  • ironic – ironic client instance.

  • kwargs – arguments to pass to Ironic client.

Raises

Error on failure

ironic_inspector.common.ironic.lookup_node(macs=None, bmc_addresses=None, introspection_data=None, ironic=None)[source]

Lookup a node in the ironic database.

ironic_inspector.common.ironic.lookup_node_by_bmc_addresses(addresses, introspection_data=None, ironic=None, fail=False)[source]

Find a node by its BMC address.

ironic_inspector.common.ironic.lookup_node_by_macs(macs, introspection_data=None, ironic=None, fail=False)[source]

Find a node by its MACs.

ironic_inspector.common.ironic.reset_ironic_session()[source]

Reset the global session variable.

Mostly useful for unit tests.

ironic_inspector.common.keystone module

ironic_inspector.common.keystone.add_auth_options(options, service_type)[source]
ironic_inspector.common.keystone.get_adapter(group, **adapter_kwargs)[source]
ironic_inspector.common.keystone.get_endpoint(group, **kwargs)[source]
ironic_inspector.common.keystone.get_session(group)[source]
ironic_inspector.common.keystone.register_auth_opts(group, service_type)[source]

ironic_inspector.common.lldp_parsers module

Names and mapping functions used to map LLDP TLVs to name/value pairs

class ironic_inspector.common.lldp_parsers.LLDPBasicMgmtParser(nv=None)[source]

Bases: ironic_inspector.common.lldp_parsers.LLDPParser

Class to handle parsing of 802.1AB Basic Management set

This class will also handle 802.1Q and 802.3 OUI TLVs.

add_capabilities(struct, name, data)[source]

Handle LLDP_TLV_SYS_CAPABILITIES

add_mgmt_address(struct, name, data)[source]

Handle LLDP_TLV_MGMT_ADDRESS

There can be multiple Mgmt Address TLVs, store in list.

handle_org_specific_tlv(struct, name, data)[source]

Handle Organizationally Unique ID TLVs

This class supports 802.1Q and 802.3 OUI TLVs.

See http://www.ieee802.org/1/pages/802.1Q-2014.html, Annex D and http://standards.ieee.org/about/get/802/802.3.html

class ironic_inspector.common.lldp_parsers.LLDPParser(node_info, nv=None)[source]

Bases: object

Base class to handle parsing of LLDP TLVs

Each class that inherits from this base class must provide a parser map. Parser maps are used to associate a LLDP TLV with a function handler and arguments necessary to parse the TLV and generate one or more name/value pairs. Each LLDP TLV maps to a tuple with the following fields:

function - handler function to generate name/value pairs

construct - name of construct definition for TLV

name - user-friendly name of TLV. For TLVs that generate only one name/value pair this is the name used

len_check - boolean indicating if length check should be done on construct

It’s valid to have a function handler of None, this is for TLVs that are not mapped to a name/value pair(e.g.LLDP_TLV_TTL).

Add name/value pairs for TLV Dot1_LinkAggregationId

This is in base class since it can be used by both dot1 and dot3.

add_nested_value(struct, name, data)[source]

Add a single nested name/value pair to the dict

add_single_value(struct, name, data)[source]

Add a single name/value pair to the nv dict

append_value(name, value)[source]

Add value to a list mapped to name

parse_tlv(tlv_type, data)[source]

Parse TLVs from mapping table

This functions takes the TLV type and the raw data for this TLV and gets a tuple from the parser_map. The construct field in the tuple contains the construct lib definition of the TLV which can be parsed to access individual fields. Once the TLV is parsed, the handler function for each TLV will store the individual fields as name/value pairs in nv_dict.

If the handler function does not exist, then no name/value pairs will be added to nv_dict, but since the TLV was handled, True will be returned.

Param

tlv_type - type identifier for TLV

Param

data - raw TLV value

Returns

True if TLV in parser_map and data is valid, otherwise False.

set_value(name, value)[source]

Set name value pair in dictionary

The value for a name should not be changed if it exists.

class ironic_inspector.common.lldp_parsers.LLDPdot1Parser(node_info, nv=None)[source]

Bases: ironic_inspector.common.lldp_parsers.LLDPParser

Class to handle parsing of 802.1Q TLVs

add_dot1_port_protocol_vlan(struct, name, data)[source]

Handle dot1_PORT_PROTOCOL_VLANID

add_dot1_protocol_identities(struct, name, data)[source]

Handle dot1_PROTOCOL_IDENTITY

There can be multiple protocol ids TLVs, store in list

add_dot1_vlans(struct, name, data)[source]

Handle dot1_VLAN_NAME

There can be multiple vlan TLVs, add dictionary entry with id/vlan to list.

class ironic_inspector.common.lldp_parsers.LLDPdot3Parser(node_info, nv=None)[source]

Bases: ironic_inspector.common.lldp_parsers.LLDPParser

Class to handle parsing of 802.3 TLVs

add_dot3_macphy_config(struct, name, data)[source]

Handle dot3_MACPHY_CONFIG_STATUS

ironic_inspector.common.lldp_tlvs module

Link Layer Discovery Protocol TLVs

ironic_inspector.common.lldp_tlvs.bytes_to_int(obj)[source]

Convert bytes to an integer

Param

obj - array of bytes

ironic_inspector.common.lldp_tlvs.get_autoneg_cap(pmd)[source]

Get autonegotiated capability strings

This returns a list of capability strings from the Physical Media Dependent (PMD) capability bits.

Parameters

pmd – PMD bits

Returns

Sorted ist containing capability strings

ironic_inspector.common.lldp_tlvs.mapping_for_enum(mapping)[source]

Return tuple used for keys as a dict

Param

mapping - dict with tuple as keys

ironic_inspector.common.lldp_tlvs.mapping_for_switch(mapping)[source]

Return dict from values

Param

mapping - dict with tuple as keys

ironic_inspector.common.locking module

class ironic_inspector.common.locking.BaseLock[source]

Bases: object

abstract acquire(blocking=True)[source]

Acquire lock.

abstract is_locked()[source]

Return lock status

abstract release()[source]

Release lock.

class ironic_inspector.common.locking.InternalLock(uuid)[source]

Bases: ironic_inspector.common.locking.BaseLock

Locking mechanism based on threading.Semaphore.

acquire(blocking=True)[source]

Acquire lock.

is_locked()[source]

Return lock status

release()[source]

Release lock.

class ironic_inspector.common.locking.ToozLock(lock)[source]

Bases: ironic_inspector.common.locking.BaseLock

Wrapper on tooz locks.

acquire(blocking=True)[source]

Acquire lock.

is_locked()[source]

Return lock status

release()[source]

Release lock.

ironic_inspector.common.locking.get_lock(uuid)[source]

ironic_inspector.common.rpc module

ironic_inspector.common.rpc.get_client(topic=None)[source]

Get a RPC client instance.

Parameters

topic – The topic of the message will be delivered to. This argument is ignored if CONF.standalone is True.

ironic_inspector.common.rpc.get_server(endpoints)[source]

Get a RPC server instance.

ironic_inspector.common.rpc.init()[source]

ironic_inspector.common.rpc_service module

class ironic_inspector.common.rpc_service.RPCService(host)[source]

Bases: oslo_service.service.Service

start()[source]

Start a service.

stop()[source]

Stop a service.

Parameters

graceful – indicates whether to wait for all threads to finish or terminate them instantly

ironic_inspector.common.service_utils module

ironic_inspector.common.service_utils.prepare_service(args=None)[source]

ironic_inspector.common.swift module

class ironic_inspector.common.swift.SwiftAPI[source]

Bases: object

API for communicating with Swift.

create_object(object, data, container=None, headers=None)[source]

Uploads a given string to Swift.

Parameters
  • object – The name of the object in Swift

  • data – string data to put in the object

  • container – The name of the container for the object. Defaults to the value set in the configuration options.

  • headers – the headers for the object to pass to Swift

Returns

The Swift UUID of the object

Raises

utils.Error, if any operation with Swift fails.

get_object(object, container=None)[source]

Downloads a given object from Swift.

Parameters
  • object – The name of the object in Swift

  • container – The name of the container for the object. Defaults to the value set in the configuration options.

Returns

Swift object

Raises

utils.Error, if the Swift operation fails.

ironic_inspector.common.swift.get_introspection_data(uuid, suffix=None)[source]

Downloads introspection data from Swift.

Parameters
  • uuid – UUID of the Ironic node that the data came from

  • suffix – optional suffix to add to the underlying swift object name

Returns

Swift object with the introspection data

ironic_inspector.common.swift.reset_swift_session()[source]

Reset the global session variable.

Mostly useful for unit tests.

ironic_inspector.common.swift.store_introspection_data(data, uuid, suffix=None)[source]

Uploads introspection data to Swift.

Parameters
  • data – data to store in Swift

  • uuid – UUID of the Ironic node that the data came from

  • suffix – optional suffix to add to the underlying swift object name

Returns

name of the Swift object that the data is stored in

Module contents