mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
python: add some missing API endpoints
This commit is contained in:
parent
b3f88de57c
commit
1fe51399f1
2 changed files with 27 additions and 13 deletions
|
@ -7,7 +7,7 @@ with open('README.md') as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='villas-node',
|
name='villas-node',
|
||||||
version='0.10.1',
|
version='0.10.2',
|
||||||
author='Steffen Vogel',
|
author='Steffen Vogel',
|
||||||
author_email='acs-software@eonerc.rwth-aachen.de',
|
author_email='acs-software@eonerc.rwth-aachen.de',
|
||||||
description='Python-support for VILLASnode simulation-data gateway',
|
description='Python-support for VILLASnode simulation-data gateway',
|
||||||
|
|
|
@ -70,9 +70,7 @@ class Node(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def active_config(self):
|
def active_config(self):
|
||||||
resp = self.request('config')
|
return self.request('config')
|
||||||
|
|
||||||
return resp
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nodes(self):
|
def nodes(self):
|
||||||
|
@ -82,17 +80,33 @@ class Node(object):
|
||||||
def paths(self):
|
def paths(self):
|
||||||
return self.request('paths')
|
return self.request('paths')
|
||||||
|
|
||||||
def request(self, action, req=None):
|
@property
|
||||||
args = {
|
def status(self):
|
||||||
'timeout': 1
|
return self.request('status')
|
||||||
|
|
||||||
|
def load_config(self, i):
|
||||||
|
if type(i) is dict:
|
||||||
|
cfg = i
|
||||||
|
elif type(i) is str:
|
||||||
|
cfg = json.loads(i)
|
||||||
|
elif hasattr(i, 'read'): # file-like?
|
||||||
|
cfg = json.load(i)
|
||||||
|
else:
|
||||||
|
raise TypeError()
|
||||||
|
|
||||||
|
req = {
|
||||||
|
'config': cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
if req is not None:
|
self.request('restart', method='POST', json=req)
|
||||||
args['json'] = req
|
|
||||||
|
|
||||||
r = requests.get(
|
def request(self, action, method='GET', **args):
|
||||||
|
|
||||||
|
if 'timeout' not in args:
|
||||||
|
args['timeout'] = 1
|
||||||
|
|
||||||
|
r = requests.request(method,
|
||||||
f'{self.api_url}/api/{self.api_version}/{action}', **args)
|
f'{self.api_url}/api/{self.api_version}/{action}', **args)
|
||||||
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
return r.json()
|
return r.json()
|
||||||
|
@ -103,9 +117,9 @@ class Node(object):
|
||||||
return ver.decode('ascii').rstrip()
|
return ver.decode('ascii').rstrip()
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
resp = self.request('capabilities')
|
resp = self.request('status')
|
||||||
|
|
||||||
return resp['build']
|
return resp['version']
|
||||||
|
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
if self.child is None:
|
if self.child is None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue