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
57 def has_call_id (server_version):
58 return server_version.has_key('call_id_support')
61 ### issue a GetVersion call
62 ### this assumes we've already somehow initialized the certificate
63 def get_version (url):
64 # make sure we have a self-signed cert
65 bootstrap.self_signed_cert()
66 server_proxy = bootstrap.server_proxy_simple(url)
67 server_version = server_proxy.GetVersion()
68 print "miniclient: GetVersion at %s returned:"%(url)
69 for (k,v) in server_version.iteritems(): print "miniclient: \tversion[%s]=%s"%(k,truncate(v))
70 print "has-call-id=",has_call_id(server_version)
72 # version_dict = {'type': 'SFA', 'version': '1', }
74 version_dict = {'type':'ProtoGENI', 'version':'2'}
77 # ditto with list resources
78 def list_resources ():
79 bootstrap.bootstrap_my_gid()
80 credential = bootstrap.my_credential_string()
81 credentials = [ credential ]
83 options [ 'geni_rspec_version' ] = version_dict
84 options [ 'call_id' ] = unique_call_id()
85 list_resources = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
86 print "miniclient: ListResources at %s returned : %s"%(aggregate_url,truncate(list_resources))
88 def list_slice_resources ():
89 bootstrap.bootstrap_my_gid()
90 credential = bootstrap.slice_credential_string (slice_hrn)
91 credentials = [ credential ]
93 options [ 'geni_rspec_version' ] = version_dict
94 options [ 'geni_slice_urn' ] = slice_urn
95 options [ 'call_id' ] = unique_call_id()
96 list_resources = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
97 print "miniclient: ListResources at %s for slice %s returned : %s"%(aggregate_url,slice_urn,truncate(list_resources))
102 get_version(registry_url)
103 get_version(aggregate_url)
105 list_slice_resources()