コード例 #1
0
def list_racks(args):
    labels = None
    if args.label:
        labels = get_strip_strings_array(str(args.label))

    (rc, result_dict) = rack_mgr.list_racks(labels, args.briefly)

    result = ""
    try:
        SEPARATOR = ","
        labels_array = result_dict['column_titles']
        tags_array = result_dict['column_tags']

        if not args.briefly:
            # find the rack id and remove from both arrays to generate list
            # result without the rack id info.
            rackid_index = tags_array.index('rackid')
            del tags_array[rackid_index]
            del labels_array[rackid_index]

        # create the CSV header line
        header = ""
        for label in labels_array:
            if header:
                header += SEPARATOR
            header += label
        header += "\n"
        result += header

        racks = result_dict['racks']
        for rack in racks:
            # per rack create the CSV line for the rack
            line = ""
            for tag in tags_array:
                if line:
                    line += SEPARATOR
                line += rack[tag] if rack[tag] else ''
            line += "\n"
            result += line
    except KeyError:
        # if a key is missing the error will be in the message
        pass

    # if a message, now output it
    if result_dict['message']:
        result += "\n"
        result += result_dict['message']
    return (rc, result)
コード例 #2
0
def retrieve_rack_metadata(self):
    __method__ = 'tabs.retrieve_rack_metadata'
    rack_meta_data = []

    # retrieve the rack details for the rack passed in (rack_id may be -1 on
    # initial pass)
    (rc, result_dict) = rack_mgr.list_racks(None, False, [self.rack_id])

    if rc != 0:
        messages.error(
            self.request,
            _('Unable to retrieve Operational'
              ' Management inventory information'
              ' for racks.'))
        logging.error(
            '%s, Unable to retrieve Operational Management'
            ' inventory information. A Non-0 return code returned'
            ' from rack_mgr.list_racks.  The return code is:'
            ' %s', __method__, rc)
    else:
        # We should have at least one rack in the results...just return
        # the metadata for the first value
        if len(result_dict['racks']) > 0:
            the_rack = rack.Rack(result_dict['racks'][0])
            counter = 0
            rack_meta_data.append(RackProperty(counter, "Label",
                                               the_rack.name))

            counter += 1
            rack_meta_data.append(
                RackProperty(counter, "Data Center", the_rack.data_center))

            counter += 1
            rack_meta_data.append(RackProperty(counter, "Room", the_rack.room))

            counter += 1
            rack_meta_data.append(RackProperty(counter, "Row", the_rack.row))

            counter += 1
            rack_meta_data.append(
                RackProperty(counter, "Notes", the_rack.notes))

    return rack_meta_data
コード例 #3
0
def create_rack_choices(request):
    __method__ = 'forms.create_rack_choices'
    rack_choices = []
    (rc, result_dict) = rack_mgr.list_racks()
    if rc is not 0:
        # Non-zero RC -- unexpected
        messages.error(
            request,
            _('Unable to retrieve Operational'
              ' Management inventory information for rack extensions.'))
        logging.error(
            "%s: Unable to retrieve Operational Management rack"
            " inventory information. A Non-0 return code returned from"
            " rack_mgr.list_racks.  The return code is: %s.  Details"
            " of the attempt: %s", __method__, rc, result_dict)
    else:
        value = result_dict['racks']
        for s in value:
            rack_choices.append((s['rackid'], s['label']))
    return rack_choices
コード例 #4
0
    def get_object(self):
        __method__ = 'views.AddResourceView.get_object'
        failure_message = str("Unable to retrieve rack information " +
                              " for the resource being added.")
        if "rack_id" in self.kwargs:
            try:
                (rc,
                 result_dict) = rack_mgr.list_racks(None, False,
                                                    [self.kwargs["rack_id"]])
            except Exception as e:
                logging.error(
                    "%s: Exception received trying to retrieve rack"
                    " information.  Exception is: %s", __method__, e)
                exceptions.handle(self.request, failure_message)
                return
        else:
            # This is unexpected.  AddResourceView called with no context of
            # what rack the resource is being added.  Need to display an error
            # message because the dialog will not be primed with required data
            logging.error(
                "%s: AddResourceView called with no rack id"
                " context.", __method__)
            messages.error(self.request, failure_message)
            return

        if rc != 0:
            messages.error(self.request, failure_message)
            return
        else:
            # We should have at least one rack in the results...just return
            # the first value
            if len(result_dict['racks']) > 0:
                return result_dict['racks'][0]
            else:
                logging.error(
                    "%s: list_rack returned no information for"
                    " rack with rack id %s", __method__,
                    self.kwargs["rack_id"])
                messages.error(self.request, failure_message)
                return
コード例 #5
0
    def __init__(self, *args, **kwargs):
        __method__ = 'tabs.InventoryRacksTabs.__init__'
        # This will instantiate the default tab (needed so generic tabs can
        # be created for each rack)

        super(InventoryRacksTabs, self).__init__(*args, **kwargs)
        # to create each generic tab, the tab group and request are needed
        tab_group = self
        request = self._tabs['default_tab'].request

        # objects to hold new list of tabs (classes) and defined_tabs objects
        list_tabs = []  # hold list of new tab classes for the tab group
        defined_tabs = self._tabs.__class__()

        # Retrieve all defined racks (so the list of actual tabs can be
        # created)
        logging.debug("%s: before retrieving rack all racks", __method__)
        (rc, result_dict) = rack_mgr.list_racks()
        if rc != 0:
            messages.error(
                self.request,
                _('Unable to retrieve Operational'
                  ' Management inventory information'
                  ' for racks.'))
            logging.error(
                '%s: Unable to retrieve Operational Management'
                ' inventory information. A Non-0 return code'
                ' returned from rack_mgr.list_racks.  The'
                ' return code is: %s', __method__, rc)
            return

        all_racks = result_dict['racks']

        if len(all_racks) <= 0:
            # Display this message at the warning-level so that it remains
            # visible until dismissed.  If sent at the info-level, it will only
            # display for a few seconds before disapparing automatically.
            messages.warning(
                self.request,
                _('No racks exist in the '
                  'Operational Management '
                  'inventory.'))

        # loop through each rack (creating a defined tab for each)
        for a_rack in all_racks:
            # For each rack, build a defined rack tab
            # create a defined rack tab (instantiating a generic tab)
            defined_rack_tab = GenericTab(tab_group, request)

            # initialize the defined rack tab (with rack information)
            defined_rack_tab.initialize(a_rack["label"], a_rack['rackid'])

            # Add the defined rack tab class to the list of classes in the
            # tab group
            list_tabs.append(defined_rack_tab.__class__)

            # Add the defined rack tab (the new tab) to the list of defined
            # tabs
            defined_tabs[a_rack["label"] + "_tab"] = defined_rack_tab

            logging.debug("%s: creating a new tab for rack with label: %s",
                          __method__, a_rack['label'])

        #  end loop through each rack

        # clear out that default tab from the tab group
        self._tabs.clear()
        # update the tab group with the list of defined tabs
        self._tabs.update(defined_tabs)
        # update tabs with the list of tab classes
        self.tabs = tuple(list_tabs)

        # Add the application URLs to the list of attributes of the tab group.
        # We need those attributes when launching various applications
        self.attrs.update(retrieve_application_links(self, request))
コード例 #6
0
def list_devices(args):
    labels = None
    types = None
    rack_ids = None
    if args.label:
        labels = get_strip_strings_array(str(args.label))
    if args.type:
        types = get_strip_strings_array(str(args.type))
    if args.rack:
        rack_ids = []
        racks = get_strip_strings_array(str(args.rack))
        for rack in racks:
            rack_id = rack_mgr.get_rack_id_by_label(rack)
            if rack_id is not None:
                rack_ids.append(rack_id)

    (rc, result_dict) = resource_mgr.list_resources(labels,
                                                    args.briefly,
                                                    types,
                                                    racks=rack_ids)

    result = ""
    try:
        SEPARATOR = ","
        labels_array = result_dict['column_titles']
        tags_array = result_dict['column_tags']

        if not args.briefly:
            # find the device id and remove from both arrays to generate list
            # result without the device id info.
            deviceid_index = tags_array.index('resourceid')
            del tags_array[deviceid_index]
            del labels_array[deviceid_index]

        # create the CSV header line
        header = ""
        for label in labels_array:
            if header:
                header += SEPARATOR
            header += label
        header += "\n"
        result += header

        rack_id_to_label_map = {}
        rc, rack_dict = rack_mgr.list_racks()
        racks = rack_dict['racks']
        for rack in racks:
            racklabel = rack['label']
            rackid = rack['rackid']
            rack_id_to_label_map[rackid] = racklabel

        devices = result_dict['resources']
        for device in devices:
            # per device create the CSV line for the device
            line = ""
            for tag in tags_array:
                if line:
                    line += SEPARATOR
                if tag == 'rackid':
                    # resolve the rackid to a label
                    rackid = device['rackid']
                    output_rack_label = rack_id_to_label_map[rackid]
                    line += output_rack_label
                elif tag == 'status':
                    line += str(device[tag])
                elif tag == 'statusTime':
                    line += str(device[tag])
                elif tag == 'auth_method':
                    line += str(device[tag])
                elif tag == 'capabilities' or tag == 'roles':
                    for item in device[tag]:
                        line += item + " "
                    line = line.rstrip()
                else:
                    # normal handling
                    line += device[tag] if device[tag] else ''
            line += "\n"
            result += line
    except KeyError:
        # if a key is missing the error will be in the message
        pass

    # if a message, now output it
    if result_dict['message']:
        result += "\n"
        result += result_dict['message']
    return (rc, result)