コード例 #1
0
    def create_schedule(self):

        try:
            sched = netapp_utils.Schedule()
            # if self.interval == 'time_interval':
            sched.frequency = netapp_utils.TimeIntervalFrequency(
                days=self.time_interval_days,
                hours=self.time_interval_hours,
                minutes=self.time_interval_minutes)

            # Create schedule
            sched.name = self.name
            sched.schedule_info = netapp_utils.ScheduleInfo(
                volume_ids=self.volumes,
                snapshot_name=self.snapshot_name,
                retention=self.retention)
            sched.paused = self.paused
            sched.recurring = self.recurring
            sched.starting_date = self.starting_date

            self.create_schedule_result = self.sfe.create_schedule(
                schedule=sched)

        except Exception as e:
            self.module.fail_json(msg='Error creating schedule %s: %s' %
                                  (self.name, to_native(e)),
                                  exception=traceback.format_exc())
コード例 #2
0
    def update_schedule(self):

        try:
            get_schedule_result = self.sfe.get_schedule(
                schedule_id=self.schedule_id)
            sched = get_schedule_result.schedule

            # Update schedule properties

            # if self.interval == 'time_interval':
            temp_frequency = netapp_utils.TimeIntervalFrequency(
                days=self.time_interval_days,
                hours=self.time_interval_hours,
                minutes=self.time_interval_minutes)

            if sched.frequency.days != temp_frequency.days or \
                sched.frequency.hours != temp_frequency.hours \
                    or sched.frequency.minutes != temp_frequency.minutes:
                sched.frequency = temp_frequency

            sched.name = self.name
            if self.volumes is not None:
                sched.schedule_info.volume_ids = self.volumes
            if self.retention is not None:
                sched.schedule_info.retention = self.retention
            if self.snapshot_name is not None:
                sched.schedule_info.snapshot_name = self.snapshot_name
            if self.paused is not None:
                sched.paused = self.paused
            if self.recurring is not None:
                sched.recurring = self.recurring
            if self.starting_date is not None:
                sched.starting_date = self.starting_date

            # Make API call
            self.sfe.modify_schedule(schedule=sched)

        except Exception as e:
            self.module.fail_json(msg='Error updating schedule %s: %s' %
                                  (self.name, to_native(e)),
                                  exception=traceback.format_exc())
コード例 #3
0
    def apply(self):
        changed = False
        schedule_exists = False
        update_schedule = False
        schedule_detail = self.get_schedule()

        if schedule_detail:
            schedule_exists = True

            if self.state == 'absent':
                changed = True

            elif self.state == 'present':
                # Check if we need to update the account

                if self.retention is not None and schedule_detail.schedule_info.retention != self.retention:
                    update_schedule = True
                    changed = True

                elif schedule_detail.name != self.name:
                    update_schedule = True
                    changed = True

                elif self.snapshot_name is not None and schedule_detail.schedule_info.snapshot_name != self.snapshot_name:
                    update_schedule = True
                    changed = True

                elif self.volumes is not None and schedule_detail.schedule_info.volume_ids != self.volumes:
                    update_schedule = True
                    changed = True

                elif self.paused is not None and schedule_detail.paused != self.paused:
                    update_schedule = True
                    changed = True

                elif self.recurring is not None and schedule_detail.recurring != self.recurring:
                    update_schedule = True
                    changed = True

                elif self.starting_date is not None and schedule_detail.starting_date != self.starting_date:
                    update_schedule = True
                    changed = True

                elif self.time_interval_minutes is not None or self.time_interval_hours is not None \
                        or self.time_interval_days is not None:

                    temp_frequency = netapp_utils.TimeIntervalFrequency(
                        days=self.time_interval_days,
                        hours=self.time_interval_hours,
                        minutes=self.time_interval_minutes)

                    if schedule_detail.frequency.days != temp_frequency.days or \
                            schedule_detail.frequency.hours != temp_frequency.hours \
                            or schedule_detail.frequency.minutes != temp_frequency.minutes:
                        update_schedule = True
                        changed = True

        else:
            if self.state == 'present':
                changed = True

        if changed:
            if self.module.check_mode:
                # Skip changes
                pass
            else:
                if self.state == 'present':
                    if not schedule_exists:
                        self.create_schedule()
                    elif update_schedule:
                        self.update_schedule()

                elif self.state == 'absent':
                    self.delete_schedule()

        if self.create_schedule_result is not None:
            self.module.exit_json(
                changed=changed,
                schedule_id=self.create_schedule_result.schedule_id)
        else:
            self.module.exit_json(changed=changed)