예제 #1
0
    def launch_instance(cfg, **kwargs):
        """
        Launches a new instance of CloudMan on the specified cloud infrastructure.

        :type cfg: CloudManConfig
        :param cfg: A CloudManConfig object containing the initial parameters
                    for this launch.
        """
        validation_result = cfg.validate()
        if validation_result is not None:
            raise VMLaunchException(
                "Invalid CloudMan configuration provided: {0}".format(
                    validation_result))
        launcher = CloudManLauncher(cfg.access_key, cfg.secret_key,
                                    cfg.cloud_metadata)
        result = launcher.launch(cfg.cluster_name, cfg.image_id,
                                 cfg.instance_type, cfg.password,
                                 cfg.kernel_id, cfg.ramdisk_id, cfg.key_name,
                                 cfg.security_groups, cfg.placement,
                                 **cfg.kwargs)
        if result['error'] is not None:
            raise VMLaunchException(
                "Error launching cloudman instance: {0}".format(
                    result['error']))
        instance = CloudManInstance(None,
                                    None,
                                    launcher=launcher,
                                    launch_result=result,
                                    cloudman_config=cfg)
        if cfg.block_until_ready and cfg.cluster_type:
            instance.get_status(
            )  # this will indirect result in initialize being invoked
        return instance
예제 #2
0
def runinstance(request):
    """Run a CloudBioLinux/CloudMan instance with current session credentials.
    """
    form = request.session["ec2data"]

    # Handle extra_user_data
    extra_user_data = form['extra_user_data']
    if extra_user_data:
        for key, value in yaml.load(extra_user_data).iteritems():
            form[key] = value
    del form['extra_user_data']

    rs = None
    instance_type = form['instance_type']
    # Create cloudman connection with provided creds
    cml = CloudManLauncher(form["access_key"], form["secret_key"], form['cloud'])
    form["freenxpass"] = form["password"]
    if form['image_id']:
        image = models.Image.objects.get(pk=form['image_id'])
    else:
        try:
            image = models.Image.objects.get(cloud=form['cloud'], default=True)
        except models.Image.DoesNotExist:
            log.error("Cannot find an image to launch for cloud {0}".format(form['cloud']))
            return False
    # Compose kwargs from form data making sure the named arguments are not included
    kwargs = copy.deepcopy(form)
    for key in form.iterkeys():
        if key in ['cluster_name', 'image_id', 'instance_type', 'password',
                   'placement', 'access_key', 'secret_key', 'cloud']:
            del kwargs[key]
    response = cml.launch(cluster_name=form['cluster_name'],
                        image_id=image.image_id,
                        instance_type=instance_type,
                        password=form["password"],
                        kernel_id=image.kernel_id if image.kernel_id != '' else None,
                        ramdisk_id=image.ramdisk_id if image.ramdisk_id != '' else None,
                        placement=form['placement'],
                        **kwargs)
    if response["error"]:
        return response
    elif response["rs"]:
        rs = response["rs"]
        request.session['ec2data']['instance_id'] = rs.instances[0].id
        request.session['ec2data']['public_ip'] = rs.instances[0].ip_address  # public_dns_name
        request.session['ec2data']['image_id'] = rs.instances[0].image_id
        request.session['ec2data']['kp_name'] = response['kp_name']
        request.session['ec2data']['kp_material'] = response['kp_material']
        request.session['ec2data']['sg_name'] = response['sg_names'][0]

        # Add an entry to the Usage table
        try:
            u = models.Usage(cloud_name=form["cloud_name"],
                             cloud_type=form["cloud_type"],
                             image_id=image.image_id,
                             instance_type=instance_type,
                             user_id=form["access_key"])
            u.save()
        except Exception, e:
            log.debug("Trouble saving Usage data: {0}".format(e))
예제 #3
0
    def launch_instance(cfg, **kwargs):
        """
        Launches a new instance of CloudMan on the specified cloud infrastructure.

        :type cfg: CloudManConfig
        :param cfg: A CloudManConfig object containing the initial parameters
                    for this launch.
        """
        validation_result = cfg.validate()
        if validation_result is not None:
            raise VMLaunchException(
                "Invalid CloudMan configuration provided: {0}"
                .format(validation_result))
        launcher = CloudManLauncher(cfg.access_key, cfg.secret_key, cfg.cloud_metadata)
        result = launcher.launch(
            cfg.cluster_name, cfg.image_id, cfg.instance_type, cfg.password,
            cfg.kernel_id, cfg.ramdisk_id, cfg.key_name, cfg.security_groups,
            cfg.placement)
        if result['error'] is not None:
            raise VMLaunchException("Error launching cloudman instance: {0}".format(result['error']))
        instance = CloudManInstance(None, None, launcher=launcher,
                                    launch_result=result, cloudman_config=cfg)
        if cfg.block_until_ready and cfg.cluster_type:
            instance.get_status()  # this will indirect result in initialize being invoked
        return instance
예제 #4
0
def run_instance(form):
    """
    Run a CloudBioLinux/CloudMan instance with current session credentials.
    """
    err_msg = None
    kernel_id = None
    ramdisk_id = None
    # Handle extra_user_data
    extra_user_data = form['extra_user_data']
    if extra_user_data:
        for key, value in yaml.load(extra_user_data).iteritems():
            form[key] = value
    del form['extra_user_data']
    instance_type = form['instance_type']
    # Create cloudman connection with provided creds
    cml = CloudManLauncher(form["access_key"], form["secret_key"], form['cloud'])
    form["freenxpass"] = form["password"]
    if form['image_id']:
        if form['image_id'] == '0':
            image_id = form['custom_image_id']
        else:
            image = models.Image.objects.get(pk=form['image_id'])
            image_id = image.image_id
            image.kernel_id if image.kernel_id != '' else None
            image.ramdisk_id if image.ramdisk_id != '' else None
    else:
        try:
            image = models.Image.objects.get(cloud=form['cloud'], default=True)
            image_id = image.image_id
            image.kernel_id if image.kernel_id != '' else None
            image.ramdisk_id if image.ramdisk_id != '' else None
        except models.Image.DoesNotExist:
            err_msg = "Cannot find an image to launch for cloud {0}".format(form['cloud'])
            log.error(err_msg)
            return False
    # Compose kwargs from form data making sure the named arguments are not included
    kwargs = copy.deepcopy(form)
    for key in form.iterkeys():
        if key in ['cluster_name', 'image_id', 'instance_type', 'password',
                   'placement', 'access_key', 'secret_key', 'cloud']:
            del kwargs[key]
    response = cml.launch(cluster_name=form['cluster_name'],
                        image_id=image_id,
                        instance_type=instance_type,
                        password=form["password"],
                        kernel_id=kernel_id,
                        ramdisk_id=ramdisk_id,
                        placement=form['placement'],
                        **kwargs)
    # Keep these parts of the form as part of the response
    response['cluster_name'] = form['cluster_name']
    response['password'] = form['password']
    response['cloud_name'] = form['cloud_name']
    response['cloud_type'] = form['cloud_type']
    response['access_key'] = form['access_key']
    response['instance_type'] = form['instance_type']
    response['image_id'] = image_id
    response['error'] = err_msg
    return response
예제 #5
0
                'ebs_optimized', 'subnet_id'
        ]:
            del kwargs[key]

    response = {}
    if not err_msg:
        log.debug("Launching cluster '{0}' on {1} cloud from image {2} on "
                  "instance type {3}{4}.".format(
                      form['cluster_name'], form['cloud_name'], image_id,
                      instance_type, " in zone '{0}'".format(form['placement'])
                      if form['placement'] else ""))
        response = cml.launch(cluster_name=form['cluster_name'],
                              image_id=image_id,
                              instance_type=instance_type,
                              password=form["password"],
                              kernel_id=kernel_id,
                              ramdisk_id=ramdisk_id,
                              placement=form['placement'],
                              ebs_optimized=ebs_optimized,
                              subnet_id=subnet_id,
                              **kwargs)
    # Keep these parts of the form as part of the response
    response['cluster_name'] = form['cluster_name']
    response['password'] = form['password']
    response['cloud_name'] = form['cloud_name']
    response['cloud_type'] = form['cloud_type']
    response['access_key'] = form['access_key']
    response['instance_type'] = instance_type
    response['cluster_type'] = form.get('initial_cluster_type', '')
    response['storage_type'] = form.get('storage_type', '')
    response['storage_size'] = form.get('storage_size', '')
    response['institutional_email'] = form.get('institutional_email', '')
예제 #6
0
파일: tasks.py 프로젝트: pli888/cloudlaunch
 if not err_msg:
     log.debug(
         "Launching cluster '{0}' on {1} cloud from image {2} on "
         "instance type {3}{4}.".format(
             form["cluster_name"],
             form["cloud_name"],
             image_id,
             instance_type,
             " in zone '{0}'".format(form["placement"]) if form["placement"] else "",
         )
     )
     response = cml.launch(
         cluster_name=form["cluster_name"],
         image_id=image_id,
         instance_type=instance_type,
         password=form["password"],
         kernel_id=kernel_id,
         ramdisk_id=ramdisk_id,
         placement=form["placement"],
         **kwargs
     )
 # Keep these parts of the form as part of the response
 response["cluster_name"] = form["cluster_name"]
 response["password"] = form["password"]
 response["cloud_name"] = form["cloud_name"]
 response["cloud_type"] = form["cloud_type"]
 response["access_key"] = form["access_key"]
 response["instance_type"] = instance_type
 response["cluster_type"] = form.get("initial_cluster_type", "")
 response["storage_type"] = form.get("storage_type", "")
 response["storage_size"] = form.get("storage_size", "")
 response["institutional_email"] = form.get("institutional_email", "")
예제 #7
0
        if key in ['cluster_name', 'image_id', 'instance_type', 'password',
                   'placement', 'access_key', 'secret_key', 'cloud', 'key_pair',
                   'ebs_optimized', 'subnet_id']:
            del kwargs[key]

    response = {}
    if not err_msg:
        log.debug("Launching cluster '{0}' on {1} cloud from image {2} on "
                  "instance type {3}{4}."
                  .format(form['cluster_name'], form['cloud_name'], image_id, instance_type,
                          " in zone '{0}'".format(form['placement']) if form['placement'] else ""))
        response = cml.launch(cluster_name=form['cluster_name'],
                              image_id=image_id,
                              instance_type=instance_type,
                              password=form["password"],
                              kernel_id=kernel_id,
                              ramdisk_id=ramdisk_id,
                              placement=form['placement'],
                              ebs_optimized=ebs_optimized,
                              subnet_id=subnet_id,
                              **kwargs)
    # Keep these parts of the form as part of the response
    response['cluster_name'] = form['cluster_name']
    response['password'] = form['password']
    response['cloud_name'] = form['cloud_name']
    response['cloud_type'] = form['cloud_type']
    response['access_key'] = form['access_key']
    response['instance_type'] = instance_type
    response['cluster_type'] = form.get('initial_cluster_type', '')
    response['storage_type'] = form.get('storage_type', '')
    response['storage_size'] = form.get('storage_size', '')
    response['institutional_email'] = form.get('institutional_email', '')
import bioblend
from bioblend.util import Bunch
from bioblend.cloudman.launch import CloudManLauncher

import logging
logging.basicConfig(filename="bioblend.log", level=logging.DEBUG)


cloud = Bunch(id='1', name='climb', cloud_type="openstack", bucket_default="cloudman_os", region_name="nova", region_endpoint="147.188.173.10", ec2_port="8773", ec2_conn_path="/services/Cloud", cidr_range="147.188.173.0/24", is_secure=False, s3_host="swift.rc.nectar.org.au", s3_port="8888", s3_conn_path='/')

cml = CloudManLauncher('ACCESS_KEY', 'SECRET_KEY', cloud)

response = cml.launch(cluster_name='test',
                              image_id='ami-00000039',
                              instance_type='m1.large',
                              password='******',
                              placement='nova')

print response
from bioblend.util import Bunch
from bioblend.cloudman.launch import CloudManLauncher

import logging

logging.basicConfig(filename="bioblend.log", level=logging.DEBUG)

cloud = Bunch(id='1',
              name='climb',
              cloud_type="openstack",
              bucket_default="cloudman_os",
              region_name="nova",
              region_endpoint="147.188.173.10",
              ec2_port="8773",
              ec2_conn_path="/services/Cloud",
              cidr_range="147.188.173.0/24",
              is_secure=False,
              s3_host="swift.rc.nectar.org.au",
              s3_port="8888",
              s3_conn_path='/')

cml = CloudManLauncher('ACCESS_KEY', 'SECRET_KEY', cloud)

response = cml.launch(cluster_name='test',
                      image_id='ami-00000039',
                      instance_type='m1.large',
                      password='******',
                      placement='nova')

print response
예제 #10
0
def run_instance(form):
    """
    Run a CloudBioLinux/CloudMan instance with current session credentials.
    """
    # Dev code only!
    # Useful when wanting to skip the instance launch process but contitnue the process
    # response = {}
    # response['cluster_name'] = form['cluster_name']
    # response['password'] = form['password']
    # response['cloud_name'] = form['cloud_name']
    # response['cloud_type'] = form['cloud_type']
    # response['access_key'] = form['access_key']
    # response['instance_type'] = form['instance_type']
    # response['image_id'] = models.Image.objects.get(pk=form['image_id']).image_id
    # response['error'] = None
    # response['sg_names'] = ['CloudMan']
    # response['kp_name'] = 'cm_kp'
    # response['kp_material'] = ''
    # response['instance_id'] = 'i-l0cal'
    # response['instance_ip'] = '127.0.0.1'
    # response['institutional_email'] = form['institutional_email']
    # return response
    # End dev code

    err_msg = None
    kernel_id = None
    ramdisk_id = None
    # Handle extra_user_data
    extra_user_data = form["extra_user_data"]
    if extra_user_data:
        for key, value in yaml.load(extra_user_data).iteritems():
            form[key] = value
    del form["extra_user_data"]
    instance_type = form["instance_type"]
    # Create cloudman connection with provided creds
    cml = CloudManLauncher(form["access_key"], form["secret_key"], form["cloud"])
    form["freenxpass"] = form["password"]
    if form["image_id"]:
        if form["image_id"] == "0":
            image_id = form["custom_image_id"]
        else:
            image = models.Image.objects.get(pk=form["image_id"])
            image_id = image.image_id
            image.kernel_id if image.kernel_id != "" else None
            image.ramdisk_id if image.ramdisk_id != "" else None
    else:
        try:
            image = models.Image.objects.get(cloud=form["cloud"], default=True)
            image_id = image.image_id
            image.kernel_id if image.kernel_id != "" else None
            image.ramdisk_id if image.ramdisk_id != "" else None
        except models.Image.DoesNotExist:
            err_msg = "Cannot find an image to launch for cloud {0}".format(form["cloud"])
            log.error(err_msg)
            return False
    # Compose kwargs from form data making sure the named arguments are not included
    kwargs = copy.deepcopy(form)
    # key_name is the parameter name for the key pair in the launch method so
    # ensure it's there as a kwqrg if provided in the form
    if form.get("key_pair", None):
        kwargs["key_name"] = form["key_pair"]
    for key in form.iterkeys():
        if key in [
            "cluster_name",
            "image_id",
            "instance_type",
            "password",
            "placement",
            "access_key",
            "secret_key",
            "cloud",
            "key_pair",
        ]:
            del kwargs[key]
    if not err_msg:
        response = cml.launch(
            cluster_name=form["cluster_name"],
            image_id=image_id,
            instance_type=instance_type,
            password=form["password"],
            kernel_id=kernel_id,
            ramdisk_id=ramdisk_id,
            placement=form["placement"],
            **kwargs
        )
    # Keep these parts of the form as part of the response
    response["cluster_name"] = form["cluster_name"]
    response["password"] = form["password"]
    response["cloud_name"] = form["cloud_name"]
    response["cloud_type"] = form["cloud_type"]
    response["access_key"] = form["access_key"]
    response["instance_type"] = form["instance_type"]
    response["institutional_email"] = form["institutional_email"]
    response["image_id"] = image_id
    response["error"] = err_msg
    return response
예제 #11
0
def runinstance(request):
    """Run a CloudBioLinux/CloudMan instance with current session credentials.
    """
    form = request.session["ec2data"]

    # Handle extra_user_data
    extra_user_data = form['extra_user_data']
    if extra_user_data:
        for key, value in yaml.load(extra_user_data).iteritems():
            form[key] = value
    del form['extra_user_data']

    rs = None
    instance_type = form['instance_type']
    # Create cloudman connection with provided creds
    cml = CloudManLauncher(form["access_key"], form["secret_key"],
                           form['cloud'])
    form["freenxpass"] = form["password"]
    if form['image_id']:
        image = models.Image.objects.get(pk=form['image_id'])
    else:
        try:
            image = models.Image.objects.get(cloud=form['cloud'], default=True)
        except models.Image.DoesNotExist:
            log.error("Cannot find an image to launch for cloud {0}".format(
                form['cloud']))
            return False
    # Compose kwargs from form data making sure the named arguments are not included
    kwargs = copy.deepcopy(form)
    for key in form.iterkeys():
        if key in [
                'cluster_name', 'image_id', 'instance_type', 'password',
                'placement', 'access_key', 'secret_key', 'cloud'
        ]:
            del kwargs[key]
    response = cml.launch(
        cluster_name=form['cluster_name'],
        image_id=image.image_id,
        instance_type=instance_type,
        password=form["password"],
        kernel_id=image.kernel_id if image.kernel_id != '' else None,
        ramdisk_id=image.ramdisk_id if image.ramdisk_id != '' else None,
        placement=form['placement'],
        **kwargs)
    if response["error"]:
        return response
    elif response["rs"]:
        rs = response["rs"]
        request.session['ec2data']['instance_id'] = rs.instances[0].id
        request.session['ec2data']['public_ip'] = rs.instances[
            0].ip_address  # public_dns_name
        request.session['ec2data']['image_id'] = rs.instances[0].image_id
        request.session['ec2data']['kp_name'] = response['kp_name']
        request.session['ec2data']['kp_material'] = response['kp_material']
        request.session['ec2data']['sg_name'] = response['sg_names'][0]

        # Add an entry to the Usage table
        try:
            u = models.Usage(cloud_name=form["cloud_name"],
                             cloud_type=form["cloud_type"],
                             image_id=image.image_id,
                             instance_type=instance_type,
                             user_id=form["access_key"])
            u.save()
        except Exception, e:
            log.debug("Trouble saving Usage data: {0}".format(e))