Enhancement to support yaml input 91/55891/1
authorHong Guan <hg4105@att.com>
Thu, 5 Jul 2018 15:04:57 +0000 (11:04 -0400)
committerHong Guan <hg4105@att.com>
Thu, 5 Jul 2018 15:08:10 +0000 (11:08 -0400)
Change-Id: Ib3d638965091a363f0c223012de9748650eb0960
Issue-ID: CCSDK-333
Signed-off-by: Hong Guan <hg4105@att.com>
helm/helm-type.yaml
helm/plugin/tasks.py
helm/plugin/workflows.py
helm/setup.py

index 2e79849..6645620 100644 (file)
@@ -19,7 +19,7 @@ plugins:
   helm-plugin:
     executor: central_deployment_agent
     package_name: onap-helm-plugin
-    package_version: 2.2.0
+    package_version: 2.3.0
 
 node_types:
 
@@ -58,6 +58,10 @@ node_types:
         description: String format config file url
         type: string
         default: ''
+      config-format:
+        description: String format config file format
+        type: string
+        default: 'json'
       runtime-config:
         default: ''
         description: String format json object. To save the runtime config generate from other nodes.
@@ -113,9 +117,12 @@ workflows:
       config_json:
         description: The changes to the new config json
         default: ''
-      config_json_url:
-        description: The changes to the new config json url
+      config_url:
+        description: The config input url
         default: ''
+      config_format:
+        description: The config url input format
+        default: 'json'
       chartVersion:
         description: chart version
       chartRepo:
index 8df29ac..5fda295 100644 (file)
@@ -146,7 +146,8 @@ def config(**kwargs):
     # create helm value file on K8s master
     #configPath = ctx.node.properties['config-path']
     configJson = str(ctx.node.properties['config'])
-    configJsonUrl = str(ctx.node.properties['config-url'])
+    configUrl = str(ctx.node.properties['config-url'])
+    configUrlInputFormat = str(ctx.node.properties['config-format'])
     runtime_config = str(ctx.node.properties['runtime-config'])  #json
     componentName = ctx.node.properties['component-name']
     config_dir_root= str(ctx.node.properties['config-dir'])
@@ -183,12 +184,17 @@ def config(**kwargs):
     ctx.logger.debug(configPath)
 
     configObj ={}
-    if configJson == '' and configJsonUrl == '':
+    if configJson == '' and configUrl == '':
         ctx.logger.debug("Will use default HELM value")
-    elif configJson == '' and configJsonUrl != '':
-        response = urllib2.urlopen(configJsonUrl)
-        configObj = json.load(response)
-    elif configJson != '' and configJsonUrl == '':
+    elif configJson == '' and configUrl != '':
+        response = urllib2.urlopen(configUrl)
+        if configUrlInputFormat == 'json':
+             configObj = json.load(response)
+        elif configUrlInputFormat == 'yaml':
+             configObj = yaml.load(response)
+        else:
+            raise NonRecoverableError("Unable to get config input format.")
+    elif configJson != '' and configUrl == '':
         configObj = json.loads(configJson)
     else:
         raise NonRecoverableError("Unable to get Json config input")
@@ -222,14 +228,14 @@ def start(**kwargs):
     configPath=config_dir_root+str(ctx.deployment.id)+'/'+componentName+'.yaml'
     namespace = ctx.node.properties['namespace']
     configJson = str(ctx.node.properties['config'])
-    configJsonUrl = str(ctx.node.properties['config-url'])
+    configUrl = str(ctx.node.properties['config-url'])
     runtimeconfigJson =  str(ctx.node.properties['runtime-config'])
 
 
     chart = chartRepo + "/" + componentName + "-" + chartVersion + ".tgz"
     chartName = namespace + "-" + componentName
 
-    if configJson == '' and runtimeconfigJson == '' and configJsonUrl == '':
+    if configJson == '' and runtimeconfigJson == '' and configUrl == '':
         installCommand = 'helm install '+ chart + ' --name ' + chartName + ' --namespace ' + namespace+tiller_host()+tls()
     else:
         installCommand = 'helm install ' + chart + ' --name ' + chartName + ' --namespace ' + namespace + ' -f '+ configPath +tiller_host()+tls()
index d341bf7..7dc8272 100644 (file)
@@ -20,9 +20,10 @@ from cloudify.workflows import ctx
 from cloudify.exceptions import NonRecoverableError
 import urllib2
 import json
+import yaml
 
 @workflow
-def upgrade(node_instance_id,config_json,config_json_url,chartVersion,chartRepo,**kwargs):
+def upgrade(node_instance_id,config_json,config_url,config_format,chartVersion,chartRepo,**kwargs):
     node_instance = ctx.get_node_instance(node_instance_id)
 
     if not node_instance_id:
@@ -31,13 +32,18 @@ def upgrade(node_instance_id,config_json,config_json_url,chartVersion,chartRepo,
                 node_instance_id))
 
     kwargs = {}
-    if config_json == '' and config_json_url == '':
-       kwargs['config'] = config_json
-    elif config_json == '' and config_json_url != '':
-        response = urllib2.urlopen(config_json_url)
-        kwargs['config'] = json.load(response)
-    elif config_json != '' and config_json_url == '':
-       kwargs['config'] = config_json
+    if config_json == '' and config_url == '':
+         kwargs['config'] = config_json
+    elif config_json == '' and config_url != '':
+         response = urllib2.urlopen(config_url)
+    if config_format == 'json':
+         kwargs['config'] = json.load(response)
+    elif config_format == 'yaml':
+         kwargs['config'] = yaml.load(response)
+    else:
+         raise NonRecoverableError("Unable to get config input format")
+    elif config_json != '' and config_url == '':
+         kwargs['config'] = config_json
     else:
         raise NonRecoverableError("Unable to get Json config input")
 
index c3bfe88..2a60585 100644 (file)
@@ -24,7 +24,7 @@ setup(
 
     # Do not use underscores in the plugin name.
     name='onap-helm-plugin',
-    version='2.2.0',
+    version='2.3.0',
     author='Nicolas Hu(AT&T)',
     author_email='jh245g@att.com',
     description='This plugin will install/uninstall/upgrade/rollback helm charts of ONAP components. ',