# -*- coding: utf-8 -*-
from lxml.html import document_fromstring
from widgetastic.utils import (
Parameter,
Version,
VersionPick
)
from widgetastic.widget import ParametrizedView, Text, View
from widgetastic_manageiq import (
BaseEntitiesView,
NonJSBaseEntity,
JSBaseEntity,
BaseListEntity,
BaseQuadIconEntity,
BaseTileIconEntity,
BreadCrumb,
ItemsToolBarViewSelector,
SummaryTable,
TimelinesView,
ManageIQTree
)
from widgetastic_patternfly import (
Dropdown,
Accordion
)
from cfme.base.login import BaseLoggedInPage
[docs]class ComputePhysicalInfrastructureSwitchesView(BaseLoggedInPage):
"""Common parts for switch views."""
title = Text('.//div[@id="center_div" or @id="main-content"]//h1')
@property
def in_compute_physical_infrastructure_switches(self):
return (self.logged_in_as_current_user and
self.navigation.currently_selected == ["Compute", "Physical Infrastructure",
"Switches"])
[docs]class PhysicalSwitchQuadIconEntity(BaseQuadIconEntity):
@property
def data(self):
return {
'no_port': int(self.browser.text(self.QUADRANT.format(pos="a"))),
'state': self.browser.get_attribute("style", self.QUADRANT.format(pos="b")),
'vendor': self.browser.get_attribute("alt", self.QUADRANT.format(pos="c")),
'health_state': self.browser.get_attribute("alt", self.QUADRANT.format(pos="d"))
}
[docs]class PhysicalSwitchTileIconEntity(BaseTileIconEntity):
quad_icon = ParametrizedView.nested(PhysicalSwitchQuadIconEntity)
[docs]class PhysicalSwitchListEntity(BaseListEntity):
pass
[docs]class NonJSPhysicalSwitchEntity(NonJSBaseEntity):
quad_entity = PhysicalSwitchQuadIconEntity
list_entity = PhysicalSwitchListEntity
tile_entity = PhysicalSwitchTileIconEntity
[docs]class JSPhysicalSwitchEntity(JSBaseEntity):
@property
def data(self):
data_dict = super(JSPhysicalSwitchEntity, self).data
if 'quadicon' in data_dict and data_dict['quadicon']:
quad_data = document_fromstring(data_dict['quadicon'])
data_dict['no_port'] = int(quad_data.xpath(self.QUADRANT.format(pos="a"))[0].text)
data_dict['state'] = quad_data.xpath(self.QUADRANT.format(pos="b"))[0].get('style')
data_dict['vendor'] = quad_data.xpath(self.QUADRANT.format(pos="c"))[0].get('alt')
data_dict['health_state'] = quad_data.xpath(self.QUADRANT.format(pos="d"))[0].get('alt')
return data_dict
[docs]def PhysicalSwitchEntity(): # noqa
""" Temporary wrapper for PhysicalSwitch Entity during transition to JS based Entity
"""
return VersionPick({
Version.lowest(): NonJSPhysicalSwitchEntity,
'5.9': JSPhysicalSwitchEntity,
})
[docs]class PhysicalSwitchDetailsEntities(View):
"""Represents Details page."""
properties = SummaryTable(title="Properties")
management_networks = SummaryTable(title="Management Networks")
relationships = SummaryTable(title="Relationships")
power_management = SummaryTable(title="Power Management")
firmwares = SummaryTable(title="Firmwares")
ports = SummaryTable(title="Ports")
[docs]class PhysicalSwitchDetailsView(ComputePhysicalInfrastructureSwitchesView):
"""Main PhysicalSwitch details page."""
breadcrumb = BreadCrumb(locator='.//ol[@class="breadcrumb"]')
toolbar = View.nested(PhysicalSwitchDetailsToolbar)
entities = View.nested(PhysicalSwitchDetailsEntities)
@property
def is_displayed(self):
title = "{name} (Summary)".format(name=self.context["object"].name)
return (self.in_compute_physical_infrastructure_switches and
self.breadcrumb.active_location == title)
[docs]class PhysicalSwitchTimelinesView(TimelinesView, ComputePhysicalInfrastructureSwitchesView):
"""Represents a PhysicalSwitch Timelines page."""
@property
def is_displayed(self):
return (self.in_compute_physical_infrastructure_switches and
super(TimelinesView, self).is_displayed)
[docs]class PhysicalSwitchProvisionView(BaseLoggedInPage):
"""Represents the Provision Physical Switch page."""
breadcrumb = BreadCrumb(locator='.//ol[@class="breadcrumb"]')
@property
def is_displayed(self):
title = "Add PhysicalSwitch"
return self.breadcrumb.active_location == title
[docs]class PhysicalSwitchEntitiesView(BaseEntitiesView):
"""Represents the view with different items like hosts."""
@property
def entity_class(self):
return PhysicalSwitchEntity().pick(self.browser.product_version)
[docs]class PhysicalSwitchesView(ComputePhysicalInfrastructureSwitchesView):
toolbar = View.nested(PhysicalSwitchesToolbar)
sidebar = View.nested(PhysicalSwitchSideBar)
including_entities = View.include(PhysicalSwitchEntitiesView, use_parent=True)
@property
def is_displayed(self):
return (self.in_compute_physical_infrastructure_switches and
self.title.text == "Physical Switches")