Add CSAR shared library with CLI tool
authorKrzysztof Frukacz <krzysztof.frukacz@gigaspaces.com>
Sun, 29 Jan 2017 05:31:22 +0000 (06:31 +0100)
committerKrzysztof Frukacz <krzysztof.frukacz@gigaspaces.com>
Sun, 29 Jan 2017 06:14:49 +0000 (07:14 +0100)
Initial commit. Shared CSAR Python library with CLI tool

Change-Id: I121982cec5c839a47068907a1c4c2b379109a882
Issue-ID: VNFSDK-2
Signed-off-by: Krzysztof Frukacz <krzysztof.frukacz@gigaspaces.com>
12 files changed:
COPYRIGHT [new file with mode: 0644]
LICENSE [new file with mode: 0644]
Makefile [new file with mode: 0644]
__init__.py [new file with mode: 0644]
assembly.xml [new file with mode: 0644]
cli/__init__.py [new file with mode: 0644]
cli/__main__.py [new file with mode: 0644]
packager/__init__.py [new file with mode: 0644]
packager/csar.py [new file with mode: 0644]
pom.xml [new file with mode: 0644]
requirements.txt [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/COPYRIGHT b/COPYRIGHT
new file mode 100644 (file)
index 0000000..a420fad
--- /dev/null
+++ b/COPYRIGHT
@@ -0,0 +1,13 @@
+Copyright (c) 2016-2017 GigaSpaces Technologies Ltd. All rights reserved.
+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.
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..37ec93a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,191 @@
+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:
+
+You must give any other recipients of the Work or Derivative Works a copy of
+this License; and
+You must cause any modified files to carry prominent notices stating that You
+changed the files; and
+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
+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.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work
+
+To apply the Apache License to your work, attach the following boilerplate
+notice, with the fields enclosed by brackets "[]" replaced with your own
+identifying information. (Don't include the brackets!) The text should be
+enclosed in the appropriate comment syntax for the file format. We also
+recommend that a file or class name and description of purpose be included on
+the same "printed page" as the copyright notice for easier identification within
+third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..f16e167
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+#
+# Copyright (c) 2016 GigaSpaces Technologies Ltd. All rights reserved.
+# 
+# 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.
+#
+
+PACKAGER_CLI=cli
+PACKAGER_LIB=packager
+
+
+.PHONY: clean requirements
+.DEFAULT_GOAL = requirements
+
+clean:
+       find . -type d -name '*.egg-info' -exec rm -rf {} \;
+       find . -type d -name '.coverage' -exec rm -rf {} \;
+       find . -type f -name '.coverage' -delete
+
+requirements:
+       pip install --upgrade --requirement "requirements.txt"
diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/assembly.xml b/assembly.xml
new file mode 100644 (file)
index 0000000..c569db1
--- /dev/null
@@ -0,0 +1,40 @@
+<!--
+Copyright (c) 2016-2017 GigaSpaces Technologies Ltd. All rights reserved.
+
+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.
+-->
+<assembly
+    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>vnfsdk</id>
+    <formats>
+        <format>zip</format>
+    </formats>
+    <fileSets>
+        <fileSet>
+            <includes>
+                <include>COPYRIGHT</include>
+                <include>LICENSE</include>
+                <include>setup.py</include>
+                <include>Makefile</include>
+                <include>cli/**</include>
+                <include>packager/**</include>
+            </includes>
+            <excludes>
+                <exclude>**/*.pyc</exclude>
+            </excludes>
+        </fileSet>
+    </fileSets>
+    <baseDirectory>.</baseDirectory>
+</assembly>
\ No newline at end of file
diff --git a/cli/__init__.py b/cli/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/cli/__main__.py b/cli/__main__.py
new file mode 100644 (file)
index 0000000..125fff1
--- /dev/null
@@ -0,0 +1,112 @@
+#\r
+# Copyright (c) 2016-2017 GigaSpaces Technologies Ltd. All rights reserved.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+# not use this file except in compliance with the License. You may obtain\r
+# a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+# License for the specific language governing permissions and limitations\r
+# under the License.\r
+#\r
+\r
+from packager import csar\r
+import logging\r
+import argparse\r
+from aria import install_aria_extensions\r
+import os\r
+import shutil\r
+import tempfile\r
+from aria.loading import LiteralLocation\r
+from aria.consumption import (\r
+    ConsumptionContext,\r
+    ConsumerChain,\r
+    Read,\r
+    Validate,\r
+    Model,\r
+    Instance\r
+)\r
+\r
+def csar_create_func(namespace):\r
+    csar.write(namespace.source,\r
+                        namespace.entry,\r
+                        namespace.destination,\r
+                        logging)\r
+def csar_open_func(namespace):\r
+    csar.read(namespace.source,\r
+                       namespace.destination,\r
+                       logging)\r
+def csar_validate_func(namespace):\r
+    workdir = tempfile.mkdtemp()\r
+    try:\r
+        reader = None\r
+        reader = csar.read(namespace.source,\r
+                           workdir,\r
+                           logging)\r
+        context = ConsumptionContext()\r
+        context.loading.prefixes += [os.path.join(reader.destination, 'definitions')]\r
+        context.presentation.location = LiteralLocation(reader.entry_definitions_yaml)\r
+        print reader.entry_definitions_yaml\r
+        chain = ConsumerChain(context, (Read, Validate, Model, Instance))\r
+        chain.consume()\r
+        if context.validation.dump_issues():\r
+            raise RuntimeError('Validation failed')\r
+        dumper = chain.consumers[-1]\r
+        dumper.dump()\r
+    finally:\r
+        shutil.rmtree(workdir, ignore_errors=True)\r
+\r
+\r
+def main():\r
+    """\r
+    CLI entry point\r
+    """\r
+    install_aria_extensions()\r
+\r
+    parser = argparse.ArgumentParser(description='VNF SDK CSAR manipulation tool')\r
+\r
+    subparsers = parser.add_subparsers(help='csar-create')\r
+    csar_create = subparsers.add_parser('csar-create')\r
+    csar_create.set_defaults(func=csar_create_func)\r
+    csar_create.add_argument('-v', '--verbose',\r
+            dest='verbosity',\r
+            action='count',\r
+            default=0,\r
+            help='Set verbosity level (can be passed multiple times)')\r
+    csar_create.add_argument(\r
+        'source',\r
+        help='Service template directory')\r
+    csar_create.add_argument(\r
+        'entry',\r
+        help='Entry definition file relative to service template directory')\r
+    csar_create.add_argument(\r
+        '-d', '--destination',\r
+        help='Output CSAR zip destination',\r
+        required=True)\r
+\r
+    csar_open = subparsers.add_parser('csar-open')\r
+    csar_open.set_defaults(func=csar_open_func)\r
+    csar_open.add_argument(\r
+        'source',\r
+        help='CSAR file location')\r
+    csar_open.add_argument(\r
+        '-d', '--destination',\r
+        help='Output directory to extract the CSAR into',\r
+        required=True)\r
+\r
+    csar_validate = subparsers.add_parser('csar-validate')\r
+    csar_validate.set_defaults(func=csar_validate_func)\r
+    csar_validate.add_argument(\r
+        'source',\r
+        help='CSAR file location')\r
+\r
+    args = parser.parse_args()\r
+    args.func(args)\r
+\r
+\r
+if __name__ == '__main__':\r
+    main()\r
diff --git a/packager/__init__.py b/packager/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/packager/csar.py b/packager/csar.py
new file mode 100644 (file)
index 0000000..ebb3023
--- /dev/null
@@ -0,0 +1,171 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more\r
+# contributor license agreements.  See the NOTICE file distributed with\r
+# this work for additional information regarding copyright ownership.\r
+# The ASF licenses this file to You under the Apache License, Version 2.0\r
+# (the "License"); you may not use this file except in compliance with\r
+# the License.  You may obtain a copy of the License at\r
+#\r
+#     http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+import os\r
+import pprint\r
+import tempfile\r
+import zipfile\r
+\r
+import requests\r
+from ruamel import yaml # @UnresolvedImport\r
+\r
+\r
+META_FILE = 'TOSCA-Metadata/TOSCA.meta'\r
+META_FILE_VERSION_KEY = 'TOSCA-Meta-File-Version'\r
+META_FILE_VERSION_VALUE = '1.0'\r
+META_CSAR_VERSION_KEY = 'CSAR-Version'\r
+META_CSAR_VERSION_VALUE = '1.1'\r
+META_CREATED_BY_KEY = 'Created-By'\r
+META_CREATED_BY_VALUE = 'ARIA'\r
+META_ENTRY_DEFINITIONS_KEY = 'Entry-Definitions'\r
+BASE_METADATA = {\r
+    META_FILE_VERSION_KEY: META_FILE_VERSION_VALUE,\r
+    META_CSAR_VERSION_KEY: META_CSAR_VERSION_VALUE,\r
+    META_CREATED_BY_KEY: META_CREATED_BY_VALUE,\r
+}\r
+\r
+\r
+def write(source, entry, destination, logger):\r
+    source = os.path.expanduser(source)\r
+    destination = os.path.expanduser(destination)\r
+    entry_definitions = os.path.join(source, entry)\r
+    meta_file = os.path.join(source, META_FILE)\r
+    if not os.path.isdir(source):\r
+        raise ValueError('{0} is not a directory. Please specify the service template '\r
+                         'directory.'.format(source))\r
+    if not os.path.isfile(entry_definitions):\r
+        raise ValueError('{0} does not exists. Please specify a valid entry point.'\r
+                         .format(entry_definitions))\r
+    if os.path.exists(destination):\r
+        raise ValueError('{0} already exists. Please provide a path to where the CSAR should be '\r
+                         'created.'.format(destination))\r
+    if os.path.exists(meta_file):\r
+        raise ValueError('{0} already exists. This commands generates a meta file for you. Please '\r
+                         'remove the existing metafile.'.format(meta_file))\r
+    metadata = BASE_METADATA.copy()\r
+    metadata[META_ENTRY_DEFINITIONS_KEY] = entry\r
+    logger.debug('Compressing root directory to ZIP')\r
+    with zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED) as f:\r
+        for root, _, files in os.walk(source):\r
+            for file in files:\r
+                file_full_path = os.path.join(root, file)\r
+                file_relative_path = os.path.relpath(file_full_path, source)\r
+                logger.debug('Writing to archive: {0}'.format(file_relative_path))\r
+                f.write(file_full_path, file_relative_path)\r
+        logger.debug('Writing new metadata file to {0}'.format(META_FILE))\r
+        f.writestr(META_FILE, yaml.dump(metadata, default_flow_style=False))\r
+\r
+\r
+class _CSARReader(object):\r
+\r
+    def __init__(self, source, destination, logger):\r
+        self.logger = logger\r
+        if os.path.isdir(destination) and os.listdir(destination):\r
+            raise ValueError('{0} already exists and is not empty. '\r
+                             'Please specify the location where the CSAR '\r
+                             'should be extracted.'.format(destination))\r
+        downloaded_csar = '://' in source\r
+        if downloaded_csar:\r
+            file_descriptor, download_target = tempfile.mkstemp()\r
+            os.close(file_descriptor)\r
+            self._download(source, download_target)\r
+            source = download_target\r
+        self.source = os.path.expanduser(source)\r
+        self.destination = os.path.expanduser(destination)\r
+        self.metadata = {}\r
+        try:\r
+            if not os.path.exists(self.source):\r
+                raise ValueError('{0} does not exists. Please specify a valid CSAR path.'\r
+                                 .format(self.source))\r
+            if not zipfile.is_zipfile(self.source):\r
+                raise ValueError('{0} is not a valid CSAR.'.format(self.source))\r
+            self._extract()\r
+            self._read_metadata()\r
+            self._validate()\r
+        finally:\r
+            if downloaded_csar:\r
+                os.remove(self.source)\r
+\r
+    @property\r
+    def created_by(self):\r
+        return self.metadata.get(META_CREATED_BY_KEY)\r
+\r
+    @property\r
+    def csar_version(self):\r
+        return self.metadata.get(META_CSAR_VERSION_KEY)\r
+\r
+    @property\r
+    def meta_file_version(self):\r
+        return self.metadata.get(META_FILE_VERSION_KEY)\r
+\r
+    @property\r
+    def entry_definitions(self):\r
+        return self.metadata.get(META_ENTRY_DEFINITIONS_KEY)\r
+\r
+    @property\r
+    def entry_definitions_yaml(self):\r
+        with open(os.path.join(self.destination, self.entry_definitions)) as f:\r
+            return yaml.load(f)\r
+\r
+    def _extract(self):\r
+        self.logger.debug('Extracting CSAR contents')\r
+        if not os.path.exists(self.destination):\r
+            os.mkdir(self.destination)\r
+        with zipfile.ZipFile(self.source) as f:\r
+            f.extractall(self.destination)\r
+        self.logger.debug('CSAR contents successfully extracted')\r
+\r
+    def _read_metadata(self):\r
+        csar_metafile = os.path.join(self.destination, META_FILE)\r
+        if not os.path.exists(csar_metafile):\r
+            raise ValueError('Metadata file {0} is missing from the CSAR'.format(csar_metafile))\r
+        self.logger.debug('CSAR metadata file: {0}'.format(csar_metafile))\r
+        self.logger.debug('Attempting to parse CSAR metadata YAML')\r
+        with open(csar_metafile) as f:\r
+            self.metadata.update(yaml.load(f))\r
+        self.logger.debug('CSAR metadata:\n{0}'.format(pprint.pformat(self.metadata)))\r
+\r
+    def _validate(self):\r
+        def validate_key(key, expected=None):\r
+            if not self.metadata.get(key):\r
+                raise ValueError('{0} is missing from the metadata file.'.format(key))\r
+            actual = str(self.metadata[key])\r
+            if expected and actual != expected:\r
+                raise ValueError('{0} is expected to be {1} in the metadata file while it is in '\r
+                                 'fact {2}.'.format(key, expected, actual))\r
+        validate_key(META_FILE_VERSION_KEY, expected=META_FILE_VERSION_VALUE)\r
+        validate_key(META_CSAR_VERSION_KEY, expected=META_CSAR_VERSION_VALUE)\r
+        validate_key(META_CREATED_BY_KEY)\r
+        validate_key(META_ENTRY_DEFINITIONS_KEY)\r
+        self.logger.debug('CSAR entry definitions: {0}'.format(self.entry_definitions))\r
+        entry_definitions_path = os.path.join(self.destination, self.entry_definitions)\r
+        if not os.path.isfile(entry_definitions_path):\r
+            raise ValueError('The entry definitions {0} referenced by the metadata file does not '\r
+                             'exist.'.format(entry_definitions_path))\r
+\r
+    def _download(self, url, target):\r
+        response = requests.get(url, stream=True)\r
+        if response.status_code != 200:\r
+            raise ValueError('Server at {0} returned a {1} status code'\r
+                             .format(url, response.status_code))\r
+        self.logger.info('Downloading {0} to {1}'.format(url, target))\r
+        with open(target, 'wb') as f:\r
+            for chunk in response.iter_content(chunk_size=8192):\r
+                if chunk:\r
+                    f.write(chunk)\r
+\r
+\r
+def read(source, destination, logger):\r
+    return _CSARReader(source=source, destination=destination, logger=logger)\r
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..d87fe07
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!--
+Copyright (c) 2016 GigaSpaces Technologies Ltd. All rights reserved.
+
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+
+    <parent>
+        <groupId>org.openo.oparent</groupId>
+        <artifactId>oparent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <relativePath>../oparent</relativePath>
+    </parent>
+
+    <groupId>org.openo.vnf-sdk-design-pkg</groupId>
+    <artifactId>vnfsdk</artifactId>
+
+    <name>vnf-sdk-design-pkg</name>
+    <description>CSAR manipulation shared library with CLI</description>
+
+    <build>
+      <plugins>
+        <plugin>
+            <artifactId>maven-assembly-plugin</artifactId>
+            <configuration>
+                <appendAssemblyId>false</appendAssemblyId>
+                <descriptors>
+                    <descriptor>assembly.xml</descriptor>
+                </descriptors>
+            </configuration>
+            <executions>
+                <execution>
+                    <id>make-assembly</id>
+                    <phase>package</phase>
+                    <goals>
+                        <goal>single</goal>
+                    </goals>
+                </execution>
+            </executions>
+        </plugin>
+      </plugins>
+    </build>
+</project>
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..416adda
--- /dev/null
@@ -0,0 +1,11 @@
+ruamel.yaml==0.12.14
+requests
+logging
+clint==0.5.1
+CacheControl[filecache]==0.11.6
+lockfile
+Jinja2==2.8
+shortuuid==0.4.3
+jsonpickle
+ordereddict==1.1 ; python_version < '2.7'
+https://nexus.open-o.org/service/local/repositories/releases/content/org/openo/common-tosca/aria/aria/1.0.0/aria-1.0.0.zip
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..ae350cb
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python\r
+\r
+#\r
+# Copyright (c) 2016-2017 GigaSpaces Technologies Ltd. All rights reserved.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+# not use this file except in compliance with the License. You may obtain\r
+# a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+# License for the specific language governing permissions and limitations\r
+# under the License.\r
+#\r
+\r
+from setuptools import setup\r
+import sys\r
+\r
+if sys.version_info < (2, 7):\r
+    sys.exit('VNF SDK requires Python 2.7+')\r
+if sys.version_info >= (3, 0):\r
+    sys.exit('VNF SDK does not support Python 3')\r
+\r
+setup(\r
+    name='vnfsdk',\r
+    version='0.1',\r
+    description='VNF SDK CSAR package tool',\r
+    license='Apache License Version 2.0',\r
+\r
+    author='GigaSpaces',\r
+    author_email='info@gigaspaces.com',\r
+\r
+    url='http://open-o.org/',\r
+\r
+    classifiers=[\r
+        'Development Status :: 4 - Beta',\r
+        'Environment :: Console',\r
+        'Environment :: Web Environment',\r
+        'Intended Audience :: Developers',\r
+        'Intended Audience :: System Administrators',\r
+        'License :: OSI Approved :: Apache Software License',\r
+        'Operating System :: OS Independent',\r
+        'Programming Language :: Python',\r
+        'Topic :: Software Development :: Libraries :: Python Modules',\r
+        'Topic :: System :: Networking',\r
+        'Topic :: System :: Systems Administration'],\r
+\r
+    packages=[\r
+        'packager',\r
+        'cli'\r
+    ],\r
+\r
+    package_dir={\r
+        'packager': 'packager',\r
+        'cli': 'cli',\r
+    },\r
+\r
+    entry_points={\r
+        'console_scripts': [\r
+            'vnfsdk = cli.__main__:main']\r
+    },\r
+    # Please make sure this is in sync with src/aria/requirements.txt\r
+    install_requires=[\r
+        'ruamel.yaml==0.12.14',\r
+        'requests',\r
+        'logging',\r
+        'clint==0.5.1',\r
+        'CacheControl[filecache]==0.11.6',\r
+        'lockfile',\r
+        'Jinja2==2.8',\r
+        'shortuuid==0.4.3',\r
+        'jsonpickle',\r
+        'aria == 0.1'])\r
+\r