Source code for cfme.networks.balancer

from navmazing import NavigateToSibling, NavigateToAttribute

from cfme.common import WidgetasticTaggable
from cfme.exceptions import ItemNotFound
from cfme.networks.views import BalancerDetailsView, BalancerView
from utils import version
from utils.appliance import Navigatable
from utils.appliance.implementations.ui import navigator, CFMENavigateStep, navigate_to


[docs]class BalancerCollection(Navigatable): """Collection object for Balancer object""" def __init__(self, appliance=None, parent_provider=None): Navigatable.__init__(self, appliance=appliance) self.parent = parent_provider
[docs] def instantiate(self, name): return Balancer(name=name, appliance=self.appliance, collection=self)
[docs] def all(self): if self.parent: view = navigate_to(self.parent, 'LoadBalancers') else: view = navigate_to(self, 'All') list_networks_obj = view.entities.get_all(surf_pages=True) return [self.instantiate(name=b.name) for b in list_networks_obj]
[docs]class Balancer(WidgetasticTaggable, Navigatable): """Class representing balancers in sdn""" in_version = ('5.8', version.LATEST) category = 'networks' page_name = 'network_balancer' string_name = 'NetworkBalancer' refresh_text = 'Refresh items and relationships' detail_page_suffix = 'network_balancer_detail' quad_name = None db_types = ['NetworkBalancer'] def __init__(self, name, provider=None, collection=None, appliance=None): self.collection = collection or BalancerCollection(appliance=appliance) Navigatable.__init__(self, appliance=self.collection.appliance) self.name = name self.provider = provider @property def health_checks(self): """ Returns health check state """ view = navigate_to(self, 'Details') return view.entities.properties.get_text_of('Health checks') @property def listeners(self): """ Returns listeners of balancer """ view = navigate_to(self, 'Details') return view.entities.properties.get_text_of('Listeners') @property def network_provider(self): """ Returns network provider """ from cfme.networks.provider import NetworkProviderCollection # balancer collection contains reference to provider if self.collection.parent: return self.collection.parent # otherwise get provider name from ui view = navigate_to(self, 'Details') try: prov_name = view.entities.relationships.get_text_of("Network Manager") collection = NetworkProviderCollection(appliance=self.appliance) return collection.instantiate(name=prov_name) except ItemNotFound: # BZ 1480577 return None
@navigator.register(BalancerCollection, 'All')
[docs]class All(CFMENavigateStep): VIEW = BalancerView prerequisite = NavigateToAttribute('appliance.server', 'LoggedIn')
[docs] def step(self): self.prerequisite_view.navigation.select('Networks', 'Load Balancers')
@navigator.register(Balancer, 'Details')
[docs]class Details(CFMENavigateStep): prerequisite = NavigateToAttribute('collection', 'All') VIEW = BalancerDetailsView
[docs] def step(self): self.prerequisite_view.entities.get_entity(by_name=self.obj.name).click()
@navigator.register(Balancer, 'EditTags')
[docs]class EditTags(CFMENavigateStep): prerequisite = NavigateToSibling('Details')
[docs] def step(self): self.prerequisite_view.toolbar.policy.item_select('Edit Tags')