Source code for cfme.networks.security_group

from navmazing import NavigateToSibling, NavigateToAttribute

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


[docs]class SecurityGroupCollection(Navigatable): """ Collection object for SecurityGroup object Note: Network providers object are not implemented in mgmt """ def __init__(self, appliance=None, parent_provider=None): Navigatable.__init__(self, appliance=appliance) self.parent = parent_provider
[docs] def instantiate(self, name): return SecurityGroup(name=name, appliance=self.appliance, collection=self)
[docs] def all(self): if self.parent: view = navigate_to(self.parent, 'SecurityGroups') else: view = navigate_to(self, 'All') list_networks_obj = view.entities.get_all(surf_pages=True) return [self.instantiate(name=s.name) for s in list_networks_obj]
[docs]class SecurityGroup(WidgetasticTaggable, Navigatable): """Class representing security group in sdn""" in_version = ('5.8', version.LATEST) category = 'networks' page_name = 'security_group' string_name = 'SecurityGroup' quad_name = None db_types = ['SecurityGroup'] def __init__(self, name, provider=None, collection=None, appliance=None): self.collection = collection or SecurityGroupCollection(appliance=appliance) Navigatable.__init__(self, appliance=self.collection.appliance) self.name = name self.provider = provider @property def network_provider(self): """ Returns network provider """ from cfme.networks.provider import NetworkProviderCollection # security group 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(SecurityGroupCollection, 'All')
[docs]class All(CFMENavigateStep): VIEW = SecurityGroupView prerequisite = NavigateToAttribute('appliance.server', 'LoggedIn')
[docs] def step(self): self.prerequisite_view.navigation.select('Networks', 'Security Groups')
@navigator.register(SecurityGroup, 'Details')
[docs]class Details(CFMENavigateStep): prerequisite = NavigateToAttribute('collection', 'All') VIEW = SecurityGroupDetailsView
[docs] def step(self): self.prerequisite_view.entities.get_entity(by_name=self.obj.name).click()
@navigator.register(SecurityGroup, 'EditTags')
[docs]class EditTags(CFMENavigateStep): prerequisite = NavigateToSibling('Details')
[docs] def step(self): self.prerequisite_view.toolbar.policy.item_select('Edit Tags')