本文整理汇总了Python中utils.subprocess_call函数的典型用法代码示例。如果您正苦于以下问题:Python subprocess_call函数的具体用法?Python subprocess_call怎么用?Python subprocess_call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了subprocess_call函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_dhcp
def sync_dhcp(self):
restart_dhcp = str(self.settings.restart_dhcp).lower()
which_dhcp_module = module_loader.get_module_name("dhcp", "module").strip()
if self.settings.manage_dhcp:
self.write_dhcp()
if which_dhcp_module == "manage_isc":
service_name = utils.dhcp_service_name(self.api)
if restart_dhcp != "0":
rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
if rc != 0:
self.logger.error("dhcpd -t failed")
return False
service_restart = "service %s restart" % service_name
rc = utils.subprocess_call(self.logger, service_restart, shell=True)
if rc != 0:
self.logger.error("%s failed" % service_name)
return False
elif which_dhcp_module == "manage_dnsmasq":
if restart_dhcp != "0":
rc = utils.subprocess_call(self.logger, "service dnsmasq restart")
if rc != 0:
self.logger.error("service dnsmasq restart failed")
return False
return True
示例2: check_service
def check_service(self, status, which, notes=""):
if notes != "":
notes = " (NOTE: %s)" % notes
rc = 0
if self.checked_dist == "redhat" or self.checked_dist == "suse":
if os.path.exists("/etc/rc.d/init.d/%s" % which):
rc = utils.subprocess_call(self.logger,"/sbin/service %s status > /dev/null 2>/dev/null" % which, shell=True)
if rc != 0:
status.append(_("service %s is not running%s") % (which,notes))
return False
elif self.checked_dist in ["debian", "ubuntu"]:
# we still use /etc/init.d
if os.path.exists("/etc/init.d/%s" % which):
rc = utils.subprocess_call(self.logger,"/etc/init.d/%s status /dev/null 2>/dev/null" % which, shell=True)
if rc != 0:
status.append(_("service %s is not running%s") % which,notes)
return False
elif self.checked_dist == "ubuntu":
if os.path.exists("/etc/init/%s.conf" % which):
rc = utils.subprocess_call(self.logger,"status %s > /dev/null 2>&1" % which, shell=True)
if rc != 0:
status.append(_("service %s is not running%s") % (which,notes))
else:
status.append(_("Unknown distribution type, cannot check for running service %s" % which))
return False
return True
示例3: check_for_wget_curl
def check_for_wget_curl(self,status):
"""
Check to make sure wget or curl is installed
"""
rc1 = utils.subprocess_call(self.logger,"which wget")
rc2 = utils.subprocess_call(self.logger,"which curl")
if rc1 != 0 and rc2 != 0:
status.append("Neither wget nor curl are installed and/or available in $PATH. Cobbler requires that one of these utilities be installed.")
示例4: update_permissions
def update_permissions(self, repo_path):
"""
Verifies that permissions and contexts after an rsync are as expected.
Sending proper rsync flags should prevent the need for this, though this is largely
a safeguard.
"""
# all_path = os.path.join(repo_path, "*")
cmd1 = "chown -R root:apache %s" % repo_path
utils.subprocess_call(self.logger, cmd1)
cmd2 = "chmod -R 755 %s" % repo_path
utils.subprocess_call(self.logger, cmd2)
示例5: after_download
def after_download(self, profile_data):
if not os.path.exists("/sbin/grubby"):
raise InfoException, "grubby is not installed"
k_args = self.calc_kernel_args(profile_data,replace_self=True)
kickstart = self.safe_load(profile_data,'kickstart')
self.build_initrd(
self.safe_load(profile_data,'initrd_local'),
kickstart,
profile_data
)
if len(k_args) > 255:
raise InfoException, "Kernel options are too long, 255 chars exceeded: %s" % k_args
cmd = [ "/sbin/grubby",
"--add-kernel", self.safe_load(profile_data,'kernel_local'),
"--initrd", self.safe_load(profile_data,'initrd_local'),
"--args", k_args,
"--copy-default"
]
if self.add_reinstall_entry:
cmd.append("--title=Reinstall")
else:
cmd.append("--make-default")
cmd.append("--title=kick%s" % int(time.time()))
if self.live_cd:
cmd.append("--bad-image-okay")
cmd.append("--boot-filesystem=/dev/sda1")
cmd.append("--config-file=/tmp/boot/boot/grub/grub.conf")
# utils.subprocess_call(["/sbin/grubby","--remove-kernel","/boot/vmlinuz"])
utils.subprocess_call(cmd)
# if grubby --bootloader-probe returns lilo,
# apply lilo changes
cmd = [ "/sbin/grubby", "--bootloader-probe" ]
probe_process = sub_process.Popen(cmd, stdout=sub_process.PIPE)
which_loader = probe_process.communicate()[0]
if probe_process.returncode == 0 and \
which_loader.find("lilo") != -1:
print "- applying lilo changes"
cmd = [ "/sbin/lilo" ]
sub_process.Popen(cmd, stdout=sub_process.PIPE).communicate()[0]
if not self.add_reinstall_entry:
print "- reboot to apply changes"
else:
print "- reinstallation entry added"
示例6: sync_dhcp
def sync_dhcp(self):
restart_dhcp = str(self.settings.restart_dhcp).lower()
service_name = utils.dhcp_service_name(self.api)
if restart_dhcp != "0":
rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
if rc != 0:
error_msg = "dhcpd -t failed"
self.logger.error(error_msg)
raise CX(error_msg)
service_restart = "service %s restart" % service_name
rc = utils.subprocess_call(self.logger, service_restart, shell=True)
if rc != 0:
error_msg = "%s failed" % service_name
self.logger.error(error_msg)
raise CX(error_msg)
示例7: run
def run(api, args, logger):
objtype = args[0] # "system" or "profile"
name = args[1] # name of system or profile
ip = args[2] # ip or "?"
if objtype != "system":
return 0
settings = api.settings()
if not str(settings.puppet_auto_setup).lower() in [ "1", "yes", "y", "true"]:
return 0
if not str(settings.sign_puppet_certs_automatically).lower() in [ "1", "yes", "y", "true"]:
return 0
system = api.find_system(name)
system = utils.blender(api, False, system)
hostname = system[ "hostname" ]
puppetca_path = settings.puppetca_path
cmd = [puppetca_path, '--sign', hostname]
rc = 0
try:
rc = utils.subprocess_call(logger, cmd, shell=False)
except:
if logger is not None:
logger.warning("failed to execute %s", puppetca_path)
if rc != 0:
if logger is not None:
logger.warning("signing of puppet cert for %s failed", name)
return 0
示例8: run
def run(api,args,logger):
# FIXME: make everything use the logger, no prints, use util.subprocess_call, etc
objtype = args[0] # "system" or "profile"
name = args[1] # name of system or profile
ip = args[2] # ip or "?"
if objtype == "system":
target = api.find_system(name)
else:
target = api.find_profile(name)
# collapse the object down to a rendered datastructure
target = utils.blender(api, False, target)
if target == {}:
logger.info("unable to locate %s " % name)
raise CX("failure looking up target")
if target['ks_meta']['vms']:
for vm in target['ks_meta']['vms'].split(','):
try:
arglist = ["/usr/local/bin/createvm",target['ip_address_vmnic1'],vm,target['server']]
logger.info("creating virtual guest %s" % vm)
rc = utils.subprocess_call(logger, arglist, shell=False)
except Exception, reason:
logger.error("unable to create %s: %s" % (name,reason))
if rc != 0:
raise CX("cobbler trigger failed: %(file)s returns ")
示例9: rsync_sync
def rsync_sync(self, repo):
"""
Handle copying of rsync:// and rsync-over-ssh repos.
"""
repo_mirror = repo.mirror
if not repo.mirror_locally:
utils.die(self.logger,"rsync:// urls must be mirrored locally, yum cannot access them directly")
if repo.rpm_list != "" and repo.rpm_list != []:
self.logger.warning("--rpm-list is not supported for rsync'd repositories")
# FIXME: don't hardcode
dest_path = os.path.join(self.settings.webdir+"/repo_mirror", repo.name)
spacer = ""
if not repo.mirror.startswith("rsync://") and not repo.mirror.startswith("/"):
spacer = "-e ssh"
if not repo.mirror.endswith("/"):
repo.mirror = "%s/" % repo.mirror
# FIXME: wrapper for subprocess that logs to logger
cmd = "rsync -rltDv --copy-unsafe-links --delete-after %s --delete --exclude-from=/etc/cobbler/rsync.exclude %s %s" % (spacer, repo.mirror, dest_path)
rc = utils.subprocess_call(self.logger, cmd)
if rc !=0:
utils.die(self.logger,"cobbler reposync failed")
os.path.walk(dest_path, self.createrepo_walker, repo)
self.create_local_file(dest_path, repo)
示例10: power
def power(self, desired_state):
"""
state is either "on" or "off". Rebooting is implemented at the api.py
level.
The user and password need not be supplied. If not supplied they
will be taken from the environment, COBBLER_POWER_USER and COBBLER_POWER_PASS.
If provided, these will override any other data and be used instead. Users
interested in maximum security should take that route.
"""
template = self.get_command_template()
template_file = open(template, "r")
meta = utils.blender(self.api, False, self.system)
meta["power_mode"] = desired_state
# allow command line overrides of the username/password
if self.force_user is not None:
meta["power_user"] = self.force_user
if self.force_pass is not None:
meta["power_pass"] = self.force_pass
tmp = templar.Templar(self.api._config)
cmd = tmp.render(template_file, meta, None, self.system)
template_file.close()
cmd = cmd.strip()
self.logger.info("cobbler power configuration is:")
self.logger.info(" type : %s" % self.system.power_type)
self.logger.info(" address: %s" % self.system.power_address)
self.logger.info(" user : %s" % self.system.power_user)
self.logger.info(" id : %s" % self.system.power_id)
# if no username/password data, check the environment
if meta.get("power_user","") == "":
meta["power_user"] = os.environ.get("COBBLER_POWER_USER","")
if meta.get("power_pass","") == "":
meta["power_pass"] = os.environ.get("COBBLER_POWER_PASS","")
# now reprocess the command so we don't feed it through the shell
cmd = cmd.split(" ")
# Try the power command 5 times before giving up.
# Some power switches are flakey
for x in range(0,5):
rc = utils.subprocess_call(self.logger, cmd, shell=False)
if rc == 0:
break
else:
time.sleep(2)
if not rc == 0:
utils.die(self.logger,"command failed (rc=%s), please validate the physical setup and cobbler config" % rc)
return rc
示例11: check_iptables
def check_iptables(self, status):
if os.path.exists("/etc/rc.d/init.d/iptables"):
rc = utils.subprocess_call(self.logger, "/sbin/service iptables status >/dev/null 2>/dev/null", shell=True)
if rc == 0:
status.append(
_("since iptables may be running, ensure 69, 80, and %(xmlrpc)s are unblocked")
% {"xmlrpc": self.settings.xmlrpc_port}
)
示例12: sync_dhcp
def sync_dhcp(self):
restart_dhcp = str(self.settings.restart_dhcp).lower()
if restart_dhcp != "0":
rc = utils.subprocess_call(self.logger, "service dnsmasq restart")
if rc != 0:
error_msg = "service dnsmasq restart failed"
self.logger.error(error_msg)
raise CX(error_msg)
示例13: run
def run(self):
"""
Simply hardlinks directories that are cobbler managed.
This is a /very/ simple command but may grow more complex
and intelligent over time.
"""
# FIXME: if these directories become configurable some
# changes will be required here.
if not os.path.exists("/usr/sbin/hardlink"):
utils.die(self.logger,"please install 'hardlink' (/usr/sbin/hardlink) to use this feature")
self.logger.info("now hardlinking to save space, this may take some time.")
utils.subprocess_call(self.logger,"/usr/sbin/hardlink -c -v /var/www/cobbler/ks_mirror /var/www/cobbler/repo_mirror",shell=True)
return rc
示例14: build_initrd
def build_initrd(self,initrd,kickstart,data):
"""
Crack open an initrd and install the kickstart file.
"""
# save kickstart to file
ksdata = utils.urlread(kickstart)
fd = open("/var/spool/koan/ks.cfg","w+")
if ksdata is not None:
fd.write(ksdata)
fd.close()
# handle insertion of kickstart based on type of initrd
fd = open("/var/spool/koan/insert.sh","w+")
fd.write(self.get_insert_script(initrd))
fd.close()
utils.subprocess_call([ "/bin/bash", "/var/spool/koan/insert.sh" ])
shutil.copyfile("/var/spool/koan/initrd_final", initrd)
示例15: rsync_it
def rsync_it(self, from_path, to_path, type=None):
from_path = "%s::%s" % (self.master, from_path)
if type == 'repo':
cmd = "rsync %s %s %s" % (self.settings.replicate_repo_rsync_options, from_path, to_path)
else:
cmd = "rsync %s %s %s" % (self.settings.replicate_rsync_options, from_path, to_path)
rc = utils.subprocess_call(self.logger, cmd, shell=True)
if rc != 0:
self.logger.info("rsync failed")