def create_bucket(self, new_bucket): self.set_config() request = CreateBucketDetails() request.compartment_id = self.compartment_id request.name = new_bucket bucket = self.object_storage.create_bucket(self.namespace, request) return bucket.data
def create_bucket(self, bucket_name): bucket_name = bucket_name or "python-sdk-example-bucket" print("Creating a new bucket {!r} in compartment {!r}".format( bucket_name, self.compartment_id)) request = CreateBucketDetails() request.compartment_id = self.compartment_id request.name = bucket_name bucket = self.object_storage.create_bucket(self.namespace, request) # pylint: disable=unused-variable
def create_bucket(self, namespace_name, bucket_name, compartment_id=None): """Connect to Oracle API and create bucket.""" bucket_details = CreateBucketDetails() bucket_details.compartment_id = self.config["tenancy"] bucket_details.name = bucket_name storage = oci.object_storage.ObjectStorageClient(self.config) created_bucket = storage.create_bucket( namespace_name=namespace_name, create_bucket_details=bucket_details).data return created_bucket
def _set_bucket(self): # try to create the bucket if it isnt there... just like s3 try: response = self.connection.head_bucket(self.namespace,self.bucket) except oci.exceptions.ServiceError as error: print(error) if error.status == 404: # bucket not found request = CreateBucketDetails() request.compartment_id = self._config['tenancy'] request.name = self.bucket response = self.connection.create_bucket(self.namespace, request) return response.data
def bucket_details_factory(bucket_details_type, module): bucket_details = None if bucket_details_type == "create": bucket_details = CreateBucketDetails() bucket_details.storage_tier = module.params["storage_tier"] elif bucket_details_type == "update": bucket_details = UpdateBucketDetails() bucket_details.compartment_id = module.params["compartment_id"] bucket_details.name = module.params["name"] bucket_details.public_access_type = module.params["public_access_type"] bucket_details.kms_key_id = module.params["kms_key_id"] bucket_details.metadata = module.params["metadata"] return bucket_details
def save_log(signer, body): object_storage = oci.object_storage.ObjectStorageClient(config={}, signer=signer) namespace = object_storage.get_namespace().data my_data = json.dumps(body) try: request = CreateBucketDetails() request.compartment_id = compartment_id request.name = bucket_name object_storage.create_bucket(namespace, request) except: print('erro') ts = str(datetime.utcnow().microsecond) object_name = 'log' + ts + str(randint(0, 10000)) object_storage.put_object(namespace, bucket_name, object_name, my_data)
def save_log(signer, body, event_type): object_storage = oci.object_storage.ObjectStorageClient(config={}, signer=signer) namespace = object_storage.get_namespace().data my_data = json.dumps(body) bucket_name = event_type try: request = CreateBucketDetails() request.compartment_id = compartment_id request.name = bucket_name object_storage.create_bucket(namespace, request) except (Exception) as ex: logging.getLogger().info('error creating bucket: ' + str(ex)) ts = str(datetime.utcnow().microsecond) object_name = 'log' + ts + str(randint(0, 10000)) + '_' + event_type object_storage.put_object(namespace, bucket_name, object_name, my_data)
def create_bucket(signer, eventType, resourceName): currentDT = datetime.datetime.now() objectName = 'readme.txt' content = 'Generated by automated event based function. This bucket is Oracle confidential.' client = oci.object_storage.ObjectStorageClient(config={}, signer=signer) request = CreateBucketDetails() request.compartment_id = signer.compartment_id request.name = resourceName + '-fnGenBucket-' + currentDT.strftime( "%Y-%m-%d-%H-%M-%S") #bucketName namespace = os.environ.get("OCI_NAMESPACE") try: bucket = client.create_bucket(namespace, request) output = "Success creating the bucket!" put_object(signer, request.name, objectName, content) except Exception as e: output = "Failed to create bucket:" + str(e.message) response = {"state": output} return response
def upload_to_object_storage(config, directory, bucket_name, filename_list): compartment_id = config["compartment"] object_storage = oci.object_storage.ObjectStorageClient(config) namespace = object_storage.get_namespace().data try: object_storage.get_bucket(namespace, bucket_name) print("Bucket already exists: {!r}".format(bucket_name)) except: print("Creating bucket: {!r} in compartment: {!r}".format( bucket_name, compartment_id)) request = CreateBucketDetails() request.compartment_id = compartment_id request.name = bucket_name object_storage.create_bucket(namespace, request) for filename in filename_list: with open(os.path.join(directory, filename), 'rb') as f: print("Uploading file: {!r}".format(filename)) object_storage.put_object(namespace, bucket_name, filename, f)
from oci.object_storage.models import CreatePreauthenticatedRequestDetails config = oci.config.from_file() compartment_id = config["tenancy"] object_storage = oci.object_storage.ObjectStorageClient(config) namespace = object_storage.get_namespace().data bucket_name = "python-sdk-example-bucket" object_name = "python-sdk-example-object" my_data = b"Hello, World!" par_name = "python-sdk-example-par" print("Creating a new bucket {!r} in compartment {!r}".format( bucket_name, compartment_id)) request = CreateBucketDetails() request.compartment_id = compartment_id request.name = bucket_name bucket = object_storage.create_bucket(namespace, request) print("Uploading new object {!r}".format(object_name)) obj = object_storage.put_object( namespace, bucket_name, object_name, my_data) same_obj = object_storage.get_object( namespace, bucket_name, object_name)
from oci.object_storage.models import CreateBucketDetails config = oci.config.from_file() compartment_id = config["tenancy"] object_storage = oci.object_storage.ObjectStorageClient(config) namespace = object_storage.get_namespace().data bucket_name = "python-sdk-example-bucket" object_name = "python-sdk-example-object" my_data = b"Hello, World!" print("Creating a new bucket {!r} in compartment {!r}".format( bucket_name, compartment_id)) request = CreateBucketDetails() request.compartment_id = compartment_id request.name = bucket_name bucket = object_storage.create_bucket(namespace, request) print("Uploading new object {!r}".format(object_name)) obj = object_storage.put_object( namespace, bucket_name, object_name, my_data) same_obj = object_storage.get_object( namespace, bucket_name, object_name)