diff --git a/README.md b/README.md index 9015af5..7d66f47 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # IM - Infrastructure Manager client -[![Build Status](http://jenkins.i3m.upv.es/buildStatus/icon?job=grycap/im-client-unit)](http://jenkins.i3m.upv.es:8080/job/grycap/job/im-client-unit/) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Coverage) [![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE) [![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://imdocs.readthedocs.io/en/latest/client.html) +[![PyPI](https://img.shields.io/pypi/v/im-client.svg)](https://pypi.org/project/im-client) +[![Build Status](http://jenkins.i3m.upv.es/buildStatus/icon?job=grycap/im-client-unit)](http://jenkins.i3m.upv.es:8080/job/grycap/job/im-client-unit/) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Grade) +[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Coverage) +[![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE) +[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://imdocs.readthedocs.io/en/latest/client.html) IM is a tool that ease the access and the usability of IaaS clouds by automating diff --git a/im_client.py b/im_client.py index 480b890..ee0c4e3 100755 --- a/im_client.py +++ b/im_client.py @@ -323,10 +323,19 @@ def main(operation, options, args, parser): print("RADL file to add resources not specified") return False - radl = radl_parse.parse_radl(args[1]) + _, file_extension = os.path.splitext(args[1]) + if file_extension in [".yaml", ".yml"]: + f = open(args[1]) + radl = "".join(f.readlines()) + f.close() + else: + radl = radl_parse.parse_radl(args[1]) + radl.check() if options.restapi: headers = {"Authorization": rest_auth_data, "Accept": "application/json"} + if file_extension in [".yaml", ".yml"]: + headers["Content-Type"] = "text/yaml" url = "%s/infrastructures/%s" % (options.restapi, inf_id) resp = requests.request("POST", url, verify=options.verify, headers=headers, data=str(radl)) success = resp.status_code == 200 @@ -905,6 +914,7 @@ def main(operation, options, args, parser): print("Error getting infrastructure outputs: %s" % res) return success + def get_parser(): """ Get Client parser @@ -933,16 +943,16 @@ def get_parser(): under certain conditions; please read the license at \n\ http://www.gnu.org/licenses/gpl-3.0.txt for details." - parser = PosOptionParser(usage="%prog [-u|--xmlrpc-url ] [-r|--restapi-url ] [-v|--verify-ssl] [-a|--auth_file ] " - "operation op_parameters" + NOTICE, version="%prog 1.5.5") + parser = PosOptionParser(usage="%prog [-u|--xmlrpc-url ] [-r|--restapi-url ] [-v|--verify-ssl] " + "[-a|--auth_file ] operation op_parameters" + NOTICE, version="%prog 1.5.6") parser.add_option("-a", "--auth_file", dest="auth_file", nargs=1, default=default_auth_file, help="Authentication" " data file", type="string") parser.add_option("-u", "--xmlrpc-url", dest="xmlrpc", nargs=1, default=default_xmlrpc, help="URL address of the " "InfrastructureManager XML-RCP daemon", type="string") parser.add_option("-r", "--rest-url", dest="restapi", nargs=1, default=default_restapi, help="URL address of the " "InfrastructureManager REST API", type="string") - parser.add_option("-v", "--verify-ssl", action="store_true", default=False, dest="verify", help="Verify the certificate of the " - "InfrastructureManager XML-RCP server") + parser.add_option("-v", "--verify-ssl", action="store_true", default=False, dest="verify", + help="Verify the certificate of the InfrastructureManager XML-RCP server") parser.add_operation_help('list', '') parser.add_operation_help('create', ' [async_flag]') parser.add_operation_help('destroy', '') @@ -969,6 +979,7 @@ def get_parser(): return parser + if __name__ == "__main__": parser = get_parser() diff --git a/test/files/tosca.yml b/test/files/tosca.yml new file mode 100644 index 0000000..b9242e7 --- /dev/null +++ b/test/files/tosca.yml @@ -0,0 +1,24 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA test for the IM client + +topology_template: + + node_templates: + + server: + type: tosca.nodes.Compute + capabilities: + # Host container properties + host: + properties: + num_cpus: 1 + mem_size: 1 GB + # Guest Operating System properties + os: + properties: + # host Operating System image properties + type: linux + distribution: scientific + version: 6.6 + diff --git a/test/unit/test_client.py b/test/unit/test_client.py index 88d6643..5e8fc20 100755 --- a/test/unit/test_client.py +++ b/test/unit/test_client.py @@ -216,6 +216,17 @@ def test_create(self, server_proxy, requests): self.assertIn("Infrastructure successfully created with ID: inf1", output) sys.stdout = oldstdout + out = StringIO() + sys.stdout = out + options.xmlrpc = None + options.restapi = "https://localhost:8800" + requests.side_effect = self.get_response + res = main("create", options, [get_abs_path("../files/tosca.yml")], parser) + self.assertEquals(res, True) + output = out.getvalue().strip() + self.assertIn("Infrastructure successfully created with ID: inf1", output) + sys.stdout = oldstdout + @patch('requests.request') @patch("im_client.ServerProxy") def test_removeresource(self, server_proxy, requests): @@ -282,6 +293,17 @@ def test_addresource(self, server_proxy, requests): self.assertIn("Resources with IDs: 1 successfully added.", output) sys.stdout = oldstdout + out = StringIO() + sys.stdout = out + options.xmlrpc = None + options.restapi = "https://localhost:8800" + requests.side_effect = self.get_response + res = main("addresource", options, ["infid", get_abs_path("../files/tosca.yml")], parser) + self.assertEquals(res, True) + output = out.getvalue().strip() + self.assertIn("Resources with IDs: 1 successfully added.", output) + sys.stdout = oldstdout + @patch('requests.request') @patch("im_client.ServerProxy") def test_alter(self, server_proxy, requests): @@ -957,9 +979,10 @@ def test_parser_help(self, option_parser_exit): parser.parse_args(["--help"]) output = out.getvalue().strip() self.assertEqual(output[:16], "Usage: nosetests") - self.assertIn("[-u|--xmlrpc-url ] [-r|--restapi-url ] [-v|--verify-ssl] [-a|--auth_file ] operation op_parameters", - output) + self.assertIn("[-u|--xmlrpc-url ] [-r|--restapi-url ] [-v|--verify-ssl] " + "[-a|--auth_file ] operation op_parameters", output) sys.stdout = oldstdout + if __name__ == '__main__': unittest.main()