summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2013-04-01 00:14:14 -0400
committerJohn Dennis <jdennis@redhat.com>2013-04-01 00:14:14 -0400
commitc40b2d3a70ce582de46db237b483184f060eb4e9 (patch)
tree085b72ef4d6d658d0b5d40f9c1384d6fbfd231ac /doc
parent97a213ae1c58fec62a27c47fa46b822032f3d504 (diff)
downloadrealmd-cim-c40b2d3a70ce582de46db237b483184f060eb4e9.tar.gz
realmd-cim-c40b2d3a70ce582de46db237b483184f060eb4e9.tar.xz
realmd-cim-c40b2d3a70ce582de46db237b483184f060eb4e9.zip
Add Python scription: realmd-cim
Add RealmName property to LMI_RealmdRealm class
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/examples/realmd-cim249
1 files changed, 249 insertions, 0 deletions
diff --git a/doc/examples/realmd-cim b/doc/examples/realmd-cim
new file mode 100755
index 0000000..01d59a4
--- /dev/null
+++ b/doc/examples/realmd-cim
@@ -0,0 +1,249 @@
+#!/usr/bin/python
+
+import sys
+import os
+import optparse
+import urlparse
+import pywbem
+
+#----------------------------------------------------------------------
+
+REALM_DBUS_KERBEROS_MEMBERSHIP_INTERFACE = "org.freedesktop.realmd.KerberosMembership"
+
+#----------------------------------------------------------------------
+
+def do_list(conn, options, args):
+ realms = conn.EnumerateInstances('LMI_RealmdKerberosRealm')
+
+ print "%d realms" % (len(realms))
+
+ for realm in realms:
+ if options.verbose > 1:
+ # Very verbose, dump all properties
+ property_names = sorted(realm.keys())
+ for name in property_names:
+ value = realm[name]
+ print " %s: %s" % (name, value)
+
+ print realm['RealmName']
+ print " type: kerberos"
+ print " realm-name: %s" % realm['RealmName']
+ print " domain-name: %s" % realm['DomainName']
+
+ is_configured = True
+ configured = realm['Configured']
+ if not configured:
+ configured = "no"
+ is_configured = False
+ elif configured == REALM_DBUS_KERBEROS_MEMBERSHIP_INTERFACE:
+ configured = "kerberos-member"
+
+ print " configured: %s" % configured
+
+ for detail in zip(realm['DetailNames'], realm['DetailValues']):
+ print " %s: %s" % (detail[0], detail[1])
+
+ if is_configured:
+ print " login-formats: %s" % ", ".join(realm['LoginFormats'])
+ print " login-policy: %s" % realm['LoginPolicy']
+ print " permitted-logins: %s" % ", ".join(realm['PermittedLogins'])
+
+ print
+
+def do_join(conn, options, args):
+ # Validate arguments
+ if len(args) != 3:
+ raise ValueError("You must supply exacly 3 arguments (user, password, domain)")
+
+ user, password, domain = args
+
+ if (options.verbose):
+ print "Joining domain: %s" % domain
+
+ try:
+ realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0]
+ except Exception, e:
+ raise ValueError("could not obtain realmd service")
+
+ try:
+ retval, outparams = conn.InvokeMethod("JoinDomain", realmd_service_instance_name,
+ Domain=domain,
+ User=user,
+ Password=password)
+ except Exception, e:
+ raise ValueError("Join failed (%s)" % (e))
+
+
+
+def do_leave(conn, options, args):
+ # Validate arguments
+ if len(args) != 3:
+ raise ValueError("You must supply exacly 3 arguments (user, password, domain)")
+
+ user, password, domain = args
+
+ if (options.verbose):
+ print "Leave domain: %s" % domain
+
+ try:
+ realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0]
+ except Exception, e:
+ raise ValueError("could not obtain realmd service")
+
+ try:
+ retval, outparams = conn.InvokeMethod("LeaveDomain", realmd_service_instance_name,
+ Domain=domain,
+ User=user,
+ Password=password)
+ except Exception, e:
+ raise ValueError("Leave failed (%s)" % (e))
+
+
+
+def do_discover(conn, options, args):
+ # Validate arguments
+ if len(args) != 1:
+ raise ValueError("You must supply exactly 1 domain.")
+
+ domain = args[0]
+
+ if (options.verbose):
+ print "Discovering domain: %s" % domain
+
+ try:
+ realmd_service_instance_name = conn.EnumerateInstanceNames('LMI_RealmdService')[0]
+ except Exception, e:
+ raise ValueError("could not obtain realmd service")
+
+ try:
+ retval, outparams = conn.InvokeMethod("Discover", realmd_service_instance_name,
+ Target=domain)
+ except Exception, e:
+ raise ValueError("Join failed (%s)" % (e))
+
+ realm_refs = outparams['DiscoveredRealms']
+
+ print "%d Discovered" % len(realm_refs)
+ for realm_ref in realm_refs:
+ #print realm_ref
+ realm = conn.GetInstance(realm_ref)
+ print realm['RealmName']
+ print " Name: %s" % realm['RealmName']
+ print " Configured: %s" % realm['Configured']
+ print " Supported Interfaces: %s" % ", ".join(realm['SupportedInterfaces'])
+ for detail in zip(realm['DetailNames'], realm['DetailValues']):
+ print " %s: %s" % (detail[0], detail[1])
+ print " login-formats: %s" % ", ".join(realm['LoginFormats'])
+ print " login-policy: %s" % realm['LoginPolicy']
+ print " permitted-logins: %s" % ", ".join(realm['PermittedLogins'])
+
+
+
+#----------------------------------------------------------------------
+
+def main():
+
+ actions = {'list': do_list,
+ 'discover': do_discover,
+ 'join': do_join,
+ 'leave': do_leave,
+ }
+
+ usage ='''
+ %%prog [options] <action> <arg> ...
+
+ %%prog [options] list
+ %%prog [options] discover domain
+ %%prog [options] join user password domain
+ %%prog [options] leave user password domain
+
+ Available Actions: %(actions)s
+ ''' % {'actions': ", ".join(sorted(actions.keys()))}
+
+ # Set-up defaults
+
+ default_cimom_port = 5989
+ default_url = os.environ.get("LMI_CIMOM_URL", "https://localhost:5989")
+
+ parsed_default_url = urlparse.urlparse(default_url)
+
+ if parsed_default_url.port:
+ default_port = parsed_default_url.port or default_cimom_port
+
+ default_username = os.environ.get("LMI_CIMOM_USERNAME", "root")
+ default_password = os.environ.get("LMI_CIMOM_PASSWORD", "")
+
+ # Set-up arg parser
+ parser = optparse.OptionParser(usage=usage)
+
+ parser.add_option('-c', '--url', dest='url', default=default_url,
+ help='CIMOM URL or hostname to connect to')
+
+ parser.add_option('-u', '--username', dest='username', default=default_username,
+ help='Username for CIMOM authentication')
+
+ parser.add_option('-p', '--password', dest='password', default=default_password,
+ help='Password for CIMOM authentication')
+
+ parser.add_option('-v', '--verbose', dest='verbose', default=0,
+ action='count',
+ help='Turn on verbose output, increases verbosity level by one each time specified')
+
+ options, args = parser.parse_args()
+
+ # Validate arguments
+
+ try:
+ action = args.pop(0)
+ except IndexError:
+ print >>sys.stderr, "You must supply an action to execute"
+ parser.print_help()
+ return 1
+
+ try:
+ action_func = actions[action]
+ except KeyError:
+ print >>sys.stderr, "Unknown action (%s)" % (action)
+ parser.print_help()
+ return 1
+
+ # Get CIMOM URL
+
+ parsed_url = urlparse.urlparse(options.url)
+
+ if not parsed_url.netloc:
+ # Handle case where URL was bare hostname
+ parsed_url = urlparse.urlparse('//' + options.url)
+
+ scheme = 'https'
+ hostname = parsed_url.hostname
+ port = parsed_url.port or default_port
+
+ url = urlparse.urlunparse((scheme, "%s:%d" % (hostname, port), '', None, None, None))
+
+ # Connect to CIMOM
+
+ if (options.verbose):
+ print "Connecting to: %s" % url
+
+ try:
+ conn = pywbem.WBEMConnection(url, (options.username, options.password))
+ except Exception, e:
+ print >>sys.stderr, "Unable to connect to %s (%s)" % (options.url, e)
+ return 1
+
+
+ # Execute action
+
+ try:
+ action_func(conn, options, args)
+ except Exception, e:
+ print >>sys.stderr, "%s failed: %s" % (action, e)
+ return 1
+
+ return 0
+
+#----------------------------------------------------------------------
+
+if __name__ == "__main__":
+ sys.exit(main())