コード例 #1
0
def _get_instance_parameters():
    """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('agents_security_group'):
        attached_group_ids.append(provider_variables['agents_security_group'])

    parameters = {
        'image_id': ctx.node.properties['image_id'],
        'instance_type': ctx.node.properties['instance_type'],
        'security_group_ids': attached_group_ids,
        'key_name': _get_instance_keypair(provider_variables),
        'subnet_id': _get_instance_subnet(provider_variables)
    }

    parameters.update(ctx.node.properties['parameters'])
    parameters = _handle_userdata(parameters)

    return parameters
コード例 #2
0
def _get_instance_parameters():
    """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('agents_security_group'):
        attached_group_ids.append(
            provider_variables['agents_security_group'])

    parameters = {
        'image_id': ctx.node.properties['image_id'],
        'instance_type': ctx.node.properties['instance_type'],
        'security_group_ids': attached_group_ids,
        'key_name': _get_instance_keypair(provider_variables),
        'subnet_id': _get_instance_subnet(provider_variables)
    }

    parameters.update(ctx.node.properties['parameters'])
    parameters = _handle_userdata(parameters)

    return parameters
コード例 #3
0
    def test_get_target_external_resource_ids(self):

        ctx = self.mock_ctx(
            'get_target_external_resource_ids')
        current_ctx.set(ctx=ctx)

        output = utils.get_target_external_resource_ids(
            'instance_connected_to_keypair',
            ctx.instance)

        self.assertEquals(0, len(output))
コード例 #4
0
def _get_connected_vpc():

    list_of_vpcs = \
        utils.get_target_external_resource_ids(
            constants.SECURITY_GROUP_VPC_RELATIONSHIP, ctx.instance
        )

    if len(list_of_vpcs) > 1:
        raise NonRecoverableError(
            'security group may only be attached to one vpc')

    return list_of_vpcs[0] if list_of_vpcs else None
コード例 #5
0
def _get_instance_keypair(provider_variables):
    """Gets the instance key pair. If more or less than one is provided,
    this will raise an error.

    """
    list_of_keypairs = utils.get_target_external_resource_ids(constants.INSTANCE_KEYPAIR_RELATIONSHIP, ctx.instance)

    if not list_of_keypairs and provider_variables.get("agents_keypair"):
        list_of_keypairs.append(provider_variables["agents_keypair"])
    elif len(list_of_keypairs) > 1:
        raise NonRecoverableError("Only one keypair may be attached to an instance.")

    return list_of_keypairs[0] if list_of_keypairs else None
コード例 #6
0
def _get_instance_subnet(provider_variables):

    list_of_subnets = \
        utils.get_target_external_resource_ids(
            constants.INSTANCE_SUBNET_RELATIONSHIP, ctx.instance
        )

    if not list_of_subnets and provider_variables.get('agents_subnet'):
        list_of_subnets.append(provider_variables['agents_subnet'])
    elif len(list_of_subnets) > 1:
        raise NonRecoverableError(
            'instance may only be attached to one subnet')

    return list_of_subnets[0] if list_of_subnets else None
コード例 #7
0
def _get_instance_subnet(provider_variables):

    list_of_subnets = \
        utils.get_target_external_resource_ids(
            constants.INSTANCE_SUBNET_RELATIONSHIP, ctx.instance
        )

    if not list_of_subnets and provider_variables.get('agents_subnet'):
        list_of_subnets.append(provider_variables['agents_subnet'])
    elif len(list_of_subnets) > 1:
        raise NonRecoverableError(
            'instance may only be attached to one subnet')

    return list_of_subnets[0] if list_of_subnets else None
コード例 #8
0
def _get_instance_keypair(provider_variables):
    """Gets the instance key pair. If more or less than one is provided,
    this will raise an error.

    """
    list_of_keypairs = \
        utils.get_target_external_resource_ids(
            constants.INSTANCE_KEYPAIR_RELATIONSHIP, ctx.instance)

    if not list_of_keypairs and provider_variables.get('agents_keypair'):
        list_of_keypairs.append(provider_variables['agents_keypair'])
    elif len(list_of_keypairs) > 1:
        raise NonRecoverableError(
            'Only one keypair may be attached to an instance.')

    return list_of_keypairs[0] if list_of_keypairs else None
コード例 #9
0
def _get_instance_parameters():
    """The parameters to the run_instance boto call.

    :param ctx:  The Cloudify ctx context.
    :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("agents_security_group"):
        attached_group_ids.append(provider_variables["agents_security_group"])

    parameters = {
        "image_id": ctx.node.properties["image_id"],
        "instance_type": ctx.node.properties["instance_type"],
        "security_group_ids": attached_group_ids,
        "key_name": _get_instance_keypair(provider_variables),
    }
    ctx.logger.info("network_interfaces_list." + str(ctx.node.properties["parameters"]))
    if ctx.node.properties["parameters"].has_key("network_interfaces"):
        network_interfaces_str = ctx.node.properties["parameters"]["network_interfaces"]
        if isinstance(network_interfaces_str, str):
            import json

            network_interfaces_list = json.loads(network_interfaces_str)
        else:
            network_interfaces_list = network_interfaces_str
        ctx.logger.info("network_interfaces_list.  " + str(type(network_interfaces_list)))
        interfaces = [NetworkInterfaceSpecification(**one) for one in network_interfaces_list]

        ctx.logger.info("interfaces.  " + str(type(interfaces)))
        ctx.logger.info("interfaces." + str(interfaces))

        mynetwork_iterfaces = NetworkInterfaceCollection(*interfaces)

    parameters.update(ctx.node.properties["parameters"])
    parameters["network_interfaces"] = mynetwork_iterfaces
    ctx.logger.info("parameters." + str(parameters))
    return parameters
コード例 #10
0
def _get_instance_parameters():
    """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': _get_instance_keypair(provider_variables),
        'subnet_id': _get_instance_subnet(provider_variables)
    })

    parameters.update(ctx.node.properties['parameters'])
    parameters = _handle_userdata(parameters)

    # [a4c_override] read the property 'placement' from runtime properties
    if 'placement' in parameters:
      if 'placement' in ctx.instance.runtime_properties:
        parameters['placement'] = ctx.instance.runtime_properties['placement']
      else:
        parameters.pop('placement', None)
    ctx.logger.debug("[OVERRIDE] parameters={}".format(json.dumps(parameters)))
    # end [a4c_override]

    return parameters