Skip to content

Commit

Permalink
Merge pull request #23 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored May 4, 2018
2 parents 30eb902 + 2645a06 commit d3d9538
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ configuration of all the user required applications providing the user with a
fully functional infrastructure.

```sh
usage: client.py [-u|--xmlrpc-url <url>] [-a|--auth_file <filename>] operation op_parameters
Usage: im_client.py [-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] operation op_parameters
```

1 INSTALLATION
Expand Down Expand Up @@ -196,7 +196,7 @@ An example of the auth file:
The :program:`im_client` is called like this:

```
$ im_client.py [-u|--xmlrpc-url url] [-r|--rest-url url] [-a|--auth_file filename] operation op_parameters
$ im_client.py [-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] operation op_parameters
```

* option: -u|--xmlrpc-url url
Expand All @@ -208,6 +208,11 @@ The :program:`im_client` is called like this:

URL to the REST API on the IM service.
This option or the ` -u` one must be specified.

.. option:: -v|--verify-ssl

Verify the certificates of the SSL connection.
The default value is `False`,

* option: -a|--auth_file filename

Expand Down
48 changes: 24 additions & 24 deletions im_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s" % (options.restapi.rstrip("/"), inf_id, vm_list)
resp = requests.request("DELETE", url, verify=False, headers=headers)
resp = requests.request("DELETE", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
if success:
vms_id = vm_list
Expand Down Expand Up @@ -330,7 +330,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data, "Accept": "application/json"}
url = "%s/infrastructures/%s" % (options.restapi, inf_id)
resp = requests.request("POST", url, verify=False, headers=headers, data=str(radl))
resp = requests.request("POST", url, verify=options.verify, headers=headers, data=str(radl))
success = resp.status_code == 200
restres = resp.text
if success:
Expand Down Expand Up @@ -370,7 +370,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures" % options.restapi
resp = requests.request("POST", url, verify=False, headers=headers, data=str(radl))
resp = requests.request("POST", url, verify=options.verify, headers=headers, data=str(radl))
success = resp.status_code == 200
inf_id = resp.text
if success:
Expand Down Expand Up @@ -404,7 +404,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s" % (options.restapi, inf_id, vm_id)
resp = requests.request("PUT", url, verify=False, headers=headers, data=str(radl))
resp = requests.request("PUT", url, verify=options.verify, headers=headers, data=str(radl))
success = resp.status_code == 200
res = resp.text
else:
Expand Down Expand Up @@ -439,7 +439,7 @@ def main(operation, options, args, parser):
url = "%s/infrastructures/%s/reconfigure" % (options.restapi, inf_id)
if len(args) >= 3:
url += "?vm_list=" + args[2]
resp = requests.request("PUT", url, verify=False, headers=headers, data=str(radl))
resp = requests.request("PUT", url, verify=options.verify, headers=headers, data=str(radl))
success = resp.status_code == 200
res = resp.text
else:
Expand All @@ -457,7 +457,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/contmsg" % (options.restapi, inf_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
cont_out = resp.text
else:
Expand All @@ -477,7 +477,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data, "Accept": "application/json"}
url = "%s/infrastructures/%s/state" % (options.restapi, inf_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
res = resp.json()['state']
else:
Expand Down Expand Up @@ -508,7 +508,7 @@ def main(operation, options, args, parser):
url = "%s/infrastructures/%s/vms/%s" % (options.restapi, inf_id, vm_id)
if propiedad:
url += "/" + propiedad
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand All @@ -531,7 +531,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data, "Accept": "application/json"}
url = "%s/infrastructures/%s" % (options.restapi, inf_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
restres = resp.text
if success:
Expand All @@ -552,7 +552,7 @@ def main(operation, options, args, parser):
url = "%s/infrastructures/%s/vms/%s" % (options.restapi, inf_id, vm_id)
if propiedad:
url += "/" + propiedad
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand All @@ -574,7 +574,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s" % (options.restapi, inf_id)
resp = requests.request("DELETE", url, verify=False, headers=headers)
resp = requests.request("DELETE", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
inf_id = resp.text
else:
Expand All @@ -590,7 +590,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data, "Accept": "application/json"}
url = "%s/infrastructures" % options.restapi
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
if success:
res = []
Expand All @@ -615,7 +615,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/start" % (options.restapi, inf_id)
resp = requests.request("PUT", url, verify=False, headers=headers)
resp = requests.request("PUT", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
inf_id = resp.text
else:
Expand All @@ -632,7 +632,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/stop" % (options.restapi, inf_id)
resp = requests.request("PUT", url, verify=False, headers=headers)
resp = requests.request("PUT", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
inf_id = resp.text
else:
Expand All @@ -649,7 +649,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/radl" % (options.restapi, inf_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
radl = resp.text
else:
Expand All @@ -672,7 +672,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s/contmsg" % (options.restapi, inf_id, vm_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand All @@ -695,7 +695,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s/start" % (options.restapi, inf_id, vm_id)
resp = requests.request("PUT", url, verify=False, headers=headers)
resp = requests.request("PUT", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand All @@ -718,7 +718,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s/stop" % (options.restapi, inf_id, vm_id)
resp = requests.request("PUT", url, verify=False, headers=headers)
resp = requests.request("PUT", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand Down Expand Up @@ -757,7 +757,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures/%s/vms/%s" % (options.restapi, inf_id, vm_id)
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
info = resp.text
else:
Expand All @@ -777,7 +777,7 @@ def main(operation, options, args, parser):
elif operation == "getversion":
if options.restapi:
url = "%s/version" % options.restapi
resp = requests.request("GET", url, verify=False)
resp = requests.request("GET", url, verify=options.verify)
success = resp.status_code == 200
version = resp.text
else:
Expand All @@ -800,7 +800,7 @@ def main(operation, options, args, parser):
url = "%s/infrastructures/%s/data" % (options.restapi, inf_id)
if delete:
url += "?delete=yes"
resp = requests.request("GET", url, verify=False, headers=headers)
resp = requests.request("GET", url, verify=options.verify, headers=headers)
success = resp.status_code == 200
if success:
data = resp.json()["data"]
Expand Down Expand Up @@ -831,7 +831,7 @@ def main(operation, options, args, parser):
if options.restapi:
headers = {"Authorization": rest_auth_data}
url = "%s/infrastructures" % options.restapi
resp = requests.request("PUT", url, verify=False, headers=headers, data=data)
resp = requests.request("PUT", url, verify=options.verify, headers=headers, data=data)
success = resp.status_code == 200
inf_id = resp.text
if success:
Expand Down Expand Up @@ -877,15 +877,15 @@ 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 <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] "
parser = PosOptionParser(usage="%prog [-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] "
"operation op_parameters" + NOTICE, version="%prog " + __version__)
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", dest="verify", help="Verify the certificate of the "
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', '<radl_file>')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ 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 <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] operation op_parameters",
self.assertIn("[-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] operation op_parameters",
output)
sys.stdout = oldstdout

Expand Down

0 comments on commit d3d9538

Please sign in to comment.