How to use the oci.identity.IdentityClient function in oci

To help you get started, we’ve selected a few oci examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / oci-ansible-modules / library / oci_identity_tag_default.py View on Github external
dict(
            compartment_id=dict(type="str"),
            tag_definition_id=dict(type="str"),
            value=dict(type="str"),
            tag_default_id=dict(aliases=["id"], type="str"),
            state=dict(type="str", default="present", choices=["present", "absent"]),
        )
    )

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    resource_helper = ResourceHelper(
        module=module, resource_type="tag_default", service_client_class=IdentityClient
    )

    result = dict(changed=False)

    if resource_helper.is_delete():
        result = resource_helper.delete()
    elif resource_helper.is_update():
        result = resource_helper.update()
    elif resource_helper.is_create():
        result = resource_helper.create()

    module.exit_json(**result)
github oracle / oci-python-sdk / examples / user_crud.py View on Github external
# coding: utf-8
# Copyright (c) 2016, 2020, Oracle and/or its affiliates.  All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.

import oci
from oci.identity.models import AddUserToGroupDetails, CreateGroupDetails, CreateUserDetails

# Default config file and profile
config = oci.config.from_file()
compartment_id = config["tenancy"]
# Service client
identity = oci.identity.IdentityClient(config)

# Get and set the home region for the compartment. User crud operations need
# to be performed in the home region.
response = identity.list_region_subscriptions(compartment_id)
for region in response.data:
    if region.is_home_region:
        identity.base_client.set_region(region.region_name)
        break

user_name = "python-sdk-example-user"
group_name = "python-sdk-example-group"

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

request = CreateUserDetails()
github oracle / oci-python-sdk / scripts / wercker_validate.py View on Github external
encoding=serialization.Encoding.PEM,
    format=serialization.PrivateFormat.TraditionalOpenSSL,
    encryption_algorithm=serialization.NoEncryption()
)

# These are dummy values and don't exist
config = {
    'log_requests': True,
    'region': 'us-ashburn-1',
    'tenancy': 'ocidv1:tenancy:oc1:phx:1111111111111:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    'user': 'ocid1.user.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    'key_content': key_content,
    'fingerprint': '00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00'
}

identity_client = oci.identity.IdentityClient(config)
try:
    identity_client.list_regions()
except ServiceError:
    # We expect a service error here because we sent dummy auth information
    pass
github oracle / oci-python-sdk / examples / invoke_function.py View on Github external
def setup_resources(oci_cfg, compartment_id, name, image):
    """
    Setup the minimal OCI resources required to establish an invocable function.

    :param compartment_id: The compartment_id in which to create the resources.
    :type compartment_id: str

    :param name: The name to identify all created resources with.
    :type name: str

    :param image: An accessible OCIR Function image that can be invoked.
    :type image: str
    """
    identity_client = identity.IdentityClient(oci_cfg)
    network_client = core.VirtualNetworkClient(oci_cfg)
    fn_management_client = functions.FunctionsManagementClient(oci_cfg)

    vn_composite_ops = oci.core.VirtualNetworkClientCompositeOperations(network_client)

    print("setup_resources")

    #  1. A VCN is required to host subnets.
    vcn = get_unique_vcn_by_name(network_client, compartment_id, vcn_name(name))
    if vcn is None:
        vcn_details = core_models.CreateVcnDetails(
            compartment_id=compartment_id, display_name=vcn_name(name), cidr_block="10.0.0.0/16"
        )
        result = vn_composite_ops.create_vcn_and_wait_for_state(
            vcn_details, wait_for_states=[oci.core.models.Vcn.LIFECYCLE_STATE_AVAILABLE]
        )
github oracle / oci-python-sdk / examples / list_resources_in_tenancy / list_compute_tags_in_tenancy.py View on Github external
cmd = parser.parse_args()

# Start print time info
start_time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print_header("Running List Compute Tags")
print("Written By Adi Zohar, June 2020")
print("Starts at " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
print("Command Line : " + ' '.join(x for x in sys.argv[1:]))

# Identity extract compartments
config, signer = create_signer(cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
compartments = []
tenancy = None
try:
    print("\nConnecting to Identity Service...")
    identity = oci.identity.IdentityClient(config, signer=signer)
    if cmd.proxy:
        identity.base_client.session.proxies = {'https': cmd.proxy}

    tenancy = identity.get_tenancy(config["tenancy"]).data
    regions = identity.list_region_subscriptions(tenancy.id).data

    print("Tenant Name : " + str(tenancy.name))
    print("Tenant Id   : " + tenancy.id)
    print("")

    compartments = identity_read_compartments(identity, tenancy)

except Exception as e:
    raise RuntimeError("\nError extracting compartments section - " + str(e))

############################################
github oracle / oci-python-sdk / examples / list_resources_in_tenancy / list_dbsystem_with_maintenance_in_tenancy.py View on Github external
cmd = parser.parse_args()

# Start print time info
start_time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print_header("Running DB Systems Extract")
print("Written By Adi Zohar, June 2020")
print("Starts at " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
print("Command Line : " + ' '.join(x for x in sys.argv[1:]))

# Identity extract compartments
config, signer = create_signer(cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
compartments = []
tenancy = None
try:
    print("\nConnecting to Identity Service...")
    identity = oci.identity.IdentityClient(config, signer=signer)
    if cmd.proxy:
        identity.base_client.session.proxies = {'https': cmd.proxy}

    tenancy = identity.get_tenancy(config["tenancy"]).data
    regions = identity.list_region_subscriptions(tenancy.id).data

    print("Tenant Name : " + str(tenancy.name))
    print("Tenant Id   : " + tenancy.id)
    print("")

    compartments = identity_read_compartments(identity, tenancy)

except Exception as e:
    raise RuntimeError("\nError extracting compartments section - " + str(e))
github oracle / oci-python-sdk / examples / get_all_instance_ip_addresses_and_dns_info.py View on Github external
print('No public IP mapping found for private IP: {} ({})'.format(private_ip.id, private_ip.ip_address))
                else:
                    print('Unexpected error when retrieving public IPs: {}'.format(str(e)))

    return instance_info


if len(sys.argv) != 2:
    raise RuntimeError('This script expects an argument of the OCID of the instance you wish to retrieve information for')

instance_id = sys.argv[1]

config = oci.config.from_file()
compute_client = oci.core.ComputeClient(config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)
virtual_network_client = oci.core.VirtualNetworkClient(config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)
identity_client = oci.identity.IdentityClient(config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)

ip_addresses_and_dns_info = get_instance_ip_addresses_and_dns_info(compute_client, virtual_network_client, identity_client, instance_id, config)
print('\n\nIP Address and DNS Info')
print('========================')
print(json.dumps(ip_addresses_and_dns_info, sort_keys=True, indent=2))
github oracle / oci-python-sdk / examples / stop_untagged_instances.py View on Github external
def list_of_regions(tenancy_id):
    identity = oci.identity.IdentityClient(config)
    list_of_regions = []
    list_regions_response = identity.list_region_subscriptions(tenancy_id)
    for r in list_regions_response.data:
        list_of_regions.append(r.region_name)
    return list_of_regions
github oracle / oci-ansible-modules / library / oci_identity_tag_default_facts.py View on Github external
dict(
            tag_default_id=dict(aliases=["id"], type="str"),
            id=dict(type="str"),
            compartment_id=dict(type="str"),
            tag_definition_id=dict(type="str"),
            lifecycle_state=dict(type="str", choices=["ACTIVE"]),
        )
    )

    module = AnsibleModule(argument_spec=module_args)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    resource_facts_helper = ResourceFactsHelper(
        module=module, resource_type="tag_default", service_client_class=IdentityClient
    )

    result = []

    if resource_facts_helper.is_get():
        result = resource_facts_helper.get()
    elif resource_facts_helper.is_list():
        result = resource_facts_helper.list()
    else:
        resource_facts_helper.fail()

    module.exit_json(tag_defaults=result)
github AnykeyNL / OCI-Python / move_instance.py View on Github external
import oci
import time

configs = ["c:\\oci\\config_frankfurt","c:\\oci\\config_phoenix","c:\\oci\\config_ashburn"] # Define config files to be used. You will need a seperate config file per region and/or account

config = oci.config.from_file(configs[0])

identity = oci.identity.IdentityClient(config)
user = identity.get_user(config["user"]).data
RootCompartmentID = user.compartment_id
  
print ("Logged in as: {} @ {}".format(user.description, config["region"]))
print (" ")

CompartmentID = "ocid1.tenancy.oc1..aaaaaaaar75ibn2rpvcnfolldaicsvl24kew3455f7tvnotuabkq7wnlphaa"
#VMID = "ocid1.instance.oc1.eu-frankfurt-1.abtheljrclqn2alu3oftkykpxjtxpcrlxqtllplwy3anc2qt2mmvjhh3axda"
VMID = "ocid1.instance.oc1.eu-frankfurt-1.abtheljr5kai22sy542s5tbwclyru3hd6ovxojf6mdfq24axadxgbpvfzejq"


ComputeClient = oci.core.ComputeClient(config)

#imageDetails = oci.core.models.CreateImageDetails(compartment_id = CompartmentID, instance_id=VMID, display_name="TempOS2")
#response = ComputeClient.create_image(imageDetails)
#print (response.data)