4 from optparse import OptionParser
5 from sfa.util.config import Config
6 from sfa.util.xmlrpcprotocol import *
7 from sfa.trust.certificate import Keypair, Certificate
8 from sfa.trust.credential import Credential
11 TRUSTED_CERTS_DIR = '/etc/sfa/trusted_roots'
12 DATA_DIR = '/var/lib/sfa'
14 def create_default_dirs():
15 all_dirs = [CONFIG_DIR, TRUSTED_CERTS_DIR, DATA_DIR]
17 if not os.path.exists(dir):
20 def get_node_key(options):
22 print "Getting the component's pkey"
23 # this call requires no authentication,
24 # so we can generate a random keypair here
26 keyfile = tempfile.mktemp()
27 certfile = tempfile.mktemp()
28 key = Keypair(create=True)
29 key.save_to_file(keyfile)
30 cert = Certificate(subject=component)
31 cert.set_issuer(key=key, subject=subject)
34 cert.save_to_file(certfile)
36 # get the registry url
39 url_parts = options.registry.split(":")
41 url = options.registry
43 url = "http://%s:12346" % options.registry
46 addr, port = config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT_
47 url = "http://%(addr)s:%(port)s" % locals()
50 print "Contacting registry at: %(url)s" % locals()
52 registry = xmlrpcprotocol.get_server(url, keyfile, certfile)
54 def get_credential(options):
56 print "Getting the component's credential"
59 def get_trusted_certs(options):
61 print "Getting the component's trusted certs"
64 def get_gids(options):
66 print "Geting the component's GIDs"
73 parser = OptionParser(usage="%(prog_name)s [options]" % locals())
74 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
75 default=False, help="Be verbose")
76 parser.add_option("-r", "--registry", dest="registry", default=None,
77 help="Url of registry to contact")
78 parser.add_option("-k", "--key", dest="key", action="store_true",
80 help="Get the node's pkey from the registry")
81 parser.add_option("-c", "--certs", dest="certs", action="store_true",
83 help="Get the trusted certs from the registry")
84 parser.add_option("-g", "--gids", dest="gids", action="store_true",
86 help="Get gids for all the slices on the component")
88 (options, args) = parser.parse_args()
98 if __name__ == '__main__':