Source code for cfme.services.catalogs.orchestration_template

# -*- coding: utf-8 -*-
import attr

from widgetastic.widget import View, Text, Checkbox
from widgetastic_patternfly import BootstrapSelect, Button, CandidateNotFound, Input
from widgetastic_manageiq import ScriptBox, Table, PaginationPane, SummaryTable
from navmazing import NavigateToAttribute, NavigateToSibling

from cfme.common import Taggable
from cfme.modeling.base import BaseCollection, BaseEntity
from cfme.utils.appliance.implementations.ui import navigator, CFMENavigateStep, navigate_to
from cfme.utils.pretty import Pretty
from cfme.utils.update import Updateable

from . import ServicesCatalogView


[docs]class OrchestrationTemplatesView(ServicesCatalogView): title = Text("#explorer_title_text") @property def is_displayed(self): return ( super(OrchestrationTemplatesView, self).is_displayed and self.title.text == 'All Orchestration Templates' and self.orchestration_templates.is_opened and self.orchestration_templates.tree.currently_selected == ["All Orchestration Templates"])
[docs]class CopyTemplateForm(ServicesCatalogView): title = Text('#explorer_title_text') name = Input(name='name') description = Input(name="description") draft = Checkbox(name='draft') content = ScriptBox(locator="//pre[@class=' CodeMirror-line ']/span") cancel_button = Button('Cancel')
[docs]class TemplateForm(ServicesCatalogView): title = Text('#explorer_title_text') template_type = BootstrapSelect("type") name = Input(name='name') description = Input(name="description") draft = Checkbox(name='draft') content = ScriptBox(locator="//pre[@class=' CodeMirror-line ']/span")
[docs]class AddTemplateView(TemplateForm): add_button = Button("Add") @property def is_displayed(self): return ( self.title.text == "Adding a new Orchestration Template" and self.orchestration_templates.is_opened )
[docs]class EditTemplateView(TemplateForm): save_button = Button('Save') reset_button = Button('Reset') @property def is_displayed(self): return ( self.title.text == "Editing {}".format(self.context['object'].name) and self.orchestration_templates.is_opened )
[docs]class CopyTemplateView(CopyTemplateForm): title = Text('#explorer_title_text') add_button = Button("Add") @property def is_displayed(self): return ( self.is_displayed and self.title.text == "Copying {}".format(self.context['object'].name) and self.orchestration_templates.is_opened )
[docs]class DetailsTemplateEntities(View): title = Text('#explorer_title_text') smart_management = SummaryTable(title='Smart Management')
[docs]class DetailsTemplateView(ServicesCatalogView): entities = View.nested(DetailsTemplateEntities) @property def is_displayed(self): """ Removing last 's' character from template_group. For ex. 'CloudFormation Templates' -> 'CloudFormation Template'""" return ( self.entities.title.text == '{} "{}"'.format(self.context['object'].template_group[:-1], self.context['object'].template_name) and self.orchestration_templates.is_opened )
[docs]class TemplateTypeView(ServicesCatalogView): title = Text('#explorer_title_text') templates = Table("//table[@class='table table-striped table-bordered " "table-hover table-selectable]'") paginator = PaginationPane() @property def is_displayed(self): return ( self.title.text == 'All {}'.format(self.context['object'].template_group) and self.orchestration_templates.is_opened )
[docs]class DialogForm(ServicesCatalogView): title = Text('#explorer_title_text') name = Input(name='dialog_name')
[docs]class AddDialogView(DialogForm): add_button = Button("Save") @property def is_displayed(self): return ( self.title.text == 'Adding a new Service Dialog from ' 'Orchestration Template "{}"'.format(self.obj.name) and self.orchestration_templates.is_opened )
@attr.s
[docs]class OrchestrationTemplate(BaseEntity, Updateable, Pretty, Taggable): template_group = attr.ib() template_name = attr.ib() content = attr.ib() description = attr.ib(default=None) draft = attr.ib(default=None)
[docs] def update(self, updates): view = navigate_to(self, 'Edit') view.fill({'description': updates.get('description'), 'name': updates.get('template_name'), 'draft': updates.get('draft'), 'content': updates.get('content')}) view.save_button.click() view.flash.assert_success_message('Orchestration Template "{}" was saved'.format( self.template_name))
[docs] def delete(self): view = navigate_to(self, 'Details') msg = "Remove this Orchestration Template" if self.appliance.version >= '5.9': msg = '{} from Inventory'.format(msg) view.toolbar.configuration.item_select(msg, handle_alert=True) view.flash.assert_success_message('Orchestration Template "{}" was deleted.'.format( self.template_name))
[docs] def delete_all_templates(self): view = navigate_to(self, 'TemplateType') view.paginator.check_all() view.configuration.item_select("Remove selected Orchestration Templates", handle_alert=True)
[docs] def copy_template(self, template_name, content, draft=None, description=None): view = navigate_to(self, 'CopyTemplate') view.fill({'name': template_name, 'content': content, 'draft': draft, 'description': description }) view.add_button.click() view.flash.assert_success_message('Orchestration Template "{}" was saved'.format( template_name)) return self.parent.instantiate(template_group=self.template_group, description=description, template_name=template_name, content=content, draft=draft)
[docs] def create_service_dialog_from_template(self, dialog_name): view = navigate_to(self, 'AddDialog') view.fill({'name': dialog_name}) view.add_button.click() view.flash.assert_success_message('Service Dialog "{}" was successfully created'.format( dialog_name)) service_dialog = self.parent.parent.collections.service_dialogs.instantiate( label=dialog_name) return service_dialog
@property def exists(self): try: navigate_to(self, "Details") return True except CandidateNotFound: return False
@attr.s
[docs]class OrchestrationTemplatesCollection(BaseCollection): """A collection for the :py:class:`cfme.services.catalogs.orchestration_template`""" ENTITY = OrchestrationTemplate
[docs] def create(self, template_name, description, template_group, template_type, draft=None, content=None): self.template_group = template_group view = navigate_to(self, 'AddTemplate') view.fill({'name': template_name, 'description': description, 'template_type': template_type, 'draft': draft, 'content': content}) view.add_button.click() template = self.instantiate(template_group=template_group, description=description, template_name=template_name, content=content, draft=draft) view = self.create_view(DetailsTemplateView) view.flash.assert_success_message('Orchestration Template ' '"{}" was saved'.format(template_name)) return template
@navigator.register(OrchestrationTemplatesCollection)
[docs]class All(CFMENavigateStep): prerequisite = NavigateToAttribute('appliance.server', 'LoggedIn') VIEW = OrchestrationTemplatesView
[docs] def step(self): self.prerequisite_view.navigation.select('Services', 'Catalogs') self.view.orchestration_templates.tree.click_path("All Orchestration Templates")
[docs] def am_i_here(self, *args, **kwargs): return self.view.is_displayed
@navigator.register(OrchestrationTemplate)
[docs]class Details(CFMENavigateStep): prerequisite = NavigateToAttribute('parent', 'All') VIEW = DetailsTemplateView
[docs] def step(self): self.view.orchestration_templates.tree.click_path("All Orchestration Templates", self.obj.template_group, self.obj.template_name)
[docs] def am_i_here(self, *args, **kwargs): return self.view.is_displayed
@navigator.register(OrchestrationTemplatesCollection)
[docs]class TemplateType(CFMENavigateStep): prerequisite = NavigateToSibling('All') VIEW = TemplateTypeView
[docs] def step(self): self.view.orchestration_templates.tree.click_path("All Orchestration Templates", self.obj.template_group)
@navigator.register(OrchestrationTemplate)
[docs]class AddDialog(CFMENavigateStep): prerequisite = NavigateToSibling('Details') VIEW = AddDialogView
[docs] def step(self): item_name = 'Create Service Dialog from Orchestration Template' self.view.toolbar.configuration.item_select(item_name)
@navigator.register(OrchestrationTemplate)
[docs]class Edit(CFMENavigateStep): prerequisite = NavigateToSibling('Details') VIEW = EditTemplateView
[docs] def step(self): self.view.toolbar.configuration.item_select("Edit this Orchestration Template")
@navigator.register(OrchestrationTemplatesCollection)
[docs]class AddTemplate(CFMENavigateStep): prerequisite = NavigateToSibling('TemplateType') VIEW = AddTemplateView
[docs] def step(self): self.view.toolbar.configuration.item_select("Create new Orchestration Template")
@navigator.register(OrchestrationTemplate)
[docs]class CopyTemplate(CFMENavigateStep): prerequisite = NavigateToSibling('Details') VIEW = CopyTemplateView
[docs] def step(self): self.view.toolbar.configuration.item_select("Copy this Orchestration Template")