Esempio n. 1
0
    def create(self, args=None, **_):
        """Creates an EC2 security group.
        """
        name = utils.get_resource_id()

        create_args = dict(name=name,
                           description=ctx.node.properties['description'],
                           vpc_id=self._get_connected_vpc())

        create_args = utils.update_args(create_args, args)

        if ctx.operation.retry_number == 0 and constants.EXTERNAL_RESOURCE_ID \
                not in ctx.instance.runtime_properties:
            try:
                security_group = self.execute(
                    self.client.create_security_group,
                    create_args,
                    raise_on_falsy=True)
            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)

        self.resource_id = \
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID]
        security_group = self.get_resource()

        if not security_group:
            return False

        self._create_group_rules(security_group)

        return True
Esempio n. 2
0
 def create(self, args=None):
     '''Override for resource create operation'''
     if ctx.operation.retry_number == 0:
         # Create the resource
         create_args = utils.update_args(
             self._generate_creation_args(), args)
         subnet = self.execute(self.client.create_subnet,
                               create_args, raise_on_falsy=True)
         self.resource_id = subnet.id
     else:
         # Get the resource object
         subnet = self.get_resource()
     # If the operation is still pending, set the ID and retry
     if hasattr(subnet, 'state'):
         ctx.logger.debug('AWS resource {0} returned a state of "{1}"'
                          .format(self.resource_id, subnet.state))
         if subnet.state == 'pending':
             set_external_resource_id(self.resource_id, ctx.instance)
             return ctx.operation.retry(
                 message='Waiting to verify that AWS resource {0} '
                 'has been added to your account.'.format(self.resource_id))
     else:
         ctx.logger.warn('AWS resource {0} returned an '
                         'unexpected response (missing state)'
                         .format(self.resource_id))
         return False
     return True
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     rules = ctx.instance.runtime_properties['rules_from_args']
     security_group = self.get_resource()
     if not security_group:
         return False
     self._create_group_rules(security_group, rules)
     return True
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     rules = ctx.instance.runtime_properties['rules_from_args']
     security_group = self.get_resource()
     if not security_group:
         return False
     self._create_group_rules(security_group, rules)
     return True
Esempio n. 5
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     address_object = self.get_resource()
     if constants.ELASTICIP['VPC_DOMAIN'] in address_object.domain:
         ctx.instance.runtime_properties[constants.ELASTICIP[
             'ALLOCATION_ID']] = address_object.allocation_id
         self.allocation_id = address_object.allocation_id
     return True
Esempio n. 6
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     address_object = self.get_resource()
     if constants.ELASTICIP['VPC_DOMAIN'] in address_object.domain:
         ctx.instance.runtime_properties[constants.ELASTICIP[
             'ALLOCATION_ID']] = address_object.allocation_id
         self.allocation_id = address_object.allocation_id
     return True
Esempio n. 7
0
 def post_create(self):
     vpc = self.get_containing_vpc()
     ctx.instance.runtime_properties['vpc_id'] = vpc.id
     ctx.instance.runtime_properties['routes'] = self.routes
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     ctx.logger.info('Added {0} {1} to Cloudify.'.format(
         self.aws_resource_type, self.resource_id))
     return True
Esempio n. 8
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     vpc = self.get_containing_vpc()
     ctx.instance.runtime_properties['vpc_id'] = vpc.id
     ctx.instance.runtime_properties['routes'] = self.routes
     ctx.logger.info(
         'Added {0} {1} to Cloudify.'
         .format(self.aws_resource_type, self.resource_id))
     return True
 def create(self, args=None, **_):
     ctx.logger.info('Going to create spot instance')
     instance_parameters = self._get_instance_parameters()
     availability_zone = instance_parameters.get('availability_zone')
     instance_type = instance_parameters.get('instance_type')
     image_id = instance_parameters.get('image_id')
     key_name = instance_parameters.get('key_name')
     max_bid_price = instance_parameters.get('max_bid_price')
     starting_bid_price = instance_parameters.get('starting_bid_price')
     security_group_ids = instance_parameters.get('security_group_ids')
     user_data = instance_parameters.get('user_data_init_script')
     ctx.logger.info(
         'Retrieving spot instance pricing history, for: {0}@{1}'.format(
             instance_type, availability_zone))
     self._max_bid_price = max_bid_price
     self._starting_bid_price = self._str_to_number(starting_bid_price)
     sg_names = self._security_group_names(security_group_ids)
     if self._starting_bid_price > 0:
         ctx.logger.info('Starting bid at given price: {0}'.format(
             self._starting_bid_price))
     else:
         self._pricing_history = self._spot_pricing_history(
             instance_type, availability_zone)
         if not self._pricing_history:
             raise NonRecoverableError(
                 'Failed to retrieve spot pricing history')
     ctx.logger.info(
         'Attempting to create EC2 Spot Instance with these API '
         'parameters: {0}.'.format(instance_parameters))
     spot_request_info = self._create_spot_instances(
         instance_type=instance_type,
         image_id=image_id,
         availability_zone_group=availability_zone,
         key_name=key_name,
         security_groups=sg_names,
         user_data=user_data)
     ctx.logger.info('Spot instance instance_id: {0}'.format(
         spot_request_info.instance_id))
     self.resource_id = spot_request_info.instance_id
     ctx.instance.runtime_properties[
         'request_id'] = spot_request_info.request_id
     instance = self._get_instance_from_id(spot_request_info.instance_id)
     if not instance:
         raise NonRecoverableError('Failed to retrieve spot instance')
     utils.set_external_resource_id(spot_request_info.instance_id,
                                    ctx.instance,
                                    external=False)
     self._instance_created_assign_runtime_properties()
     ctx.logger.info('Spot created')
     return True
Esempio n. 10
0
    def create(self, args):

        create_args = dict(
            cidr_block=ctx.node.properties['cidr_block'],
            instance_tenancy=ctx.node.properties['instance_tenancy']
        )
        create_args = utils.update_args(
            create_args,
            args)
        vpc = self.execute(self.client.create_vpc,
                           create_args, raise_on_falsy=True)
        self.resource_id = vpc.id
        utils.set_external_resource_id(vpc.id, ctx.instance)
        ctx.instance.runtime_properties['default_dhcp_options_id'] = \
            vpc.dhcp_options_id
        return True
Esempio n. 11
0
    def post_create(self):

        utils.set_external_resource_id(self.resource_id, ctx.instance)
        network_interface = self.get_resource()
        for req_runtime_prop in constants.ENI_INTERNAL_ATTRIBUTES:
            if req_runtime_prop == 'private_ip_addresses':
                ctx.instance.runtime_properties['private_ip_addresses'] = \
                    [(private_ip.private_ip_address, private_ip.primary)
                     for private_ip in getattr(network_interface,
                                               req_runtime_prop)]
            elif req_runtime_prop == 'groups':
                ctx.instance.runtime_properties['groups'] = \
                    [group.id for group in getattr(network_interface,
                                                   req_runtime_prop)]
            else:
                ctx.instance.runtime_properties[req_runtime_prop] = \
                    getattr(network_interface, req_runtime_prop)

        return True
Esempio n. 12
0
    def post_create(self):

        utils.set_external_resource_id(self.resource_id, ctx.instance)
        network_interface = self.get_resource()
        for req_runtime_prop in constants.ENI_INTERNAL_ATTRIBUTES:
            if req_runtime_prop == 'private_ip_addresses':
                ctx.instance.runtime_properties['private_ip_addresses'] = \
                    [(private_ip.private_ip_address, private_ip.primary)
                     for private_ip in getattr(network_interface,
                                               req_runtime_prop)]
            elif req_runtime_prop == 'groups':
                ctx.instance.runtime_properties['groups'] = \
                    [group.id for group in getattr(network_interface,
                                                   req_runtime_prop)]
            else:
                ctx.instance.runtime_properties[req_runtime_prop] = \
                    getattr(network_interface, req_runtime_prop)

        return True
Esempio n. 13
0
    def create(self, args=None, **_):

        instance_parameters = self._get_instance_parameters()

        ctx.logger.info('Attempting to create EC2 Instance with these API '
                        'parameters: {0}.'.format(instance_parameters))

        instance_id = self._run_instances_if_needed(instance_parameters)

        instance = self._get_instance_from_id(instance_id)

        if instance is None:
            return False

        utils.set_external_resource_id(instance_id,
                                       ctx.instance,
                                       external=False)
        self._instance_created_assign_runtime_properties()

        return True
Esempio n. 14
0
    def create(self, args=None, **_):

        instance_parameters = self._get_instance_parameters()

        ctx.logger.info(
                'Attempting to create EC2 Instance with these API '
                'parameters: {0}.'
                .format(instance_parameters))

        instance_id = self._run_instances_if_needed(instance_parameters)

        instance = self._get_instance_from_id(instance_id)

        if instance is None:
            return False

        utils.set_external_resource_id(
                instance_id, ctx.instance, external=False)
        self._instance_created_assign_runtime_properties()

        return True
Esempio n. 15
0
    def create(self, args=None, **_):
        """Creates a keypair."""

        ctx.instance.runtime_properties[constants.AWS_TYPE_PROPERTY] = \
            constants.KEYPAIR['AWS_RESOURCE_TYPE']

        create_args = {
            'key_name': utils.get_resource_id()
        }

        create_args = utils.update_args(create_args, args)

        kp = self.execute(self.client.create_key_pair,
                          create_args, raise_on_falsy=True)

        self.resource_id = kp.name

        utils.set_external_resource_id(self.resource_id, ctx.instance)

        self._save_key_pair(kp)

        return True
    def create(self, args=None, **_):

        """Creates an EC2 security group.
        """
        name = utils.get_resource_id()

        create_args = dict(
                name=name,
                description=ctx.node.properties['description'],
                vpc_id=self._get_connected_vpc()
        )

        create_args = utils.update_args(create_args, args)

        if ctx.operation.retry_number == 0 and constants.EXTERNAL_RESOURCE_ID \
                not in ctx.instance.runtime_properties:
            try:
                security_group = self.execute(
                        self.client.create_security_group, create_args,
                        raise_on_falsy=True)
            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)

        self.resource_id = \
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID]
        security_group = self.get_resource()

        if not security_group:
            return False

        self._create_group_rules(security_group)

        return True
Esempio n. 17
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     self.add_entries_to_network_acl()
     return True
Esempio n. 18
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     self._instance_created_assign_runtime_properties()
     return True
Esempio n. 19
0
 def post_create(self):
     utils.set_external_resource_id(self.resource_id, ctx.instance)
     self.add_entries_to_network_acl()
     return True