Пример #1
0
 def __init__(self, name, domain, **kwargs):
     if name is None:
         raise KeyError("'name' should not be 'None'")
     self.name = name
     self.domain = domain
     self.profile = kwargs['profile'] if 'profile' in kwargs else None
     self.feed = kwargs['feed'] if 'feed' in kwargs else None
     self.db_id = kwargs['db_id'] if 'db_id' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             # check the properties first, so it will not overwrite core attributes
             if getattr(self, attributize_string(property), None) is None:
                 setattr(self, attributize_string(property), kwargs['properties'][property])
Пример #2
0
 def __init__(self, name, provider=None, appliance=None, **kwargs):
     Navigatable.__init__(self, appliance=appliance)
     if name is None:
         raise KeyError("'name' should not be 'None'")
     self.name = name
     self.provider = provider
     self.product = kwargs['product'] if 'product' in kwargs else None
     self.feed = kwargs['feed'] if 'feed' in kwargs else None
     self.db_id = kwargs['db_id'] if 'db_id' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             # check the properties first, so it will not overwrite core attributes
             if getattr(self, attributize_string(property), None) is None:
                 setattr(self, attributize_string(property), kwargs['properties'][property])
Пример #3
0
 def __init__(self, name, provider=None, appliance=None, **kwargs):
     Navigatable.__init__(self, appliance=appliance)
     if name is None:
         raise KeyError("'name' should not be 'None'")
     self.name = name
     self.provider = provider
     self.product = kwargs['product'] if 'product' in kwargs else None
     self.feed = kwargs['feed'] if 'feed' in kwargs else None
     self.db_id = kwargs['db_id'] if 'db_id' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             # check the properties first, so it will not overwrite core attributes
             if getattr(self, attributize_string(property), None) is None:
                 setattr(self, attributize_string(property),
                         kwargs['properties'][property])
Пример #4
0
 def load(self):
     self._keys = []
     key_values = []
     for row in sel.elements(self.ROWS, root=self._entry):
         tds = sel.elements('./td', root=row)
         key = tds[0]
         klass = sel.get_attribute(key, 'class')
         if klass and 'label' in klass:
             # Ordinary field
             key_id = attributize_string(sel.text_sane(key))
             value = tuple(tds[1:])
             try:
                 rowspan = int(sel.get_attribute(key, 'rowspan'))
             except (ValueError, TypeError):
                 rowspan = None
             if rowspan:
                 key_values.append((key, key_id, [value]))
             else:
                 key_values.append((key, key_id, value))
         else:
             # value of last key_values should be extended
             key_values[-1][2].append(tuple(tds))
     for key, key_id, value in key_values:
         value_object = process_field(value)
         setattr(self, key_id, value_object)
         self._keys.append(key_id)
Пример #5
0
 def list_data_table(self, raw=False):
     """Returns list of data from table"""
     self.load_chart_reference()
     data = []
     if self.has_warning:
         return data
     table = Table(table_locator="//table[contains(@class, 'table')]")
     headers = []
     for header in table.headers:
         headers.append(attributize_string(sel.text_sane(header)))
     for row in table.rows():
         _data = {}
         for header in headers:
             if header == "datetime":
                 _datetime = sel.text_sane(row[header])
                 if raw:
                     _data[header] = _datetime
                 else:
                     # sample 10/19/16 15:23:38 UTC
                     _data['timestamp'] = self._timestamp(
                         datetime.strptime(_datetime,
                                           "%m/%d/%y %H:%M:%S %Z"))
             else:
                 _value = round_double(value_of(sel.text_sane(row[header])))
                 _data[header] = None if _value == '' else _value
         data.append(_data)
     return data
Пример #6
0
 def list_data_table(self, raw=False):
     """Returns list of data from table"""
     self.load_chart_reference()
     data = []
     if self.has_warning:
         return data
     table = Table(table_locator="//table[contains(@class, 'table')]")
     headers = []
     for header in table.headers:
         headers.append(attributize_string(sel.text_sane(header)))
     for row in table.rows():
         _data = {}
         for header in headers:
             if header == "datetime":
                 _datetime = sel.text_sane(row[header])
                 if raw:
                     _data[header] = _datetime
                 else:
                     # sample 10/19/16 15:23:38 UTC
                     _data['timestamp'] = self._timestamp(
                         datetime.strptime(_datetime, "%m/%d/%y %H:%M:%S %Z"))
             else:
                 _value = round_double(value_of(sel.text_sane(row[header])))
                 _data[header] = None if _value == '' else _value
         data.append(_data)
     return data
Пример #7
0
 def load(self):
     self._keys = []
     key_values = []
     if sel.is_displayed(self.MULTIKEY_LOC, root=self._entry):
         # WE cannot process this kind of table yet.
         return
     for row in sel.elements(self.ROWS, root=self._entry):
         tds = sel.elements('./td', root=row)
         key = tds[0]
         klass = sel.get_attribute(key, 'class')
         if klass and 'label' in klass:
             # Ordinary field
             key_id = attributize_string(sel.text_sane(key))
             value = tuple(tds[1:])
             try:
                 rowspan = int(sel.get_attribute(key, 'rowspan'))
             except (ValueError, TypeError):
                 rowspan = None
             if rowspan:
                 key_values.append((key, key_id, [value]))
             else:
                 key_values.append((key, key_id, value))
         else:
             # value of last key_values should be extended
             key_values[-1][2].append(tuple(tds))
     for key, key_id, value in key_values:
         value_object = process_field(value)
         setattr(self, key_id, value_object)
         self._keys.append(key_id)
Пример #8
0
    def _reload(self):
        self._legends = []
        self._elements = []
        self._lines = []
        self.search_box = TopologySearchBox()
        self.display_names = TopologyDisplayNames()
        # load elements
        # we have to wait few seconds, initial few seconds elements are moving
        if len(sel.elements(self.ELEMENTS)) > 0:
            self._el_ref = TopologyElement(o=self, element=sel.elements(self.ELEMENTS)[-1])
            wait_for(lambda: self._is_el_movement_stopped(), delay=2, num_sec=30)

            for element in sel.elements(self.ELEMENTS):
                self._elements.append(TopologyElement(o=self, element=element))
            # load lines
            for line in sel.elements(self.LINES):
                self._lines.append(TopologyLine(element=line))
        # load legends
        # remove old legends
        for legend_id in self._legends:
            try:
                delattr(self, legend_id)
            except AttributeError:
                pass
        # load available legends
        for legend in sel.elements(self.LEGENDS):
            legend_text = sel.text_sane(legend.find_element_by_tag_name('label'))
            legend_id = attributize_string(legend_text.strip())
            legend_object = TopologyLegend(name=legend_text, element=legend)
            setattr(self, legend_id, legend_object)
            self._legends.append(legend_id)
Пример #9
0
 def list_data_chart(self, raw=False):
     """Returns list of data from chart"""
     self.load_chart_reference()
     data = []
     lines = []
     if self.has_warning:
         return data
     if self.num_legend(only_enabled=True) == 0:
         raise RuntimeError("There is no legend enabled!")
     for _line in self._c_lines:
         if 'opacity: 1' in _line.get_attribute('style'):
             lines.append(_line)
     line = lines[0]
     # %m/%d/%Y %H:%M:%S %Z
     if self.option.get_interval(force_visible_text=True) == Option.IN_HOURLY:
         _date = self.option.get_date()
         date_format = "{} {}:00 UTC".format(_date, "{}")
     elif self.option.get_interval(force_visible_text=True) == Option.IN_MOST_RECENT_HOUR:
         _date = self.option.get_range().split(" ", 1)[0].split("-")
         date_format = "{}/{}/{} {} UTC".format(_date[1], _date[2], _date[0], "{}")
     elif self.option.get_interval(force_visible_text=True) == Option.IN_DAILY:
         _year = self.option.get_date().split('/')[-1]
         date_format = "{}/{} 00:00:00 UTC".format("{}", _year)
     else:
         raise RuntimeError("Unsupported interval:{}"
                            .format(self.option.get_interval(force_visible_text=True)))
     if raw:
         time_format = "datetime"
     else:
         time_format = "timestamp"
     for cir_index in range(len(line.find_elements_by_tag_name("circle"))):
         tp = self._get_tooltip(lines=lines, circle_index=cir_index)
         # NOTE: If all data in ZERO value(bottom of x axis),
         # tooltip is not working via "move_to_element", returns ''
         if tp and not sel.text_content(tp) == '':
             _date = sel.text_content(tp.find_element_by_tag_name('th'))
             if not raw:
                 # Format: %m/%d/%Y %H:%M:%S %Z
                 _date = self._timestamp(
                     datetime.strptime(date_format.format(_date), "%m/%d/%Y %H:%M:%S %Z"))
             _data = {time_format: _date}
             # ignore duplicate values for timestamp
             if not next((item for item in data if item.get(time_format) == _date), None):
                 for _row in tp.find_elements_by_xpath(
                         "//tr[contains(@class, 'c3-tooltip-name')]"):
                     _key = attributize_string(
                         sel.text_content(_row.find_element_by_class_name('name')))
                     # changing legend name to full name with pre defined map
                     _key = self._get_ui_key(_key)
                     _value = round_double(value_of(
                         sel.text_content(_row.find_element_by_class_name('value'))))
                     _data[_key] = _value
                 data.append(_data)
     return data
Пример #10
0
 def __init__(self, name, provider=None, **kwargs):
     if name is None:
         raise KeyError("'name' should not be 'None'")
     self.name = name
     self.provider = provider
     self.product = kwargs['product'] if 'product' in kwargs else None
     self.hostname = kwargs['hostname'] if 'hostname' in kwargs else None
     self.feed = kwargs['feed'] if 'feed' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             setattr(self, attributize_string(property), kwargs['properties'][property])
Пример #11
0
 def __init__(self, name, server, provider=None, **kwargs):
     if name is None:
         raise KeyError("'name' should not be 'None'")
     if not isinstance(server, MiddlewareServer):
         raise KeyError("'server' should be an instance of MiddlewareServer")
     self.name = name
     self.provider = provider
     self.server = server
     self.nativeid = kwargs['nativeid'] if 'nativeid' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             setattr(self, attributize_string(property), kwargs['properties'][property])
Пример #12
0
 def __init__(self, name, provider=None, **kwargs):
     if name is None:
         raise KeyError("'name' should not be 'None'")
     self.name = name
     self.provider = provider
     self.product = kwargs['product'] if 'product' in kwargs else None
     self.hostname = kwargs['hostname'] if 'hostname' in kwargs else None
     self.feed = kwargs['feed'] if 'feed' in kwargs else None
     if 'properties' in kwargs:
         for property in kwargs['properties']:
             setattr(self, attributize_string(property),
                     kwargs['properties'][property])
Пример #13
0
 def reload(self):
     for key in self._keys:
         try:
             delattr(self, key)
         except AttributeError:
             pass
     self._keys = []
     self._object.load_details(refresh=True)
     for header in sel.elements(self.HEADERS):
         header_text = sel.text_sane(header)
         header_id = attributize_string(header_text)
         table_object = SummaryTable(self._object, header_text, header)
         setattr(self, header_id, table_object)
         self._keys.append(header_id)
Пример #14
0
 def reload(self):
     for key in self._keys:
         try:
             delattr(self, key)
         except AttributeError:
             pass
     self._keys = []
     self._object.load_details(refresh=True)
     for header in sel.elements(self.HEADERS):
         header_text = sel.text_sane(header)
         header_id = attributize_string(header_text)
         table_object = SummaryTable(self._object, header_text, header)
         setattr(self, header_id, table_object)
         self._keys.append(header_id)
Пример #15
0
 def __init__(self, name, server, provider=None, appliance=None, **kwargs):
     Navigatable.__init__(self, appliance=appliance)
     if name is None:
         raise KeyError("'name' should not be 'None'")
     if not isinstance(server, MiddlewareServer):
         raise KeyError("'server' should be an instance of MiddlewareServer")
     self.name = name
     self.provider = provider
     self.server = server
     self.nativeid = kwargs["nativeid"] if "nativeid" in kwargs else None
     self.messaging_type = kwargs["messaging_type"] if "messaging_type" in kwargs else None
     if "properties" in kwargs:
         for property in kwargs["properties"]:
             setattr(self, attributize_string(property), kwargs["properties"][property])
     self.db_id = kwargs["db_id"] if "db_id" in kwargs else None
Пример #16
0
 def _reload(self, force_reload=False):
     if not force_reload and len(self._charts) > 0:
         return
     # remove old charts
     for chart_id in self._charts:
         try:
             delattr(self, chart_id)
         except AttributeError:
             pass
     self._charts = []
     # load available charts
     for chart in sel.elements(CHARTS):
         chart_text = sel.text_sane(chart.find_element_by_class_name('card-pf-title'))
         chart_id = attributize_string(chart_text.strip())
         chart_object = LineChart(chart_id=chart_id, name=chart_text, utilization_object=self)
         setattr(self, chart_id, chart_object)
         self._charts.append(chart_id)
Пример #17
0
 def _reload(self, force_reload=False):
     if not force_reload and len(self._charts) > 0:
         return
     # remove old charts
     for chart_id in self._charts:
         try:
             delattr(self, chart_id)
         except AttributeError:
             pass
     self._charts = []
     # load available charts
     for chart in sel.elements(CHARTS):
         chart_text = sel.text_sane(
             chart.find_element_by_class_name('card-pf-title'))
         chart_id = attributize_string(chart_text.strip())
         chart_object = LineChart(chart_id=chart_id,
                                  name=chart_text,
                                  utilization_object=self)
         setattr(self, chart_id, chart_object)
         self._charts.append(chart_id)
Пример #18
0
 def _reload(self):
     self._legends = []
     self.search_box = TopologySearchBox()
     self.display_names = TopologyDisplayNames()
     # load elements
     # we have to wait few seconds, initial few seconds elements are moving
     self.reload_elements()
     # load legends
     # remove old legends
     for legend_id in self._legends:
         try:
             delattr(self, legend_id)
         except AttributeError:
             pass
     # load available legends
     for legend in sel.elements(self.LEGENDS):
         legend_text = sel.text_sane(legend.find_element_by_tag_name('label'))
         legend_id = attributize_string(legend_text.strip())
         legend_object = TopologyLegend(name=legend_text, element=legend)
         setattr(self, legend_id, legend_object)
         self._legends.append(legend_id)
Пример #19
0
 def load_chart_reference(self, force_reload=False):
     """Takes current page to chart detailed page"""
     if self.is_on_chart_page and not force_reload:
         return
     if not self.is_on_chart_page:
         self._utz_object.reload()
     self._c_object = None
     if not self.is_on_chart_page:
         root_objs = sel.elements(CHARTS)
         for root_obj in root_objs:
             if sel.text_sane(
                     root_obj.find_element_by_tag_name('h2')) == self.name:
                 root_obj.find_element_by_tag_name("a").click()
                 sel.wait_for_ajax()
                 self._c_object = sel.element(CHARTS)
                 break
     else:
         self._c_object = sel.element(CHARTS)
     if self._c_object is None:
         raise RuntimeError("Unable to get detail page of '{}'".format(
             self.name))
     # remove old legends and load new legends
     for legend_id in self._legends:
         try:
             delattr(self, legend_id)
         except AttributeError:
             pass
     self._legends = []
     # load available legends
     for legend in sel.elements(self.LEGENDS):
         legend_text = sel.text_sane(legend)
         # changing legend name to full name with pre defined map
         legend_id = self._get_ui_key(
             attributize_string(legend_text.strip()))
         legend_object = Legend(name=legend_text, legend_object=legend)
         setattr(self, legend_id, legend_object)
         self._legends.append(legend_id)
     self._c_lines = self._c_object\
         .find_elements_by_xpath("//*[name()='g']//*[contains(@class, 'c3-target') "
                                 "and contains(@class, 'c3-chart-line')]")
Пример #20
0
 def _reload(self):
     self._legends = []
     self.search_box = TopologySearchBox()
     self.display_names = TopologyDisplayNames()
     # load elements
     # we have to wait few seconds, initial few seconds elements are moving
     self.reload_elements()
     # load legends
     # remove old legends
     for legend_id in self._legends:
         try:
             delattr(self, legend_id)
         except AttributeError:
             pass
     # load available legends
     for legend in sel.elements(self.LEGENDS):
         legend_text = sel.text_sane(
             legend.find_element_by_tag_name('label'))
         legend_id = attributize_string(legend_text.strip())
         legend_object = TopologyLegend(name=legend_text, element=legend)
         setattr(self, legend_id, legend_object)
         self._legends.append(legend_id)
Пример #21
0
 def load_chart_reference(self, force_reload=False):
     """Takes current page to chart detailed page"""
     if self.is_on_chart_page and not force_reload:
         return
     if not self.is_on_chart_page:
         self._utz_object.reload()
     self._c_object = None
     if not self.is_on_chart_page:
         root_objs = sel.elements(CHARTS)
         for root_obj in root_objs:
             if sel.text_sane(root_obj.find_element_by_tag_name('h2')) == self.name:
                 root_obj.find_element_by_tag_name("a").click()
                 sel.wait_for_ajax()
                 self._c_object = sel.element(CHARTS)
                 break
     else:
         self._c_object = sel.element(CHARTS)
     if self._c_object is None:
         raise RuntimeError("Unable to get detail page of '{}'".format(self.name))
     # remove old legends and load new legends
     for legend_id in self._legends:
         try:
             delattr(self, legend_id)
         except AttributeError:
             pass
     self._legends = []
     # load available legends
     for legend in sel.elements(self.LEGENDS):
         legend_text = sel.text_sane(legend)
         # changing legend name to full name with pre defined map
         legend_id = self._get_ui_key(attributize_string(legend_text.strip()))
         legend_object = Legend(name=legend_text, legend_object=legend)
         setattr(self, legend_id, legend_object)
         self._legends.append(legend_id)
     self._c_lines = self._c_object\
         .find_elements_by_xpath("//*[name()='g']//*[contains(@class, 'c3-target') "
                                 "and contains(@class, 'c3-chart-line')]")
Пример #22
0
 def _belongs_to_group(cls, server, server_group):
     server_mgmt = server.server(method='mgmt')
     return getattr(server_mgmt, attributize_string('Server Group'), None) == server_group.name
Пример #23
0
 def _belongs_to_group(cls, server, server_group):
     server_mgmt = server.server(method='mgmt')
     return getattr(server_mgmt, attributize_string('Server Group'),
                    None) == server_group.name
Пример #24
0
 def list_data_chart(self, raw=False):
     """Returns list of data from chart"""
     self.load_chart_reference()
     data = []
     lines = []
     if self.has_warning:
         return data
     if self.num_legend(only_enabled=True) == 0:
         raise RuntimeError("There is no legend enabled!")
     for _line in self._c_lines:
         if 'opacity: 1' in _line.get_attribute('style'):
             lines.append(_line)
     line = lines[0]
     # %m/%d/%Y %H:%M:%S %Z
     if self.option.get_interval(
             force_visible_text=True) == Option.IN_HOURLY:
         _date = self.option.get_date()
         date_format = "{} {}:00 UTC".format(_date, "{}")
     elif self.option.get_interval(
             force_visible_text=True) == Option.IN_MOST_RECENT_HOUR:
         _date = self.option.get_range().split(" ", 1)[0].split("-")
         date_format = "{}/{}/{} {} UTC".format(_date[1], _date[2],
                                                _date[0], "{}")
     elif self.option.get_interval(
             force_visible_text=True) == Option.IN_DAILY:
         _year = self.option.get_date().split('/')[-1]
         date_format = "{}/{} 00:00:00 UTC".format("{}", _year)
     else:
         raise RuntimeError("Unsupported interval:{}".format(
             self.option.get_interval(force_visible_text=True)))
     if raw:
         time_format = "datetime"
     else:
         time_format = "timestamp"
     for cir_index in range(len(line.find_elements_by_tag_name("circle"))):
         tp = self._get_tooltip(lines=lines, circle_index=cir_index)
         # NOTE: If all data in ZERO value(bottom of x axis),
         # tooltip is not working via "move_to_element", returns ''
         if tp and not sel.text_content(tp) == '':
             _date = sel.text_content(tp.find_element_by_tag_name('th'))
             if not raw:
                 # Format: %m/%d/%Y %H:%M:%S %Z
                 _date = self._timestamp(
                     datetime.strptime(date_format.format(_date),
                                       "%m/%d/%Y %H:%M:%S %Z"))
             _data = {time_format: _date}
             # ignore duplicate values for timestamp
             if not next(
                 (item for item in data if item.get(time_format) == _date),
                     None):
                 for _row in tp.find_elements_by_xpath(
                         "//tr[contains(@class, 'c3-tooltip-name')]"):
                     _key = attributize_string(
                         sel.text_content(
                             _row.find_element_by_class_name('name')))
                     # changing legend name to full name with pre defined map
                     _key = self._get_ui_key(_key)
                     _value = round_double(
                         value_of(
                             sel.text_content(
                                 _row.find_element_by_class_name('value'))))
                     _data[_key] = _value
                 data.append(_data)
     return data
Пример #25
0
    def load(self):
        self._raw_keys = []
        self._keys = []
        key_values = []
        if sel.is_displayed(self.MULTIKEY_LOC, root=self._entry):
            logger.warning(
                "Parent SummaryTable created for {table_name}, "
                "it might create few un-initialized SummaryTable".format(
                    table_name=self._text))
            self._multitable = True
            # get all table rows (include titles)
            table_rows = sel.elements(self.ROWS, root=self._entry)

            # parsing table titles
            table_titles = sel.elements('./td', root=table_rows[0])
            table_titles_text = [
                el.text.replace(" ", "_") for el in table_titles
            ]

            # match each line values with the relevant title
            for row in table_rows[1:]:
                # creating mapping between title and row values
                row_mapping = dict(
                    zip(table_titles_text,
                        [el.text for el in sel.elements('./td', root=row)]))

                # set the value of the "name" column to be the key of the entire table,
                # if "name" is not available setting the most left element to be the key
                row_key = row_mapping.get("Name", row_mapping.keys()[0])

                # creating empty table to populate the row data as regular table
                table = SummaryTable(self._object,
                                     row_key,
                                     row,
                                     skip_load=True)
                # set the keys of the table to table object
                table._keys = row_mapping.keys()

                # add attr for each key
                for key in row_mapping.keys():
                    setattr(table, key, row_mapping[key])

                # add the entire table to parent table keys
                self._keys.append(row_key)

                # add attr to parent table
                setattr(self, row_key, table)
            return

        for row in sel.elements(self.ROWS, root=self._entry):
            tds = sel.elements('./td', root=row)
            key = tds[0]
            klass = sel.get_attribute(key, 'class')
            if klass and 'label' in klass:
                # Ordinary field
                key_id = attributize_string(sel.text_sane(key))
                value = tuple(tds[1:])
                try:
                    rowspan = int(sel.get_attribute(key, 'rowspan'))
                except (ValueError, TypeError):
                    rowspan = None
                if rowspan:
                    key_values.append((key, key_id, [value]))
                else:
                    key_values.append((key, key_id, value))
            else:
                # value of last key_values should be extended
                key_values[-1][2].append(tuple(tds))
        for key, key_id, value in key_values:
            value_object = process_field(value)
            setattr(self, key_id, value_object)
            self._raw_keys.append(sel.text_sane(key))
            self._keys.append(key_id)