- def sfi_path (self):
- return "/root/sfi/%s"%self.slicename
-
- def locate_key(self):
- for username,keyname in self.sfa_slice_spec['usernames']:
- key_spec=self.test_plc.locate_key(keyname)
- test_key=TestKey(self.test_plc,key_spec)
- publickey=test_key.publicpath()
- privatekey=test_key.privatepath()
- if os.path.isfile(publickey) and os.path.isfile(privatekey):
- found=True
- return (found,privatekey)
-
- # dir_name is local and will be pushed later on by TestPlc
- # by default set SFI_USER to the pi, we'll overload this
- # on the command line when needed
- def sfi_config (self,dir_name):
- plc_spec=self.test_plc.plc_spec
- sfa_spec=self.sfa_spec
- sfa_slice_spec=self.sfa_slice_spec
- keys=plc_spec['keys']
- for (contents,name) in [ (keys[0]['private'], self.piuser+'.pkey'),
- (keys[0]['key_fields']['key'], self.piuser+'.pub'),
- (keys[1]['private'], self.regularuser+'.pkey'),
- (keys[0]['key_fields']['key'], self.regularuser+'.pub'),
- ]:
- file_name=os.path.join(dir_name,self.qualified_hrn(name))
- fileconf=open(file_name,'w')
- fileconf.write (contents)
- fileconf.close()
- utils.header ("(Over)wrote %s"%file_name)
- #
- file_name=dir_name + os.sep + self.addpersonfile()
- fileconf=open(file_name,'w')
- fileconf.write(sfa_slice_spec['person_record'])
- fileconf.write('\n')
- fileconf.close()
- utils.header ("(Over)wrote %s"%file_name)
- #
- file_name=dir_name + os.sep + 'sfi_config'
- fileconf=open(file_name,'w')
- SFI_AUTH="%s"%(self.site_hrn())
- fileconf.write ("SFI_AUTH='%s'"%SFI_AUTH)
- fileconf.write('\n')
- SFI_USER=SFI_AUTH + '.' + self.piuser
- fileconf.write ("SFI_USER='%s'"%SFI_USER)
- fileconf.write('\n')
- SFI_REGISTRY='http://' + sfa_spec['SFA_REGISTRY_HOST'] + ':12345/'
- fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY)
- fileconf.write('\n')
- SFI_SM='http://' + sfa_spec['SFA_SM_HOST'] + ':12347/'
- fileconf.write ("SFI_SM='%s'"%SFI_SM)
- fileconf.write('\n')
- fileconf.close()
- utils.header ("(Over)wrote %s"%file_name)
- #
- file_name=dir_name + os.sep + self.addslicefile()
- fileconf=open(file_name,'w')
- fileconf.write(sfa_slice_spec['slice_record'])
- fileconf.write('\n')
- utils.header ("(Over)wrote %s"%file_name)
- fileconf.close()
-
- # using sfaadmin to bootstrap
- def sfa_add_site (self, options):
- command="sfaadmin reg register -t authority -x %s"%self.site_hrn()
- return self.test_plc.run_in_guest(command)==0
-
- def sfa_add_pi (self, options):
- pi_hrn=self.qualified_hrn(self.piuser)
- pi_mail=self.sfa_slice_spec['pimail']
- # as installed by sfi_config
- pi_key=os.path.join(self.sfi_path(),self.qualified_hrn(self.piuser+'.pub'))
- command="sfaadmin reg register -t user -x %s --email %s --key %s"%(pi_hrn,pi_mail,pi_key)
- if self.test_plc.run_in_guest(command)!=0: return False
- command="sfaadmin reg update -t authority -x %s --pi %s"%(self.site_hrn(),pi_hrn)
- return self.test_plc.run_in_guest(command)==0
-
- # user management
- def sfa_add_user (self, options):
- return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).add_user()
- def sfa_update_user (self, options):
- return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).update_user()
- def sfa_delete_user (self, options):
- return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).delete_user()
-
- # run as pi
- def sfi_pi (self, command):
- return "sfi.py -d %s -u %s %s"%(self.sfi_path(),self.qualified_hrn(self.piuser), command,)
- # the sfi.py command line option to run as a regular user
- def sfi_user (self, command):
- return "sfi.py -d %s -u %s %s"%(self.sfi_path(),self.qualified_hrn(self.regularuser), command,)
-