Example #1
0
def run(url, version, skipupgrade):
	r = xreq.do_request(url + '/client/latest');
	n = r.text.split(".", 3);
	c = version.split(".", 3);
	nmajor = int(n[0]);
	nminor = int(n[1]);
	nrevis = int(n[2]);
	cmajor = int(c[0]);
	cminor = int(c[1]);
	crevis = int(c[2]);
	upgrade = False;
	if int(nmajor) > int(cmajor):
		upgrade = True;
	if int(nminor) > int(cminor):
		upgrade = True;
	if int(nrevis) > int(crevis):
		upgrade = True;
	
	if upgrade:
		print "An upgrade is available ({})".format(r.text);
	else:
		print "No upgrade available";
		return;
	
	if skipupgrade:
		print "Not upgrading client"
		return;
	
	path = os.path.dirname(os.path.realpath(__file__));
	rversion = "{}.{}.{}".format(nmajor, nminor, nrevis);
	archive = "xop-client-{}.tgz".format(rversion);
	download = path + '/tmp/' + archive;
	print "Downloading {}/client/version/{}/download".format(url, rversion);
	urllib.urlretrieve(url + '/client/version/{}/download'.format(rversion), download);
	
	r = xreq.do_request(url + '/client/version/{}/checksum'.format(rversion));
	rchk = r.text.rstrip();
	f = open(download, 'r');
	s = hashlib.sha1();
	while True:
		j = f.read(1024);
		if not j:
			break;
		s.update(j);
	f.close()
	lchk = s.hexdigest();

	if not rchk == lchk:
		print "Update failed checksum. Skipping";
		return
	
	print "Updating to {}".format(rversion);
	
	tar = tarfile.open(download);
	tar.extractall(path=path);
Example #2
0
def run(hostid, uri):
	url = uri + '/package/add.json';
	params = {'hostid': hostid, 'packages': pkgs};
	
	r = xreq.do_request(url, params);
	print r;
	print r.text;
Example #3
0
def run(hostid, uri):
	pattern = "[ \t]";
	disks = {}
	i = 0;
	d = {}

	fd = open('/proc/mounts', 'r');
	for line in fd:
		d = {};
		parts = re.split(pattern, line);
		disk = parts[0];
		mpoint = parts[1];
		if disk == "none": 
			continue;
		fs = os.statvfs(mpoint);
		if fs.f_blocks == 0:
			continue;
		if disk == "udev":
			continue;
		if disk == "tmpfs":
			continue;
		if disk == "rootfs":
			continue;
		size = (fs.f_blocks * fs.f_bsize);
		free = (fs.f_bfree * fs.f_bsize);
		d['name'] = disk;
		d['mountpoint'] = mpoint;
		d['size'] = size;
		d['freespace'] = free;

		#print "{} mounted on {} size: {} free: {}".format(disk, mpoint, size, free);
		disks[i] = d;
		i = i + 1;
	fd.close();
	#print disks

	url = uri + '/disk/add.json';
	params = {'hostid': hostid };
	params['disks'] = disks;

	r = xreq.do_request(url, params);
	print r;
	print r.text;
Example #4
0
def run(hostid, uri):
	i = 0;
	url = uri + "/address/add.json";
	params = {'hostid': hostid, 'interfaces': {}}
	for interface in netifaces.interfaces():
		if interface == 'lo':
			continue;
		try:
			j = netifaces.ifaddresses(interface)[netifaces.AF_INET6]
			for address in netifaces.ifaddresses(interface)[netifaces.AF_INET6]:
				iface = {}
				if address['addr'].endswith("%{}".format(interface)):
					k = -1 - len(interface);
					addr = address['addr']
					address['addr'] = addr[:k];
				iface['address'] = address['addr'];
				iface['prefix'] = 64;
				iface['version'] = 6;
				iface['iface'] = interface;
				params['interfaces'][i] = iface;
				i = i + 1;
		except KeyError:
			continue;

		try:
			j = netifaces.ifaddresses(interface)[netifaces.AF_INET]
			for address in netifaces.ifaddresses(interface)[netifaces.AF_INET]:
				iface = {}
				iface['address'] = address['addr'];
				iface['prefix'] = get_prefix_4(address['netmask']);
				iface['version'] = 4;
				iface['iface'] = interface;
				params['interfaces'][i] = iface;
				i = i + 1;
		except KeyError:
			continue;
	#print params;
	r = xreq.do_request(url, params);
	print r;

	print r.text;
Example #5
0
def run(hostid, uri):
	reboot = os.path.exists('/var/run/reboot-required');
	
	url = uri + '/host/checkIn.json'
	
	params = {};
	params['hostid'] = hostid;
	params['reboot'] = reboot;
	params['osbase'] = platform.system();
	if platform.system() == 'Linux':
		(dist, version, codename) = platform.linux_distribution();
		params['os'] = dist;
		params['osversion'] = version;
		
		f = open('/proc/uptime');
		uptime = float(f.readline().split()[0]);
		ts = time.time();
		sysboot = ts - uptime;
		#print "up since %s" % datetime.datetime.fromtimestamp(sysboot);
		params['sysboot'] = sysboot;
	
	r = xreq.do_request(url, params);
	print r;
	print r.text;