1 # Copyright (c) 2018 Amdocs
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 from multicloud_azure.pub.aria import util
20 from multicloud_azure.pub.utils.restcall import call_aria_rest
21 from aria.cli.core import aria
22 from aria.cli import utils
23 from aria.core import Core
24 from aria.cli import service_template_utils
25 from aria.storage import exceptions as storage_exceptions
27 LOG = logging.getLogger(__name__)
29 execution_state = util.SafeDict()
32 class AriaServiceImpl(object):
34 def deploy_service(self, template_name, template_body, inputs, logger):
36 service_template_name = template_name + "-template" + \
37 time.strftime('%Y%m%d%H%M%S')
38 status = self.install_template_private(service_template_name,
40 if (status[1] != 200):
41 logger.error("Error while installing the service-template")
42 return status[0], status[1]
44 logger.info("service template {0} valiadated and stored".format(
45 service_template_name))
46 status = self.create_service(
47 status, template_name + time.strftime('%Y%m%d%H%M%S'), inputs)
48 if (status[1] != 200):
49 return status[0], status[1]
50 status = call_aria_rest(status[2].id, 'install')
51 if (status[2] != "202"):
52 return status[1], status[2]
53 return json.loads(status[1])['id'], 200
55 @aria.pass_model_storage
56 @aria.pass_resource_storage
57 @aria.pass_plugin_manager
59 def install_template_private(self, service_template_name, template_body,
64 service_template_filename = "MainServiceTemplate.yaml"
65 fileSp = template_body
66 f = tempfile.NamedTemporaryFile(suffix='.csar',
68 f.write(fileSp.read())
69 f.seek(fileSp.tell(), 0)
70 service_template_path = f.name
72 file_path = service_template_utils.get(
73 service_template_path, service_template_filename)
75 core = Core(model_storage, resource_storage, plugin_manager)
76 logger.info("service-template file {}".format(file_path))
79 service_template_id = core.create_service_template(
81 os.path.dirname(file_path),
82 service_template_name)
83 except storage_exceptions.StorageError as e:
84 logger.error("storage exception")
85 utils.check_overriding_storage_exceptions(
86 e, 'service template', service_template_name)
88 except Exception as e:
89 logger.error("catchall exception")
91 return "service template installed", 200, service_template_id
93 @aria.pass_model_storage
94 @aria.pass_resource_storage
95 @aria.pass_plugin_manager
97 def create_service(self, template_id, service_name, input,
103 Creates a service from the specified service template
105 input = input['sdnc_directives'] if'sdnc_directives'in input else None
106 core = Core(model_storage, resource_storage, plugin_manager)
107 service = core.create_service(template_id, input, service_name)
108 logger.info("service {} created".format(service.name))
109 return "service {} created".format(service.name), 200, service
111 @aria.pass_model_storage
113 def show_execution(self, execution_id, model_storage, logger):
115 Return details of specified execution/Stack
118 execution = model_storage.execution.get(execution_id)
119 except BaseException:
120 return "Execution {} not found".format(execution_id), 404
121 logger.info("showing details of execution id {}".format(execution_id))
122 return json.dumps({"execution_id": execution_id,
123 "service_name": execution.service_name,
124 "service_template_name":
125 execution.service_template_name,
126 "workflow_name": execution.workflow_name,
127 "status": execution.status}), 200