summaryrefslogtreecommitdiffstats
path: root/k8s/msb/msb.py
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2018-03-22 17:43:01 +0000
committerJack Lucas <jflucas@research.att.com>2018-03-23 12:46:10 +0000
commit1ed29c111f50e33ac89915ba86b530820da3a689 (patch)
tree314ad8dc5dd2cad4ba89bac5662015f8a9c43ced /k8s/msb/msb.py
parent19a075b395d687753de0f0266842cb9af8f24682 (diff)
Add DCAE Kubernetes plugin
Change-Id: Ic329f77bb09dcccfd49a34a8f84d387e8da929c6 Issue-ID: DCAEGEN2-410 Signed-off-by: Jack Lucas <jflucas@research.att.com>
Diffstat (limited to 'k8s/msb/msb.py')
-rw-r--r--k8s/msb/msb.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/k8s/msb/msb.py b/k8s/msb/msb.py
new file mode 100644
index 0000000..5883f29
--- /dev/null
+++ b/k8s/msb/msb.py
@@ -0,0 +1,64 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 AT&T Intellectual Property. 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+
+import uuid
+import json
+
+MSB_ANNOTATION_KEY = 'msb.onap.org/service-info'
+
+def _sanitize_service_info(service_info):
+ '''
+ Sanitize a dict containing the MSB annotation parameters for registering
+ a service with MSB. (Not bullet proof, but useful.)
+ MSB registration happens asynchronously from the installation flow: an MSB process
+ watches the k8s event stream for new Service creations and looks for the MSB annotation.
+ A bad annotation will fail silently. This sanitization process should make sure that something
+ gets put into the MSB's list of services, so that the problem can be seen.
+
+ service_info is a dict containing the MSB annotation parameters.
+ -- serviceName: the name under which the service is to be registered (default: random--pretty useless!)
+ -- port: the container port on which the service can be contacted (default: "80"--nearly as useless)
+ -- version: the API version (default: "v1")
+ -- url: the path to the application's API endpoint (default: "/")
+ -- protocol: see the MSB documentation--the default is usually OK (default: "REST")
+ -- enable_ssl: a flag indicating if the service uses SSL (True) or not (False) (default: True)
+ -- visualRange: "1" means the service is exposed only in ONAP, "0" means externally (default: "1")
+ (Note this is a string value)
+ '''
+ return {
+ 'serviceName': service_info.get('serviceName', str(uuid.uuid4())),
+ 'port': str(service_info.get('port', '80')),
+ 'version': service_info.get('version','v1'),
+ 'url': service_info.get('url','/'),
+ 'protocol': service_info.get('protocol','REST'),
+ 'enable_ssl': bool(service_info.get('enable_ssl', False)),
+ 'visualRange': str(service_info.get('visualRange', '1'))
+ }
+
+def create_msb_annotation(msb_service_list):
+ '''
+ Creates an annotation that can be added to a k8s Service to trigger
+ registration with MSB.
+ msb_list is a list of dicts each containing MSB registration information for a
+ service. (One k8s Service can have multiple ports, each one of which can be
+ registered as an MSB service.)
+ '''
+ return {MSB_ANNOTATION_KEY : json.dumps([_sanitize_service_info(service_info) for service_info in msb_service_list])}