diff options
author | shangxdy <shang.xiaodong@zte.com.cn> | 2016-04-07 14:08:49 -0400 |
---|---|---|
committer | shangxdy <shang.xiaodong@zte.com.cn> | 2016-04-07 14:59:30 -0400 |
commit | c8201c119ec686e79797721156767685fe848aca (patch) | |
tree | cce6aa15ded38d89c18a14b76c21f21e0b1a24f7 /tosca2heat/tosca-parser-0.3.0/toscaparser/elements | |
parent | 4e4c86a06d58b1816c074c7f9da4c58bbf10368c (diff) |
Update tosca lib to version 0.5
Use tosca-parser and heat-translator to analyze to the basic
nfv-tosca type definitions, and use simple tosca new feature
such as policy, group and trigger, which are now supported by
the latest version of tosca-parser and heat-translator.
JIRA:PARSER-18
Change-Id: I797bcacbb5b32005d0aeb0f3f32851ac96e30f01
Signed--off-by: shangxdy <shang.xiaodong@zte.com.cn>
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser-0.3.0/toscaparser/elements')
15 files changed, 0 insertions, 2299 deletions
diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/TOSCA_definition_1_0.yaml b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/TOSCA_definition_1_0.yaml deleted file mode 100644 index 2f50ff0..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/TOSCA_definition_1_0.yaml +++ /dev/null @@ -1,778 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -########################################################################## -# The content of this file reflects TOSCA Simple Profile in YAML version -# 1.0.0. It describes the definition for TOSCA types including Node Type, -# Relationship Type, Capability Type and Interfaces. -########################################################################## -tosca_definitions_version: tosca_simple_yaml_1_0 - -########################################################################## -# Node Type. -# A Node Type is a reusable entity that defines the type of one or more -# Node Templates. -########################################################################## -tosca.nodes.Root: - description: > - The TOSCA root node all other TOSCA base node types derive from. - attributes: - tosca_id: - type: string - tosca_name: - type: string - state: - type: string - capabilities: - feature: - type: tosca.capabilities.Node - requirements: - - dependency: - capability: tosca.capabilities.Node - node: tosca.nodes.Root - relationship: tosca.relationships.DependsOn - occurrences: [ 0, UNBOUNDED ] - interfaces: - Standard: - type: tosca.interfaces.node.lifecycle.Standard - -tosca.nodes.Compute: - derived_from: tosca.nodes.Root - attributes: - private_address: - type: string - public_address: - type: string - capabilities: - host: - type: tosca.capabilities.Container - binding: - type: tosca.capabilities.network.Bindable - os: - type: tosca.capabilities.OperatingSystem - scalable: - type: tosca.capabilities.Scalable - requirements: - - local_storage: - capability: tosca.capabilities.Attachment - node: tosca.nodes.BlockStorage - relationship: tosca.relationships.AttachesTo - occurrences: [0, UNBOUNDED] - -tosca.nodes.SoftwareComponent: - derived_from: tosca.nodes.Root - properties: - # domain-specific software component version - component_version: - type: version - required: false - description: > - Software component version. - admin_credential: - type: tosca.datatypes.Credential - required: false - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.Compute - relationship: tosca.relationships.HostedOn - -tosca.nodes.DBMS: - derived_from: tosca.nodes.SoftwareComponent - properties: - port: - required: no - type: integer - description: > - The port the DBMS service will listen to for data and requests. - root_password: - required: no - type: string - description: > - The root password for the DBMS service. - capabilities: - host: - type: tosca.capabilities.Container - valid_source_types: [tosca.nodes.Database] - -tosca.nodes.Database: - derived_from: tosca.nodes.Root - properties: - user: - required: no - type: string - description: > - User account name for DB administration - name: - required: no - type: string - description: > - The name of the database. - password: - required: no - type: string - description: > - The password for the DB user account - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.DBMS - relationship: tosca.relationships.HostedOn - capabilities: - database_endpoint: - type: tosca.capabilities.Endpoint.Database - -tosca.nodes.WebServer: - derived_from: tosca.nodes.SoftwareComponent - capabilities: - data_endpoint: - type: tosca.capabilities.Endpoint - admin_endpoint: - type: tosca.capabilities.Endpoint.Admin - host: - type: tosca.capabilities.Container - valid_source_types: [tosca.nodes.WebApplication] - -tosca.nodes.WebApplication: - derived_from: tosca.nodes.Root - properties: - context_root: - type: string - required: false - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.WebServer - relationship: tosca.relationships.HostedOn - capabilities: - app_endpoint: - type: tosca.capabilities.Endpoint - -tosca.nodes.BlockStorage: - derived_from: tosca.nodes.Root - properties: - size: - type: scalar-unit.size - constraints: - - greater_or_equal: 1 MB - volume_id: - type: string - required: false - snapshot_id: - type: string - required: false - attributes: - volume_id: - type: string - capabilities: - attachment: - type: tosca.capabilities.Attachment - -tosca.nodes.network.Network: - derived_from: tosca.nodes.Root - description: > - The TOSCA Network node represents a simple, logical network service. - properties: - ip_version: - type: integer - required: no - default: 4 - constraints: - - valid_values: [ 4, 6 ] - description: > - The IP version of the requested network. Valid values are 4 for ipv4 - or 6 for ipv6. - cidr: - type: string - required: no - description: > - The cidr block of the requested network. - start_ip: - type: string - required: no - description: > - The IP address to be used as the start of a pool of addresses within - the full IP range derived from the cidr block. - end_ip: - type: string - required: no - description: > - The IP address to be used as the end of a pool of addresses within - the full IP range derived from the cidr block. - gateway_ip: - type: string - required: no - description: > - The gateway IP address. - network_name: - type: string - required: no - description: > - An identifier that represents an existing Network instance in the - underlying cloud infrastructure or can be used as the name of the - newly created network. If network_name is provided and no other - properties are provided (with exception of network_id), then an - existing network instance will be used. If network_name is provided - alongside with more properties then a new network with this name will - be created. - network_id: - type: string - required: no - description: > - An identifier that represents an existing Network instance in the - underlying cloud infrastructure. This property is mutually exclusive - with all other properties except network_name. This can be used alone - or together with network_name to identify an existing network. - segmentation_id: - type: string - required: no - description: > - A segmentation identifier in the underlying cloud infrastructure. - E.g. VLAN ID, GRE tunnel ID, etc.. - dhcp_enabled: - type: boolean - required: no - default: true - description: > - Indicates should DHCP service be enabled on the network or not. - capabilities: - link: - type: tosca.capabilities.network.Linkable - -tosca.nodes.network.Port: - derived_from: tosca.nodes.Root - description: > - The TOSCA Port node represents a logical entity that associates between - Compute and Network normative types. The Port node type effectively - represents a single virtual NIC on the Compute node instance. - properties: - ip_address: - type: string - required: no - description: > - Allow the user to set a static IP. - order: - type: integer - required: no - default: 0 - constraints: - - greater_or_equal: 0 - description: > - The order of the NIC on the compute instance (e.g. eth2). - is_default: - type: boolean - required: no - default: false - description: > - If is_default=true this port will be used for the default gateway - route. Only one port that is associated to single compute node can - set as is_default=true. - ip_range_start: - type: string - required: no - description: > - Defines the starting IP of a range to be allocated for the compute - instances that are associated with this Port. - ip_range_end: - type: string - required: no - description: > - Defines the ending IP of a range to be allocated for the compute - instances that are associated with this Port. - attributes: - ip_address: - type: string - requirements: - - binding: - description: > - Binding requirement expresses the relationship between Port and - Compute nodes. Effectevely it indicates that the Port will be - attached to specific Compute node instance - capability: tosca.capabilities.network.Bindable - relationship: tosca.relationships.network.BindsTo - - link: - description: > - Link requirement expresses the relationship between Port and Network - nodes. It indicates which network this port will connect to. - capability: tosca.capabilities.network.Linkable - relationship: tosca.relationships.network.LinksTo - -tosca.nodes.ObjectStorage: - derived_from: tosca.nodes.Root - description: > - The TOSCA ObjectStorage node represents storage that provides the ability - to store data as objects (or BLOBs of data) without consideration for the - underlying filesystem or devices - properties: - name: - type: string - required: yes - description: > - The logical name of the object store (or container). - size: - type: scalar-unit.size - required: no - constraints: - - greater_or_equal: 0 GB - description: > - The requested initial storage size. - maxsize: - type: scalar-unit.size - required: no - constraints: - - greater_or_equal: 0 GB - description: > - The requested maximum storage size. - capabilities: - storage_endpoint: - type: tosca.capabilities.Endpoint - -########################################################################## -# Relationship Type. -# A Relationship Type is a reusable entity that defines the type of one -# or more relationships between Node Types or Node Templates. -########################################################################## -tosca.relationships.Root: - description: > - The TOSCA root Relationship Type all other TOSCA base Relationship Types - derive from. - attributes: - tosca_id: - type: string - tosca_name: - type: string - interfaces: - Configure: - type: tosca.interfaces.relationship.Configure - -tosca.relationships.DependsOn: - derived_from: tosca.relationships.Root - -tosca.relationships.HostedOn: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Container ] - -tosca.relationships.ConnectsTo: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Endpoint ] - credential: - type: tosca.datatypes.Credential - required: false - -tosca.relationships.AttachesTo: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Attachment ] - properties: - location: - required: true - type: string - constraints: - - min_length: 1 - device: - required: false - type: string - -tosca.relationships.network.LinksTo: - derived_from: tosca.relationships.DependsOn - valid_target_types: [ tosca.capabilities.network.Linkable ] - -tosca.relationships.network.BindsTo: - derived_from: tosca.relationships.DependsOn - valid_target_types: [ tosca.capabilities.network.Bindable ] - -########################################################################## -# Capability Type. -# A Capability Type is a reusable entity that describes a kind of -# capability that a Node Type can declare to expose. -########################################################################## -tosca.capabilities.Root: - description: > - The TOSCA root Capability Type all other TOSCA base Capability Types - derive from. - -tosca.capabilities.Node: - derived_from: tosca.capabilities.Root - -tosca.capabilities.Container: - derived_from: tosca.capabilities.Root - properties: - num_cpus: - required: no - type: integer - constraints: - - greater_or_equal: 1 - cpu_frequency: - required: no - type: scalar-unit.frequency - constraints: - - greater_or_equal: 0.1 GHz - disk_size: - required: no - type: scalar-unit.size - constraints: - - greater_or_equal: 0 MB - mem_size: - required: no - type: scalar-unit.size - constraints: - - greater_or_equal: 0 MB - -tosca.capabilities.Endpoint: - derived_from: tosca.capabilities.Root - properties: - protocol: - type: string - default: tcp - port: - type: tosca.datatypes.network.PortDef - required: false - secure: - type: boolean - default: false - url_path: - type: string - required: false - port_name: - type: string - required: false - network_name: - type: string - required: false - initiator: - type: string - default: source - constraints: - - valid_values: [source, target, peer] - ports: - type: map - required: false - constraints: - - min_length: 1 - entry_schema: - type: tosca.datatypes.network.PortSpec - attributes: - ip_address: - type: string - -tosca.capabilities.Endpoint.Admin: - derived_from: tosca.capabilities.Endpoint - properties: - secure: - type: boolean - default: true - constraints: - - equal: true - -tosca.capabilities.Endpoint.Public: - derived_from: tosca.capabilities.Endpoint - properties: - # Change the default network_name to use the first public network found - network_name: - type: string - default: PUBLIC - constraints: - - equal: PUBLIC - floating: - description: > - Indicates that the public address should be allocated from a pool of - floating IPs that are associated with the network. - type: boolean - default: false - status: experimental - dns_name: - description: The optional name to register with DNS - type: string - required: false - status: experimental - -tosca.capabilities.Scalable: - derived_from: tosca.capabilities.Root - properties: - min_instances: - type: integer - required: yes - default: 1 - description: > - This property is used to indicate the minimum number of instances - that should be created for the associated TOSCA Node Template by - a TOSCA orchestrator. - max_instances: - type: integer - required: yes - default: 1 - description: > - This property is used to indicate the maximum number of instances - that should be created for the associated TOSCA Node Template by - a TOSCA orchestrator. - default_instances: - type: integer - required: no - description: > - An optional property that indicates the requested default number - of instances that should be the starting number of instances a - TOSCA orchestrator should attempt to allocate. - The value for this property MUST be in the range between the values - set for min_instances and max_instances properties. - -tosca.capabilities.Endpoint.Database: - derived_from: tosca.capabilities.Endpoint - -tosca.capabilities.Attachment: - derived_from: tosca.capabilities.Root - -tosca.capabilities.network.Linkable: - derived_from: tosca.capabilities.Root - description: > - A node type that includes the Linkable capability indicates that it can - be pointed by tosca.relationships.network.LinksTo relationship type, which - represents an association relationship between Port and Network node types. - -tosca.capabilities.network.Bindable: - derived_from: tosca.capabilities.Root - description: > - A node type that includes the Bindable capability indicates that it can - be pointed by tosca.relationships.network.BindsTo relationship type, which - represents a network association relationship between Port and Compute node - types. - -tosca.capabilities.OperatingSystem: - derived_from: tosca.capabilities.Root - properties: - architecture: - required: false - type: string - description: > - The host Operating System (OS) architecture. - type: - required: false - type: string - description: > - The host Operating System (OS) type. - distribution: - required: false - type: string - description: > - The host Operating System (OS) distribution. Examples of valid values - for an “type” of “Linux” would include: - debian, fedora, rhel and ubuntu. - version: - required: false - type: version - description: > - The host Operating System version. - -########################################################################## - # Interfaces Type. - # The Interfaces element describes a list of one or more interface - # definitions for a modelable entity (e.g., a Node or Relationship Type) - # as defined within the TOSCA Simple Profile specification. -########################################################################## -tosca.interfaces.node.lifecycle.Standard: - create: - description: Standard lifecycle create operation. - configure: - description: Standard lifecycle configure operation. - start: - description: Standard lifecycle start operation. - stop: - description: Standard lifecycle stop operation. - delete: - description: Standard lifecycle delete operation. - -tosca.interfaces.relationship.Configure: - pre_configure_source: - description: Operation to pre-configure the source endpoint. - pre_configure_target: - description: Operation to pre-configure the target endpoint. - post_configure_source: - description: Operation to post-configure the source endpoint. - post_configure_target: - description: Operation to post-configure the target endpoint. - add_target: - description: Operation to add a target node. - remove_target: - description: Operation to remove a target node. - add_source: > - description: Operation to notify the target node of a source node which - is now available via a relationship. - description: - target_changed: > - description: Operation to notify source some property or attribute of the - target changed - -########################################################################## - # Data Type. - # A Datatype is a complex data type declaration which contains other - # complex or simple data types. -########################################################################## -tosca.datatypes.Root: - description: > - The TOSCA root Data Type all other TOSCA base Data Types derive from - -tosca.datatypes.network.NetworkInfo: - derived_from: tosca.datatypes.Root - properties: - network_name: - type: string - network_id: - type: string - addresses: - type: list - entry_schema: - type: string - -tosca.datatypes.network.PortInfo: - derived_from: tosca.datatypes.Root - properties: - port_name: - type: string - port_id: - type: string - network_id: - type: string - mac_address: - type: string - addresses: - type: list - entry_schema: - type: string - -tosca.datatypes.network.PortDef: - derived_from: tosca.datatypes.Root - type: integer - constraints: - - in_range: [ 1, 65535 ] - -tosca.datatypes.network.PortSpec: - derived_from: tosca.datatypes.Root - properties: - protocol: - type: string - required: true - default: tcp - constraints: - - valid_values: [ udp, tcp, igmp ] - target: - type: PortDef - target_range: - type: range - constraints: - - in_range: [ 1, 65535 ] - source: - type: PortDef - source_range: - type: range - constraints: - - in_range: [ 1, 65535 ] - -tosca.datatypes.Credential: - derived_from: tosca.datatypes.Root - properties: - protocol: - type: string - token_type: - type: string - token: - type: string - keys: - type: map - entry_schema: - type: string - user: - type: string - required: false - -########################################################################## - # Artifact Type. - # An Artifact Type is a reusable entity that defines the type of one or more - # files which Node Types or Node Templates can have dependent relationships - # and used during operations such as during installation or deployment. -########################################################################## -tosca.artifacts.Root: - description: > - The TOSCA Artifact Type all other TOSCA Artifact Types derive from - properties: - version: version - -tosca.artifacts.File: - derived_from: tosca.artifacts.Root - -tosca.artifacts.Deployment: - derived_from: tosca.artifacts.Root - description: TOSCA base type for deployment artifacts - -tosca.artifacts.Deployment.Image: - derived_from: tosca.artifacts.Deployment - -tosca.artifacts.Deployment.Image.VM: - derived_from: tosca.artifacts.Deployment.Image - -tosca.artifacts.Implementation: - derived_from: tosca.artifacts.Root - description: TOSCA base type for implementation artifacts - -tosca.artifacts.Implementation.Bash: - derived_from: tosca.artifacts.Implementation - description: Script artifact for the Unix Bash shell - mime_type: application/x-sh - file_ext: [ sh ] - -tosca.artifacts.Implementation.Python: - derived_from: tosca.artifacts.Implementation - description: Artifact for the interpreted Python language - mime_type: application/x-python - file_ext: [ py ] - -tosca.artifacts.Deployment.Image.Container.Docker: - derived_from: tosca.artifacts.Deployment.Image - description: Docker container image - -tosca.artifacts.Deployment.Image.VM.ISO: - derived_from: tosca.artifacts.Deployment.Image - description: Virtual Machine (VM) image in ISO disk format - mime_type: application/octet-stream - file_ext: [ iso ] - -tosca.artifacts.Deployment.Image.VM.QCOW2: - derived_from: tosca.artifacts.Deployment.Image - description: Virtual Machine (VM) image in QCOW v2 standard disk format - mime_type: application/octet-stream - file_ext: [ qcow2 ] - -########################################################################## - # Policy Type. - # TOSCA Policy Types represent logical grouping of TOSCA nodes that have - # an implied relationship and need to be orchestrated or managed together - # to achieve some result. -########################################################################## -tosca.policies.Root: - description: The TOSCA Policy Type all other TOSCA Policy Types derive from. - -tosca.policies.Placement: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - placement of TOSCA nodes or groups of nodes. - -tosca.policies.Scaling: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - scaling of TOSCA nodes or groups of nodes. - -tosca.policies.Update: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - update of TOSCA nodes or groups of nodes. - -tosca.policies.Performance: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to declare - performance requirements for TOSCA nodes or groups of nodes. diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/__init__.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/__init__.py +++ /dev/null diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/artifacttype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/artifacttype.py deleted file mode 100644 index 3bfd7d0..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/artifacttype.py +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class ArtifactTypeDef(StatefulEntityType): - '''TOSCA built-in artifacts type.''' - - def __init__(self, atype, custom_def=None): - super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX, - custom_def) - self.type = atype - self.properties = None - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_artifacts = self._get_parent_artifacts() - - def _get_parent_artifacts(self): - artifacts = {} - parent_artif = self.parent_type - if parent_artif: - while parent_artif != 'tosca.artifacts.Root': - artifacts[parent_artif] = self.TOSCA_DEF[parent_artif] - parent_artif = artifacts[parent_artif]['derived_from'] - return artifacts - - @property - def parent_type(self): - '''Return an artifact this artifact is derived from.''' - return self.derived_from(self.defs) - - def get_artifact(self, name): - '''Return the definition of an artifact field by name.''' - if name in self.defs: - return self.defs[name] diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/attribute_definition.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/attribute_definition.py deleted file mode 100644 index 35ba27f..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/attribute_definition.py +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -class AttributeDef(object): - '''TOSCA built-in Attribute type.''' - - def __init__(self, name, value=None, schema=None): - self.name = name - self.value = value - self.schema = schema diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/capabilitytype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/capabilitytype.py deleted file mode 100644 index f9c8476..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/capabilitytype.py +++ /dev/null @@ -1,72 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.elements.property_definition import PropertyDef -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class CapabilityTypeDef(StatefulEntityType): - '''TOSCA built-in capabilities type.''' - - def __init__(self, name, ctype, ntype, custom_def=None): - self.name = name - super(CapabilityTypeDef, self).__init__(ctype, self.CAPABILITY_PREFIX, - custom_def) - self.nodetype = ntype - self.properties = None - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_capabilities = self._get_parent_capabilities() - - def get_properties_def_objects(self): - '''Return a list of property definition objects.''' - properties = [] - parent_properties = {} - if self.parent_capabilities: - for type, value in self.parent_capabilities.items(): - parent_properties[type] = value.get('properties') - if self.properties: - for prop, schema in self.properties.items(): - properties.append(PropertyDef(prop, None, schema)) - if parent_properties: - for parent, props in parent_properties.items(): - for prop, schema in props.items(): - # add parent property if not overridden by children type - if not self.properties or \ - prop not in self.properties.items(): - properties.append(PropertyDef(prop, None, schema)) - return properties - - def get_properties_def(self): - '''Return a dictionary of property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_def_objects()} - - def get_property_def_value(self, name): - '''Return the definition of a given property name.''' - props_def = self.get_properties_def() - if props_def and name in props_def: - return props_def[name].value - - def _get_parent_capabilities(self): - capabilities = {} - parent_cap = self.parent_type - if parent_cap: - while parent_cap != 'tosca.capabilities.Root': - capabilities[parent_cap] = self.TOSCA_DEF[parent_cap] - parent_cap = capabilities[parent_cap]['derived_from'] - return capabilities - - @property - def parent_type(self): - '''Return a capability this capability is derived from.''' - return self.derived_from(self.defs) diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/constraints.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/constraints.py deleted file mode 100644 index e462095..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/constraints.py +++ /dev/null @@ -1,597 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import collections -import datetime -import re - -import toscaparser -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidSchemaError -from toscaparser.common.exception import ValidationError -from toscaparser.elements import scalarunit -from toscaparser.utils.gettextutils import _ - - -class Schema(collections.Mapping): - - KEYS = ( - TYPE, REQUIRED, DESCRIPTION, - DEFAULT, CONSTRAINTS, ENTRYSCHEMA - ) = ( - 'type', 'required', 'description', - 'default', 'constraints', 'entry_schema' - ) - - PROPERTY_TYPES = ( - INTEGER, STRING, BOOLEAN, FLOAT, - NUMBER, TIMESTAMP, LIST, MAP, - SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME, - PORTDEF, VERSION - ) = ( - 'integer', 'string', 'boolean', 'float', - 'number', 'timestamp', 'list', 'map', - 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time', - 'PortDef', 'version' - ) - - SCALAR_UNIT_SIZE_DEFAULT = 'B' - SCALAR_UNIT_SIZE_DICT = {'B': 1, 'KB': 1000, 'KIB': 1024, 'MB': 1000000, - 'MIB': 1048576, 'GB': 1000000000, - 'GIB': 1073741824, 'TB': 1000000000000, - 'TIB': 1099511627776} - - def __init__(self, name, schema_dict): - self.name = name - if not isinstance(schema_dict, collections.Mapping): - msg = (_('Schema definition of "%(pname)s" must be a dict.') - % dict(pname=name)) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - try: - schema_dict['type'] - except KeyError: - msg = (_('Schema definition of "%(pname)s" must have a "type" ' - 'attribute.') % dict(pname=name)) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - self.schema = schema_dict - self._len = None - self.constraints_list = [] - - @property - def type(self): - return self.schema[self.TYPE] - - @property - def required(self): - return self.schema.get(self.REQUIRED, True) - - @property - def description(self): - return self.schema.get(self.DESCRIPTION, '') - - @property - def default(self): - return self.schema.get(self.DEFAULT) - - @property - def constraints(self): - if not self.constraints_list: - constraint_schemata = self.schema.get(self.CONSTRAINTS) - if constraint_schemata: - self.constraints_list = [Constraint(self.name, - self.type, - cschema) - for cschema in constraint_schemata] - return self.constraints_list - - @property - def entry_schema(self): - return self.schema.get(self.ENTRYSCHEMA) - - def __getitem__(self, key): - return self.schema[key] - - def __iter__(self): - for k in self.KEYS: - try: - self.schema[k] - except KeyError: - pass - else: - yield k - - def __len__(self): - if self._len is None: - self._len = len(list(iter(self))) - return self._len - - -class Constraint(object): - '''Parent class for constraints for a Property or Input.''' - - CONSTRAINTS = (EQUAL, GREATER_THAN, - GREATER_OR_EQUAL, LESS_THAN, LESS_OR_EQUAL, IN_RANGE, - VALID_VALUES, LENGTH, MIN_LENGTH, MAX_LENGTH, PATTERN) = \ - ('equal', 'greater_than', 'greater_or_equal', 'less_than', - 'less_or_equal', 'in_range', 'valid_values', 'length', - 'min_length', 'max_length', 'pattern') - - def __new__(cls, property_name, property_type, constraint): - if cls is not Constraint: - return super(Constraint, cls).__new__(cls) - - if(not isinstance(constraint, collections.Mapping) or - len(constraint) != 1): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('Invalid constraint schema.'))) - - for type in constraint.keys(): - ConstraintClass = get_constraint_class(type) - if not ConstraintClass: - msg = _('Invalid property "%s".') % type - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - return ConstraintClass(property_name, property_type, constraint) - - def __init__(self, property_name, property_type, constraint): - self.property_name = property_name - self.property_type = property_type - self.constraint_value = constraint[self.constraint_key] - self.constraint_value_msg = self.constraint_value - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - self.constraint_value = self._get_scalarunit_constraint_value() - # check if constraint is valid for property type - if property_type not in self.valid_prop_types: - msg = _('Property "%(ctype)s" is not valid for data type ' - '"%(dtype)s".') % dict( - ctype=self.constraint_key, - dtype=property_type) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - def _get_scalarunit_constraint_value(self): - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - ScalarUnit_Class = (scalarunit. - get_scalarunit_class(self.property_type)) - if isinstance(self.constraint_value, list): - return [ScalarUnit_Class(v).get_num_from_scalar_unit() - for v in self.constraint_value] - else: - return (ScalarUnit_Class(self.constraint_value). - get_num_from_scalar_unit()) - - def _err_msg(self, value): - return _('Property "%s" could not be validated.') % self.property_name - - def validate(self, value): - self.value_msg = value - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - value = scalarunit.get_scalarunit_value(self.property_type, value) - if not self._is_valid(value): - err_msg = self._err_msg(value) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - - -class Equal(Constraint): - """Constraint class for "equal" - - Constrains a property or parameter to a value equal to ('=') - the value declared. - """ - - constraint_key = Constraint.EQUAL - - valid_prop_types = Schema.PROPERTY_TYPES - - def _is_valid(self, value): - if value == self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' - 'equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class GreaterThan(Constraint): - """Constraint class for "greater_than" - - Constrains a property or parameter to a value greater than ('>') - the value declared. - """ - - constraint_key = Constraint.GREATER_THAN - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(GreaterThan, self).__init__(property_name, property_type, - constraint) - if not isinstance(constraint[self.GREATER_THAN], self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "greater_than" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value > self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'greater than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class GreaterOrEqual(Constraint): - """Constraint class for "greater_or_equal" - - Constrains a property or parameter to a value greater than or equal - to ('>=') the value declared. - """ - - constraint_key = Constraint.GREATER_OR_EQUAL - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(GreaterOrEqual, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property ' - '"greater_or_equal" expects ' - 'comparable values.'))) - - def _is_valid(self, value): - if toscaparser.functions.is_function(value) or \ - value >= self.constraint_value: - return True - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'greater than or equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class LessThan(Constraint): - """Constraint class for "less_than" - - Constrains a property or parameter to a value less than ('<') - the value declared. - """ - - constraint_key = Constraint.LESS_THAN - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(LessThan, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "less_than" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value < self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'less than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class LessOrEqual(Constraint): - """Constraint class for "less_or_equal" - - Constrains a property or parameter to a value less than or equal - to ('<=') the value declared. - """ - - constraint_key = Constraint.LESS_OR_EQUAL - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(LessOrEqual, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "less_or_equal" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value <= self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'less than or equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class InRange(Constraint): - """Constraint class for "in_range" - - Constrains a property or parameter to a value in range of (inclusive) - the two values declared. - """ - - constraint_key = Constraint.IN_RANGE - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(InRange, self).__init__(property_name, property_type, constraint) - if(not isinstance(self.constraint_value, collections.Sequence) or - (len(constraint[self.IN_RANGE]) != 2)): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "in_range" ' - 'expects a list.'))) - - for value in self.constraint_value: - if not isinstance(value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(_('The property "in_range" expects ' - 'comparable values.'))) - - self.min = self.constraint_value[0] - self.max = self.constraint_value[1] - - def _is_valid(self, value): - if value < self.min: - return False - if value > self.max: - return False - - return True - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - vmin=self.constraint_value_msg[0], - vmax=self.constraint_value_msg[1])) - - -class ValidValues(Constraint): - """Constraint class for "valid_values" - - Constrains a property or parameter to a value that is in the list of - declared values. - """ - constraint_key = Constraint.VALID_VALUES - - valid_prop_types = Schema.PROPERTY_TYPES - - def __init__(self, property_name, property_type, constraint): - super(ValidValues, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, collections.Sequence): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "valid_values" ' - 'expects a list.'))) - - def _is_valid(self, value): - if isinstance(value, list): - return all(v in self.constraint_value for v in value) - return value in self.constraint_value - - def _err_msg(self, value): - allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value) - return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' - 'valid. Expected a value from "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=allowed)) - - -class Length(Constraint): - """Constraint class for "length" - - Constrains the property or parameter to a value of a given length. - """ - - constraint_key = Constraint.LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(Length, self).__init__(property_name, property_type, constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "length" expects ' - 'an integer.'))) - - def _is_valid(self, value): - if isinstance(value, str) and len(value) == self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class MinLength(Constraint): - """Constraint class for "min_length" - - Constrains the property or parameter to a value to a minimum length. - """ - - constraint_key = Constraint.MIN_LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(MinLength, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "min_length" ' - 'expects an integer.'))) - - def _is_valid(self, value): - if isinstance(value, str) and len(value) >= self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be at least "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class MaxLength(Constraint): - """Constraint class for "max_length" - - Constrains the property or parameter to a value to a maximum length. - """ - - constraint_key = Constraint.MAX_LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(MaxLength, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "max_length" ' - 'expects an integer.'))) - - def _is_valid(self, value): - if isinstance(value, str) and len(value) <= self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be no greater than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class Pattern(Constraint): - """Constraint class for "pattern" - - Constrains the property or parameter to a value that is allowed by - the provided regular expression. - """ - - constraint_key = Constraint.PATTERN - - valid_types = (str, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(Pattern, self).__init__(property_name, property_type, constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "pattern" ' - 'expects a string.'))) - self.match = re.compile(self.constraint_value).match - - def _is_valid(self, value): - match = self.match(value) - return match is not None and match.end() == len(value) - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" does not ' - 'match pattern "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -constraint_mapping = { - Constraint.EQUAL: Equal, - Constraint.GREATER_THAN: GreaterThan, - Constraint.GREATER_OR_EQUAL: GreaterOrEqual, - Constraint.LESS_THAN: LessThan, - Constraint.LESS_OR_EQUAL: LessOrEqual, - Constraint.IN_RANGE: InRange, - Constraint.VALID_VALUES: ValidValues, - Constraint.LENGTH: Length, - Constraint.MIN_LENGTH: MinLength, - Constraint.MAX_LENGTH: MaxLength, - Constraint.PATTERN: Pattern - } - - -def get_constraint_class(type): - return constraint_mapping.get(type) diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/datatype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/datatype.py deleted file mode 100644 index 7e05a69..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/datatype.py +++ /dev/null @@ -1,56 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class DataType(StatefulEntityType): - '''TOSCA built-in and user defined complex data type.''' - - def __init__(self, datatypename, custom_def=None): - super(DataType, self).__init__(datatypename, self.DATATYPE_PREFIX, - custom_def) - self.custom_def = custom_def - - @property - def parent_type(self): - '''Return a datatype this datatype is derived from.''' - ptype = self.derived_from(self.defs) - if ptype: - return DataType(ptype, self.custom_def) - return None - - @property - def value_type(self): - '''Return 'type' section in the datatype schema.''' - return self.entity_value(self.defs, 'type') - - def get_all_properties_objects(self): - '''Return all properties objects defined in type and parent type.''' - props_def = self.get_properties_def_objects() - ptype = self.parent_type - while ptype: - props_def.extend(ptype.get_properties_def_objects()) - ptype = ptype.parent_type - return props_def - - def get_all_properties(self): - '''Return a dictionary of all property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_all_properties_objects()} - - def get_all_property_value(self, name): - '''Return the value of a given property name.''' - props_def = self.get_all_properties() - if props_def and name in props_def.key(): - return props_def[name].value diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/entity_type.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/entity_type.py deleted file mode 100644 index 54aaa7e..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/entity_type.py +++ /dev/null @@ -1,115 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import logging -import os -import toscaparser.utils.yamlparser - -log = logging.getLogger('tosca') - - -class EntityType(object): - '''Base class for TOSCA elements.''' - - SECTIONS = (DERIVED_FROM, PROPERTIES, ATTRIBUTES, REQUIREMENTS, - INTERFACES, CAPABILITIES, TYPE, ARTIFACTS) = \ - ('derived_from', 'properties', 'attributes', 'requirements', - 'interfaces', 'capabilities', 'type', 'artifacts') - - '''TOSCA definition file.''' - TOSCA_DEF_FILE = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "TOSCA_definition_1_0.yaml") - - loader = toscaparser.utils.yamlparser.load_yaml - - TOSCA_DEF = loader(TOSCA_DEF_FILE) - - RELATIONSHIP_TYPE = (DEPENDSON, HOSTEDON, CONNECTSTO, ATTACHESTO, - LINKSTO, BINDSTO) = \ - ('tosca.relationships.DependsOn', - 'tosca.relationships.HostedOn', - 'tosca.relationships.ConnectsTo', - 'tosca.relationships.AttachesTo', - 'tosca.relationships.network.LinksTo', - 'tosca.relationships.network.BindsTo') - - NODE_PREFIX = 'tosca.nodes.' - RELATIONSHIP_PREFIX = 'tosca.relationships.' - CAPABILITY_PREFIX = 'tosca.capabilities.' - INTERFACE_PREFIX = 'tosca.interfaces.' - ARTIFACT_PREFIX = 'tosca.artifacts.' - POLICY_PREFIX = 'tosca.policies.' - # currently the data types are defined only for network - # but may have changes in the future. - DATATYPE_PREFIX = 'tosca.datatypes.network.' - TOSCA = 'tosca' - - def derived_from(self, defs): - '''Return a type this type is derived from.''' - return self.entity_value(defs, 'derived_from') - - def is_derived_from(self, type_str): - '''Check if object inherits from the given type. - - Returns true if this object is derived from 'type_str'. - False otherwise. - ''' - if not self.type: - return False - elif self.type == type_str: - return True - elif self.parent_type: - return self.parent_type.is_derived_from(type_str) - else: - return False - - def entity_value(self, defs, key): - if key in defs: - return defs[key] - - def get_value(self, ndtype, defs=None, parent=None): - value = None - if defs is None: - if not hasattr(self, 'defs'): - return - defs = self.defs - if ndtype in defs: - value = defs[ndtype] - if parent and not value: - p = self.parent_type - while value is None: - # check parent node - if not p: - break - if p and p.type == 'tosca.nodes.Root': - break - value = p.get_value(ndtype) - p = p.parent_type - return value - - def get_definition(self, ndtype): - value = None - defs = self.defs - if ndtype in defs: - value = defs[ndtype] - p = self.parent_type - if p: - inherited = p.get_definition(ndtype) - if inherited: - inherited = dict(inherited) - if not value: - value = inherited - else: - inherited.update(value) - value.update(inherited) - return value diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/interfaces.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/interfaces.py deleted file mode 100644 index 88fb8ab..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/interfaces.py +++ /dev/null @@ -1,76 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.statefulentitytype import StatefulEntityType - -SECTIONS = (LIFECYCLE, CONFIGURE, LIFECYCLE_SHORTNAME, - CONFIGURE_SHORTNAME) = \ - ('tosca.interfaces.node.lifecycle.Standard', - 'tosca.interfaces.relationship.Configure', - 'Standard', 'Configure') - -INTERFACEVALUE = (IMPLEMENTATION, INPUTS) = ('implementation', 'inputs') - - -class InterfacesDef(StatefulEntityType): - '''TOSCA built-in interfaces type.''' - - def __init__(self, node_type, interfacetype, - node_template=None, name=None, value=None): - self.ntype = node_type - self.node_template = node_template - self.type = interfacetype - self.name = name - self.value = value - self.implementation = None - self.inputs = None - self.defs = {} - if interfacetype == LIFECYCLE_SHORTNAME: - interfacetype = LIFECYCLE - if interfacetype == CONFIGURE_SHORTNAME: - interfacetype = CONFIGURE - if node_type: - self.defs = self.TOSCA_DEF[interfacetype] - if value: - if isinstance(self.value, dict): - for i, j in self.value.items(): - if i == IMPLEMENTATION: - self.implementation = j - elif i == INPUTS: - self.inputs = j - else: - what = ('"interfaces" of template "%s"' % - self.node_template.name) - ExceptionCollector.appendException( - UnknownFieldError(what=what, field=i)) - else: - self.implementation = value - - @property - def lifecycle_ops(self): - if self.defs: - if self.type == LIFECYCLE: - return self._ops() - - @property - def configure_ops(self): - if self.defs: - if self.type == CONFIGURE: - return self._ops() - - def _ops(self): - ops = [] - for name in list(self.defs.keys()): - ops.append(name) - return ops diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/nodetype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/nodetype.py deleted file mode 100644 index 8ddc5a2..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/nodetype.py +++ /dev/null @@ -1,202 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.elements.capabilitytype import CapabilityTypeDef -import toscaparser.elements.interfaces as ifaces -from toscaparser.elements.interfaces import InterfacesDef -from toscaparser.elements.relationshiptype import RelationshipType -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class NodeType(StatefulEntityType): - '''TOSCA built-in node type.''' - - def __init__(self, ntype, custom_def=None): - super(NodeType, self).__init__(ntype, self.NODE_PREFIX, custom_def) - self.custom_def = custom_def - - @property - def parent_type(self): - '''Return a node this node is derived from.''' - if not hasattr(self, 'defs'): - return - pnode = self.derived_from(self.defs) - if pnode: - return NodeType(pnode, self.custom_def) - - @property - def relationship(self): - '''Return a dictionary of relationships to other node types. - - This method returns a dictionary of named relationships that nodes - of the current node type (self) can have to other nodes (of specific - types) in a TOSCA template. - - ''' - relationship = {} - requires = self.get_all_requirements() - if requires: - # NOTE(sdmonov): Check if requires is a dict. - # If it is a dict convert it to a list of dicts. - # This is needed because currently the code below supports only - # lists as requirements definition. The following check will - # make sure if a map (dict) was provided it will be converted to - # a list before proceeding to the parsing. - if isinstance(requires, dict): - requires = [{key: value} for key, value in requires.items()] - - keyword = None - node_type = None - for require in requires: - for key, req in require.items(): - if 'relationship' in req: - relation = req.get('relationship') - if 'type' in relation: - relation = relation.get('type') - node_type = req.get('node') - value = req - if node_type: - keyword = 'node' - else: - # If value is a dict and has a type key - # we need to lookup the node type using - # the capability type - value = req - if isinstance(value, dict): - captype = value['capability'] - value = (self. - _get_node_type_by_cap(key, captype)) - relation = self._get_relation(key, value) - keyword = key - node_type = value - rtype = RelationshipType(relation, keyword, req) - relatednode = NodeType(node_type, self.custom_def) - relationship[rtype] = relatednode - return relationship - - def _get_node_type_by_cap(self, key, cap): - '''Find the node type that has the provided capability - - This method will lookup all node types if they have the - provided capability. - ''' - - # Filter the node types - node_types = [node_type for node_type in self.TOSCA_DEF.keys() - if node_type.startswith(self.NODE_PREFIX) and - node_type != 'tosca.nodes.Root'] - - for node_type in node_types: - node_def = self.TOSCA_DEF[node_type] - if isinstance(node_def, dict) and 'capabilities' in node_def: - node_caps = node_def['capabilities'] - for value in node_caps.values(): - if isinstance(value, dict) and \ - 'type' in value and value['type'] == cap: - return node_type - - def _get_relation(self, key, ndtype): - relation = None - ntype = NodeType(ndtype) - caps = ntype.get_capabilities() - if caps and key in caps.keys(): - c = caps[key] - for r in self.RELATIONSHIP_TYPE: - rtypedef = ntype.TOSCA_DEF[r] - for properties in rtypedef.values(): - if c.type in properties: - relation = r - break - if relation: - break - else: - for properties in rtypedef.values(): - if c.parent_type in properties: - relation = r - break - return relation - - def get_capabilities_objects(self): - '''Return a list of capability objects.''' - typecapabilities = [] - caps = self.get_value(self.CAPABILITIES) - if caps is None: - caps = self.get_value(self.CAPABILITIES, None, True) - if caps: - for name, value in caps.items(): - ctype = value.get('type') - cap = CapabilityTypeDef(name, ctype, self.type, - self.custom_def) - typecapabilities.append(cap) - return typecapabilities - - def get_capabilities(self): - '''Return a dictionary of capability name-objects pairs.''' - return {cap.name: cap - for cap in self.get_capabilities_objects()} - - @property - def requirements(self): - return self.get_value(self.REQUIREMENTS) - - def get_all_requirements(self): - requires = self.requirements - parent_node = self.parent_type - if requires is None: - requires = self.get_value(self.REQUIREMENTS, None, True) - parent_node = parent_node.parent_type - if parent_node: - while parent_node.type != 'tosca.nodes.Root': - req = parent_node.get_value(self.REQUIREMENTS, None, True) - for r in req: - if r not in requires: - requires.append(r) - parent_node = parent_node.parent_type - return requires - - @property - def interfaces(self): - return self.get_value(self.INTERFACES) - - @property - def lifecycle_inputs(self): - '''Return inputs to life cycle operations if found.''' - inputs = [] - interfaces = self.interfaces - if interfaces: - for name, value in interfaces.items(): - if name == ifaces.LIFECYCLE: - for x, y in value.items(): - if x == 'inputs': - for i in y.iterkeys(): - inputs.append(i) - return inputs - - @property - def lifecycle_operations(self): - '''Return available life cycle operations if found.''' - ops = None - interfaces = self.interfaces - if interfaces: - i = InterfacesDef(self.type, ifaces.LIFECYCLE) - ops = i.lifecycle_ops - return ops - - def get_capability(self, name): - caps = self.get_capabilities() - if caps and name in caps.keys(): - return caps[name].value - - def get_capability_type(self, name): - captype = self.get_capability(name) - if captype and name in captype.keys(): - return captype[name].value diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/policytype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/policytype.py deleted file mode 100644 index aa53c2d..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/policytype.py +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class PolicyType(StatefulEntityType): - '''TOSCA built-in policies type.''' - - def __init__(self, ptype, custom_def=None): - super(PolicyType, self).__init__(ptype, self.POLICY_PREFIX, - custom_def) - self.type = ptype - self.properties = None - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_policies = self._get_parent_policies() - - def _get_parent_policies(self): - policies = {} - parent_policy = self.parent_type - if parent_policy: - while parent_policy != 'tosca.policies.Root': - policies[parent_policy] = self.TOSCA_DEF[parent_policy] - parent_policy = policies[parent_policy]['derived_from'] - return policies - - @property - def parent_type(self): - '''Return a policy this policy is derived from.''' - return self.derived_from(self.defs) - - def get_policy(self, name): - '''Return the definition of a policy field by name.''' - if name in self.defs: - return self.defs[name] diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/property_definition.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/property_definition.py deleted file mode 100644 index 4ffcade..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/property_definition.py +++ /dev/null @@ -1,48 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidSchemaError -from toscaparser.utils.gettextutils import _ - - -class PropertyDef(object): - '''TOSCA built-in Property type.''' - - def __init__(self, name, value=None, schema=None): - self.name = name - self.value = value - self.schema = schema - - try: - self.schema['type'] - except KeyError: - msg = (_('Schema definition of "%(pname)s" must have a "type" ' - 'attribute.') % dict(pname=self.name)) - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - @property - def required(self): - if self.schema: - for prop_key, prop_value in self.schema.items(): - if prop_key == 'required' and prop_value: - return True - return False - - @property - def default(self): - if self.schema: - for prop_key, prop_value in self.schema.items(): - if prop_key == 'default': - return prop_value - return None diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/relationshiptype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/relationshiptype.py deleted file mode 100644 index 9462d38..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/relationshiptype.py +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class RelationshipType(StatefulEntityType): - '''TOSCA built-in relationship type.''' - def __init__(self, type, capability_name=None, custom_def=None): - super(RelationshipType, self).__init__(type, self.RELATIONSHIP_PREFIX, - custom_def) - self.capability_name = capability_name - self.custom_def = custom_def - - @property - def parent_type(self): - '''Return a relationship this reletionship is derived from.''' - prel = self.derived_from(self.defs) - if prel: - return RelationshipType(prel) - - @property - def valid_target_types(self): - return self.entity_value(self.defs, 'valid_target_types') diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/scalarunit.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/scalarunit.py deleted file mode 100644 index d7f72e6..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/scalarunit.py +++ /dev/null @@ -1,129 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import logging -import re - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import validateutils - -log = logging.getLogger('tosca') - - -class ScalarUnit(object): - '''Parent class for scalar-unit type.''' - - SCALAR_UNIT_TYPES = ( - SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME - ) = ( - 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time' - ) - - def __init__(self, value): - self.value = value - - def _check_unit_in_scalar_standard_units(self, input_unit): - """Check whether the input unit is following specified standard - - If unit is not following specified standard, convert it to standard - unit after displaying a warning message. - """ - if input_unit in self.SCALAR_UNIT_DICT.keys(): - return input_unit - else: - for key in self.SCALAR_UNIT_DICT.keys(): - if key.upper() == input_unit.upper(): - log.warning(_('The unit "%(unit)s" does not follow ' - 'scalar unit standards; using "%(key)s" ' - 'instead.') % {'unit': input_unit, - 'key': key}) - return key - msg = (_('The unit "%(unit)s" is not valid. Valid units are ' - '"%(valid_units)s".') % - {'unit': input_unit, - 'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())}) - ExceptionCollector.appendException(ValueError(msg)) - - def validate_scalar_unit(self): - regex = re.compile('([0-9.]+)\s*(\w+)') - try: - result = regex.match(str(self.value)).groups() - validateutils.str_to_num(result[0]) - scalar_unit = self._check_unit_in_scalar_standard_units(result[1]) - self.value = ' '.join([result[0], scalar_unit]) - return self.value - - except Exception: - ExceptionCollector.appendException( - ValueError(_('"%s" is not a valid scalar-unit.') - % self.value)) - - def get_num_from_scalar_unit(self, unit=None): - if unit: - unit = self._check_unit_in_scalar_standard_units(unit) - else: - unit = self.SCALAR_UNIT_DEFAULT - self.validate_scalar_unit() - - regex = re.compile('([0-9.]+)\s*(\w+)') - result = regex.match(str(self.value)).groups() - converted = (float(validateutils.str_to_num(result[0])) - * self.SCALAR_UNIT_DICT[result[1]] - / self.SCALAR_UNIT_DICT[unit]) - if converted - int(converted) < 0.0000000000001: - converted = int(converted) - return converted - - -class ScalarUnit_Size(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'B' - SCALAR_UNIT_DICT = {'B': 1, 'kB': 1000, 'KiB': 1024, 'MB': 1000000, - 'MiB': 1048576, 'GB': 1000000000, - 'GiB': 1073741824, 'TB': 1000000000000, - 'TiB': 1099511627776} - - -class ScalarUnit_Time(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'ms' - SCALAR_UNIT_DICT = {'d': 86400, 'h': 3600, 'm': 60, 's': 1, - 'ms': 0.001, 'us': 0.000001, 'ns': 0.000000001} - - -class ScalarUnit_Frequency(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'GHz' - SCALAR_UNIT_DICT = {'Hz': 1, 'kHz': 1000, - 'MHz': 1000000, 'GHz': 1000000000} - - -scalarunit_mapping = { - ScalarUnit.SCALAR_UNIT_FREQUENCY: ScalarUnit_Frequency, - ScalarUnit.SCALAR_UNIT_SIZE: ScalarUnit_Size, - ScalarUnit.SCALAR_UNIT_TIME: ScalarUnit_Time, - } - - -def get_scalarunit_class(type): - return scalarunit_mapping.get(type) - - -def get_scalarunit_value(type, value, unit=None): - if type in ScalarUnit.SCALAR_UNIT_TYPES: - ScalarUnit_Class = get_scalarunit_class(type) - return (ScalarUnit_Class(value). - get_num_from_scalar_unit(unit)) - else: - ExceptionCollector.appendException( - TypeError(_('"%s" is not a valid scalar-unit type.') % type)) diff --git a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/statefulentitytype.py b/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/statefulentitytype.py deleted file mode 100644 index 9c8f4e2..0000000 --- a/tosca2heat/tosca-parser-0.3.0/toscaparser/elements/statefulentitytype.py +++ /dev/null @@ -1,83 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTypeError -from toscaparser.elements.attribute_definition import AttributeDef -from toscaparser.elements.entity_type import EntityType -from toscaparser.elements.property_definition import PropertyDef - - -class StatefulEntityType(EntityType): - '''Class representing TOSCA states.''' - - interfaces_node_lifecycle_operations = ['create', - 'configure', 'start', - 'stop', 'delete'] - - interfaces_relationship_confiure_operations = ['post_configure_source', - 'post_configure_target', - 'add_target', - 'remove_target'] - - def __init__(self, entitytype, prefix, custom_def=None): - entire_entitytype = entitytype - if not entitytype.startswith(self.TOSCA): - entire_entitytype = prefix + entitytype - if entire_entitytype in list(self.TOSCA_DEF.keys()): - self.defs = self.TOSCA_DEF[entire_entitytype] - entitytype = entire_entitytype - elif custom_def and entitytype in list(custom_def.keys()): - self.defs = custom_def[entitytype] - else: - ExceptionCollector.appendException( - InvalidTypeError(what=entitytype)) - self.type = entitytype - - def get_properties_def_objects(self): - '''Return a list of property definition objects.''' - properties = [] - props = self.get_definition(self.PROPERTIES) - if props: - for prop, schema in props.items(): - properties.append(PropertyDef(prop, None, schema)) - return properties - - def get_properties_def(self): - '''Return a dictionary of property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_def_objects()} - - def get_property_def_value(self, name): - '''Return the property definition associated with a given name.''' - props_def = self.get_properties_def() - if props_def and name in props_def.keys(): - return props_def[name].value - - def get_attributes_def_objects(self): - '''Return a list of attribute definition objects.''' - attrs = self.get_value(self.ATTRIBUTES) - if attrs: - return [AttributeDef(attr, None, schema) - for attr, schema in attrs.items()] - return [] - - def get_attributes_def(self): - '''Return a dictionary of attribute definition name-object pairs.''' - return {attr.name: attr - for attr in self.get_attributes_def_objects()} - - def get_attribute_def_value(self, name): - '''Return the attribute definition associated with a given name.''' - attrs_def = self.get_attributes_def() - if attrs_def and name in attrs_def.keys(): - return attrs_def[name].value |