add some logging

parent 8ad5c373
Pipeline #90271 passed with stages
in 1 minute and 58 seconds
import json
import copy
import logging
import requests
class Distem:
def __init__(self, serveraddr="localhost", port=4567):
def __init__(self, *, serveraddr="localhost", port=4567):
self.serveraddr = serveraddr
self.port = port
self.client = requests.Session()
......@@ -15,10 +16,10 @@ class Distem:
Args:
name(str) The name of the virtual network (unique) address(str) The
address (CIDR format: 10.0.8.0/24) the virtual network will work
with options(dict) used to store vxlan_id and number of PNODES
(should not be used directly)
name (str): The name of the virtual network (unique) address(str) The
addres (str): address in CIDR format (e.g 10.0.8.0/24)
opts (dict): used to store vxlan_id and number of PNODES
(should not be used directly)
Returns:
{dict} The virtual network description
......@@ -119,31 +120,30 @@ class Distem:
return self.post_json("/vnodes/%s" % (name), data=data)
def vnode_start(self, vnodename):
"""
Start a virtual node.
def vnode_start(self, vnodename, *, async=False):
"""Start a virtual node.
A physical node (that have enought physical resources (CPU,...))
will be automatically allocated if there is none set as +host+ at
the moment The filesystem archive will be copied on the hosting
physical node. A filesystem image *must* have been set (see
{#vnode_create} or {#vfilesystem_create}/{#vfilesystem_update}).
A physical node (that have enough physical resources (CPU,...))
will be automatically allocated if there is none set as +host+ at
the moment The filesystem archive will be copied on the hosting
physical node. A filesystem image *must* have been set (see
{#vnode_create} or {#vfilesystem_create}/{#vfilesystem_update}).
Args:
vnodename(str) The name of the virtual node
async(Boolean) Asynchronious mode, check virtual node status to know
when node is configured (see {#vnode_info})
vnodename (str): The name of the virtual node
async (bool): Asynchronious mode, check virtual node status to know
when node is configured (see {#vnode_info})
Returns:
{dict} The virtual node description
dict of the virtual node description
see :desc:`resources description<>`
"""
desc = {
"desc": {"name": str(vnodename), "status": "RUNNING"},
"type": "update",
"async": False,
"async": async,
}
return self.put_json("/vnodes/%s" % (str(vnodename)), data=desc)
......@@ -786,6 +786,7 @@ class Distem:
)
def raw_request(self, method, route, data):
logging.debug("method=%s, route=%s, data=%s", method, route, data)
result = ""
_data = copy.deepcopy(data)
for key, value in data.items():
......@@ -803,4 +804,5 @@ class Distem:
result = response.text
return result
else:
raise Exception(response.headers["X-Application-Error-Code"])
err = response.headers.get("X-Application-Error-Code", "Unknown error")
raise Exception(err)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment