/[gli]/trunk/src/net/client/gliclient.py
Gentoo

Contents of /trunk/src/net/client/gliclient.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (show annotations) (download) (as text)
Fri Sep 30 20:33:29 2005 UTC (13 years ago) by agaffney
File MIME type: text/x-python
File size: 4403 byte(s)
  pass MAC to XMLRPC functions
  src/net/server/GLIServerProfile.py:
  rename GLIClientsProfiles to GLIServerProfile

1 #!/usr/bin/python
2 # Copyright 1999-2005 Gentoo Foundation
3 # This source code is distributed under the terms of version 2 of the GNU
4 # General Public License as published by the Free Software Foundation, a copy
5 # of which can be found in the main directory of this project.
6
7 import sys, time, socket
8 sys.path.append("../../..")
9 import GLIException
10 import GLIInstallProfile
11 import GLIClientConfiguration
12 import GLIClientController
13 import GLIUtility
14 import xmlrpclib
15 import dialog
16 import GLIGenDialog
17
18 def find_macip():
19 device = None
20 device_name = 'eth'
21 for num in range(5):
22 if GLIUtility.is_eth_device(device_name + str(num)):
23 device = GLIUtility.get_eth_info(num)
24 break
25 else:
26 raise GLIException("NetFeError", 'fatal', 'setup_network',"Was unable to find a network inferface.")
27 return device[0], device[1]
28
29 def find_server():
30 device = None
31 for device in GLIUtility.get_eth_devices():
32 if device.startswith("eth"):
33 device = GLIUtility.get_eth_info(num)
34 break
35 else:
36 return False
37
38 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
39 s.bind(('', 0))
40 s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
41 s.settimeout(15)
42
43 count = 1
44 response = ""
45 while count <= 3:
46 print "Broadcasting for server...try " + str(count)
47 s.sendto("GLIAutoInstall", ('255.255.255.255', 8001))
48 response, fromaddr = s.recvfrom(1024)
49 if response:
50 print "Server found at " + str(fromaddr[0]) + " port " + str(fromaddr[1])
51 break
52 count = count + 1
53 return fromaddr[0], fromaddr[1]
54
55 if __name__ == '__main__':
56 args = {}
57 i = 0
58 while i < len(sys.argv):
59 if sys.argv[i] == "-s" or sys.argv[i] == "--server":
60 i += 1
61 tmpserver = sys.argv[i]
62 tmpserverparts = tmpserver.split(":")
63 if not len(tmpserverparts) == 2:
64 print "Invalid argument for option " + sys.argv[i-1] + ". Terminating."
65 sys.exit(0)
66 args['server_ip'] = tmpserverparts[0]
67 args['server_port'] = tmpserverparts[1]
68 else:
69 print "Invalid option " + sys.argv[i] + ". Terminating."
70 sys.exit(0)
71
72 local_mac, local_ip = find_macip()
73 if args['server_ip'] and args['server_port']:
74 server_ip, server_port = args['server_ip'], args['server_port']
75 else:
76 server_ip, server_port = find_server()
77 server = xmlrpclib.ServerProxy("http://" + server_ip + ":" + server_port + 1)
78 registered = False
79 try:
80 registered = server.register_client(local_mac, local_ip)
81 except:
82 pass
83 if not registered:
84 print "Could not register with server. Terminating."
85 sys.exit(0)
86
87 print "Waiting for client config and install profile from server"
88 while 1:
89 client_config = server.get_client_config(local_mac)
90 install_profile = server.get_install_profile(local_mac)
91 if install_profile and client_config:
92 print "Received client config and install profile from server"
93 break
94 time.sleep(1)
95
96 tmpfile = open("/tmp/client_config.xml", "w")
97 tmpfile.write(client_config)
98 tmpfile.close()
99
100 tmpfile = open("/tmp/install_profile.xml", "w")
101 tmpfile.write(install_profile)
102 tmpfile.close()
103
104 client_config = GLIClientConfiguration.ClientConfiguration()
105 client_conf.parse("/tmp/client_config.conf")
106 install_profile = GLIInstallProfile.InstallProfile()
107 install_profile.parse("/tmp/install_profile.xml")
108 cc = GLIClientController.GLIClientController(client_config,install_profile)
109
110 #Start the backend threads
111 cc.start_pre_install()
112
113 #Begin the main engine
114 cc.start_install()
115 d.gauge_start("Installation Started!", title="Installation progress")
116 num_steps_completed = 1
117 while 1:
118 notification = cc.getNotification()
119 if notification == None:
120 time.sleep(1)
121 continue
122 ntype = notification.get_type()
123 ndata = notification.get_data()
124 if ntype == "exception":
125 server.update_client_status(local_mac, "Exception: " + ndata)
126 print ndata
127 elif ntype == "int":
128 if ndata == GLIClientController.NEXT_STEP_READY:
129 next_step_waiting = False
130 next_step = cc.get_next_step_info()
131 num_steps = cc.get_num_steps()
132 print "Step " + str(num_steps_completed) + " of " + str(num_steps) + ": " + next_step
133 server.update_client_status(local_mac, "On step " + num_steps_completed + " of " + num_steps + ". Current step: " + next_step)
134 num_steps_completed += 1
135 if cc.has_more_steps():
136 cc.next_step()
137 continue
138 if ndata == GLIClientController.INSTALL_DONE:
139 print "Install complete!"
140 server.update_client_status(local_mac, "Install completed!")
141 sys.exit(0)

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20