vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / parser / consumption / inputs.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from ...utils.formatting import safe_repr
17 from ..loading import UriLocation, LiteralLocation
18 from ..reading import JsonReader
19 from .consumer import Consumer
20
21
22 class Inputs(Consumer):
23     """
24     Fills in the inputs if provided as arguments.
25     """
26
27     def consume(self):
28         inputs = self.context.get_arg_value('inputs')
29         if inputs is None:
30             return
31
32         if inputs.endswith('.json') or inputs.endswith('.yaml'):
33             location = UriLocation(inputs)
34         else:
35             location = LiteralLocation(inputs)
36
37         loader = self.context.loading.loader_source.get_loader(self.context.loading, location, None)
38
39         if isinstance(location, LiteralLocation):
40             reader = JsonReader(self.context.reading, location, loader)
41         else:
42             reader = self.context.reading.reader_source.get_reader(self.context.reading,
43                                                                    location, loader)
44
45         inputs = reader.read()
46
47         if not isinstance(inputs, dict):
48             self.context.validation.report(
49                 'Inputs consumer: inputs are not a dict: %s' % safe_repr(inputs))
50             return
51
52         for name, value in inputs.iteritems():
53             self.context.modeling.set_input(name, value)