本文整理汇总了Python中cloudmesh_client.common.Shell.Shell.unzip方法的典型用法代码示例。如果您正苦于以下问题:Python Shell.unzip方法的具体用法?Python Shell.unzip怎么用?Python Shell.unzip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.common.Shell.Shell
的用法示例。
在下文中一共展示了Shell.unzip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ec2
# 需要导入模块: from cloudmesh_client.common.Shell import Shell [as 别名]
# 或者: from cloudmesh_client.common.Shell.Shell import unzip [as 别名]
def ec2(cls, cloud, zipfile):
def sanitize(name):
return name.replace(".zip", "").replace("@", "_")
def find_exports(filename):
with open(filename, "r") as f:
content = f.read()
data = {}
for line in content.split("\n"):
if line.startswith("export "):
line = line.replace("export ", "")
attribute, value = line.split("=", 1)
value = value.replace("${NOVA_KEY_DIR}/", "")
# remove comments
data[attribute] = value.split("#")[0].strip()
return data
base = sanitize(os.path.basename(zipfile))
dest = sanitize(os.path.join(
path_expand("~"),
".cloudmesh",
"clouds",
cloud,
os.path.basename(zipfile)))
Console.msg("Unzip file {} -> {}".format(zipfile, dest))
r = Shell.unzip(zipfile, dest)
rcfile = os.path.join(dest, "ec2rc.sh")
data = find_exports(rcfile)
data["DEST"] = dest
data["CLOUD"] = cloud
d = {
"cm_heading": "{CLOUD}, EC2".format(**data),
"cm_host": None,
"cm_label": "{CLOUD}_ec2".format(**data),
"cm_type": "ec2",
"cm_type_version": "ec2",
"credentials": {
"EC2_ACCESS_KEY": "{EC2_ACCESS_KEY}".format(**data),
"EC2_SECRET_KEY": "{EC2_SECRET_KEY}".format(**data),
"keyname": "TBD_not_used",
"userid": "TBD_not_used",
"EC2_URL": "{EC2_URL}".format(**data),
"EC2_USER_ID": "{EC2_USER_ID}",
"EC2_PRIVATE_KEY": "{DEST}/pk.pem".format(**data),
"EC2_CERT": "{DEST}/cert.pem".format(**data),
"NOVA_CERT": "{DEST}/cacert.pem".format(**data),
"EUCALYPTUS_CERT": "{DEST}/cacert.pem".format(**data),
},
"default": {
"flavor": "m1.small",
"image": "None",
}
}
config = ConfigDict("cloudmesh.yaml")
config["cloudmesh"]["clouds"][cloud] = d
config.save()