You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@warble.apache.org by hu...@apache.org on 2018/06/26 16:32:28 UTC

[incubator-warble-server] 03/03: add a super simple cli tool for manual ops for now

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 6b6bed29bab6694c316ba32e2ab7cce62e2ffede
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 11:32:18 2018 -0500

    add a super simple cli tool for manual ops for now
---
 tools/cli.py | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/tools/cli.py b/tools/cli.py
new file mode 100644
index 0000000..1f29c7e
--- /dev/null
+++ b/tools/cli.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+ #the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+This is the CLI testing script for Apache Warble (incubating)
+"""
+_VERSION = '0.1.0'
+
+# Basic imports
+import os
+import sys
+import stat
+import time
+import ruamel.yaml
+import requests
+import datetime
+import argparse
+import socket
+import base64
+
+if __name__ == "__main__":
+    
+    parser = argparse.ArgumentParser(description = "Run-time configuration options for Apache Warble (incubating)")
+    parser.add_argument('--version', action = 'store_true', help = 'Print node version and exit')
+    parser.add_argument('--test', action = 'store_true', help = 'Run debug unit tests')
+    parser.add_argument('--wait', action = 'store_true', help = 'Wait for node to be fully registered on server before continuing')
+    parser.add_argument('--config', type = str, help = 'Load a specific configuration file')
+    args = parser.parse_args()
+    
+    user = input("Enter super user name: ").strip()
+    pw = input("Enter super user password: ").strip()
+    
+    rv = requests.put('http://localhost:8000/api/session', json = {
+        'username': user,
+        'password': pw
+    })
+    if rv.status_code == 200:
+        print("Logged in successfully!")
+        cookie = rv.headers['set-cookie']
+        
+        while True:
+            cmd = input("?> ").strip()
+            if cmd == 'exit':
+                print("bye bye!")
+                sys.exit(0)
+            if cmd == 'nodes':
+                rv = requests.get('http://localhost:8000/api/node/list',  headers = {
+                    'Cookie': cookie
+                    })
+                nodes = rv.json()['nodes']
+                
+                print("Nodes in registry:")
+                print("[ id ]  [          hostname        ]  [ enabled ]  [ verified ]  [        fingerprint         ]")
+                for node in nodes:
+                    print("  %3u    %-28s     %s            %s          %s" %  (node['id'], node['hostname'][:27], node['enabled'] and '✓' or 'x', node['verified'] and '✓' or 'x', node['fingerprint'][:28]))
+                
+            if 'verify' in cmd:
+                nodeid = int(cmd.replace('verify ', ''))
+                print("Verifying node no. %u" % nodeid)
+                rv = requests.post('http://localhost:8000/api/node/modify',  headers = {
+                    'Cookie': cookie
+                    },
+                    json = {
+                        'id': nodeid,
+                        'verified': True
+                    }
+                    )
+                if rv.status_code == 200:
+                    print("Node successfully verified!")
+                else:
+                    print(rv.text)
+            
+            if 'enable' in cmd:
+                nodeid = int(cmd.replace('enable ', ''))
+                print("Enabling node no. %u" % nodeid)
+                rv = requests.post('http://localhost:8000/api/node/modify',  headers = {
+                    'Cookie': cookie
+                    },
+                    json = {
+                        'id': nodeid,
+                        'enabled': True
+                    }
+                    )
+                if rv.status_code == 200:
+                    print("Node successfully enabled!")
+                else:
+                    print(rv.text)
+            
+            if 'disable' in cmd:
+                nodeid = int(cmd.replace('disable ', ''))
+                print("Disabling node no. %u" % nodeid)
+                rv = requests.post('http://localhost:8000/api/node/modify',  headers = {
+                    'Cookie': cookie
+                    },
+                    json = {
+                        'id': nodeid,
+                        'enabled': False
+                    }
+                    )
+                if rv.status_code == 200:
+                    print("Node successfully disabled!")
+                else:
+                    print(rv.text)
+    else:
+        print("log in failed!")
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org