summaryrefslogtreecommitdiffstats
path: root/cli/objects/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects/client.py')
-rw-r--r--cli/objects/client.py69
1 files changed, 67 insertions, 2 deletions
diff --git a/cli/objects/client.py b/cli/objects/client.py
index c3ad760..d438742 100644
--- a/cli/objects/client.py
+++ b/cli/objects/client.py
@@ -6,9 +6,9 @@
# (at your option) any later version.
import argparse
+import requests
-from cli.utils import print_json
-
+from cli.utils import print_json, check_address, check_mac_address
class OgClient():
@@ -56,3 +56,68 @@ class OgClient():
payload = {'clients': parsed_args.client_ip}
rest.post('/refresh', payload=payload)
+
+ @staticmethod
+ def add_client(rest, args):
+ parser = argparse.ArgumentParser(prog='ogcli add client')
+ parser.add_argument('--repo-id',
+ type=int,
+ nargs='?',
+ required=True,
+ help='specify the id of the repo')
+ parser.add_argument('--netmask',
+ nargs='?',
+ required=True,
+ help='specify netmask address')
+ parser.add_argument('--room-id',
+ nargs='?',
+ type=int,
+ required=True,
+ help='specify the id of the room where the client is')
+ parser.add_argument('--hostname',
+ nargs='?',
+ required=True,
+ help='give a name to the client')
+ parser.add_argument('--mac',
+ nargs='?',
+ required=True,
+ help='mac address should have this format xx:xx:xx:xx:xx:xx')
+ parser.add_argument('--ip',
+ nargs='?',
+ required=True,
+ help='specify the ip address of the client')
+ r = rest.get('/mode')
+ boot_choices = r.json()['modes']
+ parser.add_argument('--boot-mode',
+ nargs='?',
+ required=True,
+ choices=boot_choices,
+ help='set a valid boot mode for the client')
+ parsed_args = parser.parse_args(args)
+
+ err = False
+ if not check_address(parsed_args.netmask):
+ print('netmask address is not valid', file=sys.stderr)
+ err = True
+ if not check_address(parsed_args.ip):
+ print('client\'s ip address is not valid', file=sys.stderr)
+ err = True
+ if not check_mac_address(parsed_args.mac):
+ print('client\'s mac address is not valid', file=sys.stderr)
+ err = True
+ if err:
+ parser.print_help(file=sys.stderr)
+ sys.exit(1)
+ payload = {
+ 'name': parsed_args.hostname,
+ 'netmask': parsed_args.netmask,
+ 'ip': parsed_args.ip,
+ 'mac': parsed_args.mac.replace(":", ""),
+ 'repo_id': parsed_args.repo_id,
+ 'room': parsed_args.room_id,
+ 'boot': parsed_args.boot_mode,
+ 'netiface': 'eth0',
+ 'netdriver': 'generic',
+ 'livedir': 'ogLive'
+ }
+ rest.post('/client/add', payload=payload)