def create_instance_template(config, name): """ Create an instance template with data from the configuration file @param config: parsed configuration file @param name: the name of the new template @rtype: InstanceTemplate """ template = InstanceTemplate() template.name = name template.image = config.get("instance", "image") template.type = config.get("instance", "type") template.config = { "subnetId": config.get("instance", "subnetId"), "securityGroupsIds": config.get("instance", "securityGroupId"), "instanceNamePrefix": config.get("instance", "namePrefix"), } return template
def create_instance_template(config, name): """ Create an instance template with data from the configuration file @param config: parsed configuration file @param name: the name of the new template @rtype: InstanceTemplate """ template = InstanceTemplate() template.name = name template.image = config.get('instance', 'image') template.type = config.get('instance', 'type') template.config = { 'subnetId': config.get('instance', 'subnetId'), 'securityGroupsIds': config.get('instance', 'securityGroupId'), 'instanceNamePrefix': config.get('instance', 'namePrefix') } return template
def create_instance_template(config, name): """ Create an instance template with data from the configuration file @param config: parsed configuration file @param name: the name of the new template @rtype: InstanceTemplate """ template_config = { 'subnetId': config.get('instance', 'subnetId'), 'securityGroupsIds': config.get('instance', 'securityGroupId'), 'instanceNamePrefix': config.get('instance', 'namePrefix') } template = InstanceTemplate(name=name, image=config.get('instance', 'image'), type=config.get('instance', 'type'), config=template_config) return template
def configure_instance_template(merged_template_config, template_name, instance_provider_metadata): """ Create an instance template with data from the configuration @param merged_template_config: merged template configuration @param template_name: name of the template @param provider_type: configured provider type @param cloud_provider_metadata: cloud provider metadata for the specified provider type @rtype: InstanceTemplate @return: instance template configuration """ template = InstanceTemplate() template.name = template_name # read and set template type from config config_value = merged_template_config.get('type', '') if config_value: template.type = config_value # read and set template image from config template.image = '' config_value = merged_template_config.get('image', '') if config_value: template.image = config_value # read and set optional template ssh username from config template.sshUsername = '' config_value = merged_template_config.get('sshUsername', '') if config_value: template.sshUsername = config_value # read and set optional template normalize instance flag from config template.normalizeInstance = '' config_value = merged_template_config.get('normalizeInstance', '') if config_value: template.normalizeInstance = bool(config_value) # read and set optional template bootstrap script from config template.bootstrapScript = '' config_value = merged_template_config.get('bootstrapScript', '') if config_value: template.bootstrapScript = config_value else: # read and set optional template bootstrap script path from config config_value = merged_template_config.get('bootstrapScriptPath', '') if config_value: with open(config_value) as f: template.bootstrapScript = f.read() # read and set optional template tags from config template.tags = {} if 'tags' in merged_template_config: template.tags.update(merged_template_config.get('tags')) # read and set additional template configuration properties from config template.config = {} template.config.update( get_configuration_property_values( merged_template_config, instance_provider_metadata.templateProperties)) if debug: print "name: %s, type: %s, image: %s, sshUsername: %s, normalizeInstance: %s, bootstrapScript: %s, tags: %s" % \ (template.name, template.type, template.image, template.sshUsername, template.normalizeInstance, template.bootstrapScript, template.tags) print "template.config: %s" % template.config print "Unknown keys: %s" % (merged_template_config.viewkeys() - template.config.viewkeys()) return template
def configure_instance_template(merged_template_config, template_name, instance_provider_metadata): """ Create an instance template with data from the configuration @param merged_template_config: merged template configuration @param template_name: name of the template @param provider_type: configured provider type @param cloud_provider_metadata: cloud provider metadata for the specified provider type @rtype: InstanceTemplate @return: instance template configuration """ template = InstanceTemplate() template.name = template_name # read and set template type from config config_value = merged_template_config.get('type', '') if config_value: template.type = config_value # read and set template image from config template.image = '' config_value = merged_template_config.get('image', '') if config_value: template.image = config_value # read and set optional template ssh username from config template.sshUsername = '' config_value = merged_template_config.get('sshUsername', '') if config_value: template.sshUsername = config_value # read and set optional template normalize instance flag from config template.normalizeInstance = '' config_value = merged_template_config.get('normalizeInstance', '') if config_value: template.normalizeInstance = bool(config_value) # read and set optional template bootstrap script from config template.bootstrapScript = '' config_value = merged_template_config.get('bootstrapScript', '') if config_value: template.bootstrapScript = config_value else: # read and set optional template bootstrap script path from config config_value = merged_template_config.get('bootstrapScriptPath', '') if config_value: with open(config_value) as f: template.bootstrapScript = f.read() # read and set optional template tags from config template.tags = {} if 'tags' in merged_template_config: template.tags.update(merged_template_config.get('tags')) # read and set additional template configuration properties from config template.config = {} template.config.update(get_configuration_property_values(merged_template_config, instance_provider_metadata.templateProperties)) if debug: print "name: %s, type: %s, image: %s, sshUsername: %s, normalizeInstance: %s, bootstrapScript: %s, tags: %s" % \ (template.name, template.type, template.image, template.sshUsername, template.normalizeInstance, template.bootstrapScript, template.tags) print "template.config: %s" % template.config print "Unknown keys: %s" % (merged_template_config.viewkeys() - template.config.viewkeys()) return template