supported = [
# local code name, config variable name, default
('slice', 'SFI_SLICE' , None, '-s','--slice', "slice HRN"),
('user', 'SFI_USER', None, '-u','--user', "user HRN"),
('authority', 'SFI_AUTH', None, '-t','--auth', "users's authority HRN"),
supported = [
# local code name, config variable name, default
('slice', 'SFI_SLICE' , None, '-s','--slice', "slice HRN"),
('user', 'SFI_USER', None, '-u','--user', "user HRN"),
('authority', 'SFI_AUTH', None, '-t','--auth', "users's authority HRN"),
- ('registry', 'SFI_REGISTRY', d_registry, '-r','--registry', "registry's URL"),
- ('slicemgr', 'SFI_SM' , d_slicemgr, '-m','--slicemgr', "slice manager's URL"),
- ('aggmgr', 'SFI_AM', d_aggmgr, '-a','--aggregate', "aggregate manager's URL"),
+ ('registry', 'SFI_REGISTRY', d_registry, '-r','--registry', "registry API URL"),
+ ('slicemgr', 'SFI_SM' , d_slicemgr, '-m','--slicemgr', "slice API URL"),
+# ('aggmgr', 'SFI_AM', d_aggmgr, '-a','--aggregate', "aggregate manager's URL"),
('verbose', 'SFACE_VERBOSE',True, '-v','--verbose', "UI verbosity"),
('verbose', 'SFACE_VERBOSE',True, '-v','--verbose', "UI verbosity"),
- ('debug', 'SFACE_DEBUG', False, '-d','--debug', "UI debug flag"),
+ ('debug', 'SFACE_DEBUG', False, '-D','--debug', "UI debug flag"),
+ def __init__ (self):
+ print 'WARNING - should pass config dir'
+ self.dirname=os.path.expanduser("~/.sfi/")
+ self.read_config()
+
+ def get_dirname (self):
+ return self.dirname
+
+ # warning, might lose unsaved data..
+ def set_dirname (self, dirname):
+ self.dirname=dirname
+ self.read_config()
+
def get(self,field): return getattr(self,field)
def set(self,field,value): setattr(self,field,value)
def get(self,field): return getattr(self,field)
def set(self,field,value): setattr(self,field,value)
pass
for (field,sfi,default,_,__,___) in Config.supported:
if tmp.has_key(sfi):setattr(self,field,tmp[sfi])
else: setattr(self,field,default)
pass
for (field,sfi,default,_,__,___) in Config.supported:
if tmp.has_key(sfi):setattr(self,field,tmp[sfi])
else: setattr(self,field,default)
- configfile = self.filename()
+ configdir = self.get_dirname()
+ if not os.path.exists(configdir):
+ os.makedirs(configdir)
+
+ configfile = self.config_file()
+ if not os.path.exists(configfile):
+ open(configfile, "w").close()
+
# check if a field is a boolean field
def is_bool_field(self, field):
# check if a field is a boolean field
def is_bool_field(self, field):
if isinstance(value,types.StringTypes) and value.lower()=='true': return True
def add_options_to_OptionParser (self, parser):
if isinstance(value,types.StringTypes) and value.lower()=='true': return True
def add_options_to_OptionParser (self, parser):
+ parser.add_option ("-d","--dir",dest='dirname',action='store',
+ default=os.path.expanduser("~/.sfi/"),
+ help="sfi config dir")
for (field,_,default,short,long,msg) in Config.supported:
if isinstance(default,bool):
parser.add_option(short,long,dest=field,action="store_true",help=msg)
for (field,_,default,short,long,msg) in Config.supported:
if isinstance(default,bool):
parser.add_option(short,long,dest=field,action="store_true",help=msg)
parser.add_option(short,long,dest=field,action="store",default=None, help=msg)
def update_from_OptionParser (self, optparse_options):
parser.add_option(short,long,dest=field,action="store",default=None, help=msg)
def update_from_OptionParser (self, optparse_options):
for field in self.fields():
if not hasattr(optparse_options,field) : continue
value=getattr(optparse_options,field)
for field in self.fields():
if not hasattr(optparse_options,field) : continue
value=getattr(optparse_options,field)
- def getSliceRSpecFile(self):
- return os.path.expanduser("~/.sfi/%s.rspec" % self.getSlice())
-
+ def fullpath (self, filename): return os.path.join(self.get_dirname(),filename)
+
+ def getSliceRSpecFile(self): return self.fullpath("%s.rspec" % self.getSlice())
+
+ def getSliceRecordFile(self): return self.fullpath ("%s.record" % self.getSlice())
+
+ def getAuthorityRecordFile(self): return self.fullpath ("%s/%s.record" % self.getAuthority())
+
+ def getAuthorityListFile(self, i=None):
+ if (i != None) and (i != 0):
+ return self.fullpath ("%s_list.record.%d" % (self.getAuthority(),i))
+ else:
+ return self.fullpath ("%s_list.record" % self.getAuthority())
+