Ejemplo n.º 1
0
def main():
    payload = encode(
        'get_tar_archive',
        url=
        "https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-arm64.tar.gz",
        digest=
        "796372ef8966182ac87b927c8b97ed05ff0856f54e82a9c9bc35464cd87dbe32",
        binaries=['prometheus', 'promtool'],
    )
    print(payload)
    call(payload)
Ejemplo n.º 2
0
 def sync_requests(topic):
     try:
         options = rpc.call(topic, {}, 'sync_request')
         with open(CONF.get('option_file'), 'w') as f:
             yaml.safe_dump(options, f)
         raise LoopingCallDone()
     except IOError as e:
         LOG.error(e)
Ejemplo n.º 3
0
 def sync_requests(topic):
     try:
         options = rpc.call(topic, {}, 'sync_request')
         with open(CONF.get('option_file'), 'w') as f:
             yaml.safe_dump(options, f)
         raise LoopingCallDone()
     except:
         LOG.warn("timeout to connect to server.")
Ejemplo n.º 4
0
def client_init():
    thread.start_new_thread(rpc.Service(CONF.get('client_topic'),
                                [endpoints.ServerClient(),]).start,())

    # Need to change the sync strategy.
    kwargs = {'hostname': hostname}
    options = rpc.call(topic=CONF.get('server_topic'), ctxt={}, method='get_option', **kwargs)
    with open(CONF.get('option_file'), 'w') as f:
        yaml.safe_dump({'configurations': options}, f)
Ejemplo n.º 5
0
def main() -> None:
    cmd = sys.argv[1]

    if cmd == "call":
        rpc.call(*sys.argv[2:])

    elif cmd == "rpc-step":
        payload = sys.argv[2]
        encoded = run_step("rpc-step", payload)
        sys.stdout.write(encoded)

    elif cmd == "stdin-rpc":
        payload = sys.argv[2]
        decoded = b64decode(payload)
        steps = pickle.loads(decoded)

        results = []

        for step in steps:
            user = step['user']
            msg = step['payload']
            current_user = check_output(["id", "--user",
                                         "--name"]).decode().strip()

            step_payload = b64encode(pickle.dumps(msg, 0)).decode()

            args = ["python3", sys.argv[0], "rpc-step", step_payload]

            if user is not None and user != current_user:
                args = ["sudo", "-u", user] + args
                with timeit("rpc-step"):
                    result = check_output(args).decode()
                results.append(result)

            else:
                with timeit("rpc-int"):
                    result = run_step("rpc-int", step_payload)
                results.append(result)

        sys.stdout.write(",".join(results))

    else:
        assert 0, "unknown command"
Ejemplo n.º 6
0
def main():
    """Main entry point to script."""

    # Tell rpc module our name
    rpc.ZIPNAME = 'example'

    # Process command line options
    usage = 'Usage: %prog HOST'
    description = """\
    rpc.py Example
    """
    parser = optparse.OptionParser(usage=usage, description=description)
    parser.add_option(
        '-r', '--rpc', dest='rpc', action='store_true', default=False,
        help='RPC mode: expect serialized functions on stdin')

    options, args = parser.parse_args()

    # Redirect to RPC mode if requested -- this is how the script will
    # be invoked remotely, so process it before worrying about other
    # arguments, positional parameters, etc.
    if options.rpc:
        rpc.server_loop()
        sys.exit(0)

    if len(args) != 1:
        parser.print_usage()
        sys.exit(1)
    host = args[0]

    # Connect to the specified host
    rpc.add('hello_host', host)

    # The function that we will run remotely
    def hello_world():
        # Uncomment this and see what happens!
        #1 / 0

        # Return the hostname so we have proof of remote execution
        return socket.gethostname()

    # Now call it and print the results
    result = rpc.call('hello_host', hello_world)
    print "Received `%s' from host %s" % (result, host)
Ejemplo n.º 7
0
import rpc
TOPIC = 'sendout_request'

msg = {'method': 'add', 'args': {'v1': 2, 'v2': 3}}
rval = rpc.call(TOPIC, msg)
print('Succeed implementing RPC call. the return value is %d.\n' % rval)
Ejemplo n.º 8
0
taskManager = task_manager.TaskManager()


class ServerListener(object):
    
    version = '1.0'
    
    def __init__(self, topic, endpoints):
        self.hostname = socket.gethostname()
        self.topic = topic 
        self.transport = messaging.get_transport(cfg.CONF)
        self.target = messaging.Target(topic=self.topic, server=self.hostname, version=self.version)
        self.endpoints = endpoints 
        self.server = messaging.get_rpc_server(self.transport, self.target, self.endpoints)
        
    def start(self):
        self.server.start()
        
    def stop(self):
        self.server.stop()
        
# pool = eventlet.GreenPool()
# pool.spawn(ServerListener('test',[server_sync.MasterServerSync(),]).start)
# pool.spawn(ServerListener('test1',[server_sync.MasterServerSync(),]).start)
# pool.waitall()

kwargs0={'topic_':'test'}
kwargs1={'topic_':'test1'}
print rpc.call(topic='test',ctxt={},method='option_add',server='huwei-X230',**kwargs1)
print rpc.call(topic='test1',ctxt={},method='option_add',**kwargs1)
Ejemplo n.º 9
0
import rpc
TOPIC = 'sendout_request'

msg = {'method': 'add',
       'args':{'v1':2, 'v2':3}}
rval = rpc.call(TOPIC, msg)
print('Succeed implementing RPC call. the return value is %d.\n' % rval)


Ejemplo n.º 10
0
# -*- coding: utf-8 -*-
##
# RPC调用请求客户端的启动脚本
##
import rpc
# 主题
TOPIC = 'sendout_request'

# 消息体
msg = {
    'method': 'add',  # RPC调用的方法名
    'args': {
        'v1': 2,
        'v2': 3
    }
}  # 参数列表
rval = rpc.call(TOPIC, msg)  # 发送rpc.call请求
print('Succeed implementing RPC call. the return value is %d.\n' % rval)