cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cFSPlib.cfsp_instance Namespace Reference

Functions

def confirm_choice ()
 
def main (args)
 

Variables

string python_api_client_path = os.getcwd()+"/cFSPlib/python_api_client/"
 

Function Documentation

◆ confirm_choice()

def cFSPlib.cfsp_instance.confirm_choice ( )

Definition at line 39 of file cfsp_instance.py.

39 def confirm_choice():
40  confirm = input("[c]Confirm or [v]Void: ")
41  if confirm != 'c' and confirm != 'v':
42  print("\n Invalid Option. Please Enter a Valid Option.")
43  return confirm_choice()
44  print (confirm)
45  return confirm
46 
47 
string input
Definition: test.py:9
Here is the caller graph for this function:

◆ main()

def cFSPlib.cfsp_instance.main (   args)

Definition at line 48 of file cfsp_instance.py.

48 def main(args):
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)
53 
54  if ((len(args['<args>']) < 1) or (len(args['<args>']) > 2)):
55  print("ERROR: invalid arguments provided in 'cfsp instance' command. Aborting...")
56  exit(print(__doc__))
57 
58  username = cfsp_globals.__cfsp_username__
59  password = cfsp_globals.__cfsp_password__
60  project_name = cfsp_globals.__cfsp_project__
61 
62  if args['<args>'][0] == 'get':
63  if (len(args['<args>']) == 2):
64  try:
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)
68  exit(-1)
69  elif (len(args['<args>']) == 1):
70  try:
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)
74  exit(-1)
75  else:
76  exit(print("ERROR: invalid arguments provided in cfsp instance get. Aborting..."))
77  return(api_response)
78  elif args['<args>'][0] == 'post':
79  # create an instance of the API class
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]
83  try:
84  # Request an instance
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'])
86  # post_instance dows not return the role_ip, thus we call get_instance afterwards.
87  instance_id = api_response.instance_id
88  try:
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)
92  exit(-1)
93  return(api_response)
94  except ApiException as e:
95  print("Exception when calling InstancesApi->cf_manager_rest_api_post_instances: %s\n" % e)
96  exit(-1)
97  elif args['<args>'][0] == 'restart':
98  if (len(args['<args>']) == 2):
99  instance_id = args['<args>'][1]
100  # Restart an instance
101  print("INFO: Restarting instance " + str(instance_id) + " ... ")
102  try:
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)
106  exit(-1)
107  return(api_response)
108  else:
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 ?")
113  if confirm_choice() == 'c':
114  print("INFO: Confirmed deleting all instances")
115  try:
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):
119  # Delete an instance
120  print("INFO: Deleting instance " + str(this_instance.instance_id) + " ... ")
121  try:
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)
125  else:
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)
129  exit(-1)
130  else:
131  print ("INFO: Canceling deleting all instances")
132  elif (len(args['<args>']) == 2):
133  instance_id = args['<args>'][1]
134  # Delete an instance
135  print("INFO: Deleting instance " + str(instance_id) + " ... ")
136  try:
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)
140  exit(-1)
141  return(api_response)
142  else:
143  exit(print("ERROR: invalid arguments provided in cfsp instance delete. Aborting..."))
144  else:
145  exit(print("ERROR: invalid command provided in cfsp instance. Type 'cfsp help instance' to get a list of supported commands. Aborting..."))
Here is the call graph for this function:

Variable Documentation

◆ python_api_client_path

string cFSPlib.cfsp_instance.python_api_client_path = os.getcwd()+"/cFSPlib/python_api_client/"

Definition at line 29 of file cfsp_instance.py.