update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / common / python / rift / mano / tosca_translator / rwmano / syntax / mano_parameter.py
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13 #
14 # Copyright 2016 RIFT.io Inc
15
16 from collections import OrderedDict
17
18 from rift.mano.tosca_translator.common.utils import _
19
20
21 KEYS = (TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, HIDDEN, LABEL) = \
22 ('type', 'description', 'default', 'constraints', 'hidden', 'label')
23
24
25 class ManoParameter(object):
26 '''Attributes for RIFT.io MANO parameter section.'''
27
28 def __init__(self, log, name, type, label=None, description=None,
29 default=None, hidden=None, constraints=None):
30 self.log = log
31 self.name = name
32 self.type = type
33 self.label = label
34 self.description = description
35 self.default = default
36 self.hidden = hidden
37 self.constraints = constraints
38 log.info(_('Initialized the input parameters.'))
39
40 def __str__(self):
41 return "%s(%s,%s)" % (self.name, self.type, self.label)
42
43 # TODO(Philip): Harcoding for now, need to make this generic
44 def get_xpath(self):
45 xpath = '/rw-project:project/project-nsd:nsd-catalog/project-nsd:nsd/nsd:' + self.name
46 return xpath
47
48 def get_dict_output(self):
49 param_sections = OrderedDict()
50 param_sections[TYPE] = self.type
51 if self.label:
52 param_sections[LABEL] = self.label
53 if self.description:
54 param_sections[DESCRIPTION] = self.description
55 if self.default:
56 param_sections[DEFAULT] = self.default
57 if self.hidden:
58 param_sections[HIDDEN] = self.hidden
59 if self.constraints:
60 param_sections[CONSTRAINTS] = self.constraints
61
62 return {self.name: param_sections}