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
10 def create_default_dirs():
11 config_dir = '/etc/sfa'
12 trusted_certs_dir = '/etc/sfa/trusted_certs'
13 data_dir = '/var/lib/sfa'
14 all_dirs = [config_dir, trusted_certs_dir, data_dir]
16 if not os.path.exists(dir):
19 def get_node_key(options):
21 print "Getting the component's pkey"
22 # this call requires no authentication,
23 # so we can generate a random keypair here
25 keyfile = tempfile.mktemp()
26 certfile = tempfile.mktemp()
27 key = Keypair(create=True)
28 key.save_to_file(keyfile)
29 cert = Certificate(subject=component)
30 cert.set_issuer(key=key, subject=subject)
33 cert.save_to_file(certfile)
35 # get the registry url
38 url_parts = options.registry.split(":")
40 url = options.registry
42 url = "http://%s:12346" % options.registry
45 addr, port = config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT_
46 url = "http://%(addr)s:%(port)s" % locals()
49 print "Contacting registry at: %(url)s" % locals()
51 registry = xmlrpcprotocol.get_server(url, keyfile, certfile)
53 def get_credential(options):
55 print "Getting the component's credential"
58 def get_trusted_certs(options):
60 print "Getting the component's trusted certs"
63 def get_gids(options):
65 print "Geting the component's GIDs"
72 parser = OptionParser(usage="%(prog_name)s [options]" % locals())
73 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
74 default=False, help="Be verbose")
75 parser.add_option("-r", "--registry", dest="registry", default=None,
76 help="Url of registry to contact")
77 parser.add_option("-k", "--key", dest="key", action="store_true",
79 help="Get the node's pkey from the registry")
80 parser.add_option("-c", "--certs", dest="certs", action="store_true",
82 help="Get the trusted certs from the registry")
83 parser.add_option("-g", "--gids", dest="gids", action="store_true",
85 help="Get gids for all the slices on the component")
87 (options, args) = parser.parse_args()
97 if __name__ == '__main__':