49 conf = Configuration()
50 conf.host = cfsp_globals.__cf_manager_url__
51 api_client = ApiClient(conf)
52 api_instance = swagger_client.InstancesApi(api_client=api_client)
54 if ((len(args[
'<args>']) < 1)
or (len(args[
'<args>']) > 2)):
55 print(
"ERROR: invalid arguments provided in 'cfsp instance' command. Aborting...")
58 username = cfsp_globals.__cfsp_username__
59 password = cfsp_globals.__cfsp_password__
60 project_name = cfsp_globals.__cfsp_project__
62 if args[
'<args>'][0] ==
'get':
63 if (len(args[
'<args>']) == 2):
65 api_response = api_instance.cf_manager_rest_api_get_instance(username, password, args[
'<args>'][1])
66 except ApiException
as e:
67 print(
"Exception when calling InstancesApi->cf_manager_rest_api_get_instance: %s\n" % e)
69 elif (len(args[
'<args>']) == 1):
71 api_response = api_instance.cf_manager_rest_api_get_instances(username, password, limit=args[
'--limit'])
72 except ApiException
as e:
73 print(
"Exception when calling InstancesApi->cf_manager_rest_api_get_instances: %s\n" % e)
76 exit(print(
"ERROR: invalid arguments provided in cfsp instance get. Aborting..."))
78 elif args[
'<args>'][0] ==
'post':
80 if len(args[
'--image_id']) != 1:
81 exit(print(
"ERROR: instance post supports only one image (--image_id). Aborting..."))
82 image_id = args[
'--image_id'][0]
85 api_response = api_instance.cf_manager_rest_api_post_instances(image_id, username, password, project_name=project_name, dont_verify_memory=args[
'--dont_verify_memory'])
87 instance_id = api_response.instance_id
89 api_response = api_instance.cf_manager_rest_api_get_instance(username, password, instance_id)
90 except ApiException
as e:
91 print(
"Exception when calling InstancesApi->cf_manager_rest_api_get_instance: %s\n" % e)
94 except ApiException
as e:
95 print(
"Exception when calling InstancesApi->cf_manager_rest_api_post_instances: %s\n" % e)
97 elif args[
'<args>'][0] ==
'restart':
98 if (len(args[
'<args>']) == 2):
99 instance_id = args[
'<args>'][1]
101 print(
"INFO: Restarting instance " +
str(instance_id) +
" ... ")
103 api_response = api_instance.cf_manager_rest_api_app_restart_instance(username, password, instance_id)
104 except ApiException
as e:
105 print(
"Exception when calling InstancesApi->cf_manager_rest_api_app_restart_instance: %s\n" % e)
109 exit(print(
"ERROR: invalid arguments provided in cfsp instance restart. Aborting..."))
110 elif args[
'<args>'][0] ==
'delete':
111 if (len(args[
'<args>']) == 1):
112 print(
"INFO: Really deleting all instances ?")
114 print(
"INFO: Confirmed deleting all instances")
116 api_response_get_in_delete = api_instance.cf_manager_rest_api_get_instances(username, password, limit=args[
'--limit'])
117 if(len(api_response_get_in_delete) > 0):
118 for this_instance
in tqdm(api_response_get_in_delete):
120 print(
"INFO: Deleting instance " +
str(this_instance.instance_id) +
" ... ")
122 api_instance.cf_manager_rest_api_delete_instance(username, password, this_instance.instance_id)
123 except ApiException
as e_in_delete:
124 print(
"Exception when calling InstancesApi->cf_manager_rest_api_delete_instance: %s\n" % e_in_delete)
126 print(
"INFO: No instances to delete.")
127 except ApiException
as e_in_get:
128 print(
"Exception when calling InstancesApi->cf_manager_rest_api_get_instances: %s\n" % e_in_get)
131 print (
"INFO: Canceling deleting all instances")
132 elif (len(args[
'<args>']) == 2):
133 instance_id = args[
'<args>'][1]
135 print(
"INFO: Deleting instance " +
str(instance_id) +
" ... ")
137 api_response = api_instance.cf_manager_rest_api_delete_instance(username, password, instance_id)
138 except ApiException
as e:
139 print(
"Exception when calling InstancesApi->cf_manager_rest_api_delete_instance: %s\n" % e)
143 exit(print(
"ERROR: invalid arguments provided in cfsp instance delete. Aborting..."))
145 exit(print(
"ERROR: invalid command provided in cfsp instance. Type 'cfsp help instance' to get a list of supported commands. Aborting..."))