def create(self, name, location=None): log.debug("Creating AWS Bucket with the params " "[name: %s, location: %s]", name, location) AWSBucket.assert_valid_resource_name(name) loc_constraint = location or self.provider.region_name # Due to an API issue in S3, specifying us-east-1 as a # LocationConstraint results in an InvalidLocationConstraint. # Therefore, it must be special-cased and omitted altogether. # See: https://github.com/boto/boto3/issues/125 # In addition, us-east-1 also behaves differently when it comes # to raising duplicate resource exceptions, so perform a manual # check if loc_constraint == 'us-east-1': try: # check whether bucket already exists self.provider.s3_conn.meta.client.head_bucket(Bucket=name) except ClientError as e: if e.response['Error']['Code'] == "404": # bucket doesn't exist, go ahead and create it return self.svc.create('create_bucket', Bucket=name) raise DuplicateResourceException( 'Bucket already exists with name {0}'.format(name)) else: try: return self.svc.create('create_bucket', Bucket=name, CreateBucketConfiguration={ 'LocationConstraint': loc_constraint }) except ClientError as e: if e.response['Error']['Code'] == "BucketAlreadyOwnedByYou": raise DuplicateResourceException( 'Bucket already exists with name {0}'.format(name)) else: raise
def create(self, name, location=None): """ Create a new bucket. """ log.debug("Creating a new OpenStack Bucket with the name: %s", name) OpenStackBucket.assert_valid_resource_name(name) try: self.provider.swift.head_container(name) raise DuplicateResourceException( 'Bucket already exists with name {0}'.format(name)) except SwiftClientException: self.provider.swift.put_container(name) return self.get(name)
def create_container(self, container_name): try: self.blob_service.create_container(container_name, fail_on_exist=True) except AzureConflictHttpError as cloud_error: if cloud_error.error_code == "ContainerAlreadyExists": msg = "The given Bucket name '%s' already exists. Please " \ "use the `get` or `find` method to get a reference to " \ "an existing Bucket, or specify a new Bucket name to " \ "create.\nNote that in Azure, Buckets are contained " \ "in Storage Accounts." % container_name raise DuplicateResourceException(msg) return self.blob_service.get_container_properties(container_name)
def create(self, name, public_key_material=None): log.debug("Creating Key Pair Service %s", name) AWSKeyPair.assert_valid_resource_name(name) private_key = None if not public_key_material: public_key_material, private_key = cb_helpers.generate_key_pair() try: kp = self.svc.create('import_key_pair', KeyName=name, PublicKeyMaterial=public_key_material) kp.material = private_key return kp except ClientError as e: if e.response['Error']['Code'] == 'InvalidKeyPair.Duplicate': raise DuplicateResourceException( 'Keypair already exists with name {0}'.format(name)) else: raise e
def create(self, name, public_key_material=None): log.debug("Creating a new key pair with the name: %s", name) OpenStackKeyPair.assert_valid_resource_name(name) existing_kp = self.find(name=name) if existing_kp: raise DuplicateResourceException( 'Keypair already exists with name {0}'.format(name)) private_key = None if not public_key_material: public_key_material, private_key = cb_helpers.generate_key_pair() kp = self.provider.nova.keypairs.create(name, public_key=public_key_material) cb_kp = OpenStackKeyPair(self.provider, kp) cb_kp.material = private_key return cb_kp
def create(self, name, location=None): GCSBucket.assert_valid_resource_name(name) body = {'name': name} if location: body['location'] = location try: response = (self.provider.gcs_storage.buckets().insert( project=self.provider.project_name, body=body).execute()) # GCS has a rate limit of 1 operation per 2 seconds for bucket # creation/deletion: https://cloud.google.com/storage/quotas. # Throttle here to avoid future failures. time.sleep(2) return GCSBucket(self.provider, response) except googleapiclient.errors.HttpError as http_error: # 409 = conflict if http_error.resp.status in [409]: raise DuplicateResourceException( 'Bucket already exists with name {0}'.format(name)) else: raise
def create(self, name, public_key_material=None): GCEKeyPair.assert_valid_resource_name(name) private_key = None if not public_key_material: public_key_material, private_key = cb_helpers.generate_key_pair() # TODO: Add support for other formats not assume ssh-rsa elif "ssh-rsa" not in public_key_material: public_key_material = "ssh-rsa {}".format(public_key_material) kp_info = GCEKeyPair.GCEKeyInfo(name, public_key_material) metadata_value = json.dumps(kp_info._asdict()) try: helpers.add_metadata_item(self.provider, GCEKeyPair.KP_TAG_PREFIX + name, metadata_value) return GCEKeyPair(self.provider, kp_info, private_key) except googleapiclient.errors.HttpError as err: if err.resp.get('content-type', '').startswith('application/json'): message = (json.loads(err.content).get('error', {}).get( 'errors', [{}])[0].get('message')) if "duplicate keys" in message: raise DuplicateResourceException( 'A KeyPair with name {0} already exists'.format(name)) raise
def create(self, name, public_key_material=None): AzureKeyPair.assert_valid_resource_name(name) key_pair = self.get(name) if key_pair: raise DuplicateResourceException( 'Keypair already exists with name {0}'.format(name)) private_key = None if not public_key_material: public_key_material, private_key = cb_helpers.generate_key_pair() entity = { 'PartitionKey': AzureKeyPairService.PARTITION_KEY, 'RowKey': str(uuid.uuid4()), 'Name': name, 'Key': public_key_material } self.provider.azure_client.create_public_key(entity) key_pair = self.get(name) key_pair.material = private_key return key_pair