コード例 #1
0
class Compartment:
    def __init__(self):
        config = {}
        try:
            signer = Config.signer
            self.identity = IdentityClient(config=config, signer=signer)
            self.compartment_id = Config.tenancy_id
        except Exception:
            config = Config.config
            self.identity = IdentityClient(config)
            self.compartment_id = config["tenancy"]

        self.compartments = list()
        self.availability_domain_list = list()
        self.update_ads()

# send requests to list all compartments and its child

    def list_compartments(self):
        return oci.pagination.list_call_get_all_results(
            self.identity.list_compartments,
            self.compartment_id,
            compartment_id_in_subtree=True).data

    # Return compartment data and store in a list
    def store_compartments(self):
        for compartment in self.list_compartments():
            self.compartments.append(compartment)

    def list_availability_domain(self):
        return self.identity.list_availability_domains(
            self.compartment_id).data

    def update_ads(self):
        for i in self.list_availability_domain():
            self.availability_domain_list.append(i)

    def get_compartment_name(self, ids):
        return [i.name for i in self.compartments if i.id == ids][0]

    def get_compartment_id_list(self):
        return self.compartments
コード例 #2
0
class Identity:
	def __init__(self,tenancy_name):
		config = Config(tenancy_name)
		self.config = config.config
		self.compartment_id = self.config['tenancy']
		self.fingerprint = self.config['fingerprint']
		self.key_file = self.config["key_file"]
		self.admin_user_id = self.config["user"]
		self.identity = IdentityClient(self.config)
		self.users = list()
		self.list_users()
		self.compartments = list()
		self.availability_domains = list()
		self.store_compartments()
		self.list_availability_domains()

	def list_availability_domains(self):
		for i in self.identity.list_availability_domains(self.compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data:
			self.availability_domains.append(i)


	def store_compartments(self):
		for compartment in self.list_compartments():
			self.compartments.append(compartment)



	def get_compartment_path_name(self, compartment_id):
		temp = ""
		id = compartment_id
		while id != self.compartment_id:
			compartment = self.get_compartment_details(id)
			temp = compartment.name + "/" + temp
			id = compartment.compartment_id
		return temp

	def get_compartment_details(self, compartment_id):
		return [compartment for compartment in self.compartments if compartment.id == compartment_id][0]


	#List all compartments
	def list_compartments(self):
		return oci.pagination.list_call_get_all_results(self.identity.list_compartments,self.compartment_id,compartment_id_in_subtree=True, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data


#	List all users with pagination
	def list_users(self):
		users = self.identity.list_users(self.compartment_id)
		for user in users.data:
			self.users.append(user)
		while users.has_next_page:
			users = self.identity.list_users(self.compartment_id,page = users.next_page)
			for user in users.data:
				self.users.append(user)

		return self.users

#	Get local Users with User class logic
	def get_local_users(self):
		local_users = list()
		for user in self.users:
			user_obj = User(user)
			if user_obj.is_user_local():
				local_users.append(user)

		return local_users

#	Invalid users are the ones who is not local and not service users.
#	Fetch it from the User class logic
	def get_invalid_users(self):
		invalid_users = list()
		for user in self.users:
			user_obj = User(user)
			if not user_obj.is_user_valid():
				invalid_users.append(user)

		return invalid_users

#	Get service users from User class
	def get_service_users(self):
		service_users = list()
		for user in self.users:
			user_obj = User(user)
			if user_obj.is_user_service():
				service_users.append(user)

		return service_users