Exemple #1
0
def get_client(method, url):
    url = 'https://%s:8443/manor/cli/%s' % (generals.get_ip(), url)
    request = httpclient.HTTPRequest(url=url,
                                     method=method,
                                     validate_cert=False)
    client = httpclient.HTTPClient()
    return client, request
def get_state_count():
    url='wss://%s:8443/manor/socket/app/status'%generals.get_ip()
    request=HTTPRequest(url=url,validate_cert=False)
    conn=yield websocket_connect(request)
    try:
        normal=0
        failure=0
        apps=yield DBUtil().query("SELECT * FROM manor.manor_app_instance")
        for app in apps:
            if app['state']=='normal':
                print app
                conn.write_message(json.dumps({
                    "app_serial":app['app_serial']
                }))
                msg=yield conn.read_message()
                status=json.loads(msg)['status']
                while status=='working':
                    yield gen.sleep(1)
                    msg=yield conn.read_message()
                    status=json.loads(msg)['status']
                if status in ['normal','part','offline']:
                    normal+=1
                else:
                    failure+=1
            else:
                failure+=1
        conn.close()

        logging.getLogger('manor').debug({'normal':normal,'failure':failure})
    except:
        logging.getLogger('manor').error(generals.trace())
        conn.close()

    raise gen.Return({'normal':normal,'failure':failure})
Exemple #3
0
#!/usr/bin/env python
import argparse
import json

from tornado import gen,ioloop
from tornado.httpclient import HTTPRequest
from tornado.websocket import websocket_connect
from manor.util import generals

url='wss://%s:8443/manor/socket/app/status'%generals.get_ip()
pars=argparse.ArgumentParser()
pars.add_argument('-serial',
                  required=True,
                  help='the serial number of application.',
                  nargs='?',
                  const=True,
                  default=False)
args=pars.parse_args()
serial=args.serial


@gen.coroutine
def main():
    request=HTTPRequest(url=url,validate_cert=False)
    conn=yield websocket_connect(request)
    conn.write_message(json.dumps({
        "app_serial":serial
    }))
    while True:
        msg=yield conn.read_message()
        print '------------------------------------------------------------'