vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / parser / presentation / source.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
17 from ...extension import parser
18
19 from .exceptions import PresenterNotFoundError
20
21
22 class PresenterSource(object):
23     """
24     Base class for ARIA presenter sources.
25
26     Presenter sources provide appropriate :class:`Presenter` classes for agnostic raw data.
27     """
28
29     def get_presenter(self, raw):  # pylint: disable=unused-argument,no-self-use
30         raise PresenterNotFoundError('presenter not found')
31
32
33 class DefaultPresenterSource(PresenterSource):
34     """
35     The default ARIA presenter source.
36     """
37
38     def __init__(self, classes=None):
39         if classes is None:
40             classes = parser.presenter_class()
41         self.classes = classes
42
43     def get_presenter(self, raw):
44         for cls in self.classes:
45             if cls.can_present(raw):
46                 return cls
47
48         if 'tosca_definitions_version' in raw:
49             if raw['tosca_definitions_version'] is None:
50                 raise PresenterNotFoundError("'tosca_definitions_version' is not specified")
51             if not isinstance(raw['tosca_definitions_version'], basestring):
52                 raise PresenterNotFoundError("'tosca_definitions_version' is not a string")
53             if not raw['tosca_definitions_version']:
54                 raise PresenterNotFoundError("'tosca_definitions_version' is not specified")
55         return super(DefaultPresenterSource, self).get_presenter(raw)