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)
18 def unique_call_id(): return uuid.uuid4().urn
20 # use sys.argv to point to a completely fresh directory
24 print("Usage: %s directory" % sys.argv[0])
27 logger.debug('sfaclientsample: Using directory %s' % dir)
31 # this uses a test sfa deployment at openlab
32 registry_url = "http://sfa1.pl.sophia.inria.fr:12345/"
33 aggregate_url = "http://sfa1.pl.sophia.inria.fr:12347/"
34 # this is where the private key sits - would be ~/.ssh/id_rsa in most cases
35 # but in this context, create this local file
36 # the tests key pair can be found in
37 # http://git.onelab.eu/?p=tests.git;a=blob;f=system/config_default.py
38 # search for public_key / private_key
39 private_key = "miniclient-private-key"
41 user_hrn = "pla.inri.fake-pi1"
43 slice_hrn = "pla.inri.slpl1"
44 # hrn_to_urn(slice_hrn,'slice')
45 slice_urn = 'urn:publicid:IDN+pla:inri+slice+slpl1'
47 from sfa.client.sfaclientlib import SfaClientBootstrap
49 bootstrap = SfaClientBootstrap(user_hrn, registry_url, dir=dir, logger=logger)
50 # install the private key in the client directory from 'private_key'
51 bootstrap.init_private_key_if_missing(private_key)
54 def truncate(content, length=20, suffix='...'):
55 if isinstance(content, (int)):
57 if isinstance(content, list):
58 return truncate("%s" % content, length, suffix)
59 if len(content) <= length:
62 return content[:length + 1] + ' ' + suffix
65 # issue a GetVersion call
66 # this assumes we've already somehow initialized the certificate
68 # make sure we have a self-signed cert
69 bootstrap.self_signed_cert()
70 server_proxy = bootstrap.server_proxy_simple(url)
71 server_version = server_proxy.GetVersion()
72 print("miniclient: GetVersion at %s returned:" % (url))
73 for (k, v) in server_version.iteritems():
74 print("miniclient: \tversion[%s]=%s" % (k, truncate(v)))
76 # version_dict = {'type': 'SFA', 'version': '1', }
78 version_dict = {'type': 'ProtoGENI', 'version': '2'}
81 # ditto with list resources
83 bootstrap.bootstrap_my_gid()
84 credential = bootstrap.my_credential_string()
85 credentials = [credential]
87 options['geni_rspec_version'] = version_dict
88 options['call_id'] = unique_call_id()
89 list_resources = bootstrap.server_proxy(
90 aggregate_url).ListResources(credentials, options)
91 print("miniclient: ListResources at %s returned : %s" %
92 (aggregate_url, truncate(list_resources)))
95 def list_slice_resources():
96 bootstrap.bootstrap_my_gid()
97 credential = bootstrap.slice_credential_string(slice_hrn)
98 credentials = [credential]
100 options['geni_rspec_version'] = version_dict
101 options['geni_slice_urn'] = slice_urn
102 options['call_id'] = unique_call_id()
103 list_resources = bootstrap.server_proxy(
104 aggregate_url).ListResources(credentials, options)
105 print("miniclient: ListResources at %s for slice %s returned : %s" %
106 (aggregate_url, slice_urn, truncate(list_resources)))
110 get_version(registry_url)
111 get_version(aggregate_url)
113 list_slice_resources()