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