Ejemplo n.º 1
0
class ProvisionReporter(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.instance_metric = ProvisionInstanceMetric()
        self.self_stopped = 0

        self.metaConfigure = MetaConfigure()

    def run(self):
        while not self.self_stopped:
            self._pooling_instances()
            time.sleep(self.pooling_interval)
            if self.metaConfigure._is_debug():
                print 'polling instance ...'
        print 'stop connect to monitor'

    def join_reporter(self):
        self.self_stopped = 1
        self.join()

    def _pooling_instances(self):
        count = 0
        for inst in self.instance_metric.instance_list:
            if instance.status == "RUNNING":
                count = count + 1
            if not inst._is_booted_reported():
                #send notification to host
                print 'report one booted instance %s' % str(inst._get_info())
                inst._set_report_of_booted_instance()
            elif inst._is_terminated_reported():
                #send notification to host
                print 'report one terminated instance %s' % str(
                    inst._get_info())
                inst._set_report_of_terminated_instance()
class ProvisionReporter(threading.Thread):
    def __init__(self):
	threading.Thread.__init__(self)
	self.instance_metric = ProvisionInstanceMetric()
	self.self_stopped = 0

	self.metaConfigure = MetaConfigure()

    def run(self):
	while not self.self_stopped:
	    self._pooling_instances()
	    time.sleep(self.pooling_interval)
	    if self.metaConfigure._is_debug():
		print 'polling instance ...'
	print 'stop connect to monitor'

    def join_reporter(self):
	self.self_stopped = 1
	self.join()

    def _pooling_instances(self):
	count=0
	for inst in self.instance_metric.instance_list:
	    if instance.status == "RUNNING":
		count =count + 1
	    if not inst._is_booted_reported():
		#send notification to host
		print 'report one booted instance %s' % str(inst._get_info())
		inst._set_report_of_booted_instance()
	    elif inst._is_terminated_reported():
		#send notification to host
		print 'report one terminated instance %s' % str(inst._get_info())
		inst._set_report_of_terminated_instance()
Ejemplo n.º 3
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.instance_metric = ProvisionInstanceMetric()
        self.terminate_flag = 0

        self.metaConfigure = MetaConfigure()

        self.host_ip = self.metaConfigure._get_provision_host_ip() or '0.0.0.0'
        self.host_port = self.metaConfigure._get_provision_host_port() or 8675
        self.proxy_port = self.metaConfigure._get_proxy_port() or 8821
        self.report_online = self.metaConfigure._is_report_online()

        self.self_stopped = False
        self.httpd = make_server('', self.host_port,
                                 self.provision_monitor_app)
        self.httpd.timeout = self.metaConfigure._get_http_timeout()

        self.proxy_data = ProvisionProxyMonitorData(host_port=self.host_port)
    def __init__(self):
	threading.Thread.__init__(self)
	self.instance_metric = ProvisionInstanceMetric()
        self.terminate_flag = 0

        self.metaConfigure = MetaConfigure()

	self.host_ip = self.metaConfigure._get_provision_host_ip() or '0.0.0.0'
	self.host_port = self.metaConfigure._get_provision_host_port() or 8675
	self.proxy_port = self.metaConfigure._get_proxy_port() or 8821
	self.report_online =self.metaConfigure._is_report_online()

	self.self_stopped = False
	self.httpd = make_server('', self.host_port, self.provision_monitor_app) 
	self.httpd.timeout = self.metaConfigure._get_http_timeout()

	self.proxy_data = ProvisionProxyMonitorData(host_port = self.host_port)
Ejemplo n.º 5
0
 def __init__(self):
     self.config = MetaConfigure().config
     self.info_list = []
Ejemplo n.º 6
0
            else:
                ProvisionInstanceMetric()._update_instance(
                    instance, "DELETED", time.time())
                self.is_terminating_instances += 1
            print "#######one instance is deleting#########"
        return True

    def terminate_expired_instance(self, cloud_api):
        currenttime = time.time()
        for instance in self.instance_list:
            if instance._should_be_terminated():
                if not self._terminate_instance(cloud_api, instance):
                    print "instance.id cannot delete normally."


#config=parser.parse_args(sys.argv[1:])
if __name__ == '__main__':
    MetaConfigure()._dump_configure()
    thread_pool = []

    workload = ProvisionWorkload(MetaConfigure().config)
    workload.start_workload()

#    def signal_handler(signal, frame):
#        for th in thread_pool:
#            th.terminate()
#        sys.exit(0)

#    signal.signal(signal.SIGINT, signal_handler)
#    signal.pause()
Ejemplo n.º 7
0
class ProvisionMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.instance_metric = ProvisionInstanceMetric()
        self.terminate_flag = 0

        self.metaConfigure = MetaConfigure()

        self.host_ip = self.metaConfigure._get_provision_host_ip() or '0.0.0.0'
        self.host_port = self.metaConfigure._get_provision_host_port() or 8675
        self.proxy_port = self.metaConfigure._get_proxy_port() or 8821
        self.report_online = self.metaConfigure._is_report_online()

        self.self_stopped = False
        self.httpd = make_server('', self.host_port,
                                 self.provision_monitor_app)
        self.httpd.timeout = self.metaConfigure._get_http_timeout()

        self.proxy_data = ProvisionProxyMonitorData(host_port=self.host_port)

    def terminate_monitor(self):
        self.self_stopped = True
        self.join()

    def run(self):
        self.serve()

    def serve(self):
        print "Serving on port %d..." % self.host_port
        while not self.self_stopped:
            self.httpd.handle_request()
            if self.metaConfigure._is_debug():
                print 'handle one request or timeout ...'
        print "Stop monitor server..."
        #self.httpd.serve_forever()

    def provision_monitor_app(self, environ, start_response):
        print 'one request coming'
        status = '200 OK'  # HTTP Status
        headers = [('Content-type', 'text/plain')]  # HTTP Headers
        start_response(status, headers)

        proxy_req = urlparse.parse_qs(environ['QUERY_STRING'])
        print proxy_req.keys()
        if 'VMType' in proxy_req.keys():
            if proxy_req['VMType'] == ['proxy'
                                       ] and 'PublicIP' in proxy_req.keys(
                                       ) and 'CurTime' in proxy_req.keys():
                print "proxy private ip: %s" % self.proxy_data.priv_ip
                #if proxy_req['PrivateIP'][0] != self.proxy_data.priv_ip :
                if proxy_req['Key'][0] != self.proxy_data.key:
                    print "recieve old proxy vm connection: %s" % proxy_req
                    return ["Error: old provison proxy connection"]
                self.proxy_data.connected_with_proxy = True
                #if 'PrivateIP' in proxy_req.keys():
                #    self.proxy_data._set_pub_priv_ip(proxy_req['PublicIP'][0], proxy_req['PrivateIP'][0])
                #else:
                #    self.proxy_data._set_pub_ip(proxy_req['PublicIP'][0])

                monitor_base = time.time()
                self.proxy_data._sync_time(proxy_req['CurTime'][0],
                                           monitor_base)
                print self.proxy_data._get_info()
                print "hahhah, proxy connection is coming!!!!"
                return ["200 OK!!!%s" % monitor_base]

            #if proxy_req['VMType'] == ['instance'] and 'VMStatus' in proxy_req.keys() and 'VMName' in proxy_req.keys() and  'VMIP' in proxy_req.keys() and 'Timestamp' in proxy_req.keys():
            if proxy_req['VMType'] == ['instance'
                                       ] and 'VMStatus' in proxy_req.keys(
                                       ) and 'VMName' in proxy_req.keys(
                                       ) and 'Timestamp' in proxy_req.keys():
                instance = self.instance_metric._get_instance_by_name(
                    proxy_req['VMName'][0])
                if instance is None:
                    print 'can not find instance from metric'
                    print proxy_req['VMName']
                    return ["no found"]

                if proxy_req['VMStatus'][0] == 'BOOTED':
                    ip_lease = 0
                    if 'IPLease' in proxy_req.keys():
                        ip_lease = proxy_req['IPLease'][0]
                    ProvisionInstanceMetric()._update_instance(
                        instance, "RUNNING", proxy_req['Timestamp'][0],
                        ip_lease)  #time.time())
                    print "instance[%s] has finished booted, booted time[%s], dhcp time:%s" % (
                        proxy_req['VMName'], proxy_req['Timestamp'],
                        str(proxy_req['IPLease'][0]))
                elif proxy_req['VMStatus'][0] == 'DELETED':
                    ProvisionInstanceMetric()._update_instance(
                        instance, "DELETED",
                        proxy_req['Timestamp'][0])  #time.time())
                    print "instance[%s] has been deleted, deleted time[%s]" % (
                        proxy_req['VMName'], proxy_req['Timestamp'])
                return ["200 OK"]

        return [
            "Error:(%s) do not include \'hostname\', \'ip\' and \'status[boot|terminate]\'"
            % environ['QUERY_STRING']
        ]
Ejemplo n.º 8
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.instance_metric = ProvisionInstanceMetric()
        self.self_stopped = 0

        self.metaConfigure = MetaConfigure()
class ProvisionMonitor(threading.Thread):
    def __init__(self):
	threading.Thread.__init__(self)
	self.instance_metric = ProvisionInstanceMetric()
        self.terminate_flag = 0

        self.metaConfigure = MetaConfigure()

	self.host_ip = self.metaConfigure._get_provision_host_ip() or '0.0.0.0'
	self.host_port = self.metaConfigure._get_provision_host_port() or 8675
	self.proxy_port = self.metaConfigure._get_proxy_port() or 8821
	self.report_online =self.metaConfigure._is_report_online()

	self.self_stopped = False
	self.httpd = make_server('', self.host_port, self.provision_monitor_app) 
	self.httpd.timeout = self.metaConfigure._get_http_timeout()

	self.proxy_data = ProvisionProxyMonitorData(host_port = self.host_port)

    def terminate_monitor(self):
	self.self_stopped = True
	self.join()

    def run(self):
	self.serve()

    def serve(self):
	print "Serving on port %d..." % self.host_port
	while not self.self_stopped:
	    self.httpd.handle_request()
	    if self.metaConfigure._is_debug():
		print 'handle one request or timeout ...'
	print "Stop monitor server..."
	#self.httpd.serve_forever()
  
    def provision_monitor_app(self, environ, start_response):  
	print 'one request coming'
        status = '200 OK' # HTTP Status  
        headers = [('Content-type', 'text/plain')] # HTTP Headers  
        start_response(status, headers) 

	proxy_req = urlparse.parse_qs(environ['QUERY_STRING'])
	print proxy_req.keys()
	if 'VMType' in proxy_req.keys():
	    if proxy_req['VMType'] == ['proxy'] and 'PublicIP' in proxy_req.keys() and 'CurTime' in proxy_req.keys():
		print "proxy private ip: %s" % self.proxy_data.priv_ip
		#if proxy_req['PrivateIP'][0] != self.proxy_data.priv_ip :
		if proxy_req['Key'][0] != self.proxy_data.key :
		    print "recieve old proxy vm connection: %s" % proxy_req
		    return ["Error: old provison proxy connection"]
		self.proxy_data.connected_with_proxy=True
		#if 'PrivateIP' in proxy_req.keys():
		#    self.proxy_data._set_pub_priv_ip(proxy_req['PublicIP'][0], proxy_req['PrivateIP'][0])
		#else:
		#    self.proxy_data._set_pub_ip(proxy_req['PublicIP'][0])
		
		monitor_base = time.time()
		self.proxy_data._sync_time(proxy_req['CurTime'][0], monitor_base)
		print self.proxy_data._get_info()
		print "hahhah, proxy connection is coming!!!!"
                return ["200 OK!!!%s" % monitor_base]

	    #if proxy_req['VMType'] == ['instance'] and 'VMStatus' in proxy_req.keys() and 'VMName' in proxy_req.keys() and  'VMIP' in proxy_req.keys() and 'Timestamp' in proxy_req.keys():
	    if proxy_req['VMType'] == ['instance'] and 'VMStatus' in proxy_req.keys() and 'VMName' in proxy_req.keys() and 'Timestamp' in proxy_req.keys():
		instance = self.instance_metric._get_instance_by_name(proxy_req['VMName'][0])
		if instance is None:
		    print 'can not find instance from metric'
		    print proxy_req['VMName']
		    return ["no found"]

		if proxy_req['VMStatus'][0] == 'BOOTED' :
		    ip_lease = 0
		    if 'IPLease' in proxy_req.keys():
			ip_lease = proxy_req['IPLease'][0]
		    ProvisionInstanceMetric()._update_instance(instance, "RUNNING", proxy_req['Timestamp'][0], ip_lease) #time.time())
		    print "instance[%s] has finished booted, booted time[%s], dhcp time:%s" % (proxy_req['VMName'], proxy_req['Timestamp'], str(proxy_req['IPLease'][0]))  
		elif proxy_req['VMStatus'][0] == 'DELETED' :
		    ProvisionInstanceMetric()._update_instance(instance, "DELETED", proxy_req['Timestamp'][0]) #time.time())
		    print "instance[%s] has been deleted, deleted time[%s]" % (proxy_req['VMName'], proxy_req['Timestamp'])  
                return ["200 OK"]
	
	return ["Error:(%s) do not include \'hostname\', \'ip\' and \'status[boot|terminate]\'" % environ['QUERY_STRING']]
    def __init__(self):
	threading.Thread.__init__(self)
	self.instance_metric = ProvisionInstanceMetric()
	self.self_stopped = 0

	self.metaConfigure = MetaConfigure()