コード例 #1
0
def create_group(identity_client, module):
    result = dict()
    users = module.params.get('users')
    create_group_details = CreateGroupDetails()
    for attribute in create_group_details.attribute_map:
        create_group_details.__setattr__(attribute,
                                         module.params.get(attribute))
    response = oci_utils.call_with_backoff(
        identity_client.create_group,
        create_group_details=create_group_details)
    group_id = response.data.id
    response = oci_utils.call_with_backoff(identity_client.get_group,
                                           group_id=group_id)
    oci.wait_until(identity_client, response, 'lifecycle_state', 'ACTIVE')
    group = response.data
    try:
        if users:
            user_ids = get_user_ids_from_user_names(identity_client, users,
                                                    module)
            add_users_to_group(identity_client, group.id, user_ids)
    except (ServiceError, ClientError) as ex:
        message = None
        if isinstance(ex, ClientError):
            message = ex.args[0]
        else:
            message = ex.message
        module.params.update(dict({'id': group.id}))
        module.params.update(dict({'force': True}))
        delete_group(identity_client, module)
        module.fail_json(msg=message)
    result['group'] = to_dict(group)
    result['changed'] = True
    return result
コード例 #2
0
def create_or_update_group(identity_client, module):
    group = None
    existing_group = None
    result = dict(changed=False, group='')
    group_id = module.params.get('group_id')
    exclude_attributes = {'compartment_id': True}
    try:
        if group_id:
            existing_group = oci_utils.get_existing_resource(
                identity_client.get_group, module, group_id=group_id)
            changed, group = update_group(identity_client, existing_group,
                                          module)
            result['changed'] = changed
            result['group'] = group
        else:
            result = oci_utils.check_and_create_resource(
                resource_type='group',
                create_fn=create_group,
                kwargs_create={
                    'identity_client': identity_client,
                    'module': module
                },
                list_fn=identity_client.list_groups,
                kwargs_list={
                    'compartment_id': module.params.get('compartment_id')
                },
                module=module,
                exclude_attributes=exclude_attributes,
                model=CreateGroupDetails())
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=ex.args)
    return result
コード例 #3
0
def create_soc_group():
    """Function to create a specified or default SOC group"""
    print("Creating group " + groupName)
    request = CreateGroupDetails()
    request.compartment_id = tcompartment_id
    request.name = groupName
    request.description = "Created with the SOC setup script"
    try:
        group = identity.create_group(request)
        group_id = group.data.id
        print(group_id)
    except oci.exceptions.ServiceError as e:
        if e.status == 409:
            print("Group already exists...")
            return

        else:
            print("Operational Error" + e.message)
コード例 #4
0
ファイル: user_crud.py プロジェクト: ydgreene/oci-python-sdk
group_name = "python-sdk-example-group"

print("Creating a new user {!r} in compartment {!r}".format(
    user_name, compartment_id))

request = CreateUserDetails()
request.compartment_id = compartment_id
request.name = user_name
request.description = "Created by a Python SDK example"
user = identity.create_user(request)
print(user.data)

print("Creating a new group {!r} in compartment {!r}".format(
    group_name, compartment_id))

request = CreateGroupDetails()
request.compartment_id = compartment_id
request.name = group_name
request.description = "Created by a Python SDK example"
group = identity.create_group(request)
print(group.data)

print("Adding new user to the new group")
request = AddUserToGroupDetails()
request.user_id = user.data.id
request.group_id = group.data.id
membership = identity.add_user_to_group(request)
print(membership.data)

print("Cleaning up resources.")
print("Removing {!r} from {!r}.".format(user_name, group_name))
コード例 #5
0
 def handle(self, *args, **options):
     from oci.identity import IdentityClient
     config = oci.config.from_file()
     identity = IdentityClient(config)
     from oci.identity.models import CreateGroupDetails
     request = CreateGroupDetails()
     compartment_id = config["tenancy"]
     request.compartment_id = compartment_id
     request.name = "my-test-group"
     request.description = "Created with the Python SDK"
     group = identity.create_group(request)
     from oci.identity.models import CreateUserDetails
     request = CreateUserDetails()
     request.compartment_id = compartment_id
     request.name = "my-test-user"
     request.description = "Created with the Python SDK"
     user = identity.create_user(request)
     from oci.identity.models import AddUserToGroupDetails
     request = AddUserToGroupDetails()
     request.group_id = group.data.id
     request.user_id = user.data.id
     response = identity.add_user_to_group(request)
     print(response.status)