当前位置: 首页>>代码示例>>Python>>正文


Python GLIUtility.spawn_bash方法代码示例

本文整理汇总了Python中GLIUtility.spawn_bash方法的典型用法代码示例。如果您正苦于以下问题:Python GLIUtility.spawn_bash方法的具体用法?Python GLIUtility.spawn_bash怎么用?Python GLIUtility.spawn_bash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GLIUtility的用法示例。


在下文中一共展示了GLIUtility.spawn_bash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: configure_networking

# 需要导入模块: import GLIUtility [as 别名]
# 或者: from GLIUtility import spawn_bash [as 别名]
	def configure_networking(self):
		if self._configuration.get_verbose(): self._logger.log("DEBUG: beginning of configure_networking()")
		# Do networking setup right here.
		if self._configuration.get_network_type() != None:
			type = self._configuration.get_network_type()
			if type == "null" or type == "none":
				# don't do anything, it's not our problem if the user specifies this.
				return
			elif type == "dhcp":
				if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): DHCP selected")
				# Run dhcpcd.
				try:
					interface = self._configuration.get_network_interface()
					dhcp_options = self._configuration.get_network_dhcp_options()
				except:
					self._logger.log("No interface found.. defaulting to eth0.")
					interface = "eth0"
					dhcp_options = ""

				if interface and not dhcp_options:
					if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd -n " + interface + "'")
					status = GLIUtility.spawn("/sbin/dhcpcd -t 15 -n " + interface)
				elif interface and dhcp_options:
					if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd " + dhcp_options + " " + interface + "'")
					status = GLIUtility.spawn("/sbin/dhcpcd -t 15 " + dhcp_options + " " + interface)
				else:
					if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): running '/sbin/dhcpcd -n'")
					status = GLIUtility.spawn("/sbin/dhcpcd -t 15 -n")
				if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): call to /sbin/dhcpcd complete")

				if not GLIUtility.exitsuccess(status):
					raise GLIException("DHCPError", 'fatal', 'configure_networking', "Failed to get a dhcp address for " + interface + ".")

			elif type == "manual" and self._configuration.get_interactive():
				# Drop to bash shell and let them configure it themselves
				print "Please configure & test your network device."
				GLIUtility.spawn_bash()
			elif type == "manual" and not self._interactive.get_interactive():
				print "You cannot manually configure the network in non-interactive mode!"
				print "Please fix either the network settings or the interactive mode!"
				sys.exit(1)
			elif type == "static":
				if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): setting static IP")
				# Configure the network from the settings they gave.
				net_interface = self._configuration.get_network_interface()
				net_ip        = self._configuration.get_network_ip()
				net_broadcast = self._configuration.get_network_broadcast()
				net_netmask   = self._configuration.get_network_netmask()
				if not GLIUtility.set_ip(net_interface, net_ip, net_broadcast, net_netmask):
					raise GLIException("SetIPError", 'fatal', 'configure_networking', "Could not set the IP address!")

				route = self._configuration.get_network_gateway()
				if not GLIUtility.set_default_route(route):
					raise GLIException("DefaultRouteError", 'fatal','configure_networking', "Could not set the default route!")

				dns_servers = self._configuration.get_dns_servers()
				if dns_servers:
					try:
						resolv_conf = open("/etc/resolv.conf", "w")
						for dns_server in dns_servers:
							resolv_conf.write("nameserver " + dns_server + "\n")
						resolv_conf.close()
					except:
						raise GLIException("DNSServerError", 'fatal','configure_networking', "Could not set the DNS servers!")

				if self._configuration.get_verbose(): self._logger.log("DEBUG: configure_networking(): done setting static IP")
开发者ID:bremen77jodypurba,项目名称:pentoo,代码行数:68,代码来源:GLIClientController.py


注:本文中的GLIUtility.spawn_bash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。