cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cFSP.py
Go to the documentation of this file.
1 # /*******************************************************************************
2 # * Copyright 2016 -- 2022 IBM Corporation
3 # *
4 # * Licensed under the Apache License, Version 2.0 (the "License");
5 # * you may not use this file except in compliance with the License.
6 # * You may obtain a copy of the License at
7 # *
8 # * http://www.apache.org/licenses/LICENSE-2.0
9 # *
10 # * Unless required by applicable law or agreed to in writing, software
11 # * distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
15 # *******************************************************************************/
16 
17 # *
18 # * cloudFPGA
19 # * =============================================
20 # * Created: Apr 2019
21 # * Authors: FAB, WEI, NGL, DID
22 # *
23 # * Description:
24 # * Python tool to interact with cFRM.
25 # *
26 
27 # @file cFSP.py
28 # @brief This is the main file of cFSP
29 # @author DID
30 # @date Dec 2021
31 # @ingroup cFSP
32 # @addtogroup cFSP
33 # \{
34 
35 #! /usr/bin/env python
36 """cfsp.
37 
38 cloudFPGA Support Package (cfsp)
39 cfsp is a command-line tool that helps a cloudFPGA user to work with cloudFPGA Resource Manager (cFRM).
40 Usage:
41  cfsp [-c CFGFILE] [--version] [--help] [--username=<username>] [--password=<password>] [--project=<project>]
42  [--image_id=<image_id>]...
43  [--node_ip=<node_ip>]...
44  [--node_id=<node_id>]...
45  [--cluster_id=<cluster_id>]
46  [--image_file=<image_file>] [--comment=<comment>] [--sig_file=<sig_file>] [--pr_verify_rpt=<pr_verify_rpt] [--dont_verify_memory=<dont_verify_memory>]
47  [--limit=<limit>] [--repeat=<repeat>]
48  [<command>] [<args>...]
49 
50 Commands:
51  user Adding or showing the credentials of a user.
52  cluster Creating, showing and deleting clusters.
53  image Uploading, showing and deleting FPGA images.
54  instance Creating, showing and deleting instances.
55  debug Requests and returns the status information of all instances in acluster.
56 
57 Options:
58  -h --help Show this screen.
59  -v --version Show version.
60  -c --config CFGFILE Specify the configfile that rsnapshot should use
61  [default: ./user.json]
62  --username=<username> Your ZYC2 username [default: username_example].
63  --password=<password> Your ZYC2 password [default: password_example].
64  --project=<password> The user's project [default: project_example].
65  --image_id=<image_id> The id of the uploaded FPGA image, or NON_FPGA for a CPU VM node.
66  --node_ip=<node_ip> The ip of the user's VM, e.g. a ZYC2 VM.
67  --node_id=<node_id> The id (rank) of either the VPN user's VM or FPGAs.
68  --cluster_id=<cluster_id> The id of a cluster to update or extend.
69  --image_file=<image_file> The FPGA image file to be uploaded [default: ./image.bit].
70  --comment=<comment> A comment for the FPGA image file to be uploaded [default: None].
71  --sig_file=<sig_file> An FPGA bitstream signature file containing hashes from the build process.
72  --pr_verify_rpt=<pr_verify_rpt An FPGA report containing the output of the automatically run pr_verify command.
73  --dont_verify_memory=<dont_verify_memory> If 1, don't verify the DDR4 memory during setup [default: 0].
74  --limit=<limit> The limit of get for clusters, images, instances [default: 100].
75  --repeat=<repeat> The numper of times to repeat the command [default: 1].
76 
77 See 'cfsp help <command>' for more information on a specific command.
78 
79 Copyright IBM Research, licensed under the Apache License 2.0.
80 
81 """
82 
83 from __future__ import print_function, unicode_literals
84 
85 import json
86 import os
87 import sys
88 from docopt import docopt
89 import re
90 from PyInquirer import prompt, print_json
91 from pprint import pprint
92 from tqdm import tqdm
93 
94 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
95 import cfsp_globals
96 import cfsp_user
97 import cfsp_cluster
98 import cfsp_image
99 import cfsp_instance
100 import cfsp_debug
101 
102 from cfsp_util import print_usage
103 import mngmt
104 import comm
105 
106 
107 version_path = os.path.dirname(os.path.abspath(__file__))+"/version.txt"
108 with open(version_path,"r") as fh:
109  for line in fh:
110  __version__ = line.rstrip("\n")
111 fh.close()
112 
113 # This variable check weather we call cfsp a script from the command line,
114 # or as module from another Python file.
115 is_script = False
116 
117 def check_credentials(CFGFILE):
118  #if os.path.isfile(cfsp_globals.__cfsp_session_file__):
119  # dill.load_session(cfsp_globals.__cfsp_session_file__)
120  #else:
121  args = docopt(__doc__, version=__version__)
122  args['<args>'] = ['load']
123  cfsp_user.main(args)
124 
125 def main(args):
126 
127  argv = [args['<command>']] + args['<args>']
128  #print(args['<args>'])
129  #print([args['<command>']] + args['<args>'])
130 
131  for repeat_id in tqdm(range(0,int(args['--repeat']))):
132  cfrm_response = ''
133  print("INFO: Repeat #"+str(repeat_id))
134  if args['<command>'] == 'user':
135  cfsp_user.main(args)
136  elif args['<command>'] == 'cluster':
137  check_credentials(args['--config'])
138  cfrm_response=cfsp_cluster.main(args)
139  elif args['<command>'] == 'image':
140  check_credentials(args['--config'])
141  cfrm_response=cfsp_image.main(args)
142  elif args['<command>'] == 'instance':
143  check_credentials(args['--config'])
144  cfrm_response=cfsp_instance.main(args)
145  elif args['<command>'] == 'debug':
146  check_credentials(args['--config'])
147  cfrm_response=cfsp_debug.main(args)
148  elif args['<command>'] in ['help', None]:
149  if args['<args>'] == ['user']:
150  print("docopt user")
151  print(docopt(cfsp_user.__doc__, argv=argv))
152  elif args['<args>'] == ['cluster']:
153  print(docopt(cfsp_cluster.__doc__, argv=argv))
154  elif args['<args>'] == ['image']:
155  print(docopt(cfsp_image.__doc__, argv=argv))
156  elif args['<args>'] == ['instance']:
157  print(docopt(cfsp_instance.__doc__, argv=argv))
158  elif args['<args>'] == ['debug']:
159  print(docopt(cfsp_debug.__doc__, argv=argv))
160  else:
161  print(docopt(__doc__, version=__version__))
162  else:
163  print("ERROR: unknown command. Aborting...")
164  exit(print(docopt(__doc__, version=__version__)))
165 
166  if (is_script):
167  pprint(cfrm_response)
168  else:
169  return(cfrm_response)
170 
171 
172 if __name__ == '__main__':
173  if not (hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)):
174  # This works with virtualenv for Python 3 and 2 and also for the venv module in Python 3
175  print("ERROR: It looks like this cFSP isn't running in a virtual environment. Aborting.")
176  sys.exit(1)
177 
178  args = docopt(__doc__, version=__version__)
179  is_script = True
180  main(args)
181  exit(0)
182 
183 
184 # ! \}
def main(args)
Definition: cFSP.py:125
def check_credentials(CFGFILE)
Definition: cFSP.py:117