vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / parser / utils.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 aria.parser.loading import UriLocation
17 from aria.parser.consumption import (
18     ConsumptionContext,
19     ConsumerChain,
20     Read,
21     Validate,
22     ServiceTemplate,
23     Types,
24     Inputs,
25     ServiceInstance
26 )
27 from aria.utils.imports import import_fullname
28
29
30 def create_context(uri,
31                    loader_source='aria.parser.loading.DefaultLoaderSource',
32                    reader_source='aria.parser.reading.DefaultReaderSource',
33                    presenter_source='aria.parser.presentation.DefaultPresenterSource',
34                    presenter=None,
35                    debug=False):
36     context = ConsumptionContext()
37     context.loading.loader_source = import_fullname(loader_source)()
38     context.reading.reader_source = import_fullname(reader_source)()
39     context.presentation.location = UriLocation(uri) if isinstance(uri, basestring) else uri
40     context.presentation.presenter_source = import_fullname(presenter_source)()
41     context.presentation.presenter_class = import_fullname(presenter)
42     context.presentation.print_exceptions = debug
43     return context
44
45
46 def create_consumer(context, consumer_class_name):
47     consumer = ConsumerChain(context, (Read, Validate))
48     dumper = None
49     if consumer_class_name == 'validate':
50         dumper = None
51     elif consumer_class_name == 'presentation':
52         dumper = consumer.consumers[0]
53     elif consumer_class_name == 'template':
54         consumer.append(ServiceTemplate)
55     elif consumer_class_name == 'types':
56         consumer.append(ServiceTemplate, Types)
57     elif consumer_class_name == 'instance':
58         consumer.append(ServiceTemplate, Inputs, ServiceInstance)
59     else:
60         consumer.append(ServiceTemplate, Inputs, ServiceInstance)
61         consumer.append(import_fullname(consumer_class_name))
62
63     if dumper is None:
64         # Default to last consumer
65         dumper = consumer.consumers[-1]
66
67     return consumer, dumper