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
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
def allocate(**_): """This allocates an Elastic IP in the connected account.""" ec2_client = connection.EC2ConnectionClient().client() if _allocate_external_elasticip(): return ctx.logger.debug("Attempting to allocate elasticip.") provider_variables = utils.get_provider_variables() kw = {} domain = ctx.node.properties.get(constants.ELASTIC_IP_DOMAIN_PROPERTY) or provider_variables.get(constants.VPC) if domain: kw[constants.ELASTIC_IP_DOMAIN_PROPERTY] = constants.VPC_DOMAIN try: address_object = ec2_client.allocate_address(**kw) except (boto.exception.EC2ResponseError, boto.exception.BotoServerError) as e: raise NonRecoverableError("{0}".format(str(e))) if constants.VPC_DOMAIN in address_object.domain: ctx.instance.runtime_properties[constants.ALLOCATION_ID] = address_object.allocation_id utils.set_external_resource_id(address_object.public_ip, ctx.instance, external=False)
def test_get_provider_variable(self): ctx = self.mock_ctx('test_get_provider_variables') current_ctx.set(ctx=ctx) provider_context = \ utils.get_provider_variables() self.assertEqual('agents', provider_context['agents_keypair']) self.assertEqual('agents', provider_context['agents_security_group'])
def _get_connected_vpc(): list_of_vpcs = \ utils.get_target_external_resource_ids( constants.SECURITY_GROUP_VPC_RELATIONSHIP, ctx.instance ) manager_vpc = utils.get_provider_variables().get(constants.VPC) if manager_vpc: list_of_vpcs.append(manager_vpc) 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
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
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