Menu

[r1]: / backend / host.py  Maximize  Restore  History

Download this file

288 lines (264 with data), 12.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# -----------------------------------------------------------------------
# XenWebManager
#
# Copyright (C) 2009 Alberto Gonzalez Rodriguez alberto@pesadilla.org
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
import xmlrpclib, urllib
import asyncore, socket
import select
from os import chdir
import platform
import sys, shutil
import datetime
from threading import Thread
from configobj import ConfigObj
import xml.dom.minidom
from operator import itemgetter
import pdb
import rrdinfo
import time
from messages import messages, messages_header
from host_nics import *
from host_network import *
class host(hostnics, hostnetwork):
def upload_patch(self, ref, filename):
import httplib, os
task_uuid = self.connection.task.create(self.session_uuid, "Uploading Patch", "Uploading Patch %s " % (filename))
self.track_tasks[task_uuid['Value']] = "Upload.Patch"
size=os.stat(filename)[6]
url = self.wine.selected_ip
conn = httplib.HTTPS(url)
conn.putrequest('PUT', '/pool_patch_upload?session_id=%s&task_id=%s' % (self.session_uuid, task_uuid['Value']))
conn.putheader('Content-Type', 'text/plain')
conn.putheader('Content-Length', str(size))
conn.endheaders()
fp=open(filename, 'rb')
blocknum=0
uploaded=0
blocksize=4096
while not self.halt_import:
bodypart=fp.read(blocksize)
blocknum+=1
if blocknum % 10 == 0:
uploaded+=len(bodypart)
if not bodypart: break
conn.send(bodypart)
fp.close()
print "Finish upload.."
def remove_patch(self, ref, patch):
res = self.connection.Async.pool_patch.destroy(self.session_uuid, patch)
if "Value" in res:
self.track_tasks[res['Value']] = ref
else:
print res
def apply_patch(self, ref, patch):
res = self.connection.Async.pool_patch.apply(self.session_uuid, ref, patch)
if "Value" in res:
self.track_tasks[res['Value']] = ref
else:
print res
def reconfigure_pif(self, pif_ref, conf_mode, ip, mask, gw, dns, ref):
res = self.connection.PIF.reconfigure_ip(self.session_uuid, pif_ref, conf_mode, ip, mask, gw, dns)
if "Value" in res:
self.track_tasks[res['Value']] = self.host_vm[ref][0]
else:
print res
def change_server_password(self, old, new):
self.connection.session.change_password(self.session_uuid, old, new)
self.password = new
def install_license_key(self, ref, encoded):
res = self.connection.host.license_apply(self.session_uuid, ref, encoded)
if "Value" in res:
self.track_tasks[res['Value']] = self.host_vm[ref][0]
return "OK"
else:
#self.wine.builder.get_object("warninglicense").show()
return "ERROR"
def join_pool(self, host, user, password):
res = self.connection.pool.join(self.session_uuid, host, user, password)
if "Value" in res:
self.track_tasks[res['Value']] = self.host_vm[self.all_hosts.keys()[0]][0]
else:
self.wine.push_alert("%s: %s" % (res["ErrorDescription"][0], res["ErrorDescription"][1]))
def fill_vms_which_prevent_evacuation(self, ref):
list = []
vms = self.connection.host.get_vms_which_prevent_evacuation(self.session_uuid, ref)["Value"]
for vm in vms.keys():
# vms[vm][0]
list.append(["images/tree_running_16.png", self.all_vms[vm]['name_label'], \
"Suspend or shutdown VM"])
return list
def host_evacuate(self, ref):
res = self.connection.Async.host.evacuate(self.session_uuid, ref)
if "Value" in res:
self.track_tasks[res['Value']] = self.host_vm[ref][0]
else:
print res
def thread_restore_server(self, ref, filename, name):
Thread(target=self.restore_server, args=(ref, filename, name)).start()
def thread_backup_server(self, ref, filename, name):
Thread(target=self.backup_server, args=(ref, filename, name)).start()
def thread_host_download_logs(self, ref, filename, name):
Thread(target=self.host_download_logs, args=(ref, filename, name)).start()
def create_pool(self, name, desc):
pool_ref = self.all_pools.keys()[0]
res = self.connection.pool.set_name_label(self.session_uuid, pool_ref, name)
res = self.connection.pool.set_name_description(self.session_uuid, pool_ref, desc)
if "Value" in res:
self.track_tasks[res['Value']] = pool_ref
else:
print res
def has_hardware_script(self, ref):
error = self.connection.host.call_plugin(self.session_uuid, ref, "dmidecode", "test", {})
return "XENAPI_MISSING_PLUGIN" not in error['ErrorDescription']
def fill_host_hardware(self, ref):
hwinfo = self.connection.host.call_plugin(self.session_uuid, ref, "dmidecode", "main", {})['Value']
relation = {}
keys = []
for line in hwinfo.split("\n"):
if not line: continue
if line[0] != "\t" and line not in relation:
relation[line] = []
key = line
keys.append(key)
else:
if line[0] == "\t":
relation[key].append(line)
else:
relation[key].append("\n")
for ch in self.wine.builder.get_object("hosttablehw").get_children():
self.wine.builder.get_object("hosttablehw").remove(ch)
for key in keys:
self.add_box_hardware(key, relation[key])
def add_box_hardware(self, title, text):
vboxframe = gtk.Frame()
vboxframe.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
vboxchild = gtk.Fixed()
vboxevent = gtk.EventBox()
vboxevent.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
vboxevent.add(vboxchild)
vboxframe.add(vboxevent)
vboxchildlabel1 = gtk.Label()
vboxchildlabel1.set_selectable(True)
vboxchildlabel1.set_markup("<b>" + title + "</b>")
vboxchild.put(vboxchildlabel1, 5, 5)
vboxchildlabel2 = gtk.Label()
vboxchildlabel2.set_selectable(True)
vboxchildlabel2.set_text('\n'.join(text) + "\n")
vboxchild.put(vboxchildlabel2, 5, 35)
self.wine.builder.get_object("hosttablehw").add(vboxframe)
self.wine.builder.get_object("hosttablehw").show_all()
def fill_host_network(self, ref):
list = []
for network_key in self.all_network.keys():
network = self.all_network[network_key]
#for pif in network['PIFs']:
# if self.all_pif[pif]['host'] == ref:
# on_host = True
if network['bridge'] != "xapi0":
name = network['name_label'].replace('Pool-wide network associated with eth','Network ')
desc = network['name_description']
auto = "no"
if "automatic" in network['other_config']:
if network['other_config']['automatic'] == "true":
auto = "yes"
else:
auto = "No"
pifs = filter(lambda lista: lista["network"] == network_key, self.all_pif.values())
vlan = "-"
linkstatus = "-"
macaddress = "-"
nic = "-"
physical = ""
for pif in pifs:
if pif['host'] == ref:
nic = "NIC " + pif['device'][-1:]
if pif:
if pif['VLAN'] != "-1":
vlan = pif['VLAN']
if self.all_pif_metrics[pif['metrics']]['carrier']: # Link status
linkstatus = "Connected"
if pif['MAC'] != "fe:ff:ff:ff:ff:ff":
macaddress = pif['MAC']
if macaddress != "-" and linkstatus == "-":
linkstatus = "Disconnected"
physical = pif['physical']
# FIXME: not bond networks
list.append((name, desc, nic, vlan, auto, linkstatus, macaddress,network_key, physical))
return list
def fill_host_nics(self, ref):
list = []
for pif_key in self.all_pif.keys():
if self.all_pif[pif_key]['host'] == ref:
if self.all_pif[pif_key]['metrics'] != "OpaqueRef:NULL":
if self.all_pif[pif_key]['metrics'] not in self.all_pif_metrics:
continue
pif_metric = self.all_pif_metrics[self.all_pif[pif_key]['metrics']]
pif = self.all_pif[pif_key]
#pif = filter(lambda lista: lista["metrics"] == pif_key, self.all_pif.values())
if pif_metric['duplex']:
duplex = "full"
else:
duplex = "half"
if pif:
if "MAC" in pif:
mac = pif['MAC']
else:
mac = ""
connected = "Disconnected"
if pif_metric['carrier']:
connected = "Connected"
if connected == "Connected":
speed = pif_metric['speed'] + " mbit/s"
else:
speed = ""
if pif_metric['pci_bus_path'] != "N/A":
list.append(("NIC %s" % pif['device'][-1:],mac,connected,
speed, duplex, pif_metric['vendor_name'],
pif_metric['device_name'], pif_metric['pci_bus_path'],pif_key, len(pif['bond_master_of'])>0))
else:
if pif['bond_master_of'][0] in self.all_bond:
devices = []
for slave in self.all_bond[pif['bond_master_of'][0]]['slaves']:
devices.append(self.all_pif[slave]['device'][-1:])
devices.sort()
list.append(("Bond %s" % ('+'.join(devices)),mac,connected,
speed, duplex, pif_metric['vendor_name'],
pif_metric['device_name'], pif_metric['pci_bus_path'],pif_key, len(pif['bond_master_of'])>0))
else:
pass
#print pif, pif_metric
else:
pif = self.all_pif[pif_key]
if "MAC" in pif:
mac = pif['MAC']
else:
mac = ""
connected = "Disconnected"
if pif['bond_master_of']:
devices = []
for slave in self.all_bond[pif['bond_master_of'][0]]['slaves']:
devices.append(self.all_pif[slave]['device'][-1:])
devices.sort()
list.append(("Bond %s" % ('+'.join(devices)),mac,connected,
"-", "-", "-",
"-", "-",pif_key,len(pif['bond_master_of'])>0))
else:
list.append(("NIC %s" % pif['device'][-1:],mac,connected,
"-", "-", "-",
"-", "-",pif_key,len(pif['bond_master_of'])>0))
return list
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.