コード例 #1
0
def verify_node_extra(node):
    extra = node.extra or {}
    for key in REQUIRED_ON_EXTRAS:
        if not extra.get(key):
            raise exceptions.MissingParameterValue(
                _("Missing the following OneView data in node's extra: %s.")
                % key
            )

    return extra
コード例 #2
0
def verify_node_properties(node):
    properties = node.properties.get('capabilities', '')
    for key in REQUIRED_ON_PROPERTIES:
        if key not in properties:
            raise exceptions.MissingParameterValue(
                _("Missing the following OneView data in node's "
                  "properties/capabilities: %s.") % key
            )

    return properties
コード例 #3
0
def print_list(objs,
               fields,
               formatters=None,
               sortby_index=0,
               mixed_case_fields=None,
               field_labels=None):
    """Print a list of objects as a table, one row per object.

    :param objs: iterable of :class:`Resource`
    :param fields: attributes that correspond to columns, in order
    :param formatters: `dict` of callables for field formatting
    :param sortby_index: index of the field for sorting table rows
    :param mixed_case_fields: fields corresponding to object attributes that
        have mixed case names (e.g., 'serverId')
    :param field_labels: Labels to use in the heading of the table, default to
        fields.
    """
    formatters = formatters or {}
    mixed_case_fields = mixed_case_fields or []
    field_labels = field_labels or fields
    if len(field_labels) != len(fields):
        raise ValueError(
            _("Field labels list %(labels)s has different number "
              "of elements than fields list %(fields)s"), {
                  'labels': field_labels,
                  'fields': fields
              })

    if sortby_index is None:
        kwargs = {}
    else:
        kwargs = {'sortby': field_labels[sortby_index]}
    pt = prettytable.PrettyTable(field_labels)
    pt.align = 'l'

    for o in objs:
        row = []
        for field in fields:
            if field in formatters:
                row.append(formatters[field](o))
            else:
                if field in mixed_case_fields:
                    field_name = field.replace(' ', '_')
                else:
                    field_name = field.lower().replace(' ', '_')
                data = getattr(o, field_name, '')
                row.append(data)
        pt.add_row(row)

    if six.PY3:
        print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode())
    else:
        print(encodeutils.safe_encode(pt.get_string(**kwargs)))
コード例 #4
0
def capabilities_to_dict(capabilities):
    """Parse the capabilities string into a dictionary.

    :param capabilities: the node capabilities as a formatted string
    :raises: InvalidParameterValue if capabilities is not an string or has
             a malformed value
    """
    capabilities_dict = {}
    if capabilities:
        if not isinstance(capabilities, six.string_types):
            raise exceptions.InvalidParameterValue(
                _("Value of 'capabilities' must be string. Got %s")
                % type(capabilities))
        try:
            for capability in capabilities.split(','):
                key, value = capability.split(':')
                capabilities_dict[key] = value
        except ValueError:
            raise exceptions.InvalidParameterValue(
                _("Malformed capabilities value: %s") % capability
            )
    return capabilities_dict
コード例 #5
0
#    License for the specific language governing permissions and limitations
#    under the License.

import six

from ironicclient import client as ironic_client
from oslo_utils import importutils

from ironic_oneviewd.conf import CONF
from ironic_oneviewd import exceptions
from ironic_oneviewd.openstack.common._i18n import _

hpclient = importutils.try_import('hpOneView.oneview_client')

REQUIRED_ON_PROPERTIES = {
    'server_hardware_type_uri': _("Server Hardware Type URI Required."),
    'server_profile_template_uri': _("Server Profile Template URI required"),
}

REQUIRED_ON_EXTRAS = {
    'server_hardware_uri': _("Server Hardware URI. Required."),
}

IRONIC_API_VERSION = 1


def get_ironic_client():
    """Generate an instance of the Ironic client.

    This method creates an instance of the Ironic client using the OpenStack
    credentials from config file and the ironicclient library.
コード例 #6
0
 def __init__(self, missing):
     self.missing = missing
     msg = _("Missing arguments: %s") % ", ".join(missing)
     super(MissingArgs, self).__init__(msg)
コード例 #7
0
class OneViewErrorStateSettingPowerState(Exception):
    message = _("Get Error State in OneView trying to set power state of "
                "Server Hardware")
コード例 #8
0
class OneViewBootDeviceInvalidError(Exception):
    message = _("The device is not valid to setup the boot order")
コード例 #9
0
class OneViewServerProfileAssociatedError(Exception):
    message = _("There is no Server Profile associated to this Server"
                " Hardware")
コード例 #10
0
class OneViewMaxRetriesExceededError(Exception):
    message = _("Max connection retries to OneView exceeded")
コード例 #11
0
class OneViewServerProfileCloneError(Exception):
    message = _("Error cloning server profile")
コード例 #12
0
class OneViewServerProfileTemplateError(Exception):
    message = _("Server Profile Template not found into driver_info")
コード例 #13
0
class OneViewResourceNotFoundError(Exception):
    message = _("Resource not Found in OneView")
コード例 #14
0
class OneViewNotAuthorizedException(Exception):
    message = _("Unauthorized access to OneView. Check credentials in "
                "ironic.conf.")