fix packaging
[sfa.git] / sfa / client / sfaclientsample.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 vplc from the onelab test infrastructure
25 registry_url="http://vplc08.pl.sophia.inria.fr:12345/"
26 aggregate_url="http://vplc08.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 
29 private_key="test_private_key"
30 # user hrn
31 hrn="pla.inri.fake-pi1"
32
33 from sfa.client.sfaclientlib import SfaClientBootstrap
34
35 bootstrap = SfaClientBootstrap (hrn, registry_url, dir=dir, logger=logger)
36 # install the private key in the client directory from 'private_key'
37 bootstrap.init_private_key_if_missing(private_key)
38 bootstrap.bootstrap_gid()
39
40 ### issue a GetVersion call
41 ### this assumes we've already somehow initialized the certificate
42 def get_version (url):
43     
44     server_proxy = bootstrap.server_proxy(url)
45     retcod = server_proxy.GetVersion()
46     print "GetVersion at %s returned following keys: %s"%(url,retcod.keys())
47
48
49 # version_dict = {'type': 'SFA', 'version': '1', }
50
51 version_dict = {'type':'ProtoGENI', 'version':'2'}
52
53 # ditto with list resources
54 def list_resources ():
55     options = { 'geni_rspec_version' : version_dict}
56     credential = bootstrap.get_credential_string()
57     credentials = [ credential ]
58     retcod = bootstrap.server_proxy (aggregate_url).ListResources(credentials,options)
59     print "ListResources at %s returned : %20s..."%(aggregate_url,retcod)
60
61 def main ():
62     get_version(registry_url)
63     get_version(aggregate_url)
64     list_resources()
65
66 main()