vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / __init__.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 The ARIA root package provides entry points for extension and storage initialization.
18 """
19
20 import sys
21
22 import pkg_resources
23 aria_package_name = 'apache-ariatosca'
24 __version__ = pkg_resources.get_distribution(aria_package_name).version
25
26 from .orchestrator.decorators import workflow, operation  # pylint: disable=wrong-import-position
27 from . import (  # pylint: disable=wrong-import-position
28     extension,
29     utils,
30     parser,
31     storage,
32     modeling,
33     orchestrator,
34     cli
35 )
36
37 if sys.version_info < (2, 7):
38     # pkgutil in python2.6 has a bug where it fails to import from protected modules, which causes
39     # the entire process to fail. In order to overcome this issue we use our custom iter_modules
40     from .utils.imports import iter_modules
41 else:
42     from pkgutil import iter_modules
43
44 __all__ = (
45     '__version__',
46     'workflow',
47     'operation',
48     'install_aria_extensions',
49     'application_model_storage',
50     'application_resource_storage'
51 )
52
53
54 def install_aria_extensions():
55     """
56     Iterates all Python packages with names beginning with ``aria_extension_`` and all
57     ``aria_extension`` entry points and loads them.
58
59     It then invokes all registered extension functions.
60     """
61     for loader, module_name, _ in iter_modules():
62         if module_name.startswith('aria_extension_'):
63             loader.find_module(module_name).load_module(module_name)
64     for entry_point in pkg_resources.iter_entry_points(group='aria_extension'):
65         entry_point.load()
66     extension.init()
67
68
69 def application_model_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None):
70     """
71     Initiate model storage.
72     """
73     return storage.ModelStorage(api_cls=api,
74                                 api_kwargs=api_kwargs,
75                                 items=modeling.models.models_to_register,
76                                 initiator=initiator,
77                                 initiator_kwargs=initiator_kwargs or {})
78
79
80 def application_resource_storage(api, api_kwargs=None, initiator=None, initiator_kwargs=None):
81     """
82     Initiate resource storage.
83     """
84
85     return storage.ResourceStorage(api_cls=api,
86                                    api_kwargs=api_kwargs,
87                                    items=['service_template', 'service', 'plugin'],
88                                    initiator=initiator,
89                                    initiator_kwargs=initiator_kwargs)