Clean up licensing code
Remove "system license-list" command, replace with "system license-show" The new system license-show command shows the content of the license file Remove any validation and interpretation of license file. Partial-Bug: 1845522 Change-Id: I9dfb765d300e86eae1c554703e8e3e4f088d87b7 Signed-off-by: Bin Qian <bin.qian@windriver.com>
This commit is contained in:
parent
5e57232803
commit
54f164a193
|
@ -253,6 +253,15 @@ start()
|
||||||
rm -f $VOLATILE_CONFIG_PASS
|
rm -f $VOLATILE_CONFIG_PASS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e $CONFIG_DIR/.license ]
|
||||||
|
then
|
||||||
|
cp $CONFIG_DIR/.license /etc/platform/.license
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
fatal_error "Unable to copy $CONFIG_DIR/.license"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -e $CONFIG_DIR/server-cert.pem ]
|
if [ -e $CONFIG_DIR/server-cert.pem ]
|
||||||
then
|
then
|
||||||
cp $CONFIG_DIR/server-cert.pem /etc/ssl/private/server-cert.pem
|
cp $CONFIG_DIR/server-cert.pem /etc/ssl/private/server-cert.pem
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2017 Wind River Systems, Inc.
|
# Copyright (c) 2017-2019 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
@ -16,14 +16,13 @@ class License(base.Resource):
|
||||||
|
|
||||||
|
|
||||||
class LicenseManager(base.Manager):
|
class LicenseManager(base.Manager):
|
||||||
resource_class = License
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _path(id=None):
|
def _path(id=None):
|
||||||
return '/v1/license/%s' % id if id else '/v1/license'
|
return '/v1/license/%s' % id if id else '/v1/license'
|
||||||
|
|
||||||
def list(self):
|
def show(self):
|
||||||
return self._list(self._path(), "licenses")
|
path = "get_license_file"
|
||||||
|
return self._json_get(self._path(path))
|
||||||
|
|
||||||
def install_license(self, file):
|
def install_license(self, file):
|
||||||
path = self._path("install_license")
|
path = self._path("install_license")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Copyright (c) 2017 Wind River Systems, Inc.
|
# Copyright (c) 2017-2019 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
@ -13,21 +13,15 @@ from cgtsclient.common import utils
|
||||||
from cgtsclient import exc
|
from cgtsclient import exc
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('-a', '--all',
|
def do_license_show(cc, args):
|
||||||
action='store_true',
|
"""Show license file content"""
|
||||||
help='List all licenses information')
|
response = cc.license.show()
|
||||||
def do_license_list(cc, args):
|
error = response.get('error')
|
||||||
"""List all licenses"""
|
content = response.get('content')
|
||||||
labels = ['name', 'status', 'expiry_date']
|
if error != "":
|
||||||
fields = ['name', 'status', 'expiry_date']
|
print("Error: %s" % error + "\n")
|
||||||
|
else:
|
||||||
licenses = cc.license.list()
|
print(content + "\n")
|
||||||
for license in licenses[:]:
|
|
||||||
if not args.all:
|
|
||||||
if license.status == 'Not-installed':
|
|
||||||
licenses.remove(license)
|
|
||||||
|
|
||||||
utils.print_list(licenses, fields, labels, sortby=0)
|
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('license_file_path',
|
@utils.arg('license_file_path',
|
||||||
|
|
|
@ -16,87 +16,20 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2017 Wind River Systems, Inc.
|
# Copyright (c) 2017-2019 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pecan
|
import pecan
|
||||||
from pecan import expose
|
from pecan import expose
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
from platform_util.license import license
|
|
||||||
|
|
||||||
from wsme import types as wtypes
|
|
||||||
import wsmeext.pecan as wsme_pecan
|
|
||||||
|
|
||||||
from sysinv.api.controllers.v1 import base
|
|
||||||
from sysinv.api.controllers.v1 import collection
|
|
||||||
from sysinv.api.controllers.v1 import link
|
|
||||||
from sysinv.api.controllers.v1 import utils
|
|
||||||
from sysinv.common import utils as cutils
|
from sysinv.common import utils as cutils
|
||||||
|
|
||||||
from sysinv.openstack.common import log
|
from sysinv.openstack.common import log
|
||||||
|
from sysinv.openstack.common.rpc.common import RemoteError
|
||||||
|
from tsconfig import tsconfig
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class License(base.APIBase):
|
|
||||||
"""API representation of a license.
|
|
||||||
|
|
||||||
This class enforces type checking and value constraints, and converts
|
|
||||||
between the internal object model and the API representation of
|
|
||||||
a license.
|
|
||||||
"""
|
|
||||||
|
|
||||||
name = wtypes.text
|
|
||||||
"Name of the license"
|
|
||||||
|
|
||||||
status = wtypes.text
|
|
||||||
"Status of the license"
|
|
||||||
|
|
||||||
expiry_date = wtypes.text
|
|
||||||
"Expiry date of the license"
|
|
||||||
|
|
||||||
links = [link.Link]
|
|
||||||
"A list containing a self link and associated license links"
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
self.fields = []
|
|
||||||
|
|
||||||
# they are all an API-only attribute
|
|
||||||
for fp in ['name', 'status', 'expiry_date']:
|
|
||||||
self.fields.append(fp)
|
|
||||||
setattr(self, fp, kwargs.get(fp, None))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def convert_with_links(cls, rpc_license, expand=True):
|
|
||||||
|
|
||||||
license = License(**rpc_license)
|
|
||||||
if not expand:
|
|
||||||
license.unset_fields_except(['name', 'status',
|
|
||||||
'expiry_date'])
|
|
||||||
|
|
||||||
return license
|
|
||||||
|
|
||||||
|
|
||||||
class LicenseCollection(collection.Collection):
|
|
||||||
"""API representation of a collection of licenses."""
|
|
||||||
|
|
||||||
licenses = [License]
|
|
||||||
"A list containing License objects"
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
self._type = "licenses"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def convert_with_links(cls, rpc_license, limit, url=None,
|
|
||||||
expand=False, **kwargs):
|
|
||||||
collection = LicenseCollection()
|
|
||||||
collection.licenses = [License.convert_with_links(n, expand)
|
|
||||||
for n in rpc_license]
|
|
||||||
collection.next = collection.get_next(limit, url=url, **kwargs)
|
|
||||||
return collection
|
|
||||||
|
|
||||||
|
|
||||||
LOCK_NAME = 'LicenseController'
|
LOCK_NAME = 'LicenseController'
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,21 +38,24 @@ class LicenseController(rest.RestController):
|
||||||
|
|
||||||
_custom_actions = {
|
_custom_actions = {
|
||||||
'install_license': ['POST'],
|
'install_license': ['POST'],
|
||||||
|
'get_license_file': ['GET']
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_license_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None):
|
@expose('json')
|
||||||
|
def get_license_file(self):
|
||||||
limit = utils.validate_limit(limit)
|
license_file = tsconfig.PLATFORM_CONF_PATH + "/.license"
|
||||||
sort_dir = utils.validate_sort_dir(sort_dir)
|
content = ''
|
||||||
licenses = license.get_licenses_info()
|
error = ''
|
||||||
|
if not os.path.isfile(license_file):
|
||||||
return LicenseCollection.convert_with_links(
|
error = "License file not found. " \
|
||||||
licenses, limit, url=resource_url, expand=expand,
|
"A license may not have been installed."
|
||||||
sort_key=sort_key, sort_dir=sort_dir)
|
else:
|
||||||
|
try:
|
||||||
@wsme_pecan.wsexpose(LicenseCollection, wtypes.text, int, wtypes.text, wtypes.text)
|
with open(license_file, 'r') as f:
|
||||||
def get_all(self, marker=None, limit=None, sort_key='id', sort_dir='asc'):
|
content = f.read()
|
||||||
return self._get_license_collection(marker, limit, sort_key, sort_dir)
|
except Exception:
|
||||||
|
error = "Failed to read the license file"
|
||||||
|
return dict(content=content, error=error)
|
||||||
|
|
||||||
@expose('json')
|
@expose('json')
|
||||||
@cutils.synchronized(LOCK_NAME)
|
@cutils.synchronized(LOCK_NAME)
|
||||||
|
@ -132,7 +68,9 @@ class LicenseController(rest.RestController):
|
||||||
contents = file.file.read()
|
contents = file.file.read()
|
||||||
try:
|
try:
|
||||||
pecan.request.rpcapi.install_license_file(pecan.request.context, contents)
|
pecan.request.rpcapi.install_license_file(pecan.request.context, contents)
|
||||||
except Exception as e:
|
except RemoteError as e:
|
||||||
return dict(success="", error=str(e))
|
return dict(success="", error=e.value)
|
||||||
|
except Exception as ex:
|
||||||
|
return dict(success="", error=str(ex))
|
||||||
|
|
||||||
return dict(success="Success: new license installed", error="")
|
return dict(success="Success: new license installed", error="")
|
||||||
|
|
Loading…
Reference in New Issue