def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters) self.instances = self._resources_ self._ec2_client = None self._metrics_client = None self.cpu_high = int(self.get(PARAM_CPU_PERC_HIGH)) self.cpu_low = int(self.get(PARAM_CPU_PERC_LOW)) self.cpu_high_tags = self.get(PARAM_CPU_HIGH_TAGS) self.cpu_low_tags = self.get(PARAM_CPU_LOW_TAGS) self.interval = self.get(actions.ACTION_PARAM_INTERVAL) e = CronExpression(self.interval) previous_executions = list(e.within_last(timespan=timedelta(hours=24), end_dt=date_time_provider().utcnow() - timedelta(minutes=1))) self.period_in_minutes = max(5, int( (previous_executions[1] - previous_executions[0]).total_seconds()) / 60) self.under_utilized_instances = [] self.over_utilized_instances = [] self.result = { "account": self._account_, "region": self._region_, "task": self._task_, "instances-checked": len(self.instances), }
def __init__(self, action_args, action_parameters): self._destination_region_ = None ActionBase.__init__(self, action_args, action_parameters) # debug and dryrun self.snapshot = self._resources_ # snapshot source and destination information self.source_snapshot_id = self.snapshot["SnapshotId"] self.source_region = self.snapshot["Region"] self.owner = self.snapshot.get("OwnerId", "") self.encrypted = self.get(PARAM_ENCRYPTED, False) self.kms_key_id = self.get(PARAM_KMS_KEY_ID, None) self.accounts_with_create_permissions = self.get( PARAM_ACCOUNTS_VOLUME_CREATE_PERMISSIONS, []) self.delete_after_copy = self.get(PARAM_DELETE_AFTER_COPY, False) # filter for copied tags from source snapshot self.copied_volume_tagfiter = TagFilterSet( self.get(PARAM_COPIED_SNAPSHOT_TAGS, "")) self.tag_snapshots_in_shared_accounts = self.get( PARAM_TAG_IN_DESTINATION_ACCOUNT, False) self.tag_snapshots_in_source_account = self.get( PARAM_TAG_IN_SOURCE_ACCOUNT, False) # tagging roles self.dest_account_snapshot_tagging_rolename = self.get( PARAM_DESTINATION_ACCOUNT_TAG_ROLENAME, "") self.source_account_tagging_role_name = self.get( PARAM_SOURCE_ACCOUNT_TAG_ROLE_NAME, "") volume_id = self.snapshot["VolumeId"] if volume_id == DUMMY_VOLUME_IF_FOR_COPIED_SNAPSHOT: volume_from_tag = self.snapshot.get("Tags", {}).get( actions.marker_snapshot_tag_source_source_volume_id(), None) if volume_from_tag is not None: volume_id = volume_from_tag self.source_volume_id = volume_id self._ec2_destination_client = None self._ec2_source_client = None # setup result with known values self.result = { "account": self._account_, "task": self._task_, "destination-region": self._destination_region_, "source-region": self.source_region, "source-snapshot-id": self.source_snapshot_id, "encrypted": self.encrypted, "kms-id": self.kms_key_id if self.kms_key_id is not None else "" }
def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters) self.task_table = os.getenv(handlers.ENV_ACTION_TRACKING_TABLE, None) if self.task_table is None: raise_exception(ERR_NO_ENVIRONMENT_VARIABLE_, handlers.ENV_ACTION_TRACKING_TABLE) self.dryrun = self.get(actions.ACTION_PARAM_DRYRUN, False) self.debug = self.get(actions.ACTION_PARAM_DEBUG, False) self.S3Bucket = self.get(PARAM_S3_BUCKET) self.S3Prefix = self.get(PARAM_S3_PREFIX, "")
def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters) self.config_table = os.getenv(configuration.ENV_CONFIG_TABLE, None) self.debug = self.get(actions.ACTION_PARAM_DEBUG, False) if self.config_table is None: raise_exception(ERR_ENVIRONMENT_CONFIG_VARIABLE_, configuration.ENV_CONFIG_TABLE) self.S3Bucket = self.get(PARAM_S3_BUCKET) self.S3Prefix = self.get(PARAM_S3_PREFIX)
def __init__(self, arguments, action_parameters): ActionBase.__init__(self, arguments, action_parameters) self.instance = self._resources_ self.instance_id = self.instance["InstanceId"] self._ec2_client = None # tags on the instance self.tags_on_instance = self.instance.get("Tags", {}) self.volumes = { dev["Ebs"]["VolumeId"]: dev["DeviceName"] for dev in self.instance["BlockDeviceMappings"] } self.root_volume = None for dev in self.volumes: if self.volumes[dev] == self.instance["RootDeviceName"]: self.root_volume = dev self.accounts_with_create_permissions = self.get( PARAM_ACCOUNTS_VOLUME_CREATE_PERMISSIONS, []) self.tag_shared_snapshots = self.get(PARAM_TAG_SHARED_SNAPSHOTS, False) self.copied_instance_tagfilter = TagFilterSet( self.get(PARAM_COPIED_INSTANCE_TAGS, "")) self.copied_volume_tagfilter = TagFilterSet( self.get(PARAM_COPIED_VOLUME_TAGS, "")) self.backup_root_device = self.get(PARAM_BACKUP_ROOT_DEVICE, True) self.backup_data_devices = self.get(PARAM_BACKUP_DATA_DEVICES, True) self.set_snapshot_name = self.get(PARAM_SET_SNAPSHOT_NAME, True) volume_tag_filter = self.get(PARAM_VOLUME_TAG_FILTER, None) self.volume_tag_filter = TagFilterExpression( volume_tag_filter) if volume_tag_filter not in ["", None] else None self._all_volume_tags = None self.result = { "account": self._account_, "region": self._region_, "instance": self.instance_id, "task": self._task_, "volumes": {}, "snapshots": {} }
def __init__(self, action_arguments, action_parameters): self._table_read_units_ = None self._table_write_units_ = None self._table_name_ = None ActionBase.__init__(self, action_arguments, action_parameters) self.client = get_client_with_retries( "dynamodb", ["describe_table", "update_table"], context=self._context_, region=self._region_, session=self._session_, logger=self._logger_) self.result = {}
def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters) self.task_table = os.getenv(handlers.ENV_ACTION_TRACKING_TABLE, None) if self.task_table is None: raise_exception(ERR_MISSING_ENVIRONMENT_VARIABLE_, handlers.ENV_ACTION_TRACKING_TABLE) # adding 48 hours as TTL is used in V2 as primary mechanism to delete items self.task_retention_seconds = (int(self.get(PARAM_TASK_RETENTION_HOURS)) + 48) * 3600 self.retain_failed_tasks = self.get(PARAM_RETAIN_FAILED_TASKS, True) self.dryrun = self.get(ACTION_PARAM_DRYRUN, False) self.debug = self.get(ACTION_PARAM_DEBUG, False) self._client = None
def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters) self.snapshots = sorted(self._resources_) self.retention_days = int(self.get(PARAM_RETENTION_DAYS)) self.retention_count = int(self.get(PARAM_RETENTION_COUNT)) self.dryrun = self.get(ACTION_PARAM_DRYRUN, False) self._ec2_client = None self.result = { "account": self._account_, "region": self._region_, "task": self._task_ }
def __init__(self, action_arguments, action_parameters): ActionBase.__init__(self, action_arguments, action_parameters)