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

Classes

class  cFuser
 User functions. More...
 

Functions

def main (args)
 
def load_user_credentials (json_file)
 
def write_user_credentials (json_file)
 
def print_user_credentials_from_file (json_file)
 

Function Documentation

◆ load_user_credentials()

def cFSPlib.cfsp_user.load_user_credentials (   json_file)
returns username, password, and project from a JSON file

Definition at line 108 of file cfsp_user.py.

108 def load_user_credentials(json_file):
109  """returns username, password, and project from a JSON file"""
110  username = ""
111  password = ""
112  project = ""
113 
114  try:
115  if os.path.exists(json_file):
116  with open(json_file, 'r') as infile:
117  data = json.load(infile)
118  username = data['credentials']['username']
119  password = data['credentials']['password']
120  if 'project' in data:
121  project = data['project']
122  else:
123  project = cfsp_globals.__openstack_user_template__['project']
124  else:
125  print("INFO: Creating new user credentials file : {}\n".format(os.path.abspath(json_file)))
126  write_user_credentials(json_file)
127  except Exception as e:
128  exit(print(e))
129  return username, password, project
130 
131 
def load_user_credentials(json_file)
Definition: cfsp_user.py:108
def write_user_credentials(json_file)
Definition: cfsp_user.py:132
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

def cFSPlib.cfsp_user.main (   args)

Definition at line 75 of file cfsp_user.py.

75 def main(args):
76  if (len(args['<args>']) != 1):
77  print("ERROR: invalid arguments provided in 'cfsp user' command. Aborting...")
78  exit(print(__doc__))
79 
80  if args['<args>'][0] == 'load':
81  if (len(args['<args>']) == 1):
82  user=cFuser(args['--config'])
83  else:
84  print("ERROR: invalid arguments provided in cfsp user load. Aborting...")
85  sys.exit(-1)
86  if args['--username'] != 'username_example':
87  cfsp_globals.__cfsp_username__ = user.username = args['--username']
88  else:
89  cfsp_globals.__cfsp_username__ = user.username
90  if args['--password'] != 'password_example':
91  cfsp_globals.__cfsp_password__ = user.password = args['--password']
92  else:
93  cfsp_globals.__cfsp_password__ = user.password
94  if args['--project'] != 'project_example':
95  cfsp_globals.__cfsp_project__ = user.project = args['--project']
96  else:
97  cfsp_globals.__cfsp_project__ = user.project
98  write_user_credentials(args['--config'])
99  elif args['<args>'][0] == 'show':
100  if (len(args['<args>']) == 1):
101  print_user_credentials_from_file(args['--config'])
102  else:
103  print("ERROR: invalid arguments provided in cfsp user show. Aborting...")
104  sys.exit(-1)
105  else:
106  exit(print("ERROR: invalid command provided in cfsp user. Type 'cfsp help user' to get a list of supported commands. Aborting..."))
107 
def main(args)
Definition: cfsp_user.py:75
def print_user_credentials_from_file(json_file)
Definition: cfsp_user.py:145
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_user_credentials_from_file()

def cFSPlib.cfsp_user.print_user_credentials_from_file (   json_file)

Definition at line 145 of file cfsp_user.py.

145 def print_user_credentials_from_file(json_file):
146  try:
147  with open(json_file, 'r') as infile:
148  data = json.load(infile)
149  username = data['credentials']['username']
150  password = data['credentials']['password']
151  if 'project' in data:
152  project = data['project']
153  else:
154  project = cfsp_globals.__openstack_user_template__['project']
155  print("User : " + username)
156  print("Password : " + password)
157  print("Project : " + project)
158  return 0
159  except Exception as e:
160  print(e)
161  print("No credentials file found : "+ json_file)
162  sys.exit(1)
163 
164 
165 
166 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_user_credentials()

def cFSPlib.cfsp_user.write_user_credentials (   json_file)
writes credentials to a JSON file

Definition at line 132 of file cfsp_user.py.

132 def write_user_credentials(json_file):
133  """writes credentials to a JSON file"""
134  __cfsp_template__ = {}
135  __cfsp_template__['credentials'] = {}
136  __cfsp_template__['credentials']['username'] = cfsp_globals.__cfsp_username__
137  __cfsp_template__['credentials']['password'] = cfsp_globals.__cfsp_password__
138  __cfsp_template__['project'] = cfsp_globals.__cfsp_project__
139  try:
140  with open(json_file, 'w') as outfile:
141  json.dump(__cfsp_template__, outfile)
142  except Exception as e:
143  print(e)
144 
Here is the caller graph for this function: