vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / parser / reading / source.py
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12
13 from ..loading import LiteralLocation, UriLocation
14 from .yaml import YamlReader
15 from .json import JsonReader
16 from .jinja import JinjaReader
17 from .exceptions import ReaderNotFoundError
18
19
20 EXTENSIONS = {
21     '.yaml': YamlReader,
22     '.json': JsonReader,
23     '.jinja': JinjaReader}
24
25
26 class ReaderSource(object):
27     """
28     Base class for ARIA reader sources.
29
30     Reader sources provide appropriate :class:`Reader` instances for locations.
31     """
32
33     @staticmethod
34     def get_reader(context, location, loader):  # pylint: disable=unused-argument
35         raise ReaderNotFoundError('location: %s' % location)
36
37
38 class DefaultReaderSource(ReaderSource):
39     """
40     The default ARIA reader source will generate a :class:`YamlReader` for
41     locations that end in ".yaml", a :class:`JsonReader` for locations that
42     end in ".json",  and a :class:`JinjaReader` for locations that end in
43     ".jinja".
44     """
45
46     def __init__(self, literal_reader_class=YamlReader):
47         super(DefaultReaderSource, self).__init__()
48         self.literal_reader_class = literal_reader_class
49
50     def get_reader(self, context, location, loader):
51         if isinstance(location, LiteralLocation):
52             return self.literal_reader_class(context, location, loader)
53
54         elif isinstance(location, UriLocation):
55             for extension, reader_class in EXTENSIONS.iteritems():
56                 if location.uri.endswith(extension):
57                     return reader_class(context, location, loader)
58
59         return super(DefaultReaderSource, self).get_reader(context, location, loader)