def create(args, **_): """Creates an EBS volume. """ ec2_client = connection.EC2ConnectionClient().client() for property_name in constants.VOLUME_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) if _create_external_volume(): return ctx.logger.debug('Creating EBS volume') create_volume_args = dict( size=ctx.node.properties['size'], zone=ctx.node.properties[constants.ZONE] ) create_volume_args.update(args) try: new_volume = ec2_client.create_volume(**create_volume_args) except (boto.exception.EC2ResponseError, boto.exception.BotoServerError) as e: raise NonRecoverableError('{0}'.format(str(e))) ctx.instance.runtime_properties[constants.ZONE] = new_volume.zone utils.set_external_resource_id( new_volume.id, ctx.instance, external=False)
def run_instances(**_): ec2_client = connection.EC2ConnectionClient().client() for property_name in constants.INSTANCE_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) if _create_external_instance(): return instance_parameters = _get_instance_parameters() ctx.logger.info( 'Attempting to create EC2 Instance with these API parameters: {0}.'. format(instance_parameters)) instance_id = _run_instances_if_needed(ec2_client, instance_parameters) instance = _get_instance_from_id(instance_id) if instance is None: return ctx.operation.retry( message='Waiting to verify that instance {0} ' 'has been added to your account.'.format(instance_id)) utils.set_external_resource_id(instance_id, ctx.instance, external=False)
def create(**_): """Creates an EC2 security group. """ ec2_client = connection.EC2ConnectionClient().client() for property_name in constants.SECURITY_GROUP_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) name = utils.get_resource_id() if _create_external_securitygroup(name): return ctx.logger.debug( 'Creating Security Group: {0}' .format(name)) create_args = dict( name=name, description=ctx.node.properties['description'], vpc_id=_get_connected_vpc() ) try: group_object = ec2_client.create_security_group(**create_args) except (boto.exception.EC2ResponseError, boto.exception.BotoServerError) as e: raise NonRecoverableError('{0}'.format(str(e))) _create_group_rules(group_object) utils.set_external_resource_id( group_object.id, ctx.instance, external=False)
def run_instances(**_): ec2_client = connection.EC2ConnectionClient().client() ctx.logger.debug("connection.EC2ConnectionClient().client()") for property_name in constants.INSTANCE_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) ctx.logger.debug(str(ctx.node.properties)) if _create_external_instance(): return instance_parameters = _get_instance_parameters() ctx.logger.debug( "Attempting to create EC2 Instance with these API parameters: {0}.".format(str(instance_parameters)) ) instance_id = _run_instances_if_needed(ec2_client, instance_parameters) instance = _get_instance_from_id(instance_id) if instance is None: return ctx.operation.retry( message="Waiting to verify that instance {0} " "has been added to your account.".format(instance_id) ) utils.set_external_resource_id(instance_id, ctx.instance, external=False)
def creation_validation(**_): """ This validates all nodes before bootstrap. """ for property_key in constants.KEYPAIR_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) key_file = _get_path_to_key_file() key_file_in_filesystem = _search_for_key_file(key_file) if ctx.node.properties['use_external_resource']: if not key_file_in_filesystem: raise NonRecoverableError( 'External resource, but the key file does not exist locally.') try: _get_key_pair_by_id(ctx.node.properties['resource_id']) except NonRecoverableError as e: raise NonRecoverableError( 'External resource, ' 'but the key pair does not exist in the account: ' '{0}'.format(str(e))) else: if key_file_in_filesystem: raise NonRecoverableError('Not external resource, ' 'but the key file exists locally.') try: _get_key_pair_by_id(ctx.node.properties['resource_id']) except NonRecoverableError: pass else: raise NonRecoverableError( 'Not external resource, ' 'but the key pair exists in the account.')
def creation_validation(**_): """ This validates all nodes before bootstrap. """ for property_key in constants.KEYPAIR_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) key_file = _get_path_to_key_file() key_file_in_filesystem = _search_for_key_file(key_file) if ctx.node.properties['use_external_resource']: if not key_file_in_filesystem: raise NonRecoverableError( 'External resource, but the key file does not exist locally.') try: _get_key_pair_by_id(ctx.node.properties['resource_id']) except NonRecoverableError as e: raise NonRecoverableError( 'External resource, ' 'but the key pair does not exist in the account: ' '{0}'.format(str(e))) else: if key_file_in_filesystem: raise NonRecoverableError( 'Not external resource, ' 'but the key file exists locally.') try: _get_key_pair_by_id(ctx.node.properties['resource_id']) except NonRecoverableError: pass else: raise NonRecoverableError( 'Not external resource, ' 'but the key pair exists in the account.')
def create(args, **_): """Creates an EBS volume. """ ec2_client = connection.EC2ConnectionClient().client() for property_name in constants.VOLUME_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) if _create_external_volume(): return ctx.logger.debug('Creating EBS volume') create_volume_args = dict(size=ctx.node.properties['size'], zone=ctx.node.properties['zone']) create_volume_args.update(args) try: new_volume = ec2_client.create_volume(**create_volume_args) except (boto.exception.EC2ResponseError, boto.exception.BotoServerError) as e: raise NonRecoverableError('{0}'.format(str(e))) utils.set_external_resource_id(new_volume.id, ctx.instance, external=False)
def creation_validation(**_): """ This validates all EBS volume Nodes before bootstrap. """ for property_key in constants.VOLUME_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) volume_object = _get_volumes_from_id(utils.get_resource_id()) if ctx.node.properties['use_external_resource'] and not volume_object: raise NonRecoverableError('External resource, but the supplied ' 'EBS volume does not exist in the account.') if not ctx.node.properties['use_external_resource'] and volume_object: raise NonRecoverableError('Not external resource, but the supplied ' 'EBS volume exists in the account.')
def creation_validation(**_): """ This validates all Security Group Nodes before bootstrap. """ for property_key in constants.SECURITY_GROUP_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) security_group = _get_security_group_from_id(utils.get_resource_id()) if ctx.node.properties['use_external_resource'] and not security_group: raise NonRecoverableError( 'External resource, but the supplied ' 'security group does not exist in the account.') if not ctx.node.properties['use_external_resource'] and security_group: raise NonRecoverableError('Not external resource, but the supplied ' 'security group exists in the account.')
def creation_validation(**_): """ This checks that all user supplied info is valid """ for property_key in constants.ELB_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) if not ctx.node.properties['resource_id']: elb = None else: elb = _get_existing_elb(ctx.node.properties['resource_id']) if ctx.node.properties['use_external_resource'] and not elb: raise NonRecoverableError('External resource, but the supplied ' 'elb does not exist in the account.') if not ctx.node.properties['use_external_resource'] and elb: raise NonRecoverableError('Not external resource, but the supplied ' 'elb exists.')
def creation_validation(**_): """ This validates all EBS volume Nodes before bootstrap. """ for property_key in constants.VOLUME_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) volume_object = _get_volumes_from_id(utils.get_resource_id()) if ctx.node.properties['use_external_resource'] and not volume_object: raise NonRecoverableError( 'External resource, but the supplied ' 'EBS volume does not exist in the account.') if not ctx.node.properties['use_external_resource'] and volume_object: raise NonRecoverableError( 'Not external resource, but the supplied ' 'EBS volume exists in the account.')
def create(**_): """Creates an EC2 security group. """ ec2_client = connection.EC2ConnectionClient().client() for property_name in constants.SECURITY_GROUP_REQUIRED_PROPERTIES: utils.validate_node_property(property_name, ctx.node.properties) name = utils.get_resource_id() if _create_external_securitygroup(name): return ctx.logger.debug( 'Creating Security Group: {0}' .format(name)) create_args = dict( name=name, description=ctx.node.properties['description'], vpc_id=_get_connected_vpc() ) if ctx.operation.retry_number == 0 and constants.EXTERNAL_RESOURCE_ID \ not in ctx.instance.runtime_properties: try: security_group = ec2_client.create_security_group(**create_args) except (exception.EC2ResponseError, exception.BotoServerError) as e: raise NonRecoverableError('{0}'.format(str(e))) utils.set_external_resource_id( security_group.id, ctx.instance, external=False) security_group = _get_security_group_from_id( ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID]) if not security_group: return ctx.operation.retry( message='Waiting to verify that security group {0} ' 'has been added.'.format(constants.EXTERNAL_RESOURCE_ID)) _create_group_rules(security_group)
def creation_validation(**_): """ This validates all Security Group Nodes before bootstrap. """ for property_key in constants.SECURITY_GROUP_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) security_group = _get_security_group_from_id( utils.get_resource_id()) if ctx.node.properties['use_external_resource'] and not security_group: raise NonRecoverableError( 'External resource, but the supplied ' 'security group does not exist in the account.') if not ctx.node.properties['use_external_resource'] and security_group: raise NonRecoverableError( 'Not external resource, but the supplied ' 'security group exists in the account.')
def creation_validation(**_): """ This checks that all user supplied info is valid """ for property_key in constants.INSTANCE_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) instance = _get_instance_from_id(utils.get_resource_id()) if ctx.node.properties["use_external_resource"] and not instance: raise NonRecoverableError("External resource, but the supplied " "instance id is not in the account.") if not ctx.node.properties["use_external_resource"] and instance: raise NonRecoverableError("Not external resource, but the supplied " "but the instance already exists.") image_id = ctx.node.properties["image_id"] image_object = _get_image(image_id) if "available" not in image_object.state: raise NonRecoverableError("image_id {0} not available to this account.".format(image_id))
def creation_validation(self): """ This validates all VPC Nodes before bootstrap. """ resource = self.get_resource() for property_key in self.required_properties: ec2_utils.validate_node_property(property_key, ctx.node.properties) if self.is_external_resource and not resource: raise NonRecoverableError( 'External resource, but the supplied {0} ' 'does not exist in the account.'.format( self.aws_resource_type)) if not self.is_external_resource and resource: raise NonRecoverableError( 'Not external resource, but the supplied {0}' 'exists in the account.'.format(self.aws_resource_type))
def creation_validation(self): """ This validates all VPC Nodes before bootstrap. """ resource = self.get_resource() for property_key in self.required_properties: ec2_utils.validate_node_property(property_key, ctx.node.properties) if self.is_external_resource and not resource: raise NonRecoverableError( "External resource, but the supplied {0} " "does not exist in the account.".format(self.aws_resource_type) ) if not self.is_external_resource and resource: raise NonRecoverableError( "Not external resource, but the supplied {0}" "exists in the account.".format(self.aws_resource_type) )
def creation_validation(**_): """ This checks that all user supplied info is valid """ for property_key in constants.ELB_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) if not ctx.node.properties['resource_id']: elb = None else: elb = _get_existing_elb( ctx.node.properties['resource_id']) if ctx.node.properties['use_external_resource'] and not elb: raise NonRecoverableError( 'External resource, but the supplied ' 'elb does not exist in the account.') if not ctx.node.properties['use_external_resource'] and elb: raise NonRecoverableError( 'Not external resource, but the supplied ' 'elb exists.')
def creation_validation(**_): """ This checks that all user supplied info is valid """ for property_key in constants.INSTANCE_REQUIRED_PROPERTIES: utils.validate_node_property(property_key, ctx.node.properties) instance = _get_instance_from_id(utils.get_resource_id()) if ctx.node.properties['use_external_resource'] and not instance: raise NonRecoverableError('External resource, but the supplied ' 'instance id is not in the account.') if not ctx.node.properties['use_external_resource'] and instance: raise NonRecoverableError('Not external resource, but the supplied ' 'but the instance already exists.') image_id = ctx.node.properties['image_id'] image_object = _get_image(image_id) if 'available' not in image_object.state: raise NonRecoverableError( 'image_id {0} not available to this account.'.format(image_id))