예제 #1
0
def mk_userdata_file(out_file, server_cfg):
    work_dir = pentaho_cloud.mk_work_dir()
    userdata = pentaho_cloud.mk_multipart(prep_files(work_dir, server_cfg))
    f = open(out_file, 'wb')
    f.write(userdata)
    f.close
    pentaho_cloud.rm_work_dir(work_dir)
def mk_userdata_file(out_file, server_cfg):
  work_dir=pentaho_cloud.mk_work_dir()
  userdata=pentaho_cloud.mk_multipart(prep_files(work_dir, server_cfg))
  f = open(out_file, 'wb')
  f.write(userdata)
  f.close
  pentaho_cloud.rm_work_dir(work_dir)
def mk_request_file(out_file, instance_name, image_id, flavor_id, server_cfg):
  work_dir=pentaho_cloud.mk_work_dir()
  userdata=pentaho_cloud.mk_multipart(prep_multipart_files(work_dir, server_cfg))
  license_tarball_path=pentaho_cloud.mk_license_tarball(work_dir, server_cfg.license_dir)
  f = open(license_tarball_path, 'rb')
  licenses = f.read()
  f.close()
  pentaho_cloud.rm_work_dir(work_dir)
  f = open(out_file, 'wb')
  f.write(request_template.format(base64userdata=base64.b64encode(userdata), base64metadata=base64.b64encode(' '), base64licenses=base64.b64encode(licenses), imageid=image_id, flavorid=flavor_id, instancename=instance_name))
  f.close()
예제 #4
0
def mk_request_file(out_file, instance_name, image_id, flavor_id, server_cfg):
    work_dir = pentaho_cloud.mk_work_dir()
    userdata = pentaho_cloud.mk_multipart(
        prep_multipart_files(work_dir, server_cfg))
    license_tarball_path = pentaho_cloud.mk_license_tarball(
        work_dir, server_cfg.license_dir)
    f = open(license_tarball_path, 'rb')
    licenses = f.read()
    f.close()
    pentaho_cloud.rm_work_dir(work_dir)
    f = open(out_file, 'wb')
    f.write(
        request_template.format(base64userdata=base64.b64encode(userdata),
                                base64metadata=base64.b64encode(' '),
                                base64licenses=base64.b64encode(licenses),
                                imageid=image_id,
                                flavorid=flavor_id,
                                instancename=instance_name))
    f.close()
예제 #5
0
def run_instances(provider_cfg, server_cfg):
    work_dir = pentaho_cloud.mk_work_dir()
    #print 'work_dir=%s' % work_dir
    userdata = pentaho_cloud.mk_multipart(
        pentaho_cloud.aws.prep_files(work_dir, server_cfg))
    ec2 = boto.connect_ec2(provider_cfg.access_key_id,
                           provider_cfg.secret_access_key)

    # create key pair if necessary
    if len(ec2.get_all_key_pairs(filters={'key-name': 'pentaho_cloud'})) == 0:
        key_pair = ec2.create_key_pair(
            'pentaho_cloud')  # only needs to be done once
        kdir = os.path.expanduser('~/.pentaho_cloud')
        if not os.path.exists(kdir):
            os.mkdir(kdir)
        key_pair.save(os.path.expanduser(kdir))

    # create security group if necessary
    if len(ec2.get_all_security_groups(
            filters={'group-name': 'pentaho_cloud'})) == 0:
        ec2.create_security_group('pentaho_cloud',
                                  'Security group created by pentaho_cloud')
        ports = [22, 18080, 18088, 18143, 18443, 19080, 19443]
        for p in ports:
            ec2.authorize_security_group(group_name='pentaho_cloud',
                                         ip_protocol='tcp',
                                         from_port=p,
                                         to_port=p,
                                         cidr_ip='0.0.0.0/0')

    # get block device mapping associated with image
    images = ec2.get_all_images([provider_cfg.image_id])
    if len(images) != 1:
        raise Exception('Exactly one result not returned for image id %' %
                        provider_cfg.image_id)

    image = images[0]

    run_args = {}
    run_args['min_count'] = provider_cfg.instance_count
    run_args['max_count'] = provider_cfg.instance_count
    run_args['image_id'] = provider_cfg.image_id
    run_args['key_name'] = 'pentaho_cloud'
    run_args['security_groups'] = ['pentaho_cloud']
    run_args['instance_type'] = provider_cfg.instance_type
    run_args['user_data'] = userdata
    run_args['instance_initiated_shutdown_behavior'] = 'stop'
    run_args['disable_api_termination'] = True
    if provider_cfg.placement:
        run_args['placement'] = provider_cfg.placement
    # override the block device mapping
    block_dev_map = boto.ec2.blockdevicemapping.BlockDeviceMapping()
    block_dev = boto.ec2.blockdevicemapping.EBSBlockDeviceType()
    block_dev.size = '20'  # GiB
    block_dev.snapshot_id = image.block_device_mapping[
        image.root_device_name].snapshot_id
    block_dev.delete_on_termination = False
    block_dev_map[image.root_device_name] = block_dev
    run_args['block_device_map'] = block_dev_map

    reservation = ec2.run_instances(**run_args)

    print 'Waiting on instance(s) to get public DNS name(s)...'

    block_until_ready(ec2, reservation.id)

    short_names = False
    if len(get_instances(ec2, reservation.id)) == 1:
        short_names = True

    instance_name = provider_cfg.instance_name
    if not instance_name:
        instance_name = 'pentaho_cloud'

    aws_instances = []
    for i in get_instances(ec2, reservation.id):
        instance_tags = {}
        if (short_names):
            instance_tags['Name'] = instance_name
        else:
            instance_tags['Name'] = instance_name + '_' + str(
                i.ami_launch_index)
        instance_tags['Created by pentaho_cloud'] = ''
        ec2.create_tags([i.id], instance_tags)

        volume_tags = {}
        volume_tags['Created by pentaho_cloud'] = ''
        if (short_names):
            volume_tags['Name'] = instance_name + '_volume'
        else:
            volume_tags['Name'] = instance_name + '_' + str(
                i.ami_launch_index) + '_volume'
        ec2.create_tags([i.block_device_mapping[i.root_device_name].volume_id],
                        volume_tags)

        aws_instances.append(
            AwsInstance(i.ami_launch_index, i.id, i.public_dns_name))

    pentaho_cloud.rm_work_dir(work_dir)
    return aws_instances
예제 #6
0
def run_instances(provider_cfg, server_cfg):
  work_dir=pentaho_cloud.mk_work_dir()
  #print 'work_dir=%s' % work_dir
  userdata=pentaho_cloud.mk_multipart(pentaho_cloud.aws.prep_files(work_dir, server_cfg))
  ec2 = boto.connect_ec2(provider_cfg.access_key_id, provider_cfg.secret_access_key)
  
  # create key pair if necessary
  if len(ec2.get_all_key_pairs(filters={'key-name' : 'pentaho_cloud'})) == 0:
    key_pair = ec2.create_key_pair('pentaho_cloud')  # only needs to be done once
    kdir = os.path.expanduser('~/.pentaho_cloud')
    if not os.path.exists(kdir):
      os.mkdir(kdir)
    key_pair.save(os.path.expanduser(kdir))
    
  # create security group if necessary
  if len(ec2.get_all_security_groups(filters={'group-name' : 'pentaho_cloud'})) == 0:
    ec2.create_security_group('pentaho_cloud', 'Security group created by pentaho_cloud')
    ports = [22, 18080, 18088, 18143, 18443, 19080, 19443]
    for p in ports:
      ec2.authorize_security_group(group_name='pentaho_cloud', ip_protocol='tcp', from_port=p, to_port=p, cidr_ip='0.0.0.0/0')
  
  # get block device mapping associated with image
  images = ec2.get_all_images([provider_cfg.image_id])
  if len(images) != 1:
    raise Exception('Exactly one result not returned for image id %' % provider_cfg.image_id)
  
  image = images[0]
  
  run_args = {}
  run_args['min_count'] = provider_cfg.instance_count
  run_args['max_count'] = provider_cfg.instance_count
  run_args['image_id'] = provider_cfg.image_id
  run_args['key_name'] ='pentaho_cloud'
  run_args['security_groups'] = ['pentaho_cloud']
  run_args['instance_type'] = provider_cfg.instance_type
  run_args['user_data'] = userdata
  run_args['instance_initiated_shutdown_behavior'] = 'stop'
  run_args['disable_api_termination'] = True
  if provider_cfg.placement:
    run_args['placement'] = provider_cfg.placement
  # override the block device mapping
  block_dev_map = boto.ec2.blockdevicemapping.BlockDeviceMapping()
  block_dev = boto.ec2.blockdevicemapping.EBSBlockDeviceType()
  block_dev.size = '20' # GiB
  block_dev.snapshot_id = image.block_device_mapping[image.root_device_name].snapshot_id
  block_dev.delete_on_termination = False
  block_dev_map[image.root_device_name] = block_dev
  run_args['block_device_map'] = block_dev_map
  
  reservation = ec2.run_instances(**run_args)
  
  print 'Waiting on instance(s) to get public DNS name(s)...'
  
  block_until_ready(ec2, reservation.id)
  
  short_names = False
  if len(get_instances(ec2, reservation.id)) == 1:
    short_names = True
  
  instance_name = provider_cfg.instance_name
  if not instance_name:
    instance_name = 'pentaho_cloud'
  
  aws_instances = []
  for i in get_instances(ec2, reservation.id):
    instance_tags = {}
    if (short_names):
      instance_tags['Name'] = instance_name
    else:
      instance_tags['Name'] = instance_name + '_' + str(i.ami_launch_index)
    instance_tags['Created by pentaho_cloud'] = ''
    ec2.create_tags([i.id], instance_tags)
    
    volume_tags = {}
    volume_tags['Created by pentaho_cloud'] = ''
    if (short_names):
      volume_tags['Name'] = instance_name + '_volume'
    else:
      volume_tags['Name'] = instance_name + '_' + str(i.ami_launch_index) + '_volume'
    ec2.create_tags([i.block_device_mapping[i.root_device_name].volume_id], volume_tags)

    aws_instances.append(AwsInstance(i.ami_launch_index, i.id, i.public_dns_name))
    
  pentaho_cloud.rm_work_dir(work_dir)
  return aws_instances