1 # Copyright 2016 RIFT.io Inc
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from rift
.mano
.yang_translator
.common
.utils
import _
19 class ToscaResource(object):
20 '''Base class for YANG node type translation to RIFT.io SUBSTITUTION_MAPPINGtype.'''
22 # Used when creating the resource, so keeping separate
23 # from REQUIRED_FIELDS below
26 REQUIRED_FIELDS
= (DESC
, VERSION
, VENDOR
, ID
) = \
27 ('description', 'version', 'vendor', 'id')
29 COMMON_FIELDS
= (PATH
, PORT
, HOST
, XPATH
, TYPE
, COUNT
, FILE
,
30 NFV_COMPUTE
, HOST_EPA
, VSWITCH_EPA
, HYPERVISOR_EPA
, GUEST_EPA
) = \
31 ('path', 'port', 'host', 'xpath', 'type', 'count', 'file', 'nfv_compute',
32 'host_epa', 'vswitch_epa', 'hypervisor_epa', 'guest_epa')
34 IGNORE_FIELDS
= ['short_name']
36 FIELD_TYPES
= (STRING
, MAP
, INTEGER
, BOOL
) = \
37 ('string', 'map', 'integer', 'boolean',)
39 YANG_KEYS
= (VLD
, NSD
, VNFD
, VDU
, DASHBOARD_PARAMS
,
40 CONFIG_ATTR
, CONFIG_TMPL
,
41 CONFIG_TYPE
, CONFIG_DETAILS
, EXT_INTF
,
42 VIRT_INTF
, POLL_INTVL_SECS
,
43 MEM_VNF_INDEX_REF
, VNFD_ID_REF
,
44 MEM_VNF_INDEX
, VNF_CONFIG
, TYPE_Y
,
45 USER_DEF_SCRIPT
, SEQ
, PARAM
,
46 VALUE
, START_BY_DFLT
, VNFFGD
, ) = \
47 ('vld', 'nsd', 'vnfd', 'vdu', 'dashboard_params',
48 'config_attributes', 'config_template',
49 'config_type', 'config_details', 'external_interface',
50 'virtual_interface', 'polling_interval_secs',
51 'member_vnf_index_ref', 'vnfd_id_ref',
52 'member_vnf_index', 'vnf_configuration', 'type_yang',
53 'user_defined_script', 'seq', 'parameter',
54 'value', 'start_by_default', 'vnffgd',)
56 TOSCA_FIELDS
= (DERIVED_FROM
, PROPERTIES
, DEFAULT
, REQUIRED
,
57 NO
, CONSTRAINTS
, REALTIONSHIPS
,
58 REQUIREMENTS
, UNBOUND
, NODE
,
59 OCCURENCES
, PRIMITIVES
, MEMBERS
,
60 POLL_INTVL
, DEFAULT
, TRUE
, FALSE
,) = \
61 ('derived_from', 'properties', 'default', 'required',
62 'no', 'constraints', 'relationships',
63 'requirements', 'UNBOUND', 'node',
64 'occurences', 'primitives', 'members',
65 'polling_interval', 'default', 'true', 'false')
67 TOSCA_SEC
= (DATA_TYPES
, CAPABILITY_TYPES
, NODE_TYPES
,
68 GROUP_TYPES
, POLICY_TYPES
, REQUIREMENTS
,
69 ARTIFACTS
, PROPERTIES
, INTERFACES
,
70 CAPABILITIES
, RELATIONSHIP
,
71 ARTIFACT_TYPES
, TARGETS
) = \
72 ('data_types', 'capability_types', 'node_types',
73 'group_types', 'policy_types', 'requirements',
74 'artifacts', 'properties', 'interfaces',
75 'capabilities', 'relationship',
76 'artifact_types', 'targets')
78 TOSCA_TMPL
= (INPUTS
, NODE_TMPL
, GROUPS
, POLICIES
,
79 METADATA
, TOPOLOGY_TMPL
, OUTPUTS
, SUBSTITUTION_MAPPING
, IMPORT
) = \
80 ('inputs', 'node_templates', 'groups', 'policies',
81 'metadata', 'topology_template', 'outputs', 'substitution_mappings', 'imports')
102 ('tosca.policies.nfv.riftio.vnf_configuration',
103 'tosca.capabilities.riftio.http_endpoint_type',
104 'tosca.capabilities.riftio.mgmt_interface_type',
105 'tosca.capabilities.riftio.monitoring_param',
106 'tosca.nodes.nfv.riftio.VNF1',
107 'tosca.nodes.nfv.riftio.VDU1',
108 'tosca.nodes.nfv.riftio.CP1',
109 'tosca.nodes.riftio.VL1',
110 'tosca.groups.riftio.ConfigPrimitives',
111 'tosca.policies.riftio.ScalingGroup',
112 'tosca.artifacts.Deployment.Image.riftio.QCOW2',
113 'tosca.policies.nfv.riftio.initial_config_primitive',
114 'tosca.artifacts.Deployment.riftio.cloud_init_file',
115 'tosca.policies.nfv.riftio.placement',
116 'tosca.nodes.nfv.riftio.ELAN',
117 'tosca.groups.nfv.VNFFG',
118 'tosca.nodes.nfv.riftio.FP1',
121 SUPPORT_FILES
= ( SRC
, DEST
, EXISTING
) = \
122 ('source', 'destination', 'existing')
124 SUPPORT_DIRS
= (IMAGE_DIR
, SCRIPT_DIR
, CLOUD_INIT_DIR
) = \
125 ('images', 'scripts','cloud_init')
137 log
.debug(_('Translating YANG node %(name)s of type %(type)s') %
141 # Added the below property menthods to support methods that
142 # works on both toscaparser.NodeType and translator.ToscaResource
148 def type(self
, value
):
163 def description(self
):
164 return _("Translated from YANG")
168 if self
._vendor
is None:
169 if self
.metadata
and 'vendor' in self
.metadata
:
170 self
._vendor
= self
.metadata
['vendor']
172 self
._vendor
= "RIFT.io"
177 if self
._version
is None:
178 if self
.metadata
and 'version' in self
.metadata
:
179 self
._version
= str(self
.metadata
['version'])
181 self
._version
= '1.0'
185 return "%s(%s)" % (self
.name
, self
.type)
187 def map_yang_name_to_tosca(self
, name
):
188 new_name
= name
.replace("_", "-")
191 def map_keys_to_tosca(self
, d
):
192 if isinstance(d
, dict):
194 d
[self
.map_yang_name_to_tosca(key
)] = \
195 self
.map_keys_to_tosca(d
.pop(key
))
197 elif isinstance(d
, list):
200 arr
.append(self
.map_keys_to_tosca(memb
))
205 def handle_yang(self
):
206 self
.log
.debug(_("Need to implement handle_yang for {0}").
209 def remove_ignored_fields(self
, d
):
210 '''Remove keys in dict not used'''
211 for key
in self
.IGNORE_FIELDS
:
215 def generate_tosca_type(self
, tosca
):
216 self
.log
.debug(_("Need to implement generate_tosca_type for {0}").
219 def generate_tosca_model(self
, tosca
):
220 self
.log
.debug(_("Need to implement generate_tosca_model for {0}").
223 def get_supporting_files(self
):
224 """Get list of other required files for each resource"""
227 def get_matching_item(self
, name
, items
, key
=None):
231 if entry
[key
] == name
: