Files
python-tackerclient/tackerclient/tacker/v1_0/nfvo/vim_utils.py
Cong Phuoc Hoang 6f1792b490 Implement client to support Kubernetes as VIM
This patch will add changes to support Kubernetes as VIM feature
in python-tackerclient.

After this change, user have to provide VIM type in VIM config file
when creating or updating VIM. The default VIM type is openstack.

Partially Implements: blueprint kubernetes-as-vim

Change-Id: I1b1610cb89a78a2a8fe134265b83dd469d72fdcd
2017-10-30 17:13:40 +09:00

86 lines
3.5 KiB
Python

# Copyright 2016 Brocade Communications Systems Inc
# All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import six.moves.urllib.parse as urlparse
from tackerclient.common import exceptions
def args2body_vim(config_param, vim):
"""Create additional args to vim body
:param vim: vim request object
:return: vim body with args populated
"""
vim_type = ['openstack', 'kubernetes']
if 'type' in config_param:
vim['type'] = config_param.pop('type', '')
if not vim['type'] in vim_type:
raise exceptions.TackerClientException(
message='Supported VIM types: openstack, kubernetes',
status_code=400)
else:
vim['type'] = 'openstack'
if vim['type'] == 'openstack':
vim['vim_project'] = {
'name': config_param.pop('project_name', ''),
'project_domain_name':
config_param.pop('project_domain_name', '')}
if not vim['vim_project']['name']:
raise exceptions.TackerClientException(
message='Project name must be specified',
status_code=404)
vim['auth_cred'] = {'username': config_param.pop('username', ''),
'password': config_param.pop('password', ''),
'user_domain_name':
config_param.pop('user_domain_name', '')}
elif vim['type'] == 'kubernetes':
vim['vim_project'] = {
'name': config_param.pop('project_name', '')}
if not vim['vim_project']['name']:
raise exceptions.TackerClientException(
message='Project name must be specified in Kubernetes VIM,'
'it is namespace in Kubernetes environment',
status_code=404)
if ('username' in config_param) and ('password' in config_param):
vim['auth_cred'] = {
'username': config_param.pop('username', ''),
'password': config_param.pop('password', '')}
elif 'bearer_token' in config_param:
vim['auth_cred'] = {
'bearer_token': config_param.pop('bearer_token', '')}
else:
raise exceptions.TackerClientException(
message='username and password or bearer_token must be'
'provided',
status_code=404)
if 'ssl_ca_cert' in config_param:
ssl_ca_cert = config_param.pop('ssl_ca_cert', '')
if ssl_ca_cert == 'None':
vim['auth_cred']['ssl_ca_cert'] = None
else:
vim['auth_cred']['ssl_ca_cert'] = ssl_ca_cert
else:
raise exceptions.TackerClientException(
message='ssl_ca_cert must be provided or leave it with None',
status_code=404)
def validate_auth_url(url):
url_parts = urlparse.urlparse(url)
if not url_parts.scheme or not url_parts.netloc:
raise exceptions.TackerClientException(message='Invalid auth URL')
return url_parts