Added support for Standard - Infrequent Access stoarage class (#2134)
This commit is contained in:
parent
7618fd8749
commit
8c1b672929
1 changed files with 21 additions and 5 deletions
|
@ -65,10 +65,11 @@ options:
|
||||||
choices: [ 'enabled', 'disabled' ]
|
choices: [ 'enabled', 'disabled' ]
|
||||||
storage_class:
|
storage_class:
|
||||||
description:
|
description:
|
||||||
- "The storage class to transition to. Currently there is only one valid value - 'glacier'."
|
- "The storage class to transition to. Currently there are two supported values - 'glacier' or 'standard_ia'."
|
||||||
|
- "The 'standard_ia' class is only being available from Ansible version 2.2."
|
||||||
required: false
|
required: false
|
||||||
default: glacier
|
default: glacier
|
||||||
choices: [ 'glacier' ]
|
choices: [ 'glacier', 'standard_ia']
|
||||||
transition_date:
|
transition_date:
|
||||||
description:
|
description:
|
||||||
- "Indicates the lifetime of the objects that are subject to the rule by the date they will transition to a different storage class. The value must be ISO-8601 format, the time must be midnight and a GMT timezone must be specified. If transition_days is not specified, this parameter is required."
|
- "Indicates the lifetime of the objects that are subject to the rule by the date they will transition to a different storage class. The value must be ISO-8601 format, the time must be midnight and a GMT timezone must be specified. If transition_days is not specified, this parameter is required."
|
||||||
|
@ -127,6 +128,15 @@ EXAMPLES = '''
|
||||||
prefix: /logs/
|
prefix: /logs/
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
# Configure a lifecycle rule to transition all backup files older than 31 days in /backups/ to standard infrequent access class.
|
||||||
|
- s3_lifecycle:
|
||||||
|
name: mybucket
|
||||||
|
prefix: /backups/
|
||||||
|
storage_class: standard_ia
|
||||||
|
transition_days: 31
|
||||||
|
state: present
|
||||||
|
status: enabled
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
@ -140,6 +150,7 @@ except ImportError:
|
||||||
HAS_DATEUTIL = False
|
HAS_DATEUTIL = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import boto
|
||||||
import boto.ec2
|
import boto.ec2
|
||||||
from boto.s3.connection import OrdinaryCallingFormat, Location
|
from boto.s3.connection import OrdinaryCallingFormat, Location
|
||||||
from boto.s3.lifecycle import Lifecycle, Rule, Expiration, Transition
|
from boto.s3.lifecycle import Lifecycle, Rule, Expiration, Transition
|
||||||
|
@ -343,15 +354,15 @@ def main():
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
dict(
|
dict(
|
||||||
name = dict(required=True),
|
name = dict(required=True, type='str'),
|
||||||
expiration_days = dict(default=None, required=False, type='int'),
|
expiration_days = dict(default=None, required=False, type='int'),
|
||||||
expiration_date = dict(default=None, required=False, type='str'),
|
expiration_date = dict(default=None, required=False, type='str'),
|
||||||
prefix = dict(default=None, required=False),
|
prefix = dict(default=None, required=False),
|
||||||
requester_pays = dict(default='no', type='bool'),
|
requester_pays = dict(default='no', type='bool'),
|
||||||
rule_id = dict(required=False),
|
rule_id = dict(required=False, type='str'),
|
||||||
state = dict(default='present', choices=['present', 'absent']),
|
state = dict(default='present', choices=['present', 'absent']),
|
||||||
status = dict(default='enabled', choices=['enabled', 'disabled']),
|
status = dict(default='enabled', choices=['enabled', 'disabled']),
|
||||||
storage_class = dict(default='glacier', choices=['glacier']),
|
storage_class = dict(default='glacier', type='str', choices=['glacier', 'standard_ia']),
|
||||||
transition_days = dict(default=None, required=False, type='int'),
|
transition_days = dict(default=None, required=False, type='int'),
|
||||||
transition_date = dict(default=None, required=False, type='str')
|
transition_date = dict(default=None, required=False, type='str')
|
||||||
)
|
)
|
||||||
|
@ -392,6 +403,7 @@ def main():
|
||||||
expiration_date = module.params.get("expiration_date")
|
expiration_date = module.params.get("expiration_date")
|
||||||
transition_date = module.params.get("transition_date")
|
transition_date = module.params.get("transition_date")
|
||||||
state = module.params.get("state")
|
state = module.params.get("state")
|
||||||
|
storage_class = module.params.get("storage_class")
|
||||||
|
|
||||||
# If expiration_date set, check string is valid
|
# If expiration_date set, check string is valid
|
||||||
if expiration_date is not None:
|
if expiration_date is not None:
|
||||||
|
@ -406,6 +418,10 @@ def main():
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
module.fail_json(msg="expiration_date is not a valid ISO-8601 format. The time must be midnight and a timezone of GMT must be included")
|
module.fail_json(msg="expiration_date is not a valid ISO-8601 format. The time must be midnight and a timezone of GMT must be included")
|
||||||
|
|
||||||
|
boto_required_version = (2,40,0)
|
||||||
|
if storage_class == 'standard_ia' and tuple(map(int, (boto.__version__.split(".")))) < boto_required_version:
|
||||||
|
module.fail_json(msg="'standard_ia' class requires boto >= 2.40.0")
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
create_lifecycle_rule(connection, module)
|
create_lifecycle_rule(connection, module)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
|
|
Loading…
Reference in a new issue