本文整理汇总了Python中bioblend.cloudman.launch.CloudManLauncher类的典型用法代码示例。如果您正苦于以下问题:Python CloudManLauncher类的具体用法?Python CloudManLauncher怎么用?Python CloudManLauncher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CloudManLauncher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_placement_inner
def _get_placement_inner(request):
"""
Perform the actual work of figuring out the possible cluster placement.
.. seealso::
See :ref:`get_placements`.
"""
if request.is_ajax():
if request.method == 'POST':
cluster_name = request.POST.get('cluster_name', '')
cloud_id = request.POST.get('cloud_id', '')
a_key = request.POST.get('a_key', '')
s_key = request.POST.get('s_key', '')
inst_type = request.POST.get('instance_type', '')
placements = []
if cloud_id != '' and a_key != '' and s_key != '':
# Needed to get the cloud connection
cloud = models.Cloud.objects.get(pk=cloud_id)
cml = CloudManLauncher(a_key, s_key, cloud)
placements = cml.find_placements(cml.ec2_conn, inst_type,
cloud.cloud_type, cluster_name)
return {'placements': placements}
else:
log.error("Not a POST request")
else:
log.error("No XHR")
return {"error": "Please specify access and secret keys", "placements": []}
示例2: launch_instance
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
示例3: runinstance
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))
示例4: run_instance
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: fetch_clusters
def fetch_clusters(cloud, a_key, s_key):
"""
Given a cloud object and appropriate credentials, retrieve a list of
clusters associated with the given account. Return a dict of clusters'
persistent data.
"""
cml = CloudManLauncher(a_key, s_key, cloud)
return cml.get_clusters_pd()
示例6: userdata
def userdata(request):
"""Provide file download of user-data to re-start an instance.
"""
ec2data = request.session["ec2data"]
response = HttpResponse(mimetype="text/plain")
response["Content-Disposition"] = "attachment; filename={cluster_name}-userdata.txt".format(**ec2data)
form = request.session["ec2data"]
cml = CloudManLauncher(form["access_key"], form["secret_key"], form["cloud"])
ud = cml._compose_user_data(ec2data)
response.write(ud)
return response
示例7: userdata
def userdata(request):
"""
Provide file download of user-data to enable re-start an instance from
cloud's console or the API.
"""
ec2data = request.session["ec2data"]
response = HttpResponse(mimetype='text/plain')
response['Content-Disposition'] = 'attachment; filename={cluster_name}-userdata.txt'.format(
**ec2data)
form = request.session["ec2data"]
cml = CloudManLauncher(form["access_key"], form["secret_key"], form['cloud'])
ud = cml._compose_user_data(ec2data)
response.write(ud)
return response
示例8: instance_state
def instance_state(cloud, a_key, s_key, instance_id):
"""
Check on the state of an instance until and return the state.
"""
if not instance_id:
state = {
"instance_state": "",
"public_ip": "",
"placement": "",
"error": "Missing instance ID, cannot check the state.",
}
return state
cml = CloudManLauncher(a_key, s_key, cloud)
return cml.get_status(instance_id)
示例9: get_cluster_pd
def get_cluster_pd(a_key, s_key):
cloud = Bunch(id='-1',
name="NeCTAR",
cloud_type='openstack',
bucket_default='cloudman-os',
region_name='NeCTAR',
region_endpoint='nova.rc.nectar.org.au',
ec2_port=8773,
ec2_conn_path='/services/Cloud',
cidr_range='115.146.92.0/22',
is_secure=True,
s3_host='swift.rc.nectar.org.au',
s3_port=8888,
s3_conn_path='/')
cml = CloudManLauncher(a_key, s_key, cloud)
return cml.get_clusters_pd()
示例10: _get_placement_inner
def _get_placement_inner(request):
if request.is_ajax():
if request.method == 'POST':
cloud_id = request.POST.get('cloud_id', '')
a_key = request.POST.get('a_key', '')
s_key = request.POST.get('s_key', '')
inst_type = request.POST.get('instance_type', '')
placements = []
if cloud_id != '' and a_key != '' and s_key != '':
# Needed to get the cloud connection
cloud = models.Cloud.objects.get(pk=cloud_id)
cml = CloudManLauncher(a_key, s_key, cloud)
placements = cml._find_placements(cml.ec2_conn, inst_type, cloud.cloud_type)
return {'placements': placements}
else:
log.error("Not a POST request")
else:
log.error("No XHR")
return {"error": "Please specify access and secret keys", "placements": []}
示例11: _get_placement_inner
def _get_placement_inner(request):
if request.is_ajax():
if request.method == "POST":
cluster_name = request.POST.get("cluster_name", "")
cloud_id = request.POST.get("cloud_id", "")
a_key = request.POST.get("a_key", "")
s_key = request.POST.get("s_key", "")
inst_type = request.POST.get("instance_type", "")
placements = []
if cloud_id != "" and a_key != "" and s_key != "":
# Needed to get the cloud connection
cloud = models.Cloud.objects.get(pk=cloud_id)
cml = CloudManLauncher(a_key, s_key, cloud)
placements = cml.find_placements(cml.ec2_conn, inst_type, cloud.cloud_type, cluster_name)
return {"placements": placements}
else:
log.error("Not a POST request")
else:
log.error("No XHR")
return {"error": "Please specify access and secret keys", "placements": []}
示例12: instance_state
def instance_state(cloud, a_key, s_key, instance_id):
"""
Check on the state of an instance until and return the state.
"""
# Dev code
# if instance_id == 'i-l0cal':
# state = {'instance_state': "ready",
# 'public_ip': "127.0.0.1:42284",
# 'placement': "desktop",
# 'error': ""}
# return state
# End dev code
if not instance_id:
state = {'instance_state': "",
'public_ip': "",
'placement': "",
'error': "Missing instance ID, cannot check the state."}
return state
cml = CloudManLauncher(a_key, s_key, cloud)
return cml.get_status(instance_id)
示例13: run_instance
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
示例14: Bunch
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='test',
placement='nova')
print response
示例15: instancestate
def instancestate(request):
form = request.session["ec2data"]
cml = CloudManLauncher(form["access_key"], form["secret_key"], form['cloud'])
state = cml.get_status(form["instance_id"])
return HttpResponse(simplejson.dumps(state), mimetype="application/json")