5 from optparse import OptionParser
6 from sfa.util.config import Config
7 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
8 from sfa.trust.certificate import Keypair, Certificate
9 from sfa.trust.credential import Credential
12 TRUSTED_CERTS_DIR = '/etc/sfa/trusted_roots'
13 DATA_DIR = '/var/lib/sfa'
15 def create_default_dirs():
16 all_dirs = [CONFIG_DIR, TRUSTED_CERTS_DIR, DATA_DIR]
18 if not os.path.exists(dir):
21 def get_node_key(options):
23 print "Getting the component's pkey"
24 # this call requires no authentication,
25 # so we can generate a random keypair here
27 keyfile = tempfile.mktemp()
28 certfile = tempfile.mktemp()
29 key = Keypair(create=True)
30 key.save_to_file(keyfile)
31 cert = Certificate(subject=subject)
32 cert.set_issuer(key=key, subject=subject)
35 cert.save_to_file(certfile)
37 # get the registry url
40 url_parts = options.registry.split(":")
42 url = options.registry
44 url = "http://%s:12346" % options.registry
47 addr, port = config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT_
48 url = "http://%(addr)s:%(port)s" % locals()
51 print "Contacting registry at: %(url)s" % locals()
53 registry = xmlrpcprotocol.get_server(url, keyfile, certfile)
56 def get_credential(options):
58 print "Getting the component's credential"
61 def get_trusted_certs(options):
63 print "Getting the component's trusted certs"
66 def get_gids(options):
68 print "Geting the component's GIDs"
75 parser = OptionParser(usage="%(prog_name)s [options]" % locals())
76 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
77 default=False, help="Be verbose")
78 parser.add_option("-r", "--registry", dest="registry", default=None,
79 help="Url of registry to contact")
80 parser.add_option("-k", "--key", dest="key", action="store_true",
82 help="Get the node's pkey from the registry")
83 parser.add_option("-c", "--certs", dest="certs", action="store_true",
85 help="Get the trusted certs from the registry")
86 parser.add_option("-g", "--gids", dest="gids", action="store_true",
88 help="Get gids for all the slices on the component")
90 (options, args) = parser.parse_args()
100 if __name__ == '__main__':