Exemple #1
0
class GridOSBreakdown(PieStatSet):
    def __init__(self, app, name):
        super(GridOSBreakdown, self).__init__(app, name, None, "slot.os")

        self.os_records = Attribute(app, "os_breakdown")
        self.add_attribute(self.os_records)

        self.os_data = DashboardOSData(app)

        self.color_scheme = PieChartPage.GROUP2
        self.has_total = True

    def get_records(self, session):
        os_records = self.os_records.get(session)
        if not os_records:
            os_records = self.os_data.get_records(session)
            self.os_records.set(session, os_records)
        return os_records

    def do_render(self, session):
        records = self.get_records(session)
        if len(records):
            return super(GridOSBreakdown, self).do_render(session)

    def render_title(self, session):
        return "Slot breakdown by OS"

    def do_get_items(self, session):
        # (index, (name, value))
        return [(i, x) for i, x in enumerate(self.get_records(session))]

    def is_total(self, item):
        _, record = item
        return "total" in record[0]

    def render_item_title(self, session, item):
        _, record = item
        return record[0]

    def get_item_value(self, session, item):
        _, record = item
        return record[1]

    def render_item_value(self, session, item):
        return xml_escape(self.get_item_value(session, item))

    def render_html_title(self, session, item):
        (_, (name, value)) = item
        os, _, state = rpartition(name, " ")
        return "There are %d %s slots with an OS of %s" % (value, state, os)

    def get_legend_class(self, session, this_item):
        items = self.do_get_items(session)
        real_index = 0
        for item in items:
            if item[1][0] is this_item[1][0]:
                break
            if not self.is_total(item):
                real_index += 1
        return "legend%s" % rgb_to_string(*(PieChartPage.color_schemes[self.color_scheme][real_index]))
Exemple #2
0
    def __init__(self, app, name, negotiator):
        super(GroupHelper, self).__init__(app, name)

        self.negotiator = negotiator

        self.info = Attribute(app, "info")
        self.add_attribute(self.info)

        self.results = Attribute(app, "results")
        self.add_attribute(self.results)
Exemple #3
0
class TagObjectFrame(Frame, ModeSet):    
    '''
    This frame houses the view page for a tag, which is a non-traditional object
    in the sense that it does not live in the cumin database.  Given that, we 
    need to make a few changes to the typical functionality.
    '''
    def __init__(self, app, name, cls):
        super(TagObjectFrame, self).__init__(app, name)

        self.cls = cls

        # This will hold the id of the object that should be assigned 
        # to self.object (it is the _id field from a sql table).
        # Both the id and the object are typically determined during
        # the "process" pass before a page is rendered.
        self.id = StringParameter(app, "id")
        self.add_parameter(self.id)

        # This will be given a value during the "process" pass after
        # self.id is determined (lookup by id)
        self.object = Attribute(app, "object")
        self.add_attribute(self.object)       
        self.view = TagObjectView(app, "view", self.object)
        self.add_child(self.view)
        self.icon_href = "resource?name=action-36.png"
        self.tasks = list()

    def init(self):
        super(TagObjectFrame, self).init()
        assert self.cls, self
        for task in self.tasks:
            task.init()

    def get_href(self, session, id):
        branch = session.branch()
        self.id.set(branch, id)
        self.view.show(branch)
        return branch.marshal()

    def do_process(self, session):
        id = self.id.get(session)
        assert id
        obj = self.get_object(session, id)
        self.object.set(session, obj)
        super(TagObjectFrame, self).do_process(session)

    def get_object(self, session, id):
        return self.app.wallaby.get_tag_by_name(id)
Exemple #4
0
class DashboardSummaryStats(DefinitionSet):
    def __init__(self, app, name, cls, columns, title):
        super(DashboardSummaryStats, self).__init__(app, name, None, title)

        self.record = Attribute(app, "totals")
        self.add_attribute(self.record)

        self.columns = columns
        self.sum_columns = [x.name for x in columns]
        self.sum_cls = cls
        self.data = DashboardSumData(app, self.sum_columns, self.sum_cls)

        self.title = None

    def render_title(self, session):
        return self.title

    def do_get_items(self, session):
        return self.columns

    def render_item_title(self, session, item):
        return item.title

    def get_item_value(self, session, item):
        record = self.get_record(session)
        value = record[self.get_item_index(item)] or 0

        # if we want to show an average instead of an aggregate
        if getattr(item, "average", None):
            # the count of records is tucked away past the end of the normal fields
            total = record[len(self.columns)]
            if total:
                value = value / total
            else:
                value = 0
        return value

    def get_item_index(self, item):
        return self.sum_columns.index(item.name)

    def get_record(self, session):
        record = self.record.get(session)
        if not record:
            record = self.data.get_record(session)
            self.record.set(session, record)

        return record
Exemple #5
0
class DashboardPieSummarySet(PieStatSet):
    def __init__(self, app, name, cls, columns, title):
        super(DashboardPieSummarySet, self).__init__(app, name, None, title)

        self.record = Attribute(app, "totals")
        self.add_attribute(self.record)

        # XXX - consider using an ObjectSelector with SumSqlColumns as the data source
        self.columns = columns
        self.sum_columns = [x.name for x in columns]
        self.sum_cls = cls
        self.data = DashboardSumData(app, self.sum_columns, self.sum_cls)

        self.has_total = True
        self.color_scheme = PieChartPage.BLUES

    def do_get_items(self, session):
        return self.columns

    def get_item_index(self, item):
        return self.sum_columns.index(item.name)

    def is_total(self, item):
        index = self.get_item_index(item)
        return index == len(self.sum_columns) - 1

    def render_item_title(self, session, item):
        return item.title

    def get_item_value(self, session, item):
        record = self.get_record(session)
        return record[self.get_item_index(item)] or 0

    def get_legend_class(self, session, item):
        index = self.get_item_index(item)
        return "legend%s" % rgb_to_string(*(PieChartPage.color_schemes[self.color_scheme][index]))

    def get_record(self, session):
        record = self.record.get(session)
        if not record:
            record = self.data.get_record(session)
            self.record.set(session, record)

        return record
Exemple #6
0
    def __init__(self, app, name):
        super(GridOSBreakdown, self).__init__(app, name, None, "slot.os")

        self.os_records = Attribute(app, "os_breakdown")
        self.add_attribute(self.os_records)

        self.os_data = DashboardOSData(app)

        self.color_scheme = PieChartPage.GROUP2
        self.has_total = True
Exemple #7
0
    def __init__(self, app, name, cls, columns, title):
        super(DashboardSummaryStats, self).__init__(app, name, None, title)

        self.record = Attribute(app, "totals")
        self.add_attribute(self.record)

        self.columns = columns
        self.sum_columns = [x.name for x in columns]
        self.sum_cls = cls
        self.data = DashboardSumData(app, self.sum_columns, self.sum_cls)

        self.title = None
Exemple #8
0
    def __init__(self, app, name, cls, columns, title):
        super(DashboardPieSummarySet, self).__init__(app, name, None, title)

        self.record = Attribute(app, "totals")
        self.add_attribute(self.record)

        # XXX - consider using an ObjectSelector with SumSqlColumns as the data source
        self.columns = columns
        self.sum_columns = [x.name for x in columns]
        self.sum_cls = cls
        self.data = DashboardSumData(app, self.sum_columns, self.sum_cls)

        self.has_total = True
        self.color_scheme = PieChartPage.BLUES
Exemple #9
0
    def __init__(self, app, name, cls):
        super(TagObjectFrame, self).__init__(app, name)

        self.cls = cls

        # This will hold the id of the object that should be assigned 
        # to self.object (it is the _id field from a sql table).
        # Both the id and the object are typically determined during
        # the "process" pass before a page is rendered.
        self.id = StringParameter(app, "id")
        self.add_parameter(self.id)

        # This will be given a value during the "process" pass after
        # self.id is determined (lookup by id)
        self.object = Attribute(app, "object")
        self.add_attribute(self.object)       
        self.view = TagObjectView(app, "view", self.object)
        self.add_child(self.view)
        self.icon_href = "resource?name=action-36.png"
        self.tasks = list()
Exemple #10
0
    def __init__(self, app, name, cls):
        super(ObjectQmfSelector, self).__init__(app, name, cls)

        self.update_enabled = True
        self.table.update_enabled = False

        self.show_details = Parameter(app, "sd")
        self.add_parameter(self.show_details)

        self.status_msg = Attribute(app, "status")
        self.add_attribute(self.status_msg)

        self.details = QmfDetails(app, "details", self.status_msg)
        self.add_child(self.details)

        self.script = self.ObjectQmfSelectorScript(app, "script")
        self.script.comments_enabled = False
        self.add_child(self.script)

        self.error_tmpl = WidgetTemplate(self, "error_html")
        self.loading_tmpl = WidgetTemplate(self, "deferred_html")
Exemple #11
0
class GroupHelper(Widget):
    def __init__(self, app, name, negotiator):
        super(GroupHelper, self).__init__(app, name)

        self.negotiator = negotiator

        self.info = Attribute(app, "info")
        self.add_attribute(self.info)

        self.results = Attribute(app, "results")
        self.add_attribute(self.results)

    def get_config_info(self, session):
        info = self.info.get(session)

        if not info:
            negotiator = self.negotiator.get(session)
            info = self.get_group_info(session, negotiator)
            self.info.set(session, info)

        return info

    def get_group_info(self, session, negotiator):
        results = self.app.model.get_negotiator_group_names(negotiator)
        groups = results.data
        info = dict()

        if not results.exception:
            try:
                groups = self.split_group_names(groups)
            except:
                groups = []

            if groups:
                for group in groups:
                    info[group] = dict()

        self.results.set(session, results)

        return info

    def get_results(self, session):
        return self.get_config_info(session)

    def has_child(self, session, group):
        info = self.get_config_info(session)

        try:
            return info[group]['has_child']
        except KeyError:
            info[group]['has_child'] = False
            for key in info:
                if key.startswith(group+"."):
                    info[group]['has_child'] = True
                    break

        self.info.set(session, info)
        return info[group]['has_child']

    def get_parent(self, session, group):
        info = self.get_config_info(session)

        try:
            return info[group]['parent']
        except KeyError:
            parent = ""
            for key in info:
                if key != group and group.startswith(key):
                    if len(key) > len(parent):
                        parent = key

            info[group]['parent'] = parent

        self.info.set(session, info)
        return info[group]['parent']

    def get_siblings(self, session, node):
        info = self.get_config_info(session)

        siblings = list()
        (ng, _, _) = rpartition(node, ".")
        for group in info:
            (g, _, _) = rpartition(group, ".")
            if g == ng:
                siblings.append(group)

        return siblings

    def get_group_names(self, session):
        info = self.get_config_info(session)
        return list(info)

    def split_group_names(self, group_string):
        g_string = group_string.replace(", ", ",")
        if not "," in g_string:
            return g_string.split()
        return  g_string.split(",")

    def get_config_for_groups(self, session, config, groups):
        info = self.get_config_info(session)

        needed_groups = [x for x in groups if not config in info[x]]

        if len(needed_groups) > 0:
            negotiator = self.negotiator.get(session)

            dynamic_results, static_results = self.app.model.get_negotiator_config_values(negotiator, needed_groups, config)
            if(config == "GROUP_QUOTA_DYNAMIC"):
                raw_configs = dynamic_results.data
            else:
                raw_configs = static_results.data

            try:
                for config in raw_configs:
                    for group in raw_configs[config]:
                        if raw_configs[config][group].error:
                            info[group][config] = ""  ##raw_configs[config][group].error
                        elif raw_configs[config][group].got_data:
                            info[group][config] = raw_configs[config][group].data['Value']
            except:
                log.debug("Problem getting group config info", exc_info=True)

            self.info.set(session, info)
        return info

    def get_config_value(self, session, group, config):
        info = self.get_config_info(session)
        try:
            return info[group][config]
        except KeyError:
            try:
                info = self.get_config_for_groups(session, config, [group])
                return info[group][config]
            except:
                return self.loading_indicator()

    def loading_indicator(self):
        return  "<em>loading</em>"

    def get_unclaimed_dyn_quota(self, session, groups):
        info = self.get_config_info(session)
        total = 0.0
        for group in groups:
            try:
                value = info[group]["GROUP_QUOTA_DYNAMIC"]
            except KeyError:
                info = self.get_config_for_groups(session, "GROUP_QUOTA_DYNAMIC", [group])
            try:
                total = total + float(value)
            except:
                pass

        val = 1.0 - total
        val = max(0, val)
        val = min(1.0, val)
        return val
Exemple #12
0
class ObjectQmfSelector(ObjectSelector):
    def __init__(self, app, name, cls):
        super(ObjectQmfSelector, self).__init__(app, name, cls)

        self.update_enabled = True
        self.table.update_enabled = False

        self.show_details = Parameter(app, "sd")
        self.add_parameter(self.show_details)

        self.status_msg = Attribute(app, "status")
        self.add_attribute(self.status_msg)

        self.details = QmfDetails(app, "details", self.status_msg)
        self.add_child(self.details)

        self.script = self.ObjectQmfSelectorScript(app, "script")
        self.script.comments_enabled = False
        self.add_child(self.script)

        self.error_tmpl = WidgetTemplate(self, "error_html")
        self.loading_tmpl = WidgetTemplate(self, "deferred_html")

    def init(self):
        super(ObjectQmfSelector, self).init()

        assert self.get_qmf_results

    def do_render(self, session):
        tmpl = self.error_tmpl
        title = self.render_title(session)

        store = self.get_qmf_results(session)
        self.status_msg.set(session, store.status)
        error = None

        if store.exception:
            error = store.exception
            if "is unknown" in str(error):
                error = "%s are not available at this time." % title
                self.status_msg.set(session, store.exception)
        else:
            if store.status is None:
                error = "Loading"
                tmpl = self.loading_tmpl
            else:
                values = self.table.get_data_values(session)
                count = self.table.adapter.get_count(values)
                if count == 0:
                    error = "There are no %s" % title

                    if store.status == "OK":
                        details = "The call to get the data succeeded, but no results were returned."
                    else:
                        details = "The call status is <span>%s</span>" % store.status
                    self.status_msg.set(session, details)

        if error:
            writer = Writer()
            tmpl.render(writer, session, "%s" % error)
            return writer.to_string()

        return super(ObjectQmfSelector, self).do_render(session)

    def render_error_msg(self, session, msg):
        return msg

    def render_script(self, session):
        return self.script.render(session)

    class ObjectQmfSelectorScript(Widget):
        def render_table_id(self, session):
            return self.parent.table.render_id(session)

        def render_selector_id(self, session):
            return self.parent.render_id(session)