3 # this is designed to use a totally empty new directory
4 # so we demonstrate how to bootstrap the whole thing
6 # init logging on console
8 console = logging.StreamHandler()
9 logger=logging.getLogger('')
10 logger.addHandler(console)
11 logger.setLevel(logging.DEBUG)
14 def unique_call_id(): return uuid.uuid4().urn
16 # use sys.argv to point to a completely fresh directory
20 print "Usage: %s directory"%sys.argv[0]
23 logger.debug('sfaclientsample: Using directory %s'%dir)
27 # this uses a test sfa deployment at openlab
28 registry_url="http://sfa1.pl.sophia.inria.fr:12345/"
29 aggregate_url="http://sfa1.pl.sophia.inria.fr:12347/"
30 # this is where the private key sits - would be ~/.ssh/id_rsa in most cases
31 # but in this context, create this local file
32 # the tests key pair can be found in
33 # http://git.onelab.eu/?p=tests.git;a=blob;f=system/config_default.py
34 # search for public_key / private_key
35 private_key="miniclient-private-key"
37 user_hrn="pla.inri.fake-pi1"
39 slice_hrn="pla.inri.slpl1"
40 # hrn_to_urn(slice_hrn,'slice')
41 slice_urn='urn:publicid:IDN+pla:inri+slice+slpl1'
43 from sfa.client.sfaclientlib import SfaClientBootstrap
45 bootstrap = SfaClientBootstrap (user_hrn, registry_url, dir=dir, logger=logger)
46 # install the private key in the client directory from 'private_key'
47 bootstrap.init_private_key_if_missing(private_key)
49 def truncate(content, length=20, suffix='...'):
50 if isinstance (content, (int) ): return content
51 if isinstance (content, list): return truncate ( "%s"%content, length, suffix)
52 if len(content) <= length:
55 return content[:length+1]+ ' '+suffix
58 ### issue a GetVersion call
59 ### this assumes we've already somehow initialized the certificate
60 def get_version (url):
61 # make sure we have a self-signed cert
62 bootstrap.self_signed_cert()
63 server_proxy = bootstrap.server_proxy_simple(url)
64 server_version = server_proxy.GetVersion()
65 print "miniclient: GetVersion at %s returned:"%(url)
66 for (k,v) in server_version.iteritems(): print "miniclient: \tversion[%s]=%s"%(k,truncate(v))
68 # version_dict = {'type': 'SFA', 'version': '1', }
70 version_dict = {'type':'ProtoGENI', 'version':'2'}
73 # ditto with list resources
74 def list_resources ():
75 bootstrap.bootstrap_my_gid()
76 credential = bootstrap.my_credential_string()
77 credentials = [ credential ]
79 options [ 'geni_rspec_version' ] = version_dict
80 options [ 'call_id' ] = unique_call_id()
81 list_resources = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
82 print "miniclient: ListResources at %s returned : %s"%(aggregate_url,truncate(list_resources))
84 def list_slice_resources ():
85 bootstrap.bootstrap_my_gid()
86 credential = bootstrap.slice_credential_string (slice_hrn)
87 credentials = [ credential ]
89 options [ 'geni_rspec_version' ] = version_dict
90 options [ 'geni_slice_urn' ] = slice_urn
91 options [ 'call_id' ] = unique_call_id()
92 list_resources = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
93 print "miniclient: ListResources at %s for slice %s returned : %s"%(aggregate_url,slice_urn,truncate(list_resources))
98 get_version(registry_url)
99 get_version(aggregate_url)
101 list_slice_resources()