from osmclient.sol005 import http
from osmclient.sol005 import sdncontroller
from osmclient.common.exceptions import ClientException
+import json
class Client(object):
postfields_dict = {'username': self._user,
'password': self._password,
'project-id': self._project}
- token = self._http_client.post_cmd(endpoint=self._auth_endpoint,
+ http_code, resp = self._http_client.post_cmd(endpoint=self._auth_endpoint,
postfields_dict=postfields_dict)
+ if http_code not in (200, 201, 202, 204):
+ raise ClientException(resp)
+ token = json.loads(resp) if resp else None
if token is not None:
return token['_id']
return None
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
curl_cmd.close()
- if http_code not in (200, 201, 202, 204):
- raise ClientException(data.getvalue().decode())
- if postfields_dict is not None:
- if data.getvalue():
- return json.loads(data.getvalue().decode())
- return None
- elif formfile is not None:
- if data.getvalue():
- return yaml.safe_load(data.getvalue().decode())
- return None
- elif filename is not None:
- if data.getvalue():
- return yaml.safe_load(data.getvalue().decode())
- return None
- return None
+ if data.getvalue():
+ return http_code, data.getvalue().decode()
+ else:
+ return http_code, None
def post_cmd(self, endpoint='', postfields_dict=None,
formfile=None, filename=None):
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
curl_cmd.close()
if data.getvalue():
- return http_code, data.getvalue()
+ return http_code, data.getvalue().decode()
return http_code, None
self._apiResource = '/ns_instances_content'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
- resp = self._http.post_cmd(endpoint=self._apiBase,
+ http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=ns)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp or 'id' not in resp:
raise ClientException('unexpected response from server: '.format(
filter_string = '&{}'.format(filter)
http_code, resp = self._http.get2_cmd('{}?nsInstanceId={}'.format(self._apiBase, ns['_id'],
filter_string) )
- resp = json.loads(resp.decode())
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if http_code == 200:
return resp
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
http_code, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, operationId))
- resp = json.loads(resp.decode())
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if http_code == 200:
return resp
endpoint = '{}/{}/{}'.format(self._apiBase, ns['_id'], op_name)
#print 'OP_NAME: {}'.format(op_name)
#print 'OP_DATA: {}'.format(json.dumps(op_data))
- resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
+ http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp or 'id' not in resp:
raise ClientException('unexpected response from server: '.format(
data["create_alarm_request"] = {}
data["create_alarm_request"]["alarm_create_request"] = alarm
try:
- resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
+ http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp:
raise ClientException('unexpected response from server: '.format(
data["delete_alarm_request"]["alarm_delete_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"]["alarm_uuid"] = name
try:
- resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
+ http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp:
raise ClientException('unexpected response from server: '.format(
data = {}
data["read_metric_data_request"] = metric
try:
- resp = self._http.post_cmd(endpoint='/test/message/metric_request',
+ http_code, resp = self._http.post_cmd(endpoint='/test/message/metric_request',
postfields_dict=data)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp:
raise ClientException('unexpected response from server: '.format(
from osmclient.common.exceptions import ClientException
from osmclient.common import utils
import yaml
+import json
import magic
#from os import stat
#from os.path import basename
nsd = self.get(name)
headers = self._client._headers
headers['Accept'] = 'application/binary'
- http_code, resp2 = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing))
+ http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing))
#print yaml.safe_dump(resp2)
- if resp2:
+ if resp:
#store in a file
- return resp2
+ return resp
raise NotFound("nsd {} not found".format(name))
def get_descriptor(self, name, filename):
for (key,val) in headers.items()]
self._http.set_http_header(http_header)
if update_endpoint:
- resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
+ http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
else:
ow_string = ''
if overwrite:
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
endpoint = '{}{}'.format(self._apiBase,ow_string)
- resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ if resp:
+ resp = json.loads(resp)
#print resp
if not resp or 'id' not in resp:
raise ClientException("failed to upload package")
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
+import json
class Package(object):
http_header = ['{}: {}'.format(key,val)
for (key,val) in headers.items()]
self._http.set_http_header(http_header)
- resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(yaml.safe_dump(resp))
if not resp or 'id' not in resp:
raise ClientException("failed to upload package")
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
-import yaml
+import yaml
+import json
class SdnController(object):
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
def create(self, name, sdn_controller):
- resp = self._http.post_cmd(endpoint=self._apiBase,
+ http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=sdn_controller)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp or 'id' not in resp:
raise ClientException('failed to create SDN controller: '.format(
def update(self, name, sdn_controller):
sdnc = self.get(name)
- resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
+ http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
postfields_dict=sdn_controller)
+ if resp:
+ resp = json.loads(resp)
print 'RESP: {}'.format(resp)
if not resp or 'id' not in resp:
raise ClientException('failed to update SDN controller: '.format(
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
import yaml
+import json
class Vim(object):
vim_account['config'] = vim_config
- resp = self._http.post_cmd(endpoint=self._apiBase,
+ http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=vim_account)
+ if resp:
+ resp = json.loads(resp)
if not resp or 'id' not in resp:
raise ClientException('failed to create vim {}: {}'.format(
name, resp))
def update(self, vim_name, vim_account):
vim = self.get(vim_name)
- #resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
- resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
+ #http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
+ http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
postfields_dict=vim_account)
+ if resp:
+ resp = json.loads(resp)
#print 'RESP: {}'.format(resp)
if not resp or 'id' not in resp:
raise ClientException('failed to update vim: '.format(resp))
from osmclient.common.exceptions import ClientException
from osmclient.common import utils
import yaml
+import json
import magic
#from os import stat
#from os.path import basename
vnfd = self.get(name)
headers = self._client._headers
headers['Accept'] = 'application/binary'
- http_code, resp2 = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing))
+ http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing))
#print yaml.safe_dump(resp2)
- if resp2:
+ if resp:
#store in a file
- return resp2
+ return resp
raise NotFound("vnfd {} not found".format(name))
def get_descriptor(self, name, filename):
for (key,val) in headers.items()]
self._http.set_http_header(http_header)
if update_endpoint:
- resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
+ http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
else:
ow_string = ''
if overwrite:
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
endpoint = '{}{}'.format(self._apiBase,ow_string)
- resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ if resp:
+ resp = json.loads(resp)
#print resp
if not resp or 'id' not in resp:
raise ClientException("failed to upload package")