@click.option('--description',
default='no description',
help='human readable description')
+@click.option('--sdn_controller', default=None, help='Name or id of the SDN controller associated to this VIM account')
+@click.option('--sdn_port_mapping', default=None, help="File describing the port mapping between compute nodes' ports and switch ports")
@click.pass_context
def vim_create(ctx,
name,
tenant,
config,
account_type,
- description):
+ description,
+ sdn_controller,
+ sdn_port_mapping):
'''creates a new VIM account
'''
- vim = {}
- vim['vim-username'] = user
- vim['vim-password'] = password
- vim['vim-url'] = auth_url
- vim['vim-tenant-name'] = tenant
- vim['config'] = config
- vim['vim-type'] = account_type
- vim['description'] = description
try:
- ctx.obj.vim.create(name, vim)
+ if sdn_controller:
+ check_client_version(ctx.obj, '--sdn_controller')
+ if sdn_port_mapping:
+ check_client_version(ctx.obj, '--sdn_port_mapping')
+ vim = {}
+ vim['vim-username'] = user
+ vim['vim-password'] = password
+ vim['vim-url'] = auth_url
+ vim['vim-tenant-name'] = tenant
+ vim['vim-type'] = account_type
+ vim['description'] = description
+ vim ['config'] = config
+ if sdn_controller or sdn_port_mapping:
+ ctx.obj.vim.create(name, vim, sdn_controller, sdn_port_mapping)
+ else:
+ ctx.obj.vim.create(name, vim)
except ClientException as inst:
print(inst.message)
exit(1)
@click.option('--tenant', help='VIM tenant name')
@click.option('--config', help='VIM specific config parameters')
@click.option('--account_type', help='VIM type')
-@click.option('--sdn_controller', help='Name or id of the SDN controller associated to this VIM account')
-@click.option('--sdn_port_mapping', default=None, help="File describing the port mapping between compute nodes' ports and switch ports")
@click.option('--description', help='human readable description')
+@click.option('--sdn_controller', default=None, help='Name or id of the SDN controller associated to this VIM account')
+@click.option('--sdn_port_mapping', default=None, help="File describing the port mapping between compute nodes' ports and switch ports")
@click.pass_context
def vim_update(ctx,
name,
tenant,
config,
account_type,
- description):
+ description,
+ sdn_controller,
+ sdn_port_mapping):
'''updates a VIM account
NAME: name or ID of the VIM account
'''
- vim = {}
- if newname: vim['name'] = newname
- if user: vim['vim_user'] = user
- if password: vim['vim_password'] = password
- if auth_url: vim['vim_url'] = auth_url
- if tenant: vim['vim-tenant-name'] = tenant
- if account_type: vim['vim_type'] = account_type
- if description: vim['description'] = description
- config_dict = {}
- if config is not None:
- if config=="" and (sdncontroller or sdn_port_mapping):
- raise ClientException("clearing config is incompatible with updating SDN info")
- if config=="":
- vim['config'] = None
- else:
- config_dict = yaml.safe_load(config)
- if sdn_controller: config_dict['sdn_controller'] = sdn_controller
- if sdn_port_mapping:
- with open(sdn_port_mapping, 'r') as f:
- config_dict['sdn_port_mapping'] = yaml.safe_load(f.read())
- if 'config' not in vim and config_dict:
- vim['config'] = yaml.safe_dump(config_dict)
try:
check_client_version(ctx.obj, ctx.command.name)
- ctx.obj.vim.update(name, vim)
+ vim = {}
+ if newname: vim['name'] = newname
+ if user: vim['vim_user'] = user
+ if password: vim['vim_password'] = password
+ if auth_url: vim['vim_url'] = auth_url
+ if tenant: vim['vim-tenant-name'] = tenant
+ if account_type: vim['vim_type'] = account_type
+ if description: vim['description'] = description
+ if config: vim['config'] = config
+ ctx.obj.vim.update(name, vim, sdn_controller, sdn_port_mapping)
except ClientException as inst:
print(inst.message)
exit(1)
if ro_host is None:
ro_host = host
- ro_http_client = http.Http('http://{}:{}/'.format(ro_host, ro_port))
+ ro_http_client = http.Http('http://{}:{}/openmano'.format(ro_host, ro_port))
ro_http_client.set_http_header(
- ['Accept: application/vnd.yand.data+json',
+ ['Accept: application/json',
'Content-Type: application/json'])
self._http_client = http.Http(
data = BytesIO()
curl_cmd = self._get_curl_cmd(endpoint)
if put_method:
- curl_cmd.setopt(pycurl.PUT, 1)
+ curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PUT")
elif patch_method:
curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PATCH")
- else:
- curl_cmd.setopt(pycurl.POST, 1)
+ curl_cmd.setopt(pycurl.POST, 1)
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
if postfields_dict is not None:
def update(self, name, sdn_controller):
sdnc = self.get(name)
- http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
+ http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
postfields_dict=sdn_controller)
if resp:
resp = json.loads(resp)
self._apiResource = '/vims'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
- def create(self, name, vim_access):
+ def create(self, name, vim_access, sdn_controller, sdn_port_mapping):
if 'vim-type' not in vim_access:
#'openstack' not in vim_access['vim-type']):
raise Exception("vim type not provided")
vim_account = {}
- vim_config = {'hello': 'hello'}
vim_account['name'] = name
vim_account = self.update_vim_account_dict(vim_account, vim_access)
vim_config = {}
if 'config' in vim_access and vim_access['config'] is not None:
- vim_config = yaml.load(vim_access['config'])
-
- vim_account['config'] = vim_config
+ vim_config = json.loads(vim_access['config'])
+ if sdn_controller:
+ sdnc = self._client.sdnc.get(sdn_controller)
+ vim_config['sdn-controller'] = sdnc['_id']
+ if sdn_port_mapping:
+ with open(sdn_port_mapping, 'r') as f:
+ vim_config['sdn-port-mapping'] = yaml.safe_load(f.read())
+ if vim_config:
+ vim_account['config'] = vim_config
+ #vim_account['config'] = json.dumps(vim_config)
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=vim_account)
+ #print 'HTTP CODE: {}'.format(http_code)
+ #print 'RESP: {}'.format(resp)
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
else:
print resp['id']
- def update(self, vim_name, vim_account):
+ def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping):
vim = self.get(vim_name)
- #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']),
+
+ vim_config = {}
+ if 'config' in vim_account:
+ if config=="" and (sdncontroller or sdn_port_mapping):
+ raise ClientException("clearing config is incompatible with updating SDN info")
+ if config=="":
+ vim_config = None
+ else:
+ vim_config = json.loads(vim_account['config'])
+ if sdn_controller:
+ sdnc = self._client.sdnc.get(sdn_controller)
+ vim_config['sdn-controller'] = sdnc['_id']
+ if sdn_port_mapping:
+ with open(sdn_port_mapping, 'r') as f:
+ vim_config['sdn-port-mapping'] = yaml.safe_load(f.read())
+ vim_account['config'] = vim_config
+ #vim_account['config'] = json.dumps(vim_config)
+ http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
postfields_dict=vim_account)
+ #print 'HTTP CODE: {}'.format(http_code)
+ #print 'RESP: {}'.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: