當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。