def get_frequency(self):
     # Configuring frequency depends on self.schedule_type
     frequency = None
     if self.schedule_type is not None and self.schedule_type == 'DaysOfWeekFrequency':
         if self.weekdays is not None:
             params = dict(weekdays=self.weekdays)
             if self.days_of_week_hours is not None:
                 params['hours'] = self.days_of_week_hours
             if self.days_of_week_minutes is not None:
                 params['minutes'] = self.days_of_week_minutes
             frequency = DaysOfWeekFrequency(**params)
     elif self.schedule_type is not None and self.schedule_type == 'DaysOfMonthFrequency':
         if self.days_of_month_monthdays is not None:
             params = dict(monthdays=self.days_of_month_monthdays)
             if self.days_of_month_hours is not None:
                 params['hours'] = self.days_of_month_hours
             if self.days_of_month_minutes is not None:
                 params['minutes'] = self.days_of_month_minutes
             frequency = DaysOfMonthFrequency(**params)
     elif self.schedule_type is not None and self.schedule_type == 'TimeIntervalFrequency':
         params = dict()
         if self.time_interval_days is not None:
             params['days'] = self.time_interval_days
         if self.time_interval_hours is not None:
             params['hours'] = self.time_interval_hours
         if self.time_interval_minutes is not None:
             params['minutes'] = self.time_interval_minutes
         if not params or sum(params.values()) == 0:
             self.module.fail_json(
                 msg=
                 'Specify at least one non zero value with TimeIntervalFrequency.'
             )
         frequency = netapp_utils.TimeIntervalFrequency(**params)
     return frequency
Ejemplo n.º 2
0
    def to_schedule(api):
        """
        Converts an ApiSchedule object into a Schedule object

        :param api: the ApiSchedule object to be converted
        :type api: solidfire.apiactual.ApiSchedule

        :return: solidfire.models.Schedule
        """
        schedule = Schedule()

        schedule.has_error = api.has_error
        schedule.last_run_status = api.last_run_status
        schedule.last_run_time_start = api.last_run_time_start
        schedule.name = api.schedule_name
        schedule.paused = api.paused
        schedule.recurring = api.recurring
        schedule.run_next_interval = api.run_next_interval
        schedule.schedule_id = api.schedule_id
        schedule.starting_date = api.starting_date
        schedule.to_be_deleted = api.to_be_deleted

        schedule.schedule_info = ScheduleAdaptor.to_schedule_info(
            api.schedule_info)

        try:
            freq = api.attributes["frequency"]

            if freq == "Time Interval":
                schedule.frequency = TimeIntervalFrequency()
                schedule.frequency.days = int(api.hours / 24)
                schedule.frequency.hours = int(api.hours % 24)
                schedule.frequency.minutes = api.minutes
                schedule.frequency.weekdays = None
                schedule.frequency.monthdays = None
            elif freq == "Days Of Month":
                schedule.frequency = DaysOfMonthFrequency()
                schedule.frequency.hours = api.hours
                schedule.frequency.minutes = api.minutes
                schedule.frequency.monthdays = api.monthdays
                schedule.frequency.weekdays = None
            elif freq == "Days Of Week":
                schedule.frequency = DaysOfWeekFrequency()
                schedule.frequency.hours = api.hours
                schedule.frequency.minutes = api.minutes
                schedule.frequency.weekdays = ScheduleAdaptor \
                    .to_weekdays(api.weekdays)
                schedule.frequency.monthdays = None
            else:
                raise Exception("Cannot determine frequency")
        except:
            LOG.error("Cannot deserialize Schedule {0}. The frequency "
                      "property has an unknown value.".format(
                schedule.name))

        return schedule
    def to_schedule(api):
        """
        Converts an ApiSchedule object into a Schedule object

        :param api: the ApiSchedule object to be converted
        :type api: solidfire.apiactual.ApiSchedule

        :return: solidfire.models.Schedule
        """
        schedule_info = ScheduleAdaptor.to_schedule_info(api.schedule_info)

        frequency = None
        try:
            freq = api.attributes["frequency"]

            if freq == "Time Interval":
                frequency = TimeIntervalFrequency(days=int(api.hours / 24),
                                                  hours=int(api.hours % 24),
                                                  minutes=api.minutes)
            elif freq == "Days Of Month":
                frequency = DaysOfMonthFrequency(
                    hours=api.hours,
                    minutes=api.minutes,
                    monthdays=api.monthdays,
                )
            elif freq == "Days Of Week":
                frequency = DaysOfWeekFrequency(
                    hours=api.hours,
                    minutes=api.minutes,
                    weekdays=ScheduleAdaptor.to_weekdays(api.weekdays),
                )
            else:
                raise Exception("Cannot determine frequency")
        except:
            LOG.error("Cannot deserialize Schedule {0}. The frequency "
                      "property has an unknown value.".format(
                          api.schedule_name))

        return Schedule(has_error=api.has_error,
                        last_run_status=api.last_run_status,
                        last_run_time_started=api.last_run_time_started,
                        name=api.schedule_name,
                        paused=api.paused,
                        recurring=api.recurring,
                        run_next_interval=api.run_next_interval,
                        schedule_id=api.schedule_id,
                        starting_date=api.starting_date,
                        to_be_deleted=api.to_be_deleted,
                        schedule_info=schedule_info,
                        frequency=frequency)
Ejemplo n.º 4
0
 def get_frequency(self):
     # Configuring frequency depends on self.schedule_type
     frequency = None
     if self.schedule_type is not None and self.schedule_type == 'DaysOfWeekFrequency':
         if self.weekdays is not None:
             frequency = DaysOfWeekFrequency(weekdays=self.weekdays,
                                             hours=self.days_of_week_hours,
                                             minutes=self.days_of_week_minutes)
     elif self.schedule_type is not None and self.schedule_type == 'DaysOfMonthFrequency':
         if self.days_of_month_monthdays is not None:
             frequency = DaysOfMonthFrequency(monthdays=self.days_of_month_monthdays,
                                              hours=self.days_of_month_hours,
                                              minutes=self.days_of_month_minutes)
     elif self.schedule_type is not None and self.schedule_type == 'TimeIntervalFrequency':
         frequency = netapp_utils.TimeIntervalFrequency(days=self.time_interval_days,
                                                        hours=self.time_interval_hours,
                                                        minutes=self.time_interval_minutes)
     return frequency