class Timer(object): form = Form(fields=[ ("run", { version.LOWEST: Select("//select[@id='timer_typ']"), '5.5': AngularSelect('timer_typ')}), ("hours", { version.LOWEST: Select("//select[@id='timer_hours']"), '5.5': AngularSelect('timer_hours')}), ("days", { version.LOWEST: Select("//select[@id='timer_days']"), '5.5': AngularSelect('timer_days')}), ("weeks", { version.LOWEST: Select("//select[@id='timer_weeks']"), '5.5': AngularSelect('timer_weeks')}), ("months", { version.LOWEST: Select("//select[@id='timer_months']"), '5.5': AngularSelect('timer_months')}), ("time_zone", { version.LOWEST: Select("//select[@id='time_zone']"), '5.5': AngularSelect('time_zone')}), ("start_date", Calendar("miq_date_1")), ("start_hour", { version.LOWEST: Select("//select[@id='start_hour']"), '5.5': AngularSelect('start_hour')}), ("start_min", { version.LOWEST: Select("//select[@id='start_min']"), '5.5': AngularSelect('start_min')}), ])
class Timer(object): form = Form(fields=[ ("run", Select("//select[@id='timer_typ']")), ("hours", Select("//select[@id='timer_hours']")), ("days", Select("//select[@id='timer_days']")), ("weeks", Select("//select[@id='timer_weeks']")), ("months", Select("//select[@id='timer_months']")), ("time_zone", Select("//select[@id='time_zone']")), ("start_date", Calendar("miq_date_1")), ("start_hour", Select("//select[@id='start_hour']")), ("start_min", Select("//select[@id='start_min']")), ])
from datetime import datetime from cfme.web_ui import flash, jstimelines, Form, AngularSelect, Calendar, fill NONE_GROUP = 'NONE' timelines_form = Form(fields=[ ('event_type', AngularSelect('tl_show')), ('interval', AngularSelect('tl_typ')), ('date', Calendar('miq_date_1')), ('days_back', AngularSelect('tl_days')), ('level', AngularSelect('tl_fl_typ')), ('group1', AngularSelect('tl_fl_grp1')), ('group2', AngularSelect('tl_fl_grp2')), ('group3', AngularSelect('tl_fl_grp3')), ]) class Timelines(object): """ Represents Common UI Page for showing generated events of different Providers as a timeline. UI page contains several drop-down items which are doing filtering of displayed events. In this class, there are described several methods to change those filters. After each filter change, UI page is reloaded and the displayed events graphic is changed. And after each page reload, the displayed events are re-read by this class. The main purpose of this class is to check whether particular event is displayed or not in timelines page. Usage: timelines.change_interval('Hourly') timelines.change_event_groups('Application') timelines.change_level('Summary')
}) template_select_form = Form(fields=[('template_table', Table('//div[@id="pre_prov_div"]//table') ), ('cancel_button', form_buttons.cancel)]) snapshot_form = Form( fields=[('name', Input('name')), ('description', Input('description')), ('snapshot_memory', Input('snap_memory')), ( 'create_button', create_button), ('cancel_button', form_buttons.cancel)]) retirement_date_form = Form( fields=[('retirement_date_text', Calendar("miq_date_1")), ('retirement_warning_select', Select("//select[@id='retirement_warn']"))]) retire_remove_button = "//span[@id='remove_button']/a/img" match_page = partial(match_location, controller='vm_infra', title='Virtual Machines') vm_templates_tree = partial(accordion.tree, "VMs & Templates") vms_tree = partial(accordion.tree, "VMs") templates_tree = partial(accordion.tree, "Templates") def reset_page(): tb.select("Grid View")
### # Form handling # field_form = Form(fields=[ ("type", Select("select#chosen_typ")), ("field", Select("select#chosen_field")), ("key", Select("select#chosen_key")), ("value", Input("chosen_value")), ("user_input", Input("user_input")), ]) field_date_form = Form( fields=[("dropdown_select", Select("select#chosen_from_1") ), ("input_select_date", Calendar("miq_date_1_0") ), ("input_select_time", Select("select#miq_time_1_0"))]) count_form = Form(fields=[ ("type", Select("select#chosen_typ")), ("count", Select("select#chosen_count")), ("key", Select("select#chosen_key")), ("value", Input("chosen_value")), ("user_input", Input("user_input")), ]) tag_form = Form(fields=[ ("type", Select("select#chosen_typ")), ("tag", Select("select#chosen_tag")), ("value", Select("#chosen_value")), ("user_input", Input("user_input")),
('Customize', [ ('customize_type', Select('//select[@id="customize__sysprep_enabled"]')), ('specification_name', Table('//div[@id="prov_vc_div"]/table')), ('linux_host_name', '//input[@id="customize__linux_host_name"]'), ('linux_domain_name', '//input[@id="customize__linux_domain_name"]'), ('dns_servers', '//input[@id="customize__dns_servers"]'), ('dns_suffixes', '//input[@id="customize__dns_suffixes"]'), ('custom_template', Table('//div[@id="prov_template_div"]/table')), ('root_password', '//input[@id="customize__root_password"]'), ('vm_host_name', '//input[@id="customize__hostname"]'), ]), ('Schedule', [ ('schedule_type', Radio('schedule__schedule_type')), ('provision_date', Calendar('miq_date_1')), ('provision_start_hour', Select('//select[@id="start_hour"]')), ('provision_start_min', Select('//select[@id="start_min"]')), ('retirement', Select('//select[@id="schedule__retirement"]')), ('retirement_warning', Select('//select[@id="schedule__retirement_warn"]')), ]) ])) # Nav targets and helpers def _nav_to_provision_form(context): toolbar.select('Lifecycle', 'Provision VMs') provider = context['provider'] template_name = context['template_name']
class DatabaseBackupSchedule(Schedule): """ Configure/Configuration/Region/Schedules - Database Backup type Args: name: Schedule name description: Schedule description active: Whether the schedule should be active (default `True`) protocol: One of ``{'Samba', 'Network File System'}`` run_type: Once, Hourly, Daily, ... run_every: If `run_type` is not Once, then you can specify how often it should be run time_zone: Time zone selection start_date: Specify start date (mm/dd/yyyy or datetime.datetime()) start_hour: Starting hour start_min: Starting minute Usage: smb_schedule = DatabaseBackupSchedule( name="Bi-hourly Samba Database Backup", description="Everybody's favorite backup schedule", protocol="Samba", uri="samba.example.com/share_name", username="******", password="******", password_verify="secret", time_zone="UTC", start_date=datetime.datetime.utcnow(), run_type="Hourly", run_every="2 Hours" ) smb_schedule.create() smb_schedule.delete() ... or ... nfs_schedule = DatabaseBackupSchedule( name="One-time NFS Database Backup", description="The other backup schedule", protocol="Network File System", uri="nfs.example.com/path/to/share", time_zone="Chihuahua", start_date="21/6/2014", start_hour="7", start_min="45" ) nfs_schedule.create() nfs_schedule.delete() """ form = Form(fields=[ ("name", Input("name")), ("description", Input("description")), ("active", Input("enabled")), ("action", { version.LOWEST: Select("select#action_typ"), '5.5': AngularSelect('action_typ') }), ("log_protocol", { version.LOWEST: Select("select#log_protocol"), '5.5': AngularSelect('log_protocol') }), ("depot_name", Input("depot_name")), ("uri", Input("uri")), ("log_userid", Input("log_userid")), ("log_password", Input("log_password")), ("log_verify", Input("log_verify")), ("timer_type", { version.LOWEST: Select("select#timer_typ"), '5.5': AngularSelect('timer_typ') }), ("timer_hours", Select("select#timer_hours")), ("timer_days", Select("select#timer_days")), ("timer_weeks", Select("select#timer_weekss")), # Not a typo! ("timer_months", Select("select#timer_months")), ("timer_value", AngularSelect('timer_value'), { "appeared_in": "5.5" }), ("time_zone", AngularSelect('time_zone')), ("start_date", Calendar("start_date")), ("start_hour", AngularSelect('start_hour')), ("start_min", AngularSelect('start_min')), ]) def __init__(self, name, description, active=True, protocol=None, depot_name=None, uri=None, username=None, password=None, password_verify=None, run_type="Once", run_every=None, time_zone=None, start_date=None, start_hour=None, start_min=None): assert protocol in {'Samba', 'Network File System'},\ "Unknown protocol type '{}'".format(protocol) if protocol == 'Samba': self.details = dict( name=name, description=description, active=active, action='Database Backup', log_protocol=sel.ByValue(protocol), depot_name=depot_name, uri=uri, log_userid=username, log_password=password, log_verify=password_verify, time_zone=sel.ByValue(time_zone), start_date=start_date, start_hour=start_hour, start_min=start_min, ) else: self.details = dict( name=name, description=description, active=active, action='Database Backup', log_protocol=sel.ByValue(protocol), depot_name=depot_name, uri=uri, time_zone=sel.ByValue(time_zone), start_date=start_date, start_hour=start_hour, start_min=start_min, ) if run_type == "Once": self.details["timer_type"] = "Once" else: field = version.pick({ version.LOWEST: self.tab[run_type], '5.5': 'timer_value' }) self.details["timer_type"] = run_type self.details[field] = run_every def create(self, cancel=False, samba_validate=False): """ Create a new schedule from the informations stored in the object. Args: cancel: Whether to click on the cancel button to interrupt the creation. samba_validate: Samba-only option to click the `Validate` button to check if entered samba credentials are valid or not """ navigate_to(self, 'Add') fill(self.form, self.details) if samba_validate: sel.click(form_buttons.validate) if cancel: form_buttons.cancel() else: form_buttons.add() flash.assert_message_contain('Schedule "{}" was saved'.format( self.details['name'])) def update(self, updates, cancel=False, samba_validate=False): """ Modify an existing schedule with informations from this instance. Args: updates: Dict with fields to be updated cancel: Whether to click on the cancel button to interrupt the editation. samba_validate: Samba-only option to click the `Validate` button to check if entered samba credentials are valid or not """ navigate_to(self, 'Edit') self.details.update(updates) fill(self.form, self.details) if samba_validate: sel.click(form_buttons.validate) if cancel: form_buttons.cancel() else: form_buttons.save() def delete(self): super(DatabaseBackupSchedule, self).delete() flash.assert_message_contain('Schedule "{}": Delete successful'.format( self.details['description'])) @property def last_date(self): navigate_to(self, 'All') name = self.details["name"] row = records_table.find_row("Name", name) return row[6].text
class Schedule(Pretty, Navigatable): """ Configure/Configuration/Region/Schedules functionality Create, Update, Delete functionality. Args: name: Schedule's name. description: Schedule description. active: Whether the schedule should be active (default `True`) action: Action type filter_type: Filtering type filter_value: If a more specific `filter_type` is selected, here is the place to choose hostnames, machines and so ... run_type: Once, Hourly, Daily, ... run_every: If `run_type` is not Once, then you can specify how often it should be run. time_zone: Time zone selection. start_date: Specify start date (mm/dd/yyyy or datetime.datetime()). start_hour: Starting hour start_min: Starting minute. Usage: schedule = Schedule( "My very schedule", "Some description here.", action="Datastore Analysis", filter_type="All Datastores for Host", filter_value="datastore.intra.acme.com", run_type="Hourly", run_every="2 Hours" ) schedule.create() schedule.disable() schedule.enable() schedule.delete() # Or Schedule.enable_by_names("One schedule", "Other schedule") # And so. Note: TODO: Maybe the row handling might go into Table class? """ tab = { "Hourly": "timer_hours", "Daily": "timer_days", "Weekly": "timer_weeks", "Monthly": "timer_months" } form = Form(fields=[ ("name", Input("name")), ("description", Input("description")), ("active", Input("enabled")), ("action", { version.LOWEST: Select("select#action_typ"), '5.5': AngularSelect('action_typ') }), ("filter_type", { version.LOWEST: Select("select#filter_typ"), '5.5': AngularSelect('filter_typ') }), ("filter_value", { version.LOWEST: Select("select#filter_value"), '5.5': AngularSelect('filter_value') }), ("timer_type", { version.LOWEST: Select("select#timer_typ"), '5.5': AngularSelect('timer_typ') }), ("timer_hours", Select("select#timer_hours")), ("timer_days", Select("select#timer_days")), ("timer_weeks", Select("select#timer_weekss")), # Not a typo! ("timer_months", Select("select#timer_months")), ("timer_value", AngularSelect('timer_value'), { "appeared_in": "5.5" }), ("time_zone", { version.LOWEST: Select("select#time_zone"), '5.5': AngularSelect('time_zone') }), ("start_date", Calendar("miq_angular_date_1")), ("start_hour", { version.LOWEST: Select("select#start_hour"), '5.5': AngularSelect('start_hour') }), ("start_min", { version.LOWEST: Select("select#start_min"), '5.5': AngularSelect('start_min') }), ]) pretty_attrs = [ 'name', 'description', 'run_type', 'run_every', 'start_date', 'start_hour', 'start_min' ] def __init__(self, name, description, active=True, action=None, filter_type=None, filter_value=None, run_type="Once", run_every=None, time_zone=None, start_date=None, start_hour=None, start_min=None, appliance=None): Navigatable.__init__(self, appliance=appliance) self.details = dict( name=name, description=description, active=active, action=action, filter_type=filter_type, filter_value=filter_value, time_zone=sel.ByValue(time_zone), start_date=start_date, start_hour=start_hour, start_min=start_min, ) if run_type == "Once": self.details["timer_type"] = "Once" else: field = version.pick({ version.LOWEST: self.tab[run_type], '5.5': 'timer_value' }) self.details["timer_type"] = run_type self.details[field] = run_every def create(self, cancel=False): """ Create a new schedule from the informations stored in the object. Args: cancel: Whether to click on the cancel button to interrupt the creation. """ navigate_to(self, 'Add') if cancel: action = form_buttons.cancel else: action = form_buttons.add fill(self.form, self.details, action=action) def update(self, updates, cancel=False): """ Modify an existing schedule with informations from this instance. Args: updates: Dict with fields to be updated cancel: Whether to click on the cancel button to interrupt the editation. """ navigate_to(self, 'Edit') if cancel: action = form_buttons.cancel else: action = form_buttons.save self.details.update(updates) fill(self.form, self.details, action=action) def delete(self, cancel=False): """ Delete the schedule represented by this object. Calls the class method with the name of the schedule taken out from the object. Args: cancel: Whether to click on the cancel button in the pop-up. """ navigate_to(self, 'Details') tb.select("Configuration", "Delete this Schedule from the Database", invokes_alert=True) sel.handle_alert(cancel) def enable(self): """ Enable the schedule via table checkbox and Configuration menu. """ self.select() tb.select("Configuration", "Enable the selected Schedules") def disable(self): """ Enable the schedule via table checkbox and Configuration menu. """ self.select() tb.select("Configuration", "Disable the selected Schedules") def select(self): """ Select the checkbox for current schedule """ navigate_to(self, 'All') for row in records_table.rows(): if row.name.strip() == self.details['name']: checkbox = row[0].find_element_by_xpath( "//input[@type='checkbox']") if not checkbox.is_selected(): sel.click(checkbox) break else: raise ScheduleNotFound( "Schedule '{}' could not be found for selection!".format( self.details['name']))