Add .gitreview file and apply cookiecutter template.

Add .getreview file and add files generated via cookiecutter template.
Also delete some originally added files to have project's initial layout
ready.

Change-Id: I494f52469b5a4aff1c1f12d58bcf41140ad3e680
This commit is contained in:
Sahdev Zala 2014-03-12 19:06:04 -05:00
parent 4112cf5607
commit d4d826ef96
72 changed files with 544 additions and 772 deletions

7
.coveragerc Normal file
View File

@ -0,0 +1,7 @@
[run]
branch = True
source = heat-translator
omit = heat-translator/tests/*,heat-translator/openstack/*
[report]
ignore-errors = True

51
.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
.testrepository
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Complexity
output/*.html
output/*/index.html
# Sphinx
doc/build
# pbr generates these
AUTHORS
ChangeLog
# Editors
*~
.*.swp

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
project=stackforge/heat-translator.git

3
.mailmap Normal file
View File

@ -0,0 +1,3 @@
# Format is:
# <preferred e-mail> <other e-mail 1>
# <preferred e-mail> <other e-mail 2>

7
.testr.conf Normal file
View File

@ -0,0 +1,7 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

17
CONTRIBUTING.rst Normal file
View File

@ -0,0 +1,17 @@
If you would like to contribute to the development of OpenStack,
you must follow the steps in the "If you're a developer, start here"
section of this page:
http://wiki.openstack.org/HowToContribute
Once those steps have been completed, changes to OpenStack
should be submitted for review via the Gerrit tool, following
the workflow documented at:
http://wiki.openstack.org/GerritWorkflow
Pull requests submitted through GitHub will be ignored.
Bugs should be filed on Launchpad, not GitHub:
https://bugs.launchpad.net/heat-translator

4
HACKING.rst Normal file
View File

@ -0,0 +1,4 @@
heat-translator Style Commandments
===============================================
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/

175
LICENSE Normal file
View File

@ -0,0 +1,175 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

6
MANIFEST.in Normal file
View File

@ -0,0 +1,6 @@
include AUTHORS
include ChangeLog
exclude .gitignore
exclude .gitreview
global-exclude *.pyc

13
README.rst Normal file
View File

@ -0,0 +1,13 @@
===============================
heat-translator
===============================
Tool to translate non-heat templates to Heat Orchestration Template.
* Free software: Apache license
* Documentation: http://docs.openstack.org/developer/heat-translator
Features
--------
* TODO

1
babel.cfg Normal file
View File

@ -0,0 +1 @@
[python: **.py]

75
doc/source/conf.py Executable file
View File

@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
# 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 os
import sys
sys.path.insert(0, os.path.abspath('../..'))
# -- General configuration ----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
#'sphinx.ext.intersphinx',
'oslo.sphinx'
]
# autodoc generation is a bit aggressive and a nuisance when doing heavy
# text edit cycles.
# execute "export SPHINX_DEBUG=1" in your terminal to disable
# The suffix of source filenames.
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'heat-translator'
copyright = u'2013, OpenStack Foundation'
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
add_module_names = True
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# -- Options for HTML output --------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
# html_theme_path = ["."]
# html_theme = '_theme'
# html_static_path = ['static']
# Output file base name for HTML help builder.
htmlhelp_basename = '%sdoc' % project
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index',
'%s.tex' % project,
u'%s Documentation' % project,
u'OpenStack Foundation', 'manual'),
]
# Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/': None}

View File

@ -0,0 +1 @@
.. include:: ../../CONTRIBUTING.rst

24
doc/source/index.rst Normal file
View File

@ -0,0 +1,24 @@
.. heat-translator documentation master file, created by
sphinx-quickstart on Tue Jul 9 22:26:36 2013.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to heat-translator's documentation!
========================================================
Contents:
.. toctree::
:maxdepth: 2
readme
installation
usage
contributing
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -0,0 +1,12 @@
============
Installation
============
At the command line::
$ pip install heat-translator
Or, if you have virtualenvwrapper installed::
$ mkvirtualenv heat-translator
$ pip install heat-translator

1
doc/source/readme.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../README.rst

7
doc/source/usage.rst Normal file
View File

@ -0,0 +1,7 @@
========
Usage
========
To use heat-translator in a project::
import heat-translator

View File

@ -1,2 +0,0 @@
def write_output(output):
pass

Binary file not shown.

Binary file not shown.

View File

@ -1,38 +0,0 @@
#!/usr/bin/env python
import exit
import os
import sys
from source import Source
from tosca.translate import TOSCATranslator
from tosca.tosca_profile import Tosca
from tosca.validate import ToscaValidator
def main():
sourcetype = sys.argv[1]
path = sys.argv[2]
#sourcetype = "tosca"
#path = "/heat-translator/tosca/tests/tosca.yaml"
if not sourcetype:
print("Translation type is needed. For example, 'tosca'")
if not path.endswith(".yaml"):
print "Only YAML file is supported at this time."
if os.path.isdir(path):
print('Translation of directory is not supported at this time : %s' % path)
elif os.path.isfile(path):
heat_tpl = translate(sourcetype, path)
exit.write_output(heat_tpl)
else:
print('%s is not a valid file.' % path)
def translate(sourcetype, path):
tpl = Source(path)
if sourcetype == "tosca":
tosca = Tosca(tpl)
ToscaValidator(tosca).validate()
return TOSCATranslator(tosca).translate()
if __name__ == '__main__':
main()

View File

@ -1,18 +0,0 @@
from yaml_loader import Loader
class Source(object):
def __init__(self, path):
self.profile = Loader(path).load()
def __contains__(self, key):
return key in self.profile
def __iter__(self):
return iter(self.profile)
def __len__(self):
return len(self.profile)
def __getitem__(self, key):
'''Get a section.'''
return self.profile[key]

Binary file not shown.

Binary file not shown.

View File

@ -1,66 +0,0 @@
from tosca.nodetemplates.schema import Schema
from tosca.nodetemplates.constraints import Constraint
class InputParameters(object):
def __init__(self, inputs):
self.inputs = inputs
def __contains__(self, key):
return key in self.inputs
def __iter__(self):
return iter(self.inputs)
def __len__(self):
return len(self.inputs)
def __getitem__(self, key):
'''Get a input value.'''
return self.inputs[key]
class Input(object):
def __init__(self, name, schema):
self.name = name
self.schema = schema
def get_type(self):
return self.schema['type']
def get_description(self):
if self.has_default():
return self.schema['description']
return ''
def get_default(self):
if self.has_default():
return self.schema['default']
return ''
def get_constraints(self):
return self.schema['constraints']
def has_default(self):
'''Return whether the parameter has a default value.'''
return Schema.DEFAULT in self.schema
def has_description(self):
'''Return whether the parameter has a default value.'''
return Schema.DESCRIPTION in self.schema
def validate(self):
self.validate_type(self.get_type())
self.validate_constraints(self.get_constraints())
def validate_type(self, input_type):
if input_type not in Schema.TYPES:
raise ValueError('Invalid type %s' % type)
def validate_constraints(self, constraints):
for constraint in constraints:
for key in constraint.keys():
if key not in Constraint.CONSTRAINTS:
raise ValueError('Invalid constraint %s' % constraint)
if isinstance(key, dict): #and is_required to have a min or max or in certain range or equal to something etc.
pass

Binary file not shown.

View File

@ -1,87 +0,0 @@
import numbers
class Constraint(object):
CONSTRAINTS = (EQUAL, GREATER_THAN,
GREATER_OR_EQUAL, LESS_THAN, LESS_OR_EQUAL, IN_RANGE, VALID_VALUES,
LENGTH, MIN_LENGHT, 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 __init__(self, propertyname, value, constraint):
self.propertyname = propertyname
self.value = value
self.constraint = constraint #dictionary e.g. valid_values: [ 1, 2, 4, 8 ] or greater_or_equal: 1
def validate(self):
# for key in self.constraint.iterkeys():
for key, value in self.constraint.iteritems():
if key == "greater_or_equal":
self.validate_greater_than(value)
def validate_equal(self):
pass
def validate_greater_than(self, value):
if self.value < value:
print("%s value requires to be greater than %s" % (self.propertyname, value))
def validate_greater_or_equal(self):
pass
def validate_less_than(self):
pass
def validate_less_or_equal(self):
pass
def validate_in_range(self):
pass
def validate_valid_values(self):
pass
def validate_length(self):
pass
def validate_min_length(self):
pass
def validate_max_length(self):
pass
def validate_pattern(self):
pass
@staticmethod
def validate_integer(value):
if not isinstance(value, (int, long)):
import pdb
pdb.set_trace()
raise TypeError('value is not an integer for %s' %value)
return Constraint.validate_number(value)
@staticmethod
def validate_number(value):
return Constraint.str_to_num(value)
@staticmethod
def validate_string(value):
if not isinstance(value, basestring):
raise ValueError('Value must be a string %s' %value)
return value
@staticmethod
def validate_list(self, value):
pass
@staticmethod
def str_to_num(value):
"""Convert a string representation of a number into a numeric type."""
if isinstance(value, numbers.Number):
return value
try:
return int(value)
except ValueError:
return float(value)

View File

@ -1,117 +0,0 @@
from properties import Property
from tosca.nodetemplates.schema import Schema
from tosca.inputs import InputParameters
from tosca.inputs import Input
from tosca.nodetemplates.node_templates import NodeTemplates
class NodeTemplate(object):
def __init__(self, name, nodetemplate, tosca):
self.name = name
self.nodetemplate = nodetemplate
self.tosca = tosca
def get_node(self):
return self.nodetemplate
def get_name(self):
return self.name
def get_type(self):
return self.nodetemplate['type']
def get_properties(self):
return self.nodetemplate['properties']
def validate(self):
self.validate_prpoerties()
self.validate_type()
#TODO
def validate_type(self):
pass
#TODO
def validate_relationship(self):
pass
def validate_prpoerties(self):
'''validate that required properties for a particular nodetype is provided and matches constraints'''
nodetype = self.get_type()
required_props = Schema(nodetype).required()
for req in required_props:
if req not in self.get_properties():
raise ValueError('Missing required property %s' %req)
for prop, val in self.get_properties().iteritems():
if isinstance(val, dict):
for key, value in val.iteritems():
if key == "get_input":
val = self.get_input_ref(value)
break
if key == "get_property":
val = self.get_property_ref(value, self.tosca)
if val is not None:
Property(prop, self.get_type(), val).validate()
def get_input_ref(self, ref):
''' get input reference, for example, get_input: db_user '''
input_val = self.tosca.get_inputs()[ref]
if Input(ref, input_val).has_default():
return Input(ref, input_val).get_default()
@classmethod
def get_property_ref(cls, ref, t):
''' get property reference, for example, get_property: [ mysql, db_user ] '''
item = ref[0]
n = t.get_nodetemplates()[item]
c = cls(item, n, t)
for val in c.get_properties().itervalues():
if isinstance(val, dict):
for key, value in val.iteritems():
if key == "get_input":
return c.get_input_ref(value)
def get_relationship(self):
return self.nodetemplate['requirements']
def get_hostedOn_relationship(self):
hosted = []
r = self.get_relationship()
for key, value in r.iteritems():
if key == "host":
hosted.append(value)
return hosted
def get_dependsOn_relationship(self):
depends = []
r = self.get_relationship()
for key, value in r.iteritems():
if key == "dependency":
depends.append(value)
return depends
def get_connectedTo_relationship(self):
connected = []
r = self.get_relationship()
for key, value in r.iteritems():
if key == "database":
connected.append(value)
return connected
def is_hostedOn(self):
pass
def is_dependsOn(self):
pass
def is_connectedTo(self):
pass
def get_interfaces(self):
return self.nodetemplate['interfaces']
def get_interface_inputs(self, interface):
i = self.get_interfaces()
for key, value in i.iteritems():
if key == interface:
return value

View File

@ -1,19 +0,0 @@
from tosca.tosca_profile import Tosca
class NodeTemplates(object):
def __init__(self, nodetemplates):
self.nodetemplates = nodetemplates
def __contains__(self, key):
return key in self.nodetemplates
def __iter__(self):
return iter(self.nodetemplates)
def __len__(self):
return len(self.nodetemplates)
def __getitem__(self, key):
'''Get a node template value.'''
return self.nodetemplates[key]

View File

@ -1,29 +0,0 @@
from rootnodetype import RootNodeType
class NodeType(RootNodeType):
def __init__(self, nodetype):
super(NodeType, self).__init__()
self.nodetype = nodetype
''' get properties for a given node type'''
def get_properties(self):
properties = []
nodetype = self.get_nodetype()
for prop_key, prop_vale in nodetype.iteritems():
if prop_key == 'properties':
properties = prop_vale
return properties
''' get capabilities for a given node type'''
def get_capabilities(self):
pass
def derived_from(self):
pass
def set_requirements(self):
pass
def get_requirements(self):
return self.requirements()

View File

@ -1,49 +0,0 @@
tosca_nodes_Compute:
num_cpus:
required: no
type: integer
constraints:
- greater_or_equal: 1
description: >
Number of (actual or virtual) CPUs associated with the Compute node.
disk_size:
required: no
type: integer
constraints:
- greater_or_equal: 0
description: >
Size of the local disk, in Gigabytes (GB), available to applications running on the Compute node.
mem_size:
required: no
type: integer
constraints:
- greater_or_equal: 0
description: >
Size of memory, in Megabytes (MB), available to applications running on the Compute node.
os_arch:
required: no
default: x86_64
type: string
description: >
The host Operating System (OS) architecture.
os_type:
required: yes
type: string
description: >
The host Operating System (OS) type.
os_distribution:
required: no
type: string
description: >
The host Operating System (OS) distribution. Examples of valid values for an “os_type” of “Linux” would include:
debian, fedora, rhel and ubuntu.
os_version:
required: no
type: integer
description: >
The host Operating System version.
ip_address:
required: no
type: string
description: >
The primary IP address assigned by the cloud provider that applications may use to access the Compute node.

View File

@ -1,46 +0,0 @@
tosca_nodes_Root:
properties:
- property
capabilities:
- capability1: somecapbility
interfaces:
- create
- start
- stop
- install
- delete
tosca_nodes_Compute:
derived_from: tosca_nodes_Root
properties:
- num_cpus
- disk_size
- mem_size
- os_arch
- os_type
- os_version
- ip_address
requirements:
- host: none
- database: none
capabilities:
container:
type: Container
containee_types: [tosca_nodes_SoftwareComponent]
tosca_nodes_SoftwareComponent:
derived_from: tosca_nodes_Root
requirements:
- host: tosca.nodes.Compute
capabilities:
containee:
type: Containee
container_types: [tosca.nodes.Compute]
tosca.nodes.MySQL:
derived_from: tosca_nodes_SoftwareComponent
properties:
- db_user
- db_pwd
- db_root_pwd

View File

@ -1,35 +0,0 @@
from tosca.nodetemplates.schema import Schema
from tosca.nodetemplates.constraints import Constraint
class Property(object):
def __init__(self, name, nodetype, value):
self.name = name
self.nodetype = nodetype
self.value = value
def is_required(self):
return Schema(self.nodetype).is_required(self.name)
def get_name(self):
return self.name
def validate(self):
self.validate_data_type()
self.validate_constraints()
def validate_data_type(self):
data_type = Schema(self.nodetype).get_type(self.name)
if data_type == Schema.STRING:
return Constraint.validate_string(self.value)
elif data_type == Schema.INTEGER:
return Constraint.validate_integer(self.value)
elif data_type == Schema.NUMBER:
return Constraint.validate_number(self.value)
def validate_constraints(self):
constraints = Schema(self.nodetype).get_constraints(self.name)
if constraints:
for constraint in constraints:
Constraint(self.name, self.value, constraint).validate()
pass

View File

@ -1,6 +0,0 @@
from rootnodetype import RootRelationshipType
class RelatonshipType(RootRelationshipType):
def __init__(self, relatointype):
super(RelatonshipType, self).__init__()
self.nodetype = relatointype

View File

@ -1,31 +0,0 @@
from yaml_loader import Loader
import os
nodetype_def_file = os.path.dirname(os.path.abspath(__file__)) + os.sep + "nodetypesdef.yaml"
nodetype_def = Loader(nodetype_def_file).load()
class RootNodeType(object):
def __init__(self):
self.nodetypes = self._set_nodetypes()
'''set a list of node names from the nodetype definition'''
def _set_nodetypes(self):
nodetypes = []
if isinstance(nodetype_def, dict):
for key in nodetype_def.iterkeys():
nodetypes.append(key)
return nodetypes
def get_nodetype(self, nodetype=None):
rtype = {}
if nodetype == None:
nodetype = self.nodetype
ntype = nodetype
ntype = ntype.replace(".", "_")
if ntype in self.nodetypes:
rtype = nodetype_def[ntype]
return rtype
class RootRelationshipType(object):
def __init__(self):
pass

View File

@ -1,88 +0,0 @@
from yaml_loader import Loader
import os
schema_file = os.path.dirname(os.path.abspath(__file__)) + os.sep + "nodetypeschema.yaml"
schema = Loader(schema_file).load()
class Schema(object):
TYPES = (
INTEGER,
STRING, NUMBER, BOOLEAN,
LIST
) = (
'integer',
'string', 'number', 'boolean',
'list'
)
KEYS = (
TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS,
) = (
'type', 'description', 'default', 'constraints'
)
def __init__(self, nodetype):
self.nodetype = nodetype
self.nodes = self._set_nodes()
'''set a list of node names from the schema'''
def _set_nodes(self):
sections = []
if isinstance(schema, dict):
for key in schema.iterkeys():
sections.append(key)
return sections
def _get_section(self, section_name):
section = {}
if section_name in self.nodes:
return schema[section_name]
return section
''' return true if property is a required for a given node '''
def is_required(self, property_name):
return property_name in self.required()
''' get schemata for a given node type'''
def get_schemata(self):
ntype = self.nodetype
ntype = ntype.replace(".", "_")
return self._get_section(ntype)
''' get schema for a given property'''
def get_schema(self, property_name):
schema = {}
schemata = self.get_schemata()
for prop_key, prop_vale in schemata.iteritems():
if prop_key == property_name:
for attr, value in prop_vale.iteritems():
schema[attr] = value
return schema
def get_type(self, property_name):
return self.get_schema(property_name)['type']
def get_constraints(self, property_name):
s = self.get_schema(property_name)
if 'constraints' in s:
s['constraints']
def get_description(self, property_name):
return self.get_schema(property_name)['description']
def get_greater_or_equal(self, property_name):
pass
def get_equal(self, property_name):
pass
''' list all the required properties for a given nodetype '''
def required(self):
required = []
schemata = self.get_schemata()
for prop_key, prop_vale in schemata.iteritems():
for attr, value in prop_vale.iteritems():
if attr == 'required' and value:
required.append(prop_key)
return required

View File

@ -1,4 +0,0 @@
class Outputs(object):
def __init__(self):
pass

Binary file not shown.

View File

@ -1,30 +0,0 @@
tosca_definitions_version: tosca_simple_1_0
description: >
TOSCA simple profile that just defines a single compute instance. Note, this example does not include inputs values.
inputs:
cpus:
type: integer
description: cpu
constraints:
- valid_values: [ 1, 2, 4, 8 ]
node_templates:
my_server:
type: tosca.nodes.Compute
properties:
# compute properties (flavor)
disk_size: 10
num_cpus: { get_input: cpus }
mem_size: 4096
# host image properties
os_arch: x86_64
os_type: Linux
os_distribution: Ubuntu
os_version: 12
outputs:
instance_ip:
description: The IP address of the deployed instance.
value: { get_property: [my_server, ip_address ] }

View File

@ -1,24 +0,0 @@
SECTIONS = (VERSION, DESCRIPTION, INPUTS,
NODE_TEMPLATES, OUTPUTS) = \
('tosca_definitions_version', 'description', 'inputs',
'node_templates', 'outputs')
class Tosca(object):
def __init__(self, sourcedata):
self.sourcedata = sourcedata
def get_version(self):
return self.sourcedata[VERSION]
def get_description(self):
return self.sourcedata[DESCRIPTION]
def get_inputs(self):
return self.sourcedata[INPUTS]
def get_nodetemplates(self):
return self.sourcedata[NODE_TEMPLATES]
def get_outputs(self):
return self.sourcedata[OUTPUTS]

View File

@ -1,34 +0,0 @@
import yaml
HEAT_VERSIONS = '2013-05-23'
if hasattr(yaml, 'CSafeDumper'):
yaml_dumper = yaml.CSafeDumper
else:
yaml_dumper = yaml.SafeDumper
yaml_tpl = {}
class TOSCATranslator(object):
def __init__(self, tosca):
super(TOSCATranslator, self).__init__()
self.tosca = tosca
def translate(self):
self._translate_version()
self._translate_inputs()
self._translate_node_templates()
self._translate_outputs()
def _translate_version(self):
pass
def _translate_inputs(self):
pass
def _translate_node_templates(self):
pass
def _translate_outputs(self):
pass

Binary file not shown.

View File

@ -1,20 +0,0 @@
from tosca.inputs import Input
from tosca.nodetemplates.node_template import NodeTemplate
class ToscaValidator():
def __init__(self, Tosca):
self.inputs = Tosca.get_inputs()
self.nodetemplates = Tosca.get_nodetemplates()
self.tosca = Tosca
def validate(self):
#validate inputs
for name, attrs in self.inputs.iteritems():
if not isinstance(attrs, dict):
print ("The input %s has no attributes", name)
Input(name, attrs).validate()
#validate node templates
for nodetemplate, value in self.nodetemplates.iteritems():
NodeTemplate(nodetemplate, value, self.tosca).validate()

Binary file not shown.

View File

@ -1,26 +0,0 @@
import numbers
def validate_integer(value):
if not isinstance(value, (int, long)):
raise TypeError('value is not an integer for %s' %value)
return validate_number(value)
def validate_number(value):
return str_to_num(value)
def validate_string(value):
if not isinstance(value, basestring):
raise ValueError(_('Value must be a string'))
return value
def validate_list(self, value):
pass
def str_to_num(value):
'''Convert a string representation of a number into a numeric type.'''
if isinstance(value, numbers.Number):
return value
try:
return int(value)
except ValueError:
return float(value)

View File

@ -1,3 +1,18 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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 yaml import yaml
if hasattr(yaml, 'CSafeLoader'): if hasattr(yaml, 'CSafeLoader'):
@ -12,7 +27,7 @@ class Loader(object):
def load(self): def load(self):
f = open(self.file_name, 'r') f = open(self.file_name, 'r')
profile = f.read() # string profile = f.read()
try: try:
doc = yaml.load(profile, Loader=yaml_loader) doc = yaml.load(profile, Loader=yaml_loader)
except yaml.YAMLError as error: except yaml.YAMLError as error:

Binary file not shown.

6
openstack-common.conf Normal file
View File

@ -0,0 +1,6 @@
[DEFAULT]
# The list of modules to copy from oslo-incubator.git
# The base module to hold the copy of openstack.common
base=heat-translator

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pbr>=0.5.21,<1.0
Babel>=0.9.6

46
setup.cfg Normal file
View File

@ -0,0 +1,46 @@
[metadata]
name = heat-translator
summary = Tool to translate non-heat templates to Heat Orchestration Template.
description-file =
README.rst
author = OpenStack
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 2.6
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
[files]
packages =
heat-translator
[build_sphinx]
source-dir = doc/source
build-dir = doc/build
all_files = 1
[upload_sphinx]
upload-dir = doc/build/html
[compile_catalog]
directory = heat-translator/locale
domain = heat-translator
[update_catalog]
domain = heat-translator
output_dir = heat-translator/locale
input_file = heat-translator/locale/heat-translator.pot
[extract_messages]
keywords = _ gettext ngettext l_ lazy_gettext
mapping_file = babel.cfg
output_file = heat-translator/locale/heat-translator.pot

22
setup.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# 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.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
setuptools.setup(
setup_requires=['pbr>=0.5.21,<1.0'],
pbr=True)

11
test-requirements.txt Normal file
View File

@ -0,0 +1,11 @@
hacking>=0.5.6,<0.8
coverage>=3.6
discover
fixtures>=0.3.14
python-subunit
sphinx>=1.1.2
oslo.sphinx
testrepository>=0.0.17
testscenarios>=0.4,<0.5
testtools>=0.9.32

31
tox.ini Normal file
View File

@ -0,0 +1,31 @@
[tox]
minversion = 1.6
envlist = py26,py27,py33,pypy,pep8
skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
commands = flake8
[testenv:venv]
commands = {posargs}
[testenv:cover]
commands = python setup.py testr --coverage --testr-args='{posargs}'
[flake8]
# H803 skipped on purpose per list discussion.
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125,H803
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build