本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider类的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider类的具体用法?Python CloudProvider怎么用?Python CloudProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CloudProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(cls,
category='general',
group=None,
name=None):
# name is anme of the rule
if category=='general':
if name is None and group is not None:
# delete the entire group
cls.cm.delete(kind="secgrouprule", group=group)
elif name is not None and group is not None:
# delete specific rule
cls.cm.delete(name=name, kind="secgrouprule", group=group)
elif name is None and group is None:
# delete all groups
cls.cm.delete(kind="secgrouprule")
if group == Default.secgroup or Default.secgroup is None:
cls.reset_defaults()
else:
provider = CloudProvider(category).provider
# delete on cloud
if group is not None:
provider.delete_secgroup(name)
# delete the entire group
elif group is None:
# delete all groups
pass
示例2: test_002
def test_002(self):
""" test flavor list :return: """
HEADING()
from pprint import pprint
cloud = "chameleon-ec2"
provider = CloudProvider(cloud).provider
# print (provider, type(provider))
# r = provider.list_flavor(cloud)
# pprint(r)
kind = 'flavor'
r = provider.list(kind, cloud)
pprint(r)
assert 't2.small' in str(r)
r = provider.list_flavor(cloud)
pprint(r)
assert 't2.small' in str(r)
r = provider.provider.list_sizes(cloud)
pprint(r)
assert 't2.small' in str(r)
示例3: delete_rule
def delete_rule(cls, cloud, secgroup, from_port, to_port, protocol, cidr):
try:
args = {
"groupid": secgroup.uuid,
"fromPort": from_port,
"toPort": to_port,
"protocol": protocol,
"cidr": cidr
}
rule = cls.cm_db.find("secgrouprule", output="object",
**args).first()
if rule is not None:
# get the nova client for cloud
cloud_provider = CloudProvider(cloud).provider
# delete the rule from the cloud
cloud_provider.delete_secgroup_rule(rule.uuid)
# delete the local db record
cls.cm_db.delete(rule)
return "Rule [{} | {} | {} | {}] deleted" \
.format(from_port, to_port, protocol, cidr)
else:
return None
except Exception as ex:
Console.error(ex.message, ex)
return
示例4: stop
def stop(cls, **kwargs):
arg = dotdict(kwargs)
cloud_provider = CloudProvider(arg.cloud).provider
for server in kwargs["servers"]:
cloud_provider.stop_vm(server)
Console.ok("Machine {:} is being stopped on {:} Cloud..."
.format(server, cloud_provider.cloud))
示例5: delete_rule
def delete_rule(cls, cloud, secgroup, from_port, to_port, protocol, cidr):
try:
args = {
"group": secgroup["uuid"],
"fromPort": from_port,
"toPort": to_port,
"protocol": protocol,
"cidr": cidr
}
rule = cls.cm.find(kind="secgrouprule",
output="object",
scope="first",
**args)
if rule is not None:
# get the nova client for cloud
cloud_provider = CloudProvider(cloud).provider
# delete the rule from the cloud
cloud_provider.delete_secgroup_rule(rule.uuid)
# delete the local db record
cls.cm.delete(rule)
return "Rule [{fromPort} | {toPort} | {protocol} | {cidr}] deleted" \
.format(**args)
else:
return None
except Exception as ex:
Console.error("delete rule")
return
示例6: boot
def boot(cls, **kwargs):
cloud_provider = CloudProvider(kwargs["cloud"]).provider
if kwargs["cloud"] == 'kilo':
# For kilo, we use a different network interface
net_id = None
# Get list of networks in kilo
network_list = cloud_provider.provider.networks.list()
# Validate each interface
for network in network_list:
# Check if interface name is fg478-net,
# Get the interface id
if network.label == "fg478-net":
net_id = network.id
nics = [{"net-id": net_id}]
# TODO: BUG: nics seems unexpected argument
vm_id = cloud_provider.boot_vm(kwargs["name"],
kwargs["image"],
kwargs["flavor"],
key=kwargs["key_name"],
secgroup=kwargs["secgroup_list"],
nics=nics)
else:
vm_id = cloud_provider.boot_vm(kwargs["name"], kwargs["image"], kwargs["flavor"], key=kwargs["key_name"],
secgroup=kwargs["secgroup_list"])
print("Machine {:} is being booted on {:} Cloud...".format(kwargs["name"], cloud_provider.cloud))
# Explicit refresh called after VM boot, to update db.
# cls.refresh(cloud=kwargs["cloud"])
return vm_id
示例7: get_floating_ip
def get_floating_ip(cls, cloudname, floating_ip_or_id):
"""
Method to get floating ip info
:param cloudname:
:param floating_ip_or_id:
:return: floating ip info
"""
try:
cloud_provider = CloudProvider(cloudname).provider
result = None
# check if argument is ip or uuid
if cls.isIPAddr(ip_or_id=floating_ip_or_id):
# get floating ip list
floating_ips = cls.get_floating_ip_list(cloudname)
for floating_ip in floating_ips.values():
ip_addr = floating_ip["ip"]
# if argument ip matches floating ip addr
if ip_addr == floating_ip_or_id:
result = floating_ip
break
else:
# find by floating ip uuid
result = cloud_provider.get_floating_ip(floating_ip_id=floating_ip_or_id)
# Could not find floating IP from given args
if result is None:
return None
instance_id = result["instance_id"]
instance_name = None
if instance_id is not None:
# lookup instance_name from id
instance_name = cls.find_instance_name(cloudname=cloudname, instance_id=instance_id)
# add instance_name to dict
result["instance_name"] = instance_name
# add misc details to response
result["cloud"] = cloudname
result["user"] = cloud_provider.cloud_details["credentials"]["OS_USERNAME"]
result["project"] = cloud_provider.cloud_details["credentials"]["OS_TENANT_NAME"]
return attribute_printer(result, header=["name", "value"])
except Exception as ex:
# auto detect floating-ip-id
floating_ips = cls.get_floating_ip_list(cloudname)
# for each floating-ip from list
for floating_ip in floating_ips.values():
if floating_ip["id"].startswith(floating_ip_or_id) or floating_ip["ip"].startswith(floating_ip_or_id):
# confirm choice with user
print("Did you mean floating-ip [{}] ? (y/n)".format(floating_ip["ip"]))
choice = raw_input().lower()
# if yes, return dict
if choice == "y":
return attribute_printer(floating_ip, header=["name", "value"])
# Console.error(ex.message)
return
示例8: delete_all_rules_cloud
def delete_all_rules_cloud(cls, cloud, groupname):
rules = cls.list_rules_cloud(cloud, groupname)
provider = CloudProvider(cloud).provider
if rules:
for rule in rules:
ruleid = rule['id']
provider.delete_secgroup_rule(ruleid)
return
示例9: delete_secgroup
def delete_secgroup(cls, name=None, cloud=None):
try:
# Find the secgroup from the cloud
cloud_provider = CloudProvider(cloud).provider
result = cloud_provider.delete_secgroup(name)
return result
except Exception as ex:
Console.error("delete group")
示例10: delete_secgroup
def delete_secgroup(cls, label, cloud):
try:
# Find the secgroup from the cloud
cloud_provider = CloudProvider(cloud).provider
result = cloud_provider.delete_secgroup(label)
return result
except Exception as ex:
Console.error(ex.message, ex)
示例11: list_rules_cloud
def list_rules_cloud(cls, cloud, groupname):
provider = CloudProvider(cloud).provider
groups = provider.list_secgroup(cloud)
for id in groups:
group = groups[id]
if groupname == group["name"]:
return group["rules"]
return None
示例12: delete
def delete(cls, **kwargs):
cloud_provider = CloudProvider(kwargs["cloud"]).provider
for server in kwargs["servers"]:
cloud_provider.delete_vm(server)
print("Machine {:} is being deleted on {:} Cloud...".format(server, cloud_provider.cloud))
# Explicit refresh called after VM delete, to update db.
cls.refresh(cloud=kwargs["cloud"])
示例13: rename
def rename(cls, **kwargs):
cloud_provider = CloudProvider(kwargs["cloud"]).provider
new_name = kwargs["new_name"]
for server in kwargs["servers"]:
cloud_provider.rename_vm(server, new_name)
print("Machine {:} renamed to {:} on {:} Cloud...".format(server, new_name, cloud_provider.cloud))
# Explicit refresh called after VM delete, to update db.
cls.refresh(cloud=kwargs["cloud"])
示例14: get_group_cloud
def get_group_cloud(cls, cloud, groupname):
provider = CloudProvider(cloud).provider
groups = provider.list_secgroup(cloud)
ret = None
for groupkey in groups:
group = groups[groupkey]
if group["name"] == groupname:
ret = group
break
return ret
示例15: delete_rule_cloud
def delete_rule_cloud(cls, cloud, groupname, rulename):
ret = None
provider = CloudProvider(cloud).provider
ruleid = cls.get_rule_cloud(cloud, groupname, rulename)
if ruleid:
ret = provider.delete_secgroup_rule(ruleid)
#else:
# Console.error("Rule does not exist - Rule:{}, Group:{}"\
# .format(rulename, groupname), traceflag=False)
return ret