Annotation of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in
Parent Directory | Revision Log
Revision 2701 -
(hide annotations)
(download)
Wed Dec 16 14:42:45 2015 UTC (8 years, 4 months ago) by niro
File size: 2978 byte(s)
Wed Dec 16 14:42:45 2015 UTC (8 years, 4 months ago) by niro
File size: 2978 byte(s)
-fixed netboot state update
1 | niro | 2435 | # $Id$ |
2 | niro | 2430 | |
3 | validate_client() | ||
4 | { | ||
5 | local mac_address="$1" | ||
6 | niro | 2442 | local ip_address="$2" |
7 | niro | 2430 | local serial |
8 | niro | 2431 | local mtime |
9 | niro | 2457 | local serial_id |
10 | niro | 2506 | local os |
11 | local tools | ||
12 | niro | 2699 | local netboot |
13 | niro | 2430 | |
14 | if [[ -z ${mac_address} ]] | ||
15 | then | ||
16 | eecho "Error: No mac_address given" | ||
17 | return 1 | ||
18 | fi | ||
19 | |||
20 | niro | 2442 | if [[ -z ${ip_address} ]] |
21 | then | ||
22 | eecho "Error: No ip_address given" | ||
23 | return 1 | ||
24 | fi | ||
25 | |||
26 | niro | 2439 | decho "registering mac_address='${mac_address}'" |
27 | niro | 2445 | decho "registering ip_address='${ip_address}'" |
28 | niro | 2439 | |
29 | niro | 2430 | # first check if mac is registered |
30 | serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") | ||
31 | |||
32 | niro | 2476 | # current mtime |
33 | mtime=$(date +%s) | ||
34 | |||
35 | niro | 2430 | if [[ -z ${serial} ]] |
36 | then | ||
37 | # request a new serial; one command now (cause must be done in the same session) | ||
38 | niro | 2431 | serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") |
39 | niro | 2430 | fi |
40 | |||
41 | niro | 2433 | if [[ -z ${serial} ]] |
42 | then | ||
43 | return 1 | ||
44 | else | ||
45 | niro | 2441 | decho "serial='${serial}'" |
46 | rvecho "${serial}" | ||
47 | niro | 2442 | |
48 | niro | 2445 | SSLSAY_IP="${ip_address}" |
49 | niro | 2442 | SSLSAY_PORT="6666" |
50 | niro | 2447 | nsslsay_fingerprint "register '${serial}'" |
51 | niro | 2442 | |
52 | niro | 2701 | # get netboot state |
53 | nsslsay_queue_init | ||
54 | nsslsay_queue_add "nocolors" | ||
55 | nsslsay_queue_add "get version.netboot" | ||
56 | netboot=$(control_client "${serial}" run-queue) | ||
57 | |||
58 | niro | 2457 | # register the client as online |
59 | serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") | ||
60 | if [[ -n ${serial_id} ]] | ||
61 | then | ||
62 | niro | 2701 | mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}', netboot='${netboot}' where serial=${serial};" |
63 | niro | 2457 | else |
64 | niro | 2701 | mysqldo "insert into state_connected(serial,ip,mac,mtime,netboot) values('${serial}','${ip_address}','${mac_address}','${mtime}', '${netboot}');" |
65 | niro | 2457 | fi |
66 | |||
67 | niro | 2506 | # update tools and os version info |
68 | nsslsay_queue_init | ||
69 | nsslsay_queue_add "nocolors" | ||
70 | nsslsay_queue_add "get version.os" | ||
71 | os=$(control_client "${serial}" run-queue) | ||
72 | import_resource client_version "${serial}" os "${os}" | ||
73 | nsslsay_queue_init | ||
74 | nsslsay_queue_add "nocolors" | ||
75 | nsslsay_queue_add "get version.tools" | ||
76 | niro | 2507 | tools=$(control_client "${serial}" run-queue) |
77 | niro | 2506 | import_resource client_version "${serial}" utils "${tools}" |
78 | |||
79 | niro | 2497 | # run hardware detection |
80 | if is_provided hardware | ||
81 | then | ||
82 | niro | 2499 | run_hardware_detect "${serial}" |
83 | niro | 2497 | fi |
84 | |||
85 | niro | 2433 | return 0 |
86 | fi | ||
87 | niro | 2430 | } |
88 | |||
89 | register_client() | ||
90 | { | ||
91 | local control_server_ip | ||
92 | local iface_ip | ||
93 | local iface | ||
94 | local mac_address | ||
95 | |||
96 | control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) | ||
97 | iface_ip=$(iface_for_remote_addr ${control_server_ip}) | ||
98 | iface=$(iface_for_ip ${iface_ip}) | ||
99 | mac_address=$(mac_for_iface ${iface}) | ||
100 | |||
101 | niro | 2439 | decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" |
102 | decho "iface_ip='${iface_ip}'" | ||
103 | decho "iface='${iface}'" | ||
104 | decho "mac_address='${mac_address}'" | ||
105 | niro | 2430 | |
106 | niro | 2439 | decho "register '${mac_address}'" |
107 | niro | 2447 | nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
108 | niro | 2430 | } |
109 | niro | 2442 | |
110 | register_client_local() | ||
111 | { | ||
112 | local serial="$1" | ||
113 | |||
114 | if [[ -z ${serial} ]] | ||
115 | then | ||
116 | eecho "No serial given" | ||
117 | return 1 | ||
118 | fi | ||
119 | |||
120 | niro | 2461 | install -d "${MCORE_CONFIG_PATH}" |
121 | niro | 2442 | CONFIG="${MCORE_CONFIG_PATH}/serial" |
122 | clearconfig | ||
123 | addconfig "CLIENT_SERIAL=\"${serial}\"" | ||
124 | } |