def create_instance_template(tem_name, env_name=None, image_id=None, vm_type=None, subnet_id=None, sec_id=None): # This assumes that Cloudbreak aor Director have been deployed details = horton.cbd.extra env_name = env_name if env_name else horton.cadcred.name image_id = image_id if image_id else details['image_id'] vm_type = vm_type if vm_type else details['instance_type'] subnet_id = subnet_id if subnet_id else details['subnet_id'] sec_id = sec_id if sec_id else details['groups'][0]['group_id'] cd.InstanceTemplatesApi(horton.cad).create( environment=env_name, instance_template=cd.InstanceTemplate(name=tem_name, image=image_id, type=vm_type, config={ 'subnetId': subnet_id, 'securityGroupsIds': sec_id, 'instanceNamePrefix': horton.namespace }, tags=config.profile['tags']))
def create_instance_template(tem_name, env_name=None, image_id=None, scripts=None, vm_type=None, subnet_id=None, sec_id=None): # This assumes that Cloudbreak aor Director have been deployed platform = config.profile.get('platform') details = horton.cbd.extra env_name = env_name if env_name else horton.cdcred.name # Script installs JDK1.8 and force-sets Chronyd to work if present bootstraps = [ cd.Script( content='#!/bin/sh' '\nyum remove --assumeyes *openjdk*' '\nrpm -ivh "https://whoville.s3.eu-west-2.amazonaws.com/v2/or-jdk-8-212.rpm"' '\necho "server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4" >> /etc/chrony.conf' '\nservice chronyd restart' '\nexit 0') ] if scripts is not None: for s in scripts: bootstraps.append(cd.Script(content=s)) if platform['provider'] == 'GCE': log.info("*** setting up GCE instance template ***") # Director won't recognise the GCE image name as valid, have to use the URL # https://community.cloudera.com/t5/Cloudera-Altus-Director/Instance-Template-Image-URLs-for-Cloudera-Director-on-Azure/td-p/45445 image_id = image_id if image_id else [ x for x in infra.create_libcloud_session().list_images() if details['image'] in x.name ][0].extra['selfLink'] vm_type = vm_type if vm_type else details['machineType'].split('/')[-1] params = { 'zone': horton.cbd.extra["zone"].name, 'instanceNamePrefix': tem_name, } else: # assume AWS log.info("*** setting up AWS instance template ***") image_id = image_id if image_id else details['image_id'] vm_type = vm_type if vm_type else details['instance_type'] subnet_id = subnet_id if subnet_id else details['subnet_id'] sec_id = sec_id if sec_id else details['groups'][0]['group_id'] params = { 'subnetId': subnet_id, 'securityGroupsIds': sec_id, 'instanceNamePrefix': tem_name, } cd.InstanceTemplatesApi(horton.cad).create( environment=env_name, instance_template=cd.InstanceTemplate(name=tem_name, image=image_id, type=vm_type, config=params, tags=config.profile['tags'], bootstrap_scripts=bootstraps))
def get_instance_template(env_name=None, tem_name=None): env_name = env_name if env_name else horton.cdcred.name tem_name = tem_name if tem_name else horton.cdcred.name try: return cd.InstanceTemplatesApi(horton.cad).get(environment=env_name, template=tem_name) except ApiException as e: if e.status == 404: return [] # not found else: raise e
def create_instance_template(tem_name, env_name=None, image_id=None, scripts=None, vm_type=None, subnet_id=None, sec_id=None): # This assumes that Cloudbreak aor Director have been deployed platform = config.profile.get('platform') details = horton.cbd.extra env_name = env_name if env_name else horton.cadcred.name bootstraps = [ cd.Script( content='#!/bin/sh\nyum remove --assumeyes *openjdk*\nrpm -ivh ' '"https://archive.cloudera.com/director/redhat/7/x86_64/' 'director/2.8.0/RPMS/x86_64/oracle-j2sdk1.8-1.8.0+update1' '21-1.x86_64.rpm"\nexit 0') ] if scripts is not None: for s in scripts: bootstraps.append(cd.Script(content=s)) if platform['provider'] == 'GCE': log.info("*** setting up GCE instance template ***") # Director won't recognise the GCE image name as valid, have to use the URL # https://community.cloudera.com/t5/Cloudera-Altus-Director/Instance-Template-Image-URLs-for-Cloudera-Director-on-Azure/td-p/45445 image_id = image_id if image_id else [ x for x in infra.create_libcloud_session().list_images() if details['image'] in x.name ][0].extra['selfLink'] vm_type = vm_type if vm_type else details['machineType'].split('/')[-1] params = { 'zone': horton.cbd.extra["zone"].name, 'instanceNamePrefix': horton.namespace } else: # assume AWS log.info("*** setting up AWS instance template ***") image_id = image_id if image_id else details['image_id'] vm_type = vm_type if vm_type else details['instance_type'] subnet_id = subnet_id if subnet_id else details['subnet_id'] sec_id = sec_id if sec_id else details['groups'][0]['group_id'] params = { 'subnetId': subnet_id, 'securityGroupsIds': sec_id, 'instanceNamePrefix': horton.namespace } cd.InstanceTemplatesApi(horton.cad).create( environment=env_name, instance_template=cd.InstanceTemplate(name=tem_name, image=image_id, type=vm_type, config=params, tags=config.profile['tags'], bootstrap_scripts=bootstraps))