Esempio n. 1
0
	def cron_daily(self):
		self.require_remote()

		# get VMs
		ac = api.api_call("server_vms", {
			'server_id': self.get_server_id()
		})
		ret = ac.execute()
		if ret != errors.ERR_SUCCESS: return ret
		result = ac.output()

		# get backend
		from backend import backend

		# update stats on each VPS
		for vps in result:
			vps['server'] = self.remote_server
			backend.execute("vpsctl", "usage_bandwidth", str(vps))

		# we return here because this is never called by the cron directly...
		# the cron is actually called by cron_daily() of masterctl
		return errors.throw(errors.ERR_SUCCESS)
Esempio n. 2
0
	def execute(self, id):
		# get cmd dict
		q_item = self.q.pop(id)

		self.log("q.execute(id): %s" % id)

		# execute deps first
		for dep in q_item['deps']:
			if self.q.has_key(dep):
				self.log("q.execute(...): dependency: %s" % dep)
				self.execute(dep)

		# fail if any dependency failed
		for dep in q_item['deps']:
			try:
				self.fail.index(dep)
				self.log("q.execute(...): dependency failed: %s" % dep)
				return (None, errors.throw(errors.ERR_QUEUE_DEP_FAILED))
			except ValueError: pass

		# continue with normal execution, set up the attributes
		cls = q_item['cls']
		cmd = q_item['cmd']
		args = q_item['args']

		# pre-execute log
		self.log("backend.execute(cls, cmd, args, True): %s %s %s True" %
			(cls, cmd, str(args))
		)

		# execute (debug mode on)
		(control, error_code) = backend.execute(cls, cmd, args, True)

		# post-execute log
		self.log("(control, error_code) = backend.execute(...): %s %s" %
			(str(control), str(error_code))
		)

		# log to event table in DB
		self.event_log(cls, cmd, control, error_code)

		# append to fail list if it didn't succeed
		if error_code != errors.ERR_SUCCESS:
			self.fail.append(id)

		return (control, error_code)
Esempio n. 3
0
from backend import backend
from execute import *
import api
import vps

# get server list
ac = api.api_call("server_list", {})
ret = ac.execute()
if ret != errors.ERR_SUCCESS:
	sys.exit(1)
servers = ac.output()

# for each server, call bandwidth initialize
for server in servers:
	# get the dictionary
	server_text = urllib.unquote(str(server)).replace("+", " ")
	server_dict = eval(server_text)
	server_dict['remote_server'] = copy.copy(server_dict)
	server_text = str(server_dict)

	# create bandwidth cron on master, and that's all
	if server['parent_server_id'] == 0:
		print backend.execute(
			"masterctl", "initialize_bw_cron", server_text, True
		)
		continue

	# initialize bandwidth on the server
	print backend.execute("serverctl", "initialize_bw", server_text, True)