projects
/
osm
/
osmclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
proper handling of http_codes in http.post_cmd
[osm/osmclient.git]
/
osmclient
/
sol005
/
vim.py
diff --git
a/osmclient/sol005/vim.py
b/osmclient/sol005/vim.py
index
8a0b11a
..
8aee453
100644
(file)
--- a/
osmclient/sol005/vim.py
+++ b/
osmclient/sol005/vim.py
@@
-22,6
+22,7
@@
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
import yaml
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
import yaml
+import json
class Vim(object):
class Vim(object):
@@
-49,8
+50,10
@@
class Vim(object):
vim_account['config'] = vim_config
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)
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))
if not resp or 'id' not in resp:
raise ClientException('failed to create vim {}: {}'.format(
name, resp))
@@
-59,13
+62,16
@@
class Vim(object):
def update(self, vim_name, vim_account):
vim = self.get(vim_name)
def update(self, vim_name, vim_account):
vim = self.get(vim_name)
- resp = self._http.put_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)
postfields_dict=vim_account)
- if not resp or '_id' not in resp:
- raise ClientException('failed to update vim: '.format(
- resp))
+ 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))
else:
else:
- print resp['
_
id']
+ print resp['id']
def update_vim_account_dict(self, vim_account, vim_access):
vim_account['vim_type'] = vim_access['vim-type']
def update_vim_account_dict(self, vim_account, vim_access):
vim_account['vim_type'] = vim_access['vim-type']
@@
-88,8
+94,11
@@
class Vim(object):
vim_id = vim_name
if not utils.validate_uuid4(vim_name):
vim_id = self.get_id(vim_name)
vim_id = vim_name
if not utils.validate_uuid4(vim_name):
vim_id = self.get_id(vim_name)
- resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vim_id))
- if resp is None:
+ http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase,vim_id))
+ #print 'RESP: {}'.format(resp)
+ if http_code == 202:
+ print 'Deletion in progress'
+ elif http_code == 204:
print 'Deleted'
else:
raise ClientException("failed to delete vim {} - {}".format(vim_name, resp))
print 'Deleted'
else:
raise ClientException("failed to delete vim {} - {}".format(vim_name, resp))