Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pacogomez committed Jul 24, 2015
1 parent 0cdc04e commit 59c637b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
1 change: 1 addition & 0 deletions changes.txt
Expand Up @@ -23,6 +23,7 @@ new features:
- login with instance, org and vdc
- no need to enter service type
- use instance and vdc (vca type)
- commands exit with error code == 1 when fail

pending work:
- actual session logout on VC
2 changes: 2 additions & 0 deletions tests/login-vca.sh
@@ -1,4 +1,6 @@
#!/bin/bash

set -e
vca logout
vca login $VCA_CLI_USER --password $VCA_CLI_PASS --instance $VCA_CLI_INSTANCE
vca status
30 changes: 23 additions & 7 deletions vca_cli/vca_cli.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import os
import operator
import click
Expand Down Expand Up @@ -182,6 +183,7 @@ def login(cmd_proc, user, host, password, do_not_save_password,
"'%s', profile '%s'" %
(vdc, cmd_proc.profile),
cmd_proc)
sys.exit(1)
cmd_proc.save_current_config()
elif cmd_proc.vca.service_type in [VCA.VCA_SERVICE_TYPE_VCHS]:
if instance is not None or org is not None:
Expand All @@ -204,6 +206,7 @@ def login(cmd_proc, user, host, password, do_not_save_password,
"'%s', profile '%s'" %
(vdc, cmd_proc.profile),
cmd_proc)
sys.exit(1)
cmd_proc.save_current_config()
elif (cmd_proc.vca.service_type in
[VCA.VCA_SERVICE_TYPE_STANDALONE]):
Expand All @@ -229,23 +232,30 @@ def login(cmd_proc, user, host, password, do_not_save_password,
"'%s' , profile '%s'" %
(vdc, cmd_proc.profile),
cmd_proc)
sys.exit(1)
cmd_proc.save_current_config()
else:
utils.print_error('Can\'t login', cmd_proc)
sys.exit(1)
except Exception as e:
utils.print_error('Can\'t login: ' + str(e), cmd_proc)
sys.exit(1)


@cli.command()
@click.pass_obj
def logout(cmd_proc):
"""Logout from a vCloud service"""
user = cmd_proc.vca.username
if user is None:
utils.print_message('Not logged in', cmd_proc)
exit(0)
profile = cmd_proc.profile
cmd_proc.logout()
utils.print_message("User '%s' logged out, profile '%s'" %
(user, profile),
cmd_proc)
if user is not None:
utils.print_message("User '%s' logged out, profile '%s'" %
(user, profile),
cmd_proc)


def _use_instance(cmd_proc, instance):
Expand All @@ -263,6 +273,7 @@ def _use_instance(cmd_proc, instance):
", profile '%s'" %
(instance, cmd_proc.profile),
cmd_proc)
sys.exit(1)
return result


Expand Down Expand Up @@ -323,11 +334,11 @@ def instance(cmd_proc, operation, instance, org, vdc):
if cmd_proc.vca.service_type not in \
[VCA.VCA_SERVICE_TYPE_VCA, VCA.VCA_SERVICE_TYPE_VCHS]:
utils.print_message('This service type doesn\'t support this command')
return
sys.exit(1)
result = cmd_proc.re_login()
if not result:
utils.print_error('Not logged in', cmd_proc)
return
sys.exit(1)
if 'list' == operation:
headers = []
table = []
Expand Down Expand Up @@ -405,8 +416,10 @@ def instance(cmd_proc, operation, instance, org, vdc):
"'%s' , profile '%s'" %
(vdc, cmd_proc.profile),
cmd_proc)
sys.exit(1)
else:
utils.print_message('Not implemented')
sys.exit(1)
cmd_proc.save_current_config()


Expand All @@ -424,13 +437,13 @@ def org(cmd_proc, operation, instance, org):
result = cmd_proc.re_login()
if not result:
utils.print_error('Not logged in', cmd_proc)
return
sys.exit(1)
if 'list' == operation:
if cmd_proc.vca.service_type == VCA.VCA_SERVICE_TYPE_VCHS:
if '' == instance:
instance = cmd_proc.instance
_list_orgs_in_instance(cmd_proc, instance)
return
sys.exit(1)
headers = ['Org', 'Selected']
table = []
if cmd_proc.vca is not None and\
Expand Down Expand Up @@ -458,6 +471,7 @@ def org(cmd_proc, operation, instance, org):
headers, table, cmd_proc)
else:
utils.print_error("Org not found '%s'" % org)
sys.exit(1)
elif 'use' == operation:
if cmd_proc.vca.service_type == VCA.VCA_SERVICE_TYPE_VCA:
utils.print_message('Operation not supported in '
Expand All @@ -482,6 +496,7 @@ def org(cmd_proc, operation, instance, org):
"'%s' , profile '%s'" %
(vdc, cmd_proc.profile),
cmd_proc)
sys.exit(1)
elif cmd_proc.vca.service_type == VCA.VCA_SERVICE_TYPE_STANDALONE:
utils.print_message('Operation not supported in '
'this service type. '
Expand All @@ -490,6 +505,7 @@ def org(cmd_proc, operation, instance, org):
else:
utils.print_message('Operation not supported '
'in this service type')
sys.exit(1)
cmd_proc.save_current_config()


Expand Down
4 changes: 3 additions & 1 deletion vca_cli/vca_cli_blueprint.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import click
from vca_cli import cli, utils

Expand All @@ -21,4 +22,5 @@
@click.pass_obj
def blueprint(cmd_proc):
"""Operations with Blueprints"""
utils.print_message('blueprint', cmd_proc)
utils.print_message('Not implemented')
sys.exit(1)
15 changes: 11 additions & 4 deletions vca_cli/vca_cli_compute.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import click
import operator
from vca_cli import cli, utils, default_operation
Expand All @@ -30,7 +31,7 @@ def vdc(cmd_proc, operation, vdc):
result = cmd_proc.re_login()
if not result:
utils.print_error('Not logged in', cmd_proc)
return
sys.exit(1)
if 'list' == operation:
headers = ['Virtual Data Center', "Selected"]
table = ['', '']
Expand All @@ -57,6 +58,7 @@ def vdc(cmd_proc, operation, vdc):
else:
utils.print_error("Unable to select vdc '%s' in profile '%s'" %
(vdc, cmd_proc.profile), cmd_proc)
sys.exit(1)
elif 'info' == operation:
if vdc is None:
vdc = cmd_proc.vdc_name
Expand Down Expand Up @@ -91,6 +93,7 @@ def vdc(cmd_proc, operation, vdc):
else:
utils.print_error("Unable to select vdc '%s' in profile '%s'" %
(vdc, cmd_proc.profile), cmd_proc)
sys.exit(1)
cmd_proc.save_current_config()


Expand Down Expand Up @@ -143,7 +146,7 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
result = cmd_proc.re_login()
if not result:
utils.print_error('Not logged in', cmd_proc)
return
sys.exit(1)
if vdc is None:
vdc = cmd_proc.vdc_name
the_vdc = cmd_proc.vca.get_vdc(vdc)
Expand Down Expand Up @@ -184,7 +187,7 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
get_vcloud_headers())
else:
utils.print_error("can't create the vApp", cmd_proc)
return
sys.exit(1)
the_vdc = cmd_proc.vca.get_vdc(vdc)
the_vapp = cmd_proc.vca.get_vapp(the_vdc, vapp_name)
if ((vm_name is not None) and
Expand All @@ -203,7 +206,7 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
get_vcloud_headers())
else:
utils.print_error("can't set VM name", cmd_proc)
return
sys.exit(1)
the_vapp = cmd_proc.vca.get_vapp(the_vdc, vapp_name)
if vm_name is not None:
utils.print_message(
Expand All @@ -217,6 +220,7 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
get_vcloud_headers())
else:
utils.print_error("can't set computer name", cmd_proc)
sys.exit(1)
the_vapp = cmd_proc.vca.get_vapp(the_vdc, vapp_name)
if cpu is not None:
utils.print_message(
Expand All @@ -229,6 +233,7 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
get_vcloud_headers())
else:
utils.print_error("can't configure virtual CPUs", cmd_proc)
sys.exit(1)
the_vapp = cmd_proc.vca.get_vapp(the_vdc, vapp_name)
# if ram is not None:
# print_message("configuring '%s' MB of memory"
Expand Down Expand Up @@ -305,6 +310,8 @@ def vapp(cmd_proc, operation, vdc, vapp, catalog, template,
get_vcloud_headers())
else:
utils.print_error("can't delete the vApp", cmd_proc)
sys.exit(1)
else:
utils.print_message('not implemented', cmd_proc)
sys.exit(1)
cmd_proc.save_current_config()
4 changes: 3 additions & 1 deletion vca_cli/vca_cli_network.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import click
from vca_cli import cli, utils

Expand All @@ -21,4 +22,5 @@
@click.pass_obj
def gateway(cmd_proc):
"""Operations with Edge Gateway"""
utils.print_message('gateway', cmd_proc)
utils.print_message('Not implemented')
sys.exit(1)
4 changes: 3 additions & 1 deletion vca_cli/vca_cli_sql.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import click
from vca_cli import cli, utils

Expand All @@ -21,4 +22,5 @@
@click.pass_obj
def sql(cmd_proc):
"""Operations with SQL Air Service"""
utils.print_message('sql', cmd_proc)
utils.print_message('Not implemented')
sys.exit(1)
8 changes: 5 additions & 3 deletions vca_cli/vca_cli_vca.py
Expand Up @@ -13,6 +13,7 @@
#


import sys
import click
import operator
from vca_cli import cli, utils, default_operation
Expand All @@ -33,12 +34,12 @@ def user(cmd_proc, operation, username, password):
if cmd_proc.vca.service_type != VCA.VCA_SERVICE_TYPE_VCA:
utils.print_message('Operation not supported '
'in this service type')
return
sys.exit(1)
# see https://wiki.eng.vmware.com/Praxis_IAM_API_Details
result = cmd_proc.re_login()
if not result:
utils.print_error('Not logged in', cmd_proc)
return
sys.exit(1)
if 'list' == operation:
headers = ['User Name', 'First', 'Last', 'Email', 'State', 'Roles']
table = []
Expand All @@ -56,5 +57,6 @@ def user(cmd_proc, operation, username, password):
headers, sorted_table,
cmd_proc)
elif 'info' == operation:
pass
utils.print_message('Not implemented')
sys.exit(1)
cmd_proc.save_current_config()

0 comments on commit 59c637b

Please sign in to comment.