def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS ELB classic load balancer"""

    # Add Subnets
    subnets_list = params.get(SUBNETS, [])
    params[SUBNETS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnets_list) or utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnets_list)

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list) or \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE_DEPRECATED,
            secgroups_list)

    create_response = iface.create(params)

    # Actually create the resource
    ctx.instance.runtime_properties['DNSName'] = \
        create_response['DNSName']
    ctx.instance.runtime_properties['create_response'] = \
        create_response
Example #2
0
    def test_add_resources_from_rels(self):

        mock_instance, mock_child = self._prepare_for_find_rel()

        self.assertEqual(
            utils.add_resources_from_rels(mock_instance.instance,
                                          'cloudify.nodes.Network', []), [])

        self.assertEqual(
            utils.add_resources_from_rels(mock_instance.instance,
                                          'cloudify.nodes.Root', []), ['a'])
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Group"""
    # Try to populate the Launch Configuration field
    # with a relationship
    lc_name = params.get(LC_NAME)
    instance_id = params.get(INSTANCE_ID)

    if not lc_name and not instance_id:
        lc_name = \
            utils.find_resource_id_by_type(
                ctx.instance,
                LC_TYPE)
        if lc_name:
            params.update({LC_NAME: lc_name})

    # If no LC_NAME, try to populate the
    # InstanceId field with a relationship.
    if not lc_name:
        instance_id = \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params[INSTANCE_ID] = instance_id

    subnet_list_string = params.get(SUBNET_LIST)
    subnet_list = \
        sub("[^\w]", " ", subnet_list_string).split() if \
        subnet_list_string else []

    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnet_list)
    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnet_list)

    if subnet_list:
        # Remove any duplicate items from subnet list
        subnet_list = list(set(subnet_list))
        params[SUBNET_LIST] = ', '.join(subnet_list)

    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    iface.update_resource_id(iface.properties.get(RESOURCE_NAME))
    utils.update_resource_id(
        ctx.instance, iface.properties.get(RESOURCE_NAME))
    utils.update_resource_arn(
        ctx.instance, iface.properties.get(GROUP_ARN))
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Group"""
    # Try to populate the Launch Configuration field
    # with a relationship
    lc_name = params.get(LC_NAME)
    instance_id = params.get(INSTANCE_ID)

    if not lc_name and not instance_id:
        lc_name = \
            utils.find_resource_id_by_type(
                ctx.instance,
                LC_TYPE)
        if lc_name:
            params.update({LC_NAME: lc_name})

    # If no LC_NAME, try to populate the
    # InstanceId field with a relationship.
    if not lc_name:
        instance_id = \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params[INSTANCE_ID] = instance_id

    subnet_list_string = params.get(SUBNET_LIST)
    subnet_list = \
        sub("[^\w]", " ", subnet_list_string).split() if \
        subnet_list_string else []

    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnet_list)
    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnet_list)

    if subnet_list:
        # Remove any duplicate items from subnet list
        subnet_list = list(set(subnet_list))
        params[SUBNET_LIST] = ', '.join(subnet_list)

    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    iface.update_resource_id(iface.properties.get(RESOURCE_NAME))
    utils.update_resource_id(ctx.instance, iface.properties.get(RESOURCE_NAME))
    utils.update_resource_arn(ctx.instance, iface.properties.get(GROUP_ARN))
def create(ctx, iface, resource_config, **_):
    """Creates an AWS EFS Mount Target"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    # Add File System ID
    file_system_id = params.get(FILESYSTEM_ID)
    if not file_system_id:
        file_system = \
            utils.find_rel_by_node_type(
                ctx.instance,
                FILESYSTEM_TYPE)
        file_system_id = file_system.target.instance.runtime_properties[
            EXTERNAL_RESOURCE_ID]
        params[FILESYSTEM_ID] = file_system_id

    # Add Subnet
    subnet_id = params.get(SUBNET_ID)
    if not subnet_id:
        subnet = \
            utils.find_rel_by_node_type(
                ctx.instance,
                SUBNET_TYPE) or utils.find_rel_by_node_type(
                ctx.instance,
                SUBNET_TYPE_DEPRECATED)

        subnet_id = \
            subnet.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID]
        params[SUBNET_ID] = subnet_id

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list) or \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE_DEPRECATED,
            secgroups_list)

    output = iface.create(params)
    utils.update_resource_id(ctx.instance, output.get(MOUNTTARGET_ID))
    ctx.instance.runtime_properties[FILESYSTEM_ID] = output.get(FILESYSTEM_ID)
    ctx.instance.runtime_properties[SUBNET_ID] = output.get(SUBNET_ID)
    ctx.instance.runtime_properties[IP_ADDRESS] = output.get(IP_ADDRESS)
    ctx.instance.runtime_properties[NAT_ID] = output.get(NAT_ID)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS EFS Mount Target"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    # Add File System ID
    file_system_id = params.get(FILESYSTEM_ID)
    if not file_system_id:
        file_system = \
            utils.find_rel_by_node_type(
                ctx.instance,
                FILESYSTEM_TYPE)
        file_system_id = file_system.target.instance.runtime_properties[
            EXTERNAL_RESOURCE_ID]
        params[FILESYSTEM_ID] = file_system_id

    # Add Subnet
    subnet_id = params.get(SUBNET_ID)
    if not subnet_id:
        subnet = \
            utils.find_rel_by_node_type(
                ctx.instance,
                SUBNET_TYPE) or utils.find_rel_by_node_type(
                ctx.instance,
                SUBNET_TYPE_DEPRECATED)

        subnet_id = \
            subnet.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID]
        params[SUBNET_ID] = subnet_id

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list) or \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE_DEPRECATED,
            secgroups_list)

    output = iface.create(params)
    utils.update_resource_id(ctx.instance, output.get(MOUNTTARGET_ID))
    ctx.instance.runtime_properties[FILESYSTEM_ID] = output.get(FILESYSTEM_ID)
    ctx.instance.runtime_properties[SUBNET_ID] = output.get(SUBNET_ID)
    ctx.instance.runtime_properties[IP_ADDRESS] = output.get(IP_ADDRESS)
    ctx.instance.runtime_properties[NAT_ID] = output.get(NAT_ID)
    def test_add_resources_from_rels(self):

        mock_instance, mock_child = self._prepare_for_find_rel()

        self.assertEqual(
            utils.add_resources_from_rels(
                mock_instance.instance, 'cloudify.nodes.Network', []
            ), []
        )

        self.assertEqual(
            utils.add_resources_from_rels(
                mock_instance.instance, 'cloudify.nodes.Root', []
            ), ['a']
        )
Example #8
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS ELB classic load balancer"""

    # Create a copy of the resource config for clean manipulation.
    params = utils.clean_params(
        dict() if not resource_config else resource_config.copy())
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)
    ctx.instance.runtime_properties[RESOURCE_NAME] = \
        resource_id

    # Add Subnets
    subnets_list = params.get(SUBNETS, [])
    params[SUBNETS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnets_list) or utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnets_list)

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list) or \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE_DEPRECATED,
            secgroups_list)

    create_response = iface.create(params)

    # Actually create the resource
    ctx.instance.runtime_properties['DNSName'] = \
        create_response['DNSName']
    ctx.instance.runtime_properties['create_response'] = \
        create_response
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Autoscaling Launch Configuration"""

    # Check if the "IamInstanceProfile" is passed or not and then update it
    iam_instance_profile = params.get(IAM_INSTANCE_PROFILE)
    if iam_instance_profile:
        if isinstance(iam_instance_profile, basestring):
            iam_instance_profile = iam_instance_profile.strip()
            params[IAM_INSTANCE_PROFILE] = str(iam_instance_profile)
        else:
            raise NonRecoverableError('Invalid {0} data type for {1}'
                                      ''.format(type(iam_instance_profile),
                                                IAM_INSTANCE_PROFILE))

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list)

    image_id = params.get(IMAGEID)

    # Add Instance and Instance Type
    instance_id = params.get(INSTANCEID)
    instance_type = params.get(INSTANCE_TYPE_PROPERTY)
    if not image_id and not instance_id:
        instance_id = utils.find_resource_id_by_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params.update({INSTANCEID: instance_id})
    if instance_id and not instance_type:
        targ = utils.find_rel_by_node_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                INSTANCE_TYPE)
        if targ:
            instance_type = \
                targ.target.instance.runtime_properties.get(
                    'resource_config', {}).get(
                        INSTANCE_TYPE_PROPERTY) or \
                targ.target.node.properties.get(
                    INSTANCE_TYPE_PROPERTY_DEPRECATED)
        params.update({INSTANCE_TYPE_PROPERTY: instance_type})

    utils.update_resource_id(ctx.instance, params.get(RESOURCE_NAME))
    iface.update_resource_id(params.get(RESOURCE_NAME))
    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    resource_arn = iface.properties[LC_ARN]
    utils.update_resource_arn(ctx.instance, resource_arn)
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Autoscaling Launch Configuration"""

    # Check if the "IamInstanceProfile" is passed or not and then update it
    iam_instance_profile = params.get(IAM_INSTANCE_PROFILE)
    if iam_instance_profile:
        if isinstance(iam_instance_profile, basestring):
            iam_instance_profile = iam_instance_profile.strip()
            params[IAM_INSTANCE_PROFILE] = str(iam_instance_profile)
        else:
            raise NonRecoverableError(
                'Invalid {0} data type for {1}'
                ''.format(type(iam_instance_profile), IAM_INSTANCE_PROFILE))

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list)

    image_id = params.get(IMAGEID)

    # Add Instance and Instance Type
    instance_id = params.get(INSTANCEID)
    instance_type = params.get(INSTANCE_TYPE_PROPERTY)
    if not image_id and not instance_id:
        instance_id = utils.find_resource_id_by_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params.update({INSTANCEID: instance_id})
    if instance_id and not instance_type:
        targ = utils.find_rel_by_node_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                INSTANCE_TYPE)
        if targ:
            instance_type = \
                targ.target.instance.runtime_properties.get(
                    'resource_config', {}).get(
                        INSTANCE_TYPE_PROPERTY) or \
                targ.target.node.properties.get(
                    INSTANCE_TYPE_PROPERTY_DEPRECATED)
        params.update({INSTANCE_TYPE_PROPERTY: instance_type})

    utils.update_resource_id(
        ctx.instance, params.get(RESOURCE_NAME))
    iface.update_resource_id(params.get(RESOURCE_NAME))
    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    resource_arn = iface.properties[LC_ARN]
    utils.update_resource_arn(
        ctx.instance, resource_arn)