示例#1
0
    def associate(self, args=None, **_):
        """ Associates an Elastic IP created by Cloudify with an EC2 Instance
        that was also created by Cloudify.
        """

        instance_id = self.source_resource_id
        elasticip = self.target_resource_id

        associate_args = dict(instance_id=instance_id, public_ip=elasticip)

        if constants.ELASTICIP['ALLOCATION_ID'] in \
                ctx.target.instance.runtime_properties:
            associate_args.pop('public_ip')
            associate_args.update({
                constants.ELASTICIP['ALLOCATION_ID']:
                ctx.target.instance.runtime_properties[
                    constants.ELASTICIP['ALLOCATION_ID']]
            })

        associate_args = utils.update_args(associate_args, args)

        try:
            self.execute(self.client.associate_address,
                         associate_args,
                         raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return True
    def associate(self, args=None, **_):
        """ Associates an Elastic IP created by Cloudify with an EC2 Instance
        that was also created by Cloudify.
        """

        instance_id = self.source_resource_id
        elasticip = self.target_resource_id

        associate_args = dict(instance_id=instance_id, public_ip=elasticip)

        if constants.ELASTICIP['ALLOCATION_ID'] in \
                ctx.target.instance.runtime_properties:
            associate_args.pop('public_ip')
            associate_args.update(
                    {constants.ELASTICIP['ALLOCATION_ID']:
                     ctx.target.instance.runtime_properties[
                             constants.ELASTICIP['ALLOCATION_ID']]})

        associate_args = utils.update_args(associate_args, args)

        try:
            self.execute(self.client.associate_address, associate_args,
                         raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return True
示例#3
0
    def disassociate(self, args=None, **_):
        """ Disassocates an Elastic IP created by Cloudify from an EC2 Instance
        that was also created by Cloudify.
        """

        elasticip = self.target_resource_id

        elasticip_object = self.get_target_resource()

        if not elasticip_object:
            raise NonRecoverableError(
                'no matching elastic ip in account: {0}'.format(elasticip))

        disassociate_args = dict(
            public_ip=elasticip_object.public_ip,
            association_id=elasticip_object.association_id)

        disassociate_args = utils.update_args(disassociate_args, args)

        try:
            self.execute(self.client.disassociate_address,
                         disassociate_args,
                         raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return True
示例#4
0
    def disassociate(self, args=None, **_):
        """ Disassocates an ENI created by Cloudify from an EC2 Instance
        that was also created by Cloudify.
        """

        attachment_id = \
            ctx.source.instance.runtime_properties.pop('attachment_id')

        detach_args = dict(attachment_id=attachment_id)

        detach_args = utils.update_args(detach_args, args)

        try:
            output = self.execute(self.client.detach_network_interface,
                                  detach_args,
                                  raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if not output:
            ctx.source.instance.runtime_properties['attachment_id'] = \
                attachment_id
            raise RecoverableError('Failed to detach network interface {0} '
                                   'from instance {1}'.format(
                                       self.source_resource_id,
                                       self.target_resource_id))
        return output
示例#5
0
    def associate(self, args=None, **_):
        """ Associates an ENI created by Cloudify with an EC2 Instance
        that was also created by Cloudify.
        """

        network_interface_id = self.source_resource_id
        instance_id = self.target_resource_id

        attachment_args = dict(network_interface_id=network_interface_id,
                               instance_id=instance_id,
                               device_index=1)

        attachment_args = utils.update_args(attachment_args, args)

        try:
            output = self.execute(self.client.attach_network_interface,
                                  attachment_args,
                                  raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if not output:
            raise RecoverableError(
                'Failed to attach eni    {0} to instance {1}'.format(
                    self.source_resource_id, self.target_resource_id))

        network_interface = self.get_source_resource()
        ctx.source.instance.runtime_properties['attachment_id'] = \
            network_interface.attachment.id

        return output
    def delete(self, args=None, **_):

        delete_args = dict(group_id=self.resource_id)
        delete_args = utils.update_args(delete_args, args)
        return self.execute(self.client.delete_security_group,
                            delete_args,
                            raise_on_falsy=True)
示例#7
0
 def create(self, args):
     create_args = self.generate_create_args()
     create_args = utils.update_args(create_args, args)
     dhcp_options = self.execute(self.client.create_dhcp_options,
                                 create_args, raise_on_falsy=True)
     self.resource_id = dhcp_options.id
     return True
示例#8
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 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)

        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)))

        self.resource_id = security_group.id

        return True
示例#10
0
 def associate(self, args):
     associate_args = dict(dhcp_options_id=self.source_resource_id,
                           vpc_id=self.target_resource_id)
     associate_args = utils.update_args(associate_args, args)
     return self.execute(self.client.associate_dhcp_options,
                         associate_args,
                         raise_on_falsy=True)
示例#11
0
    def create_snapshot(self, args=None, **_):
        """ Create a snapshot of an EBS Volume
        """

        volume_id = \
            utils.get_external_resource_id_or_raise(
                'create snapshot', ctx.instance)

        ctx.logger.info(
            'Trying to create a snapshot of EBS volume {0}.'.format(volume_id))

        snapshot_desc = \
            unicode(datetime.datetime.now()) + \
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID]
        create_args = dict(volume_id=volume_id, description=snapshot_desc)
        create_args = utils.update_args(create_args, args)

        try:
            new_snapshot = self.execute(self.client.create_snapshot,
                                        create_args,
                                        raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE'] not in \
                ctx.instance.runtime_properties:
            ctx.instance.runtime_properties[
                constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE']] = list()

        ctx.instance.runtime_properties[
            constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE']].append(new_snapshot.id)

        return True
示例#12
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
示例#13
0
    def _create_elb(self, args):

        create_args = self._create_elb_params()
        create_args = utils.update_args(create_args, args)

        try:
            lb = self.execute(self.client.create_load_balancer, create_args,
                              raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError,
                exception.BotoClientError) as e:
            raise RecoverableError('Load Balancer not created '
                                   '{0}'.format(str(e)))

        if not lb:
            raise NonRecoverableError(
                'Load Balancer not created. While the create '
                'request was completed'
                ' successfully, verifying the load balancer '
                'afterwards has failed')

        ctx.instance.runtime_properties['elb_name'] = create_args['name']
        self.resource_id = create_args['name']

        return lb
示例#14
0
    def associate(self, args=None, **_):
        """ Associates an ENI created by Cloudify with an EC2 Instance
        that was also created by Cloudify.
        """

        network_interface_id = self.source_resource_id
        instance_id = self.target_resource_id

        attachment_args = dict(network_interface_id=network_interface_id,
                               instance_id=instance_id,
                               device_index=1)

        attachment_args = utils.update_args(attachment_args, args)

        try:
            output = self.execute(self.client.attach_network_interface,
                                  attachment_args,
                                  raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if not output:
            raise RecoverableError(
                'Failed to attach eni    {0} to instance {1}'
                .format(self.source_resource_id,
                        self.target_resource_id)
            )

        network_interface = self.get_source_resource()
        ctx.source.instance.runtime_properties['attachment_id'] = \
            network_interface.attachment.id

        return output
示例#15
0
    def disassociate(self, args=None, **_):
        """ Disassocates an ENI created by Cloudify from an EC2 Instance
        that was also created by Cloudify.
        """

        attachment_id = \
            ctx.source.instance.runtime_properties.pop('attachment_id')

        detach_args = dict(attachment_id=attachment_id)

        detach_args = utils.update_args(detach_args, args)

        try:
            output = self.execute(self.client.detach_network_interface,
                                  detach_args, raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if not output:
            ctx.source.instance.runtime_properties['attachment_id'] = \
                attachment_id
            raise RecoverableError(
                'Failed to detach network interface {0} '
                'from instance {1}'
                .format(
                    self.source_resource_id,
                    self.target_resource_id
                )
            )
        return output
示例#16
0
    def associate(self, args=None, **_):

        elb_name = self.target_resource_id

        instance_id = self.source_resource_id

        ctx.logger.info('Attemping to add instance: {0} to elb {1}'
                        .format(instance_id, elb_name))

        associate_args = dict(
            load_balancer_name=elb_name,
            instances=[instance_id])
        associate_args = utils.update_args(associate_args, args)

        try:
            self.execute(self.client.register_instances, associate_args,
                         raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError,
                exception.BotoClientError) as e:
            raise NonRecoverableError('Instance not added to Load '
                                      'Balancer {0}'.format(str(e)))

        ctx.logger.info(
            'Instance {0} added to Load Balancer {1}.'
            .format(instance_id, elb_name))

        self._add_instance_to_elb_list_in_properties(instance_id)

        return True
示例#17
0
    def create_snapshot(self, args=None, **_):
        """ Create a snapshot of an EBS Volume
        """

        volume_id = \
            utils.get_external_resource_id_or_raise(
                'create snapshot', ctx.instance)

        ctx.logger.info(
            'Trying to create a snapshot of EBS volume {0}.'
            .format(volume_id))

        snapshot_desc = \
            unicode(datetime.datetime.now()) + \
            ctx.instance.runtime_properties[constants.EXTERNAL_RESOURCE_ID]
        create_args = dict(volume_id=volume_id, description=snapshot_desc)
        create_args = utils.update_args(create_args, args)

        try:
            new_snapshot = self.execute(self.client.create_snapshot,
                                        create_args, raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        if constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE'] not in \
                ctx.instance.runtime_properties:
            ctx.instance.runtime_properties[
                constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE']] = list()

        ctx.instance.runtime_properties[
            constants.EBS['VOLUME_SNAPSHOT_ATTRIBUTE']].append(new_snapshot.id)

        return True
示例#18
0
    def create(self, args=None, **_):
        """This allocates an Elastic IP in the connected account."""

        ctx.logger.debug('Attempting to allocate elasticip.')

        provider_variables = utils.get_provider_variables()

        create_args = {}
        domain = ctx.node.properties.get(
                constants.ELASTICIP['ELASTIC_IP_DOMAIN_PROPERTY']) or \
            provider_variables.get(constants.ELASTICIP['VPC_DOMAIN'])
        if domain:
            create_args[constants.ELASTICIP['ELASTIC_IP_DOMAIN_PROPERTY']] = \
                constants.ELASTICIP['VPC_DOMAIN']

        create_args = utils.update_args(create_args, args)

        try:
            address_object = self.execute(self.client.allocate_address,
                                          create_args, raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        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

        self.resource_id = address_object.public_ip

        return True
示例#19
0
    def disassociate(self, args=None, **_):

        """ Detaches an EBS Volume created by Cloudify from an EC2 Instance
        that was also created by Cloudify.
        """

        volume_id = self.source_resource_id
        instance_id = self.target_resource_id

        volume_object = self.get_source_resource()

        if not volume_object:
            raise NonRecoverableError(
                'EBS volume {0} not found in account.'.format(volume_id))

        disassociate_args = dict(
            volume_id=volume_id,
            instance_id=instance_id,
            device=ctx.source.node.properties['device']
        )

        disassociate_args = utils.update_args(disassociate_args, args)

        return self.execute(self.client.detach_volume, disassociate_args,
                            raise_on_falsy=True)
示例#20
0
    def create(self, args=None, **_):
        """This allocates an Elastic IP in the connected account."""

        ctx.logger.debug('Attempting to allocate elasticip.')

        provider_variables = utils.get_provider_variables()

        create_args = {}
        domain = ctx.node.properties.get(
                constants.ELASTICIP['ELASTIC_IP_DOMAIN_PROPERTY']) or \
            provider_variables.get(constants.ELASTICIP['VPC_DOMAIN'])
        if domain:
            create_args[constants.ELASTICIP['ELASTIC_IP_DOMAIN_PROPERTY']] = \
                constants.ELASTICIP['VPC_DOMAIN']

        create_args = utils.update_args(create_args, args)

        try:
            address_object = self.execute(self.client.allocate_address,
                                          create_args,
                                          raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        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

        self.resource_id = address_object.public_ip

        return True
示例#21
0
    def disassociate(self, args=None, **_):
        """ Disassocates an Elastic IP created by Cloudify from an EC2 Instance
        that was also created by Cloudify.
        """

        elasticip = self.target_resource_id

        elasticip_object = self.get_target_resource()

        if not elasticip_object:
            raise NonRecoverableError(
                    'no matching elastic ip in account: {0}'.format(elasticip))

        disassociate_args = dict(
                public_ip=elasticip_object.public_ip,
                association_id=elasticip_object.association_id
        )

        disassociate_args = utils.update_args(disassociate_args, args)

        try:
            self.execute(self.client.disassociate_address,
                         disassociate_args, raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return True
示例#22
0
 def create(self, args):
     create_args = self.generate_create_args()
     create_args = utils.update_args(create_args, args)
     dhcp_options = self.execute(self.client.create_dhcp_options,
                                 create_args,
                                 raise_on_falsy=True)
     self.resource_id = dhcp_options.id
     return True
示例#23
0
 def associate(self, args=None):
     associate_args = dict(route_table_id=self.source_resource_id,
                           subnet_id=self.target_resource_id)
     associate_args = utils.update_args(associate_args, args)
     self.association_id = \
         self.execute(self.client.associate_route_table,
                      associate_args, raise_on_falsy=True)
     return True
示例#24
0
 def create(self, args):
     create_args = self.generate_create_args()
     create_args = utils.update_args(create_args, args)
     ctx.instance.runtime_properties['vpc_id'] = create_args['vpc_id']
     network_acl = self.execute(self.client.create_network_acl,
                                create_args, raise_on_falsy=True)
     self.resource_id = network_acl.id
     return True
示例#25
0
 def associate(self, args):
     associate_args = dict(
         dhcp_options_id=self.source_resource_id,
         vpc_id=self.target_resource_id
     )
     associate_args = utils.update_args(associate_args, args)
     return self.execute(self.client.associate_dhcp_options,
                         associate_args, raise_on_falsy=True)
示例#26
0
    def create(self, args=None):
        '''Override for resource create operation'''

        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
        return True
示例#27
0
    def disassociate(self, args):
        disassociate_args = dict(
            subnet_id=self.target_resource_id,
            vpc_id=ctx.source.instance.runtime_properties['vpc_id']
        )
        disassociate_args = utils.update_args(disassociate_args, args)

        return self.execute(self.client.disassociate_network_acl,
                            disassociate_args, raise_on_falsy=True)
    def associate(self, args):
        assoicate_args = dict(network_acl_id=self.source_resource_id,
                              subnet_id=self.target_resource_id)
        assoicate_args = utils.update_args(assoicate_args, args)

        self.association_id = \
            self.execute(self.client.associate_network_acl,
                         assoicate_args, raise_on_falsy=True)
        return True
示例#29
0
 def create(self, args=None):
     create_args = utils.update_args(self._generate_creation_args(), args)
     route_table = \
         self.execute(self.client.create_route_table,
                      create_args, raise_on_falsy=True)
     self.resource_id = route_table.id
     for route in self.routes:
         self.create_route(route_table.id, route, ctx.instance)
     return True
示例#30
0
    def create(self, args=None):
        '''Override for resource create operation'''

        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
        return True
    def disassociate(self, args):
        disassociate_args = dict(
            subnet_id=self.target_resource_id,
            vpc_id=ctx.source.instance.runtime_properties['vpc_id'])
        disassociate_args = utils.update_args(disassociate_args, args)

        return self.execute(self.client.disassociate_network_acl,
                            disassociate_args,
                            raise_on_falsy=True)
示例#32
0
 def create(self, args):
     create_args = self.generate_create_args()
     create_args = utils.update_args(create_args, args)
     ctx.instance.runtime_properties['vpc_id'] = create_args['vpc_id']
     network_acl = self.execute(self.client.create_network_acl,
                                create_args,
                                raise_on_falsy=True)
     self.resource_id = network_acl.id
     return True
示例#33
0
 def create(self, args):
     create_args = dict(type=ctx.node.properties['type'],
                        ip_address=ctx.node.properties['ip_address'],
                        bgp_asn=ctx.node.properties['bgp_asn'])
     create_args = utils.update_args(create_args, args)
     gateway = self.execute(self.client.create_customer_gateway,
                            create_args,
                            raise_on_falsy=True)
     self.resource_id = gateway.id
     return True
示例#34
0
 def create(self, args):
     create_args = dict(type=ctx.node.properties['type'],
                        availability_zone=ctx.node.properties.get(
                            'availability_zone', None))
     create_args = utils.update_args(create_args, args)
     gateway = self.execute(self.client.create_vpn_gateway,
                            create_args,
                            raise_on_falsy=True)
     self.resource_id = gateway.id
     return True
示例#35
0
 def create(self, args=None):
     create_args = utils.update_args(self._generate_creation_args(),
                                     args)
     route_table = \
         self.execute(self.client.create_route_table,
                      create_args, raise_on_falsy=True)
     self.resource_id = route_table.id
     for route in self.routes:
         self.create_route(route_table.id, route, ctx.instance)
     return True
示例#36
0
 def associate(self, args=None):
     associate_args = dict(
         route_table_id=self.source_resource_id,
         subnet_id=self.target_resource_id
     )
     associate_args = utils.update_args(associate_args, args)
     self.association_id = \
         self.execute(self.client.associate_route_table,
                      associate_args, raise_on_falsy=True)
     return True
示例#37
0
    def associate(self, args):
        assoicate_args = dict(
            network_acl_id=self.source_resource_id,
            subnet_id=self.target_resource_id
        )
        assoicate_args = utils.update_args(assoicate_args, args)

        self.association_id = \
            self.execute(self.client.associate_network_acl,
                         assoicate_args, raise_on_falsy=True)
        return True
示例#38
0
    def delete(self, args=None, **_):
        """Deletes a keypair."""

        key_pair_name = utils.get_external_resource_id_or_raise(
            'delete key pair', ctx.instance)
        delete_args = {'key_name': key_pair_name}
        delete_args = utils.update_args(delete_args, args)

        return self.execute(self.client.delete_key_pair,
                            delete_args,
                            raise_on_falsy=True)
示例#39
0
 def create(self, args):
     create_args = dict(
         type=ctx.node.properties['type'],
         availability_zone=ctx.node.properties.get(
             'availability_zone', None)
     )
     create_args = utils.update_args(create_args, args)
     gateway = self.execute(self.client.create_vpn_gateway,
                            create_args, raise_on_falsy=True)
     self.resource_id = gateway.id
     return True
示例#40
0
    def disassociate(self, args):
        self.delete_routes()
        disassociate_args = dict(
            vpc_peering_connection_id=self.source_vpc_peering_connection_id
        )
        disassociate_args = utils.update_args(
            disassociate_args,
            args)

        return self.execute(self.client.delete_vpc_peering_connection,
                            disassociate_args, raise_on_falsy=True)
示例#41
0
 def create(self, args):
     create_args = dict(
         type=ctx.node.properties['type'],
         ip_address=ctx.node.properties['ip_address'],
         bgp_asn=ctx.node.properties['bgp_asn']
     )
     create_args = utils.update_args(create_args, args)
     gateway = self.execute(self.client.create_customer_gateway,
                            create_args, raise_on_falsy=True)
     self.resource_id = gateway.id
     return True
示例#42
0
    def delete(self, args=None, **_):

        network_interface_id = self.resource_id

        delete_args = dict(network_interface_id=network_interface_id)
        delete_args = utils.update_args(delete_args, args)

        output = self.execute(self.client.delete_network_interface,
                              delete_args,
                              raise_on_falsy=True)

        return output
示例#43
0
 def delete(self, args):
     for route in self.routes:
         self.delete_route(ctx.instance.runtime_properties.get(
             constants.EXTERNAL_RESOURCE_ID),
                           route,
                           route_table_ctx_instance=ctx.instance)
     delete_args = dict(route_table_id=ctx.instance.runtime_properties.get(
         constants.EXTERNAL_RESOURCE_ID))
     delete_args = utils.update_args(delete_args, args)
     return self.execute(self.client.delete_route_table,
                         delete_args,
                         raise_on_falsy=True)
示例#44
0
    def delete(self, args=None, **_):

        network_interface_id = self.resource_id

        delete_args = dict(network_interface_id=network_interface_id)
        delete_args = utils.update_args(delete_args, args)

        output = self.execute(self.client.delete_network_interface,
                              delete_args,
                              raise_on_falsy=True)

        return output
示例#45
0
    def delete(self, args=None, **_):
        """Deletes a keypair."""

        key_pair_name = utils.get_external_resource_id_or_raise(
                'delete key pair', ctx.instance)
        delete_args = {
            'key_name': key_pair_name
        }
        delete_args = utils.update_args(delete_args, args)

        return self.execute(self.client.delete_key_pair,
                            delete_args, raise_on_falsy=True)
示例#46
0
    def associate(self, args=None, **_):

        volume_id = \
            utils.get_external_resource_id_or_raise(
                'attach volume', ctx.source.instance)
        instance_id = \
            utils.get_external_resource_id_or_raise(
                'attach volume', ctx.target.instance)

        if ctx.source.node.properties[constants.ZONE] not in \
                ctx.target.instance.runtime_properties.get('placement'):
            ctx.logger.info(
                'Volume Zone {0} and Instance Zone {1} do not match. '
                'This may lead to an error.'.format(
                    ctx.source.node.properties[constants.ZONE],
                    ctx.target.instance.runtime_properties
                    .get('placement')
                )
            )

        volume_object = self.get_source_resource()

        if not volume_object:
            raise NonRecoverableError(
                'EBS volume {0} not found in account.'.format(volume_id))

        if constants.EBS['VOLUME_CREATING'] in volume_object.update():
            return False
        elif constants.EBS['VOLUME_AVAILABLE'] not in volume_object.update():
            raise NonRecoverableError(
                'Cannot attach Volume {0} because it is in state {1}.'
                .format(volume_object.id, volume_object.status))

        associate_args = dict(
            volume_id=volume_id,
            instance_id=instance_id,
            device=ctx.source.node.properties['device']
        )
        associate_args = utils.update_args(associate_args, args)

        out = self.execute(self.client.attach_volume,
                           associate_args,
                           raise_on_falsy=True)

        volume = associate_args.get('volume_id')
        self.target_resource_id = associate_args.get('instance_id')
        device = associate_args.get('device')

        ctx.source.instance.runtime_properties['device'] = device
        ctx.target.instance.runtime_properties[
            '{0}-device'.format(volume)] = device
        return out
示例#47
0
    def create(self, args=None, **_):

        create_args = ctx.node.properties['parameters']

        list_of_subnets = \
            utils.get_target_external_resource_ids(
                'cloudify.aws.relationships.connected_to_subnet', ctx.instance
            )

        if not list_of_subnets:
            ctx.logger.debug('There is no relationship of type '
                             'cloudify.aws.relationships.connected_to_subnet '
                             'The user is expected to provide a '
                             'parameters.subnet_id property.')
        elif len(list_of_subnets) == 1:
            ctx.logger.info('Setting subnet ID to {0}'
                            .format(list_of_subnets[0]))
            create_args.update({'subnet_id': list_of_subnets[0]})
        elif len(list_of_subnets) > 1 \
                or len(list_of_subnets) == 1 and \
                ctx.node.properties['parameters'].get('subnet_id') is not None:
            raise NonRecoverableError(
                'More than one subnet was specified. '
                'A network interface can only exist in one subnet.'
            )

        list_of_groups = \
            utils.get_target_external_resource_ids(
                'cloudify.aws.relationships.connected_to_security_group',
                ctx.instance
            )
        if list_of_groups:
            create_args.update({'groups': list_of_groups})

        create_args = utils.update_args(create_args, args)

        ctx.logger.info(
            'Attempting to create Network Interface with these API '
            'parameters: {0}.'
            .format(create_args))

        try:
            network_interface = self.execute(
                self.client.create_network_interface,
                create_args, raise_on_falsy=True)
        except (exception.EC2ResponseError,
                exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        self.resource_id = network_interface.id

        return True
示例#48
0
 def disassociate(self, args):
     if self.routes:
         for route in self.routes:
             args = self.generate_route_args(self.vpn_connection_id, route)
             if self.execute(
                     self.client.delete_vpn_connection_route,
                     args, raise_on_falsy=True):
                 ctx.source.instance.runtime_properties['routes'].remove(
                     route)
     disassociate_args = dict(vpn_connection_id=self.vpn_connection_id)
     disassociate_args = utils.update_args(disassociate_args, args)
     return self.execute(self.client.delete_vpn_connection,
                         disassociate_args, raise_on_falsy=True)
示例#49
0
 def disassociate(self, args):
     if self.routes:
         for route in self.routes:
             args = self.generate_route_args(self.vpn_connection_id, route)
             if self.execute(self.client.delete_vpn_connection_route,
                             args,
                             raise_on_falsy=True):
                 ctx.source.instance.runtime_properties['routes'].remove(
                     route)
     disassociate_args = dict(vpn_connection_id=self.vpn_connection_id)
     disassociate_args = utils.update_args(disassociate_args, args)
     return self.execute(self.client.delete_vpn_connection,
                         disassociate_args,
                         raise_on_falsy=True)
示例#50
0
    def create(self, args=None, **_):

        create_args = ctx.node.properties['parameters']

        list_of_subnets = \
            utils.get_target_external_resource_ids(
                'cloudify.aws.relationships.connected_to_subnet', ctx.instance
            )

        if not list_of_subnets:
            ctx.logger.debug('There is no relationship of type '
                             'cloudify.aws.relationships.connected_to_subnet '
                             'The user is expected to provide a '
                             'parameters.subnet_id property.')
        elif len(list_of_subnets) == 1:
            ctx.logger.info('Setting subnet ID to {0}'.format(
                list_of_subnets[0]))
            create_args.update({'subnet_id': list_of_subnets[0]})
        elif len(list_of_subnets) > 1 \
                or len(list_of_subnets) == 1 and \
                ctx.node.properties['parameters'].get('subnet_id') is not None:
            raise NonRecoverableError(
                'More than one subnet was specified. '
                'A network interface can only exist in one subnet.')

        list_of_groups = \
            utils.get_target_external_resource_ids(
                'cloudify.aws.relationships.connected_to_security_group',
                ctx.instance
            )
        if list_of_groups:
            create_args.update({'groups': list_of_groups})

        create_args = utils.update_args(create_args, args)

        ctx.logger.info(
            'Attempting to create Network Interface with these API '
            'parameters: {0}.'.format(create_args))

        try:
            network_interface = self.execute(
                self.client.create_network_interface,
                create_args,
                raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError) as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        self.resource_id = network_interface.id

        return True
示例#51
0
    def delete(self, args=None, **_):

        delete_args = dict(name=ctx.node.properties['elb_name'])
        delete_args = utils.update_args(delete_args, args)

        try:
            self.execute(self.client.delete_load_balancer,
                         delete_args,
                         raise_on_falsy=True)
        except (exception.EC2ResponseError, exception.BotoServerError,
                exception.BotoClientError) as e:
            raise NonRecoverableError('Load Balancer {0} not deleted.'.format(
                str(e)))

        return True
示例#52
0
    def _get_instance_parameters(self, args=None):
        """The parameters to the run_instance boto call.

        :returns parameters dictionary
        """

        provider_variables = utils.get_provider_variables()

        attached_group_ids = \
            utils.get_target_external_resource_ids(
                    constants.INSTANCE_SECURITY_GROUP_RELATIONSHIP,
                    ctx.instance)

        if provider_variables.get(constants.AGENTS_SECURITY_GROUP):
            attached_group_ids.append(
                    provider_variables[constants.AGENTS_SECURITY_GROUP])

        parameters = \
            provider_variables.get(constants.AGENTS_AWS_INSTANCE_PARAMETERS)
        parameters.update({
            'image_id': ctx.node.properties['image_id'],
            'instance_type': ctx.node.properties['instance_type'],
            'security_group_ids': attached_group_ids,
            'key_name': self._get_instance_keypair(provider_variables)
        })

        network_interfaces_collection = \
            self._get_network_interfaces(
                parameters.get('network_interfaces', []))

        if network_interfaces_collection:
            parameters.update({
                'network_interfaces': network_interfaces_collection
            })
        else:
            parameters.update({
                'subnet_id': self._get_instance_subnet(provider_variables)
            })

        parameters.update(ctx.node.properties['parameters'])
        parameters = self._handle_userdata(parameters)
        parameters = utils.update_args(parameters, args)
        parameters['block_device_map'] = \
            self._create_block_device_mapping(
                parameters.get('block_device_map', {})
            )

        return parameters
示例#53
0
 def delete(self, args):
     for route in self.routes:
         self.delete_route(
             ctx.instance.runtime_properties.get(
                 constants.EXTERNAL_RESOURCE_ID),
             route,
             route_table_ctx_instance=ctx.instance
         )
     delete_args = dict(
         route_table_id=ctx.instance.runtime_properties.get(
             constants.EXTERNAL_RESOURCE_ID
         )
     )
     delete_args = utils.update_args(delete_args, args)
     return self.execute(self.client.delete_route_table,
                         delete_args, raise_on_falsy=True)
示例#54
0
    def create(self, args=None, **_):
        """Creates an EBS volume.
        """

        create_volume_args = dict(size=ctx.node.properties['size'],
                                  zone=ctx.node.properties[constants.ZONE])
        create_volume_args = utils.update_args(create_volume_args, args)

        new_volume = self.execute(self.client.create_volume,
                                  create_volume_args,
                                  raise_on_falsy=True)
        ctx.instance.runtime_properties[constants.ZONE] = new_volume.zone

        self.resource_id = new_volume.id

        return True
示例#55
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