本文整理汇总了Python中cloudmesh_base.Shell.Shell类的典型用法代码示例。如果您正苦于以下问题:Python Shell类的具体用法?Python Shell怎么用?Python Shell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, name, command):
"""executes the command on the named host"""
if name in ["localhost"]:
r = '\n'.join(Shell.sh("-c", command).split()[-1:])
else:
r = '\n'.join(Shell.ssh(name, command).split()[-1:])
return r
示例2: qsub
def qsub(self, name, host, script, template=None, kind="dict"):
"""
Executes the qsub command on a given host.
NOTE this method may not yet be fully implemented
:param name: name of the script
:param host: host on which the script is to be run
:param script: The name of the script
:param template: The script is wrapped into a template
:param kind: The return is passed as dict, yaml, xml
:return:
"""
self.jobid_incr()
jobscript = self.create_script(name, script, template)
# copy the script to the remote host
self._write_to_file(jobscript, name)
# copy script to remote host
remote_path = self.data.get("cloudmesh", "pbs", host, "scripts")
print(remote_path)
xmkdir(host, remote_path)
manager_host = self.manager(host)
# call qsub on the remot host
r = Shell.scp(name, manager_host + ":" + remote_path)
jobid = Shell.ssh(manager_host, "qsub {0}/{1}".format(remote_path, name)).rstrip()
return self.jobstatus(host, jobid, kind=kind)
示例3: open
def open(self, filename=None):
if filename is not None:
self.filename = filename
else:
self.filename = path_expand(self.pbs.database_filename())
path = os.path.dirname(self.filename)
Shell.mkdir(path)
self.load()
示例4: create_cloudmesh_yaml
def create_cloudmesh_yaml(filename):
if not os.path.exists(filename):
path = os.path.dirname(filename)
if not os.path.isdir(path):
Shell.mkdir(path)
etc_path = os.path.dirname(cloudmesh_client.__file__)
etc_file = os.path.join(etc_path, "etc", "cloudmesh.yaml")
to_dir = path_expand("~/.cloudmesh")
shutil.copy(etc_file, to_dir)
Console.ok("~/.cloudmesh/cloudmesh.yaml created")
示例5: create_config
def create_config(cls, username):
dir_path = path_expand("~/.cloudmesh/{0}".format("accounts"))
if not os.path.exists(dir_path):
Shell.mkdir(dir_path)
filename = path_expand("~/.cloudmesh/{0}/{1}".format("accounts", ".config"))
data = dict(user=username)
with open(filename, 'w') as outfile:
outfile.write(yaml.dump(data, default_flow_style=True))
示例6: delete
def delete(cls, cluster, job, group=None):
"""
This method is used to terminate a job with the specified or a group of jobs
job_id or job_name in a given cluster
:param group:
:param cluster: the cluster like comet
:param job: the job id or name
:return: success message or error
"""
try:
if group is not None:
# get the job ids from the db
cm = CloudmeshDatabase()
arguments = {'cluster': cluster,
'group': group}
db_jobs = cm.find('batchjob',
**arguments)
list1 = []
for i in db_jobs:
list1.append(db_jobs[i]['job_id'])
# read active jobs
active_jobs = json.loads(cls.queue(cluster))
list2 = []
for i in active_jobs:
list2.append(active_jobs[i]['jobid'])
# find intersection
res = set(list1).intersection(set(list2))
if res is not None:
for j in res:
cmd = 'scancel {}'.format(str(j))
Shell.ssh(cluster, cmd)
print("Deleted {}".format(j))
return "All jobs for group {} killed successfully".format(group)
else:
args = 'scancel '
if job.isdigit():
args += job
else:
args += "-n {}".format(job)
Shell.ssh(cluster, args)
return "Job {} killed successfully".format(job)
except Exception as ex:
print("in exceptio")
print(ex)
return ex
示例7: run
def run(self):
banner("Setup the cmd3.yaml file")
cmd3_yaml = path_expand("~/.cloudmesh/cmd3.yaml")
if os.path.isfile(cmd3_yaml):
print ("ERROR: the file {0} already exists".format(cmd3_yaml))
print
print ("If you like to reinstall it, please remove the file")
else:
print ("Copy file: {0} -> {1} ".format(path_expand("etc/cmd3.yaml"), cmd3_yaml))
Shell.mkdir("~/.cloudmesh")
shutil.copy("etc/cmd3.yaml", path_expand("~/.cloudmesh/cmd3.yaml"))
示例8: stat
def stat(self, email):
"""
returns a statistic of a git author with the given e_mail.
:param email: name of the author
:rtype: a dict with the statistics
"""
result = Shell.git("log", "--all", "--stat", '--author={0}'.format(email)).split("\n")
sums = [0, 0, 0]
for line in result:
if " files changed" in line:
line = line.strip()
line = line.replace(" insertions(+)", "")
line = line.replace(" insertion(+)", "")
line = line.replace(" deletion(-)", "")
line = line.replace(" deletions(-)", "")
line = line.replace(" files changed", "")
line = line.split(",")
data = [int(i) for i in line]
for index in range(0, len(data)):
sums[index] += data[index]
return {"email": email,
"fileschanged": sums[0],
"inserted": sums[1],
"deleted": sums[2],
"lineschanged": sums[1] + sums[2]}
示例9: get_authors_by_date
def get_authors_by_date(header=False):
"""lists the authors of a git repository sorted by date.
Example:
0001 (2015-02-25): Gregor von Laszewski ([email protected])
0002 (2015-04-14): Fugang Wang ([email protected])
:rtype: str
"""
# modified from https://github.com/jgehrcke/git-authors
result = ""
# if header:
# result = result + "Authors\n"
# result = result + "=======\n\n"
r = Shell.git("log",
"--encoding=utf-8",
"--full-history",
"--reverse",
"--format=format:%at;%an;%ae").split("\n")
seen = set()
for line in r:
timestamp, name, email = line.strip().split(";")
if name not in seen:
seen.add(name)
day = time.strftime("%Y-%m-%d", time.gmtime(float(timestamp)))
result = result + "* {:04d} ({:}): {:} ({:})\n".format(len(seen), day, name, email)
return result
示例10: start
def start(self):
"""
Starts the cloudmesh_job process in the background.
"""
for key in ['dbpath', 'logpath']:
path = os.dirname(self.config[key])
Shell.mkdir(path)
r = Shell.sh("mongod", "--fork",
"--logpath", self.config['logpath'],
"--prot", self.config['port'],
'--dbpath', self.config['dbpath'])
print (r)
# TODO
# get the id from r
self.config['id'] = None # put here the real id
示例11: start
def start(self):
try:
mongod = Shell.which("mongod")
command = [
mongod,
"--dbpath", str(self.db_path),
"--port", str(self.port),
"--fork",
"--logpath", str(self.log_file),
"--bind_ip", "127.0.0.1"
]
print(" ".join(command))
#a = subprocess.call(command)
os.system(" ".join(command))
os.system ("ps aux | fgrep mongod |fgrep -v fgrep")
Console.ok("MongoDB has been deployed")
self.info()
except Exception, e:
Console.error("we had a problem starting the mongo daemon")
print(e)
Console.error("MongoDB has stopped")
# TODO remove the exit in final code, for debugging only
sys.exit()
示例12: _grep
def _grep(self, search, platform):
if not search:
search = "'OS_PASSWORD': '[a-zA-Z0-9]+'"
cmd = "egrep -ri \"{0}\" * | cut -d\":\" -f1 > a.tmp".format(search)
print("[{0}]:{1}".format(platform, cmd))
os.system(cmd)
res = Shell.cat("a.tmp")
if res:
print ('[{0}]: [ERROR] PASSWORD(OR SECRET KEY) DETECTED, SEE FILES '
'BELOW'.format(platform))
print ("")
print (res)
else:
print ("[{0}]: NO PASSWORD DETECTED".format(platform))
Shell.rm("a.tmp")
print ("")
示例13: list_quotas
def list_quotas(cls, cloud, format):
Quota.set_os_environment(cloud)
result = Shell.execute("nova", "quota-show")
d = Quota.convert_to_dict(result)
return dict_printer(d, order=['Quota',
'Limit'],
output=format)
示例14: list
def list(cls, cloud, start=None, end=None, tenant=None, format="table"):
# set the environment variables
set_os_environ(cloud)
try:
# execute the command
args = ["usage"]
if start is not None:
args.extend(["--start", start])
if end is not None:
args.extend(["--end", end])
if tenant is not None:
args.extend(["--tenant", tenant])
result = Shell.execute("nova", args)
result = Nova.remove_subjectAltName_warning(result)
lines = result.splitlines()
dates = lines[0]
# TODO: as stated below, nova returns additional lines,
# on my pc, SecurityWarning is returned, so filtering..
for l in lines[1:]:
if l.__contains__("SecurityWarning"):
lines.remove(l)
table = '\n'.join(lines[1:])
dates = dates.replace("Usage from ", "").replace("to", "").replace(" +", " ")[:-1].split()
#
# TODO: for some reason the nova command has returned not the
# first + char, so we could not ignore the line we may set - as
# additional comment char, but that did not work
#
d = TableParser.convert(table, comment_chars="+#")
# d["0"]["start"] = "start"
# d["0"]["end"] = "end"
d["0"]["start"] = dates[0]
d["0"]["end"] = dates[1]
# del d['0']
return dict_printer(d,
order=["start",
"end",
"servers",
"cpu hours",
"ram mb-hours",
"disk gb-hours"],
output=format)
except Exception, e:
return e
示例15: run
def run(self):
banner("Setup the cloudmesh management yaml files ")
yamlfiles = ['cloudmesh_user.yaml', 'cloudmesh_project.yaml']
dir_path = path_expand("~/.cloudmesh/{0}".format("accounts"))
if not os.path.exists(dir_path):
Shell.mkdir(dir_path)
for yamlfile in yamlfiles:
filename = path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yamlfile))
if os.path.isfile(filename):
Console.error("File {0} already exists. If you like to reinstall it, please remove the file".format(yamlfile))
else:
Console.info("Copying file: {0} -> {1} ".format(path_expand("etc/{0}/{1}".format("accounts", yamlfile)), filename))
shutil.copy("etc/{0}/{1}".format("accounts", yamlfile), path_expand("~/.cloudmesh/{0}/{1}".format("accounts", yamlfile)))