dbfa3fada7e3d9232bf0249eff1461b5213b8785
[sfa.git] / sfa / examples / miniclient.py
1 #!/usr/bin/env python
2
3 # this is designed to use a totally empty new directory
4 # so we demonstrate how to bootstrap the whole thing
5
6 # init logging on console
7 import logging
8 console = logging.StreamHandler()
9 logger=logging.getLogger('')
10 logger.addHandler(console)
11 logger.setLevel(logging.DEBUG)
12
13 # use sys.argv to point to a completely fresh directory
14 import sys
15 args=sys.argv[1:]
16 if len(args)!=1:
17     print "Usage: %s directory"%sys.argv[0]
18     sys.exit(1)
19 dir=args[0]
20 logger.debug('sfaclientsample: Using directory %s'%dir)
21
22 ###
23
24 # this uses a test sfa deployment at openlab
25 registry_url="http://sfa1.pl.sophia.inria.fr:12345/"
26 aggregate_url="http://sfa1.pl.sophia.inria.fr:12347/"
27 # this is where the private key sits - would be ~/.ssh/id_rsa in most cases
28 # but in this context, create this local file
29 # the tests key pair can be found in
30 # http://git.onelab.eu/?p=tests.git;a=blob;f=system/config_default.py
31 # search for public_key / private_key
32 private_key="miniclient-private-key"
33 # user hrn
34 hrn="pla.inri.fake-pi1"
35
36 from sfa.client.sfaclientlib import SfaClientBootstrap
37
38 bootstrap = SfaClientBootstrap (hrn, registry_url, dir=dir, logger=logger)
39 # install the private key in the client directory from 'private_key'
40 bootstrap.init_private_key_if_missing(private_key)
41 bootstrap.bootstrap_gid()
42
43 ### issue a GetVersion call
44 ### this assumes we've already somehow initialized the certificate
45 def get_version (url):
46     
47     server_proxy = bootstrap.server_proxy(url)
48     retcod = server_proxy.GetVersion()
49     print "GetVersion at %s returned following keys: %s"%(url,retcod.keys())
50
51
52 # version_dict = {'type': 'SFA', 'version': '1', }
53
54 version_dict = {'type':'ProtoGENI', 'version':'2'}
55
56 # ditto with list resources
57 def list_resources ():
58     options = { 'geni_rspec_version' : version_dict}
59     credential = bootstrap.get_credential_string()
60     credentials = [ credential ]
61     retcod = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
62     print "ListResources at %s returned : %20s..."%(aggregate_url,retcod)
63
64 def main ():
65     get_version(registry_url)
66     get_version(aggregate_url)
67     list_resources()
68
69 main()