class GenericObjectDefinition(BaseEntity, Updateable, sentaku.modeling.ElementMixin): """Generic Objects Definition class to context switch between UI and REST. Read/Update/Delete functionality. """ _collections = { 'generic_objects': GenericObjectInstanceCollection, 'generic_object_groups_buttons': GenericObjectButtonGroupsCollection, 'generic_object_buttons': GenericObjectButtonsCollection } update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() exists = sentaku.ContextualProperty() add_button = sentaku.ContextualMethod() add_button_group = sentaku.ContextualMethod() generic_objects = sentaku.ContextualProperty() instance_count = sentaku.ContextualProperty() name = attr.ib() description = attr.ib() attributes = attr.ib(default=None) # e.g. {'address': 'string'} associations = attr.ib(default=None) # e.g. {'services': 'Service'} methods = attr.ib(default=None) # e.g. ['method1', 'method2'] custom_image_file_path = attr.ib(default=None) rest_response = attr.ib(default=None, init=False)
class Zone(Pretty, BaseEntity, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = [ 'name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user' ] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() region = sentaku.ContextualProperty() name = attr.ib(default="default") description = attr.ib(default="Default Zone") id = attr.ib(default=None) smartproxy_ip = attr.ib(default=None) ntp_servers = attr.ib(default=None) max_scans = attr.ib(default=None) user = attr.ib(default=None) _region = attr.ib(init=False, default=None) _collections = {'servers': ServerCollection} @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ZoneCollectLog return ZoneCollectLog(self.appliance)
class Server(BaseEntity, sentaku.modeling.ElementMixin): name = attr.ib() sid = attr.ib(default=1) _zone = attr.ib(init=False, default=None) address = sentaku.ContextualMethod() login = sentaku.ContextualMethod() login_admin = sentaku.ContextualMethod() logout = sentaku.ContextualMethod() update_password = sentaku.ContextualMethod() logged_in = sentaku.ContextualMethod() current_full_name = sentaku.ContextualMethod() current_username = sentaku.ContextualMethod() zone = sentaku.ContextualProperty() slave_servers = sentaku.ContextualProperty() @property def settings(self): from cfme.configure.configuration.server_settings import ServerInformation setting = ServerInformation(appliance=self.appliance) return setting @property def authentication(self): from cfme.configure.configuration.server_settings import AuthenticationSetting auth_settings = AuthenticationSetting(self.appliance) return auth_settings @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ServerCollectLog return ServerCollectLog(self.appliance)
class Zone(Pretty, Navigatable, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = ['name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user'] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() def __init__(self, appliance, region=None, name=None, description=None, smartproxy_ip=None, ntp_servers=None, max_scans=None, user=None): self.appliance = appliance self.servers = set() self.region = region or self.appliance.server.zone.region self.name = name or "default" self.description = description or "Default Zone" self.region.zones.add(self) self.smartproxy_ip = smartproxy_ip self.ntp_servers = ntp_servers self.max_scans = max_scans self.user = user self.parent = self.appliance.context
class MyService(Updateable, Navigatable, Taggable, sentaku.modeling.ElementMixin): """ My Service main class to context switch between ui and ssui. All the below methods are implemented in both ui and ssui side . """ update = sentaku.ContextualMethod() retire = sentaku.ContextualMethod() retire_on_date = sentaku.ContextualMethod() exists = sentaku.ContextualProperty() delete = sentaku.ContextualMethod() set_ownership = sentaku.ContextualMethod() get_ownership = sentaku.ContextualMethod() edit_tags = sentaku.ContextualMethod() check_vm_add = sentaku.ContextualMethod() download_file = sentaku.ContextualMethod() reconfigure_service = sentaku.ContextualMethod() launch_vm_console = sentaku.ContextualMethod() service_power = sentaku.ContextualMethod() def __init__(self, appliance, name=None, description=None, vm_name=None): self.appliance = appliance self.name = name self.description = description self.vm_name = vm_name self.parent = self.appliance.context
class Zone(Pretty, BaseEntity, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = ['name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user'] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() region = attr.ib(default=None) name = attr.ib(default="default") description = attr.ib(default="Default Zone") smartproxy_ip = attr.ib(default=None) ntp_servers = attr.ib(default=None) max_scans = attr.ib(default=None) user = attr.ib(default=None) # TODO we need to fix this set() addition def __attrs_post_init__(self): self.servers = [] self.region = self.region or self.appliance.server.zone.region self.region.zones.append(self) @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ZoneCollectLog return ZoneCollectLog(self.appliance)
class Zone(Pretty, BaseEntity, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = ['name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user'] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() # region = sentaku.ContextualProperty() name = attr.ib(default="default") description = attr.ib(default="Default Zone") id = attr.ib(default=None) smartproxy_ip = attr.ib(default=None) ntp_servers = attr.ib(default=None) max_scans = attr.ib(default=None) user = attr.ib(default=None) _collections = {'servers': ServerCollection} @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ZoneCollectLog return ZoneCollectLog(self.appliance) @property def region(self): zone_res = self.appliance.rest_api.collections.zones.find_by(id=self.id) zone = zone_res[0] zone.reload(attributes=['region_number']) region_obj = self.appliance.collections.regions.instantiate(number=zone.region_number) return region_obj @property def _api_settings_url(self): return '/'.join([self.appliance.rest_api.collections.zones._href, str(self.id), 'settings']) @property def advanced_settings(self): """"GET zones/:id/settings api endpoint to query zone configuration""" return self.appliance.rest_api.get(self._api_settings_url) def update_advanced_settings(self, settings_dict): """PATCH settings from the zone's api/zones/:id/settings endpoint Args: settings_dict: dictionary of the changes to be made to the yaml configuration JSON dumps settings_dict to pass as raw hash data to rest_api session Raises: AssertionError: On an http result >=400 (RequestsResponse.ok) """ # Calling the _session patch method because the core patch will wrap settings_dict in a list result = self.appliance.rest_api._session.patch( url=self._api_settings_url, data=json.dumps(settings_dict) ) assert result.ok
class MyService(Updateable, Navigatable, Taggable, sentaku.modeling.ElementMixin): """ My Service main class to context switch between ui and ssui. All the below methods are implemented in both ui and ssui side . """ update = sentaku.ContextualMethod() retire = sentaku.ContextualMethod() is_retired = sentaku.ContextualProperty() retire_on_date = sentaku.ContextualMethod() exists = sentaku.ContextualProperty() delete = sentaku.ContextualMethod() status = sentaku.ContextualProperty() set_ownership = sentaku.ContextualMethod() get_ownership = sentaku.ContextualMethod() edit_tags = sentaku.ContextualMethod() check_vm_add = sentaku.ContextualMethod() download_file = sentaku.ContextualMethod() reconfigure_service = sentaku.ContextualMethod() launch_vm_console = sentaku.ContextualMethod() service_power = sentaku.ContextualMethod() add_resource_generic_object = sentaku.ContextualMethod() def __init__(self, appliance, name=None, name_base=None, description=None, vm_name=None): self.appliance = appliance self.name = name self.description = description self.vm_name = vm_name self.parent = self.appliance.context @property def rest_api_entity(self): try: return self.appliance.rest_api.collections.services.get( name=self.name, display=True) except ValueError: raise RestLookupError( f'No service rest entity found matching name {self.name}')
class GenericObjectDefinition(BaseEntity, Updateable, sentaku.modeling.ElementMixin): """Generic Objects Definition class to context switch between UI and REST. Read/Update/Delete functionality. """ update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() exists = sentaku.ContextualProperty() name = attr.ib() description = attr.ib() attributes = attr.ib(default=None) # e.g. {'address': 'string'} associations = attr.ib(default=None) # e.g. {'services': 'Service'} methods = attr.ib(default=None) # e.g. ['method1', 'method2'] rest_response = attr.ib(default=None, init=False)
class GenericObjectInstance(BaseEntity, Updateable, sentaku.modeling.ElementMixin): """Generic Objects class to context switch between REST and Automate. Read/Update/Delete functionality. """ update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() exists = sentaku.ContextualProperty() name = attr.ib() definition = attr.ib() # generic object definition attributes = attr.ib(default=None) # e.g. {'address': 'Test Address'} associations = attr.ib( default=None) # e.g. {'services': [myservice1, myservice2]} rest_response = attr.ib(default=None, init=False)
class Zone(Pretty, BaseEntity, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = [ 'name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user' ] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() # region = sentaku.ContextualProperty() name = attr.ib(default="default") description = attr.ib(default="Default Zone") id = attr.ib(default=None) smartproxy_ip = attr.ib(default=None) ntp_servers = attr.ib(default=None) max_scans = attr.ib(default=None) user = attr.ib(default=None) _collections = {'servers': ServerCollection} @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ZoneCollectLog return ZoneCollectLog(self.appliance) @property def region(self): zone_res = self.appliance.rest_api.collections.zones.find_by( id=self.id) zone = zone_res[0] zone.reload(attributes=['region_number']) region_obj = self.appliance.collections.regions.instantiate( number=zone.region_number) return region_obj
class TodoItem(sentaku.Element): """describing a todo list element""" name = attr.ib() completed = sentaku.ContextualProperty()
class Zone(Pretty, BaseEntity, sentaku.modeling.ElementMixin): """ Configure/Configuration/Region/Zones functionality Create/Read/Update/Delete functionality. """ pretty_attrs = ['name', 'description', 'smartproxy_ip', 'ntp_servers', 'max_scans', 'user'] exists = sentaku.ContextualProperty() update = sentaku.ContextualMethod() delete = sentaku.ContextualMethod() # region = sentaku.ContextualProperty() name = attr.ib(default="default") description = attr.ib(default="Default Zone") id = attr.ib(default=None) smartproxy_ip = attr.ib(default=None) ntp_servers = attr.ib(default=None) max_scans = attr.ib(default=None) user = attr.ib(default=None) _collections = {'servers': ServerCollection} @property def collect_logs(self): from cfme.configure.configuration.diagnostics_settings import ZoneCollectLog return ZoneCollectLog(self.appliance) @cached_property def region(self): possible_parent = parent_of_type(self, Region) if possible_parent: return possible_parent else: zone_res = self.appliance.rest_api.collections.zones.find_by(id=self.id) zone, = zone_res zone.reload(attributes=['region_number']) return self.appliance.collections.regions.instantiate(number=zone.region_number) @property def _api_settings_url(self): return '/'.join([self.appliance.rest_api.collections.zones._href, str(self.id), 'settings']) @property def advanced_settings(self): """"GET zones/:id/settings api endpoint to query zone configuration""" return self.appliance.rest_api.get(self._api_settings_url) @property def current_string(self): """Returns the string ' (current)' if the appliance serving the UI request is in this zone. Used to generate the appropriate tree_path for navigating configuration accordion trees.""" return ' (current)' if ( self.id == self.appliance.server.zone.id ) else '' def title_string(self, quote_str=''): """Used to generate the title.text for Zone-related views. Returns a string of the form: "Zone Description" (current) [or] "Zone Description" Args: quote_str: The optional string to include before and after the zone description. To reproduce the title.text as shown above, quote_str='"'. In accordion trees, the zone appears in the form: Zone Description (current) [or] Zone Description (without the quotation marks surrounding the description). In this case, we can pass quote_str='' (the default). """ return f"{quote_str}{self.description}{quote_str}{self.current_string}" @property def tree_path(self): """Generate the tree path list for the settings tree in the configuration accordion Returns: list of path elements for tree navigation """ path = [ self.region.settings_string, "Zones", f"Zone: {self.title_string()}" ] return path @property def diagnostics_tree_path(self): """Generate tree path list for the diagnostics tree in the configuration accordion""" path = self.tree_path path.remove("Zones") return path def update_advanced_settings(self, settings_dict): """PATCH settings from the zone's api/zones/:id/settings endpoint Args: settings_dict: dictionary of the changes to be made to the yaml configuration JSON dumps settings_dict to pass as raw hash data to rest_api session Raises: AssertionError: On an http result >=400 (RequestsResponse.ok) """ # Calling the _session patch method because the core patch will wrap settings_dict in a list result = self.appliance.rest_api._session.patch( url=self._api_settings_url, data=json.dumps(settings_dict) ) assert result.ok