mirror of https://git.48k.eu/ogcli/
Add ogcli list hardware command
This requests GET /hardware by calling something like: ogcli list hardware --scope-id=6 It is important to notice that 'scope-id' must be a "computer" type scope id.master
parent
e3d30d23ff
commit
f4e1bb767b
12
cli/cli.py
12
cli/cli.py
|
@ -48,16 +48,18 @@ class OgCLI():
|
|||
self.rest = OgREST(cfg['ip'], cfg['port'], cfg['api_token'])
|
||||
|
||||
def list(self, args):
|
||||
choices = ['clients', 'scopes', 'modes']
|
||||
choices = ['clients', 'scopes', 'modes', 'hardware']
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('item', choices=choices)
|
||||
args = parser.parse_args(args)
|
||||
parsed_args = parser.parse_args([args[0]])
|
||||
|
||||
if args.item == 'clients':
|
||||
if parsed_args.item == 'clients':
|
||||
OgClient.list_clients(self.rest)
|
||||
elif args.item == 'modes':
|
||||
elif parsed_args.item == 'hardware':
|
||||
OgClient.list_client_hardware(self.rest, args[1:])
|
||||
elif parsed_args.item == 'modes':
|
||||
OgModes.list_available_modes(self.rest)
|
||||
elif args.item == 'scopes':
|
||||
elif parsed_args.item == 'scopes':
|
||||
OgScope.list_scopes(self.rest)
|
||||
|
||||
def set(self, args):
|
||||
|
|
|
@ -6,9 +6,25 @@
|
|||
# Free Software Foundation, version 3.
|
||||
#
|
||||
|
||||
import argparse
|
||||
|
||||
class OgClient():
|
||||
|
||||
@staticmethod
|
||||
def list_clients(rest):
|
||||
r = rest.get('/clients')
|
||||
print(r.json())
|
||||
|
||||
@staticmethod
|
||||
def list_client_hardware(rest, args):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--scope-id',
|
||||
nargs=1,
|
||||
required=True,
|
||||
help='ID of the computer scope')
|
||||
parsed_args = parser.parse_args(args)
|
||||
|
||||
payload = {'scope': {'id': int(parsed_args.scope_id[0]),
|
||||
'type': 'computer'}}
|
||||
r = rest.get('/hardware', payload=payload)
|
||||
print(r.json())
|
||||
|
|
Loading…
Reference in New Issue