예제 #1
0
def update_bucket(module, blade, bucket):
    """ Update Bucket """
    changed = True
    if not module.check_mode:
        changed = False
        api_version = blade.api_version.list_versions().versions
        if VERSIONING_VERSION in api_version:
            module.warn('{0}'.format(bucket.versioning))
            if bucket.versioning != 'none':
                if module.params['versioning'] == 'absent':
                    versioning = 'suspended'
                else:
                    versioning = module.params['versioning']
                if bucket.versioning != versioning:
                    try:
                        blade.buckets.update_buckets(names=[module.params['name']],
                                                     bucket=BucketPatch(versioning=versioning))
                        changed = True
                    except Exception:
                        module.fail_json(msg='Object Store Bucket {0}: Versioning change failed'.format(module.params['name']))
            elif module.params['versioning'] != 'absent':
                try:
                    blade.buckets.update_buckets(names=[module.params['name']],
                                                 bucket=BucketPatch(versioning=module.params['versioning']))
                    changed = True
                except Exception:
                    module.fail_json(msg='Object Store Bucket {0}: Versioning change failed'.format(module.params['name']))
    module.exit_json(changed=changed)
예제 #2
0
def create_bucket(module, blade):
    """Create bucket"""
    changed = True
    if not module.check_mode:
        try:
            api_version = blade.api_version.list_versions().versions
            if VERSIONING_VERSION in api_version:
                attr = BucketPost()
                attr.account = Reference(name=module.params["account"])
                blade.buckets.create_buckets(names=[module.params["name"]],
                                             bucket=attr)
            else:
                attr = Bucket()
                attr.account = Reference(name=module.params["account"])
                blade.buckets.create_buckets(names=[module.params["name"]],
                                             account=attr)
            if (module.params["versioning"] != "absent"
                    and VERSIONING_VERSION in api_version):
                try:
                    blade.buckets.update_buckets(
                        names=[module.params["name"]],
                        bucket=BucketPatch(
                            versioning=module.params["versioning"]),
                    )
                except Exception:
                    module.fail_json(
                        msg=
                        "Object Store Bucket {0} Created but versioning state failed"
                        .format(module.params["name"]))
        except Exception:
            module.fail_json(msg="Object Store Bucket {0}: Creation failed".
                             format(module.params["name"]))
    module.exit_json(changed=changed)
예제 #3
0
def delete_bucket(module, blade):
    """Delete Bucket"""
    changed = True
    if not module.check_mode:
        try:
            api_version = blade.api_version.list_versions().versions
            if VERSIONING_VERSION in api_version:
                blade.buckets.update_buckets(
                    names=[module.params["name"]], bucket=BucketPatch(destroyed=True)
                )
            else:
                blade.buckets.update_buckets(
                    names=[module.params["name"]], destroyed=Bucket(destroyed=True)
                )
            if module.params["eradicate"]:
                try:
                    blade.buckets.delete_buckets(names=[module.params["name"]])
                except Exception:
                    module.fail_json(
                        msg="Object Store Bucket {0}: Eradication failed".format(
                            module.params["name"]
                        )
                    )
        except Exception:
            module.fail_json(
                msg="Object Store Bucket {0}: Deletion failed".format(
                    module.params["name"]
                )
            )
    module.exit_json(changed=changed)
예제 #4
0
def update_bucket(module, blade, bucket):
    """Update Bucket"""
    changed = False
    api_version = blade.api_version.list_versions().versions
    if VERSIONING_VERSION in api_version:
        module.warn("{0}".format(bucket.versioning))
        if bucket.versioning != "none":
            if module.params["versioning"] == "absent":
                versioning = "suspended"
            else:
                versioning = module.params["versioning"]
            if bucket.versioning != versioning:
                changed = True
                if not module.check_mode:
                    try:
                        blade.buckets.update_buckets(
                            names=[module.params["name"]],
                            bucket=BucketPatch(versioning=versioning),
                        )
                        changed = True
                    except Exception:
                        module.fail_json(
                            msg="Object Store Bucket {0}: Versioning change failed".format(
                                module.params["name"]
                            )
                        )
        elif module.params["versioning"] != "absent":
            changed = True
            if not module.check_mode:
                try:
                    blade.buckets.update_buckets(
                        names=[module.params["name"]],
                        bucket=BucketPatch(versioning=module.params["versioning"]),
                    )
                    changed = True
                except Exception:
                    module.fail_json(
                        msg="Object Store Bucket {0}: Versioning change failed".format(
                            module.params["name"]
                        )
                    )
    module.exit_json(changed=changed)
예제 #5
0
def recover_bucket(module, blade):
    """ Recover Bucket"""
    changed = True
    if not module.check_mode:
        try:
            api_version = blade.api_version.list_versions().versions
            if VERSIONING_VERSION in api_version:
                blade.buckets.update_buckets(names=[module.params['name']],
                                             bucket=BucketPatch(destroyed=False))
            else:
                blade.buckets.update_buckets(names=[module.params['name']],
                                             destroyed=Bucket(destroyed=False))
        except Exception:
            module.fail_json(msg='Object Store Bucket {0}: Recovery failed'.format(module.params['name']))
    module.exit_json(changed=changed)
def update_bucket(module, blade, bucket):
    """ Update Bucket """
    changed = True
    if not module.check_mode:
        api_version = blade.api_version.list_versions().versions
        if VERSIONING_VERSION in api_version:
            if bucket.versioning != module.params['versioning']:
                try:
                    blade.buckets.update_buckets(
                        names=[module.params['name']],
                        bucket=BucketPatch(
                            versioning=module.params['versioning']))
                except Exception:
                    module.fail_json(
                        msg='Object Store Bucket {0}: Versioning change failed'
                        .format(module.params['name']))
    module.exit_json(changed=changed)