You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by rg...@apache.org on 2011/09/30 13:47:23 UTC

svn commit: r1177661 [1/2] - in /incubator/tashi/trunk: ./ etc/ src/ src/tashi/agents/ src/tashi/client/ src/tashi/clustermanager/ src/tashi/nodemanager/ src/zoni/ src/zoni/agents/ src/zoni/bootstrap/ src/zoni/client/ src/zoni/data/ src/zoni/extra/ src...

Author: rgass
Date: Fri Sep 30 13:47:21 2011
New Revision: 1177661

URL: http://svn.apache.org/viewvc?rev=1177661&view=rev
Log:
moving zoni-dev back into trunk

Added:
    incubator/tashi/trunk/src/tashi/agents/primitive_zoni.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/tashi/agents/primitive_zoni.py
    incubator/tashi/trunk/src/tashi/client/tashi-client-hack.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/tashi/client/tashi-client-hack.py
    incubator/tashi/trunk/src/zoni/hardware/hpilo.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/hpilo.py
    incubator/tashi/trunk/src/zoni/hardware/systemmanagement.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/systemmanagement.py
    incubator/tashi/trunk/src/zoni/install/dnsdhcp/
      - copied from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/dnsdhcp/
    incubator/tashi/trunk/src/zoni/install/dnsdhcp/zoniDnsDhcpSetup.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/dnsdhcp/zoniDnsDhcpSetup.py
    incubator/tashi/trunk/src/zoni/services/
      - copied from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/services/
    incubator/tashi/trunk/src/zoni/services/__init__.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/services/__init__.py
    incubator/tashi/trunk/src/zoni/services/pcvciservice.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/services/pcvciservice.py
    incubator/tashi/trunk/src/zoni/services/rpycservices.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/services/rpycservices.py
    incubator/tashi/trunk/src/zoni/services/zonimanager.py
      - copied unchanged from r1177646, incubator/tashi/branches/zoni-dev/trunk/src/zoni/services/zonimanager.py
Modified:
    incubator/tashi/trunk/   (props changed)
    incubator/tashi/trunk/Makefile   (contents, props changed)
    incubator/tashi/trunk/etc/   (props changed)
    incubator/tashi/trunk/etc/TashiDefaults.cfg
    incubator/tashi/trunk/etc/ZoniDefaults.cfg   (contents, props changed)
    incubator/tashi/trunk/src/   (props changed)
    incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
    incubator/tashi/trunk/src/tashi/agents/locality-server.py
    incubator/tashi/trunk/src/tashi/clustermanager/clustermanager.py
    incubator/tashi/trunk/src/tashi/nodemanager/nodemanager.py
    incubator/tashi/trunk/src/zoni/Makefile   (props changed)
    incubator/tashi/trunk/src/zoni/__init__.py   (props changed)
    incubator/tashi/trunk/src/zoni/agents/dhcpdns.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/bootstrap/bootstrapinterface.py   (props changed)
    incubator/tashi/trunk/src/zoni/bootstrap/pxe.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/client/zoni-cli.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/data/resourcequerysql.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/data/usermanagement.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/data/usermanagementinterface.py   (props changed)
    incubator/tashi/trunk/src/zoni/extra/util.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/delldrac.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/dellswitch.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/hpswitch.py   (props changed)
    incubator/tashi/trunk/src/zoni/hardware/hwswitchinterface.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/ipmi.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/raritanpdu.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/hardware/systemmanagementinterface.py   (contents, props changed)
    incubator/tashi/trunk/src/zoni/install/db/zoniDbSetup.py
    incubator/tashi/trunk/src/zoni/install/pxe/base-menu
    incubator/tashi/trunk/src/zoni/install/pxe/zoniPxeSetup.py
    incubator/tashi/trunk/src/zoni/install/www/zoniWebSetup.py
    incubator/tashi/trunk/src/zoni/system/registration/register/register_automate
    incubator/tashi/trunk/src/zoni/system/registration/register/register_node
    incubator/tashi/trunk/src/zoni/system/registration/www/zoni-register.php
    incubator/tashi/trunk/src/zoni/version.py   (props changed)

Propchange: incubator/tashi/trunk/
------------------------------------------------------------------------------
    svn:mergeinfo = /incubator/tashi/branches/zoni-dev/trunk:1034098-1177646

Modified: incubator/tashi/trunk/Makefile
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/Makefile?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/Makefile (original)
+++ incubator/tashi/trunk/Makefile Fri Sep 30 13:47:21 2011
@@ -110,8 +110,12 @@ rmdoc:
 bin/zoni-cli.py:
 	@echo Symlinking in zoni-cli...
 	(cd bin; ln -s ../src/zoni/client/zoni-cli.py .)
+usr/local/bin/zoni:
+	@echo Creating /usr/local/bin/zoni
+	(echo '#!/bin/bash\nPYTHONPATH=$(shell pwd)/src $(shell pwd)/bin/zoni-cli.py $$*' > /usr/local/bin/zoni; chmod 755 /usr/local/bin/zoni)
 rmzoni-cli:
 	if test -e bin/zoni-cli.py; then echo Removing zoni-cli symlink...; rm bin/zoni-cli.py; fi
+	if test -e /usr/local/bin/zoni; then echo Removing zoni...; rm /usr/local/bin/zoni; fi
 
 ## for now only print warnings having to do with bad indentation. pylint doesn't make it easy to enable only 1,2 checks
 disabled_warnings=$(shell pylint --list-msgs|grep :W0| awk -F: '{ORS=","; if ($$2 != "W0311" && $$2 != "W0312"){ print $$2}}')

Propchange: incubator/tashi/trunk/Makefile
            ('svn:mergeinfo' removed)

Propchange: incubator/tashi/trunk/etc/
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/etc/TashiDefaults.cfg
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/etc/TashiDefaults.cfg?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/etc/TashiDefaults.cfg (original)
+++ incubator/tashi/trunk/etc/TashiDefaults.cfg Fri Sep 30 13:47:21 2011
@@ -45,7 +45,8 @@ publisher = tashi.messaging.GangliaPubli
 nodeManagerPort = 9883
 
 [ClusterManagerService]
-host = localhost ; Clustermanager hostname
+# Clustermanager hostname
+host = localhost 
 convertExceptions = True
 port = 9882
 expireHostTime = 30.0
@@ -100,7 +101,8 @@ port = 9883
 registerHost = False
 registerFrequency = 10.0
 infoFile = /var/tmp/nm.dat
-clusterManagerHost = localhost ;  Clustermanger hostname
+# Clustermanger hostname
+clusterManagerHost = localhost 
 clusterManagerPort = 9882
 statsInterval = 0.0
 ;bind = 0.0.0.0 ; not supported (Thrift is missing support to specify what to bind to!)
@@ -135,7 +137,8 @@ staticLayout = /location/of/layout/file
 
 # Client configuration
 [Client]
-clusterManagerHost = localhost ; Clustermanager hostname
+# Clustermanager hostname
+clusterManagerHost = localhost 
 clusterManagerPort = 9882
 clusterManagerTimeout = 5.0
 
@@ -157,17 +160,21 @@ defaultJobTime = 8640000000
 
 [DhcpDns]
 dnsEnabled = True
-dnsKeyFile = /location/of/private/key/for/dns
+dnsSecretKey = ABcdEf12GhIJKLmnOpQrsT==
+dnsKeyName = name_of_dns_key_hostname
 dnsServer = 1.2.3.4 53
 dnsDomain = tashi.example.com
 dnsExpire = 300
 dhcpEnabled = True
 dhcpServer = 1.2.3.4
+# Host key name
 dhcpKeyName = OMAPI
 dhcpSecretKey = ABcdEf12GhIJKLmnOpQrsT==
+#  ipRangeX - where X is the vlan number 
 ipRange1 = 172.16.128.2-172.16.255.254
 reverseDns = True
-clustermanagerhost = localhost ; Clustermanager hostname
+# Clustermanager hostname
+clustermanagerhost = localhost
 clustermanagerport = 9886
 
 [GangliaPublisher]

Modified: incubator/tashi/trunk/etc/ZoniDefaults.cfg
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/etc/ZoniDefaults.cfg?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/etc/ZoniDefaults.cfg (original)
+++ incubator/tashi/trunk/etc/ZoniDefaults.cfg Fri Sep 30 13:47:21 2011
@@ -26,6 +26,11 @@ INSTALL_BASE_DIR = /usr/local/tashi
 [logging]
 LOG_FILE = /var/tmp/zoni_logfile.txt
 
+[management]
+#  Specify data store
+INFO_STORE = sql
+USER_MANAGEMENT = ldap
+
 #  DB host
 [dbConnection]
 DB_HOST = xx_hostname_or_ip_
@@ -50,8 +55,9 @@ TFTP_UPDATE_FILE = /var/lib/tftpboot/pxe
 TFTP_BASE_FILE = /var/lib/tftpboot/pxelinux.cfg/base.zoni
 TFTP_BASE_MENU_FILE = /var/lib/tftpboot/pxelinux.cfg/base-menu
 PXE_SERVER_IP = IP_OF_PXE_SERVER_IN_DOMAIN_0
-#  Relative to TFTP_ROOT_DIR
-INITRD_ROOT = initrd
+#  Must be relative to TFTP_ROOT_DIR
+INITRD_ROOT = builds/initrd
+KERNEL_ROOT = builds/kernel
 
 [www]
 WWW_DOCUMENT_ROOT = /var/www
@@ -71,7 +77,8 @@ ZONI_IPMI_NETWORK = 10.10.16.0/20
 VLAN_MAX = 4095
 
 [hardware]
-HARDWARE_CONTROL = ["ipmi", "drac", "pdu"]
+#  Hardware control available for the cluster 
+HARDWARE_CONTROL = {"ipmi": {"class":"zoni.hardware.ipmi.Ipmi"}, "drac": {"class":"zoni.hardware.delldrac.dellDrac"}, "pdu":{"class": "zoni.hardware.raritanpdu.raritanDominionPx"}, "dellswitch" : {"class", "zoni.hardware.dellswitch.HwDellSwitch", "accessmode" : "ssh"}}
 HARDWARE_PDU = "raritan"
 HARDWARE_DRAC = "DELL DRAC"
 
@@ -79,7 +86,9 @@ HARDWARE_DRAC = "DELL DRAC"
 dnsEnabled = True
 reverseDns = True
 #  Key file must be in the same directory or this will get denied
-dnsKeyFile = xx_Kname.+157+36480.private_xx
+#dnsKeyFile = xx_Kname.+157+36480.private_xx
+dnsKeyName = xx_dnsKeyName__xx
+dnsSecretKey = xx_secretkey_xx
 dnsServer = xx_dns_server_ip_xx xx_port_xx
 dnsDomain = xx_fqdn_xx
 dnsExpire = 60

Propchange: incubator/tashi/trunk/etc/ZoniDefaults.cfg
            ('svn:mergeinfo' removed)

Propchange: incubator/tashi/trunk/src/
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/dhcpdns.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/dhcpdns.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/dhcpdns.py Fri Sep 30 13:47:21 2011
@@ -28,7 +28,8 @@ from tashi import boolean
 class DhcpDns(InstanceHook):
 	def __init__(self, config, client, post=False):
 		InstanceHook.__init__(self, config, client, post)
-		self.dnsKeyFile = self.config.get('DhcpDns', 'dnsKeyFile')
+		self.dnsKeyName = self.config.get('DhcpDns', 'dnsKeyName')
+		self.dnsSecretKey = self.config.get('DhcpDns', 'dnsSecretKey')
 		self.dnsServer = self.config.get('DhcpDns', 'dnsServer')
 		self.dnsDomain = self.config.get('DhcpDns', 'dnsDomain')
 		self.dnsExpire = int(self.config.get('DhcpDns', 'dnsExpire'))
@@ -153,14 +154,12 @@ class DhcpDns(InstanceHook):
 			self.removeDns(name)
 		except:
 			pass
-		if (self.dnsKeyFile != ""):
-			cmd = "nsupdate -k %s" % (self.dnsKeyFile)
-		else:
-			cmd = "nsupdate"
+		cmd = "nsupdate"
 		child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 		try:
 			(stdin, stdout) = (child.stdin, child.stdout)
 			stdin.write("server %s\n" % (self.dnsServer))
+			stdin.write("key %s %s\n" % (self.dnsKeyName, self.dnsSecretKey))
 			stdin.write("update add %s.%s %d A %s\n" % (name, self.dnsDomain, self.dnsExpire, ip))
 			stdin.write("\n")
 			if (self.reverseDns):
@@ -181,14 +180,12 @@ class DhcpDns(InstanceHook):
 				(pid, status) = os.waitpid(child.pid, os.WNOHANG)
 	
 	def removeDns(self, name):
-		if (self.dnsKeyFile != ""):
-			cmd = "nsupdate -k %s" % (self.dnsKeyFile)
-		else:
-			cmd = "nsupdate"
+		cmd = "nsupdate"
 		child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 		try:
 			(stdin, stdout) = (child.stdin, child.stdout)
 			stdin.write("server %s\n" % (self.dnsServer))
+			stdin.write("key %s %s\n" % (self.dnsKeyName, self.dnsSecretKey))
 			if (self.reverseDns):
 				ip = socket.gethostbyname(name)
 				ipSegments = map(int, ip.split("."))

Modified: incubator/tashi/trunk/src/tashi/agents/locality-server.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/locality-server.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/locality-server.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/locality-server.py Fri Sep 30 13:47:21 2011
@@ -1,5 +1,4 @@
 #!/usr/bin/python
-
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information

Modified: incubator/tashi/trunk/src/tashi/clustermanager/clustermanager.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/clustermanager.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/clustermanager.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/clustermanager.py Fri Sep 30 13:47:21 2011
@@ -30,7 +30,7 @@ import tashi
 
 from tashi.rpycservices import rpycservices
 from rpyc.utils.server import ThreadedServer
-from rpyc.utils.authenticators import VdbAuthenticator
+from rpyc.utils.authenticators import TlsliteVdbAuthenticator
 
 def startClusterManager(config):
 	global service, data
@@ -47,7 +47,7 @@ def startClusterManager(config):
 				users[user.name] = user.passwd
 		users[config.get('AllowedUsers', 'nodeManagerUser')] = config.get('AllowedUsers', 'nodeManagerPassword')
 		users[config.get('AllowedUsers', 'agentUser')] = config.get('AllowedUsers', 'agentPassword')
-		authenticator = VdbAuthenticator.from_dict(users)
+		authenticator = TlsliteVdbAuthenticator.from_dict(users)
 		t = ThreadedServer(service=rpycservices.ManagerService, hostname='0.0.0.0', port=int(config.get('ClusterManagerService', 'port')), auto_register=False, authenticator=authenticator)
 	else:
 		t = ThreadedServer(service=rpycservices.ManagerService, hostname='0.0.0.0', port=int(config.get('ClusterManagerService', 'port')), auto_register=False)

Modified: incubator/tashi/trunk/src/tashi/nodemanager/nodemanager.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/nodemanager.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/nodemanager/nodemanager.py (original)
+++ incubator/tashi/trunk/src/tashi/nodemanager/nodemanager.py Fri Sep 30 13:47:21 2011
@@ -28,7 +28,7 @@ from tashi import boolean
 
 from tashi.rpycservices import rpycservices
 from rpyc.utils.server import ThreadedServer
-from rpyc.utils.authenticators import VdbAuthenticator
+from rpyc.utils.authenticators import TlsliteVdbAuthenticator
 
 @signalHandler(signal.SIGTERM)
 def handleSIGTERM(signalNumber, stackFrame):
@@ -51,7 +51,7 @@ def main():
 	if boolean(config.get("Security", "authAndEncrypt")):
 		users = {}
 		users[config.get('AllowedUsers', 'clusterManagerUser')] = config.get('AllowedUsers', 'clusterManagerPassword')
-		authenticator = VdbAuthenticator.from_dict(users)
+		authenticator = TlsliteVdbAuthenticator.from_dict(users)
 		t = ThreadedServer(service=rpycservices.ManagerService, hostname='0.0.0.0', port=int(config.get('NodeManagerService', 'port')), auto_register=False, authenticator=authenticator)
 	else:
 		t = ThreadedServer(service=rpycservices.ManagerService, hostname='0.0.0.0', port=int(config.get('NodeManagerService', 'port')), auto_register=False)

Propchange: incubator/tashi/trunk/src/zoni/Makefile
            ('svn:mergeinfo' removed)

Propchange: incubator/tashi/trunk/src/zoni/__init__.py
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/zoni/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/agents/dhcpdns.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/zoni/agents/dhcpdns.py (original)
+++ incubator/tashi/trunk/src/zoni/agents/dhcpdns.py Fri Sep 30 13:47:21 2011
@@ -155,7 +155,8 @@ class DhcpDns():
 			stdin.write("update delete %s.%s A\n" % (name, self.dnsDomain))
 			stdin.write("\n")
 			if (self.reverseDns):
-				ip = socket.gethostbyname(name)
+				hostInfo = socket.gethostbyaddr(name)
+				ip = hostInfo[2][0]
 				ipSegments = map(int, ip.split("."))
 				ipSegments.reverse()
 				reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2], ipSegments[3]))
@@ -175,15 +176,20 @@ class DhcpDns():
 				(pid, status) = os.waitpid(child.pid, os.WNOHANG)
 
 	def addCname(self, name, origName):
+		
 		cmd = "nsupdate"
 		child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 		try:
 			#  Check for existance of hostname
-			ip = socket.gethostbyname(origName)
+			#ip = socket.gethostbyname(origName)
+			#  add this to make sure we always input the textual name instead of the ip address by mistake
+			hostInfo = socket.gethostbyaddr(origName)
+			hostName = hostInfo[0].split(".")[0]
+
 			(stdin, stdout) = (child.stdin, child.stdout)
 			stdin.write("server %s\n" % (self.dnsServer))
 			stdin.write("key %s %s\n" % (self.dnsKeyName, self.dnsSecretKey))
-			stdin.write("update add %s.%s %d CNAME %s.%s\n" % (name, self.dnsDomain, self.dnsExpire, origName, self.dnsDomain))
+			stdin.write("update add %s.%s %d CNAME %s.%s\n" % (name, self.dnsDomain, self.dnsExpire, hostName, self.dnsDomain))
 			stdin.write("\n")
 			stdin.close()
 			output = stdout.read()

Propchange: incubator/tashi/trunk/src/zoni/agents/dhcpdns.py
            ('svn:mergeinfo' removed)

Propchange: incubator/tashi/trunk/src/zoni/bootstrap/bootstrapinterface.py
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/zoni/bootstrap/pxe.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/bootstrap/pxe.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/zoni/bootstrap/pxe.py (original)
+++ incubator/tashi/trunk/src/zoni/bootstrap/pxe.py Fri Sep 30 13:47:21 2011
@@ -25,12 +25,13 @@ import datetime
 import subprocess
 import MySQLdb
 import traceback
+import logging
 
-from zoni.extra.util import logit
+from zoni.extra.util import normalizeMac
 from zoni.bootstrap.bootstrapinterface import BootStrapInterface
 
 class Pxe(BootStrapInterface):
-	def __init__(self, config, verbose=None):
+	def __init__(self, config, data, verbose=None):
 		self.verbose  = verbose
 		self.host = config['dbHost']
 		self.user = config['dbUser']
@@ -43,19 +44,26 @@ class Pxe(BootStrapInterface):
 		self.tftpUpdateFile = config['tftpUpdateFile']
 		self.tftpBaseFile = config['tftpBaseFile']
 		self.tftpBaseMenuFile = config['tftpBaseMenuFile']
+		self.initrdRoot = config['initrdRoot']
+		self.kernelRoot = config['kernelRoot']
+
+		self.log = logging.getLogger(os.path.basename(__file__))
 
-		self.logFile = config['logFile']
 
 		if config['dbPort'] == "":
 			config['dbPort'] = 3306
 
 		self.port = config['dbPort']
 
-		self.vlan_max = config['vlan_max']
-		self.vlan_reserved = config['vlan_reserved']
+		self.vlan_max = config['vlanMax']
+		
+		self.data = data
+		#self.vlan_reserved = config['vlanReserved']
 		
+		#data = instantiateImplementation("zoni.data.resourcequerysql.ResourceQuerySql", configs, options.verbosity)
 		#  Connect to DB
-		self.conn = MySQLdb.connect(host = self.host, port = self.port, user = self.user, passwd = self.passwd, db = self.db)
+		#self.conn = MySQLdb.connect(host = self.ho st, port = self.port, user = self.user, passwd = self.passwd, db = self.db)
+
 		#cursor.execute ("SELECT VERSION()")
 		#print "server version:", row[0]
 		#mysql -Dirp-cluster -hrodimus -u reader -e "select * from hostinfo;"
@@ -97,4 +105,73 @@ class Pxe(BootStrapInterface):
 			os.system(cmd)
 		except Exception:
 			traceback.print_exc(sys.exc_info())
+
+	def generateBootOptions(self, image):
+		name = self.tftpBootOptionsDir + "/" + image
+		tftpdir = os.path.basename(self.tftpImageDir)
+		bootdir = os.path.basename(self.tftpBootOptionsDir)
+		imagedir = os.path.join(tftpdir, bootdir, image)
+
+		#  Write out boot image file
+		val = "DISPLAY boot-screens/boot.txt\n"
+		val += "DEFAULT vesamenu.c32\n"
+		val += "MENU BACKGROUND boot-screens/zoni_pxe.jpg\n"
+		val += "PROMPT 0\n"
+		
+		val += "MENU COLOR border 49;37 #00FFFFFF #00FFFFFF none\n"
+		val += "MENU INCLUDE %s-menu\n" % imagedir
+		f = open(name, "w")
+		f.write(val)
+		f.close()
+
+		
+		#  Write out the menu file
+		#  Eventually iterate over all images this machine should be able to select from
+		name = self.tftpBootOptionsDir + "/" + image + "-menu"
+		kOpt= self.data.getKernelOptions(image)
+		kernelPath = os.path.join(self.kernelRoot, kOpt['kernel_arch'], kOpt['kernel_name'])
+		initrdPath = os.path.join(self.initrdRoot, kOpt['kernel_arch'], kOpt['initrd_name'])
+		val = "DISPLAY boot-screens/boot.txt\n\n"
+		val += "LABEL %s\n" % kOpt['image_name']
+		val += "	MENU DEFAULT\n"
+		val += "	kernel %s\n" % kernelPath
+		val += "	append initrd=%s %s\n" % (initrdPath, kOpt['initrd_options'])
+
+		f = open(name, "w")
+		f.write(val)
+		f.close()
+
+		
+
+	def setBootImage(self, mac, image):
+		mac_addr = "01-" + string.replace(normalizeMac(mac), ":", "-")
+		maclink = self.tftpImageDir + "/" + mac_addr
+		self.generateBootOptions(image)
+		#  Check if it exists first
+		if os.path.exists(maclink):
+			try:
+				os.unlink(maclink)
+			except Exception, e:
+				traceback.print_exc(sys.exc_info())
+				if OSError:
+					print OSError, e
+					mesg = "ERROR : %s\n" % e
+					self.log.error(mesg)
+					return 1
+				return 1
+		#  Create the boot option file
+		#  Relink
+		newlink = os.path.basename(self.tftpBootOptionsDir) + "/" + image
+		try:
+			os.symlink(newlink, maclink)
+			mesg = "Image assignment Successful %s -> %s " % (mac, image)
+			self.log.info(mesg)
+		except Exception, e:
+			if OSError:
+				#mesg = "Cannot modify file.  Please use sudo\n"
+				mesg = "ERROR : %s\n" % e
+				self.log.info(mesg)
+				return 1
+			return 1
+
 		

Propchange: incubator/tashi/trunk/src/zoni/bootstrap/pxe.py
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/zoni/client/zoni-cli.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/client/zoni-cli.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/zoni/client/zoni-cli.py (original)
+++ incubator/tashi/trunk/src/zoni/client/zoni-cli.py Fri Sep 30 13:47:21 2011
@@ -1,4 +1,5 @@
 #! /usr/bin/env python 
+
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
@@ -19,7 +20,6 @@
 #
 #  $Id$
 #
-
 import os
 import sys
 import optparse
@@ -49,10 +49,13 @@ from zoni.hardware.raritanpdu import rar
 from zoni.hardware.delldrac import dellDrac
 from zoni.agents.dhcpdns import DhcpDns
 
+from zoni.hardware.systemmanagement import SystemManagement
+
 
 from zoni.extra.util import * 
 from zoni.version import *
 
+from tashi.util import instantiateImplementation, signalHandler
 #import zoni.data.usermanagement 
 #from usermanagement import UserManagement
 
@@ -91,6 +94,7 @@ def main():
 	group.add_option("--reboot", "--reboot", dest="REBOOTNODE", help="Reboot node (Soft)", action="store_true", default=False)
 	group.add_option("--powerCycle", "--powercycle", dest="POWERCYCLE", help="Power Cycle (Hard)", action="store_true", default=False)
 	group.add_option("--powerOff", "--poweroff", dest="POWEROFF", help="Power off node", action="store_true", default=False)
+	group.add_option("--powerOffSoft", "--poweroffsoft", dest="POWEROFFSOFT", help="Power off node (soft)", action="store_true", default=False)
 	group.add_option("--powerOn", "--poweron", dest="POWERON", help="Power on node", action="store_true", default=False)
 	group.add_option("--powerReset", "--powerreset", dest="POWERRESET", help="Power reset node", action="store_true", default=False)
 	group.add_option("--console", dest="CONSOLE", help="Console mode", action="store_true", default=False)
@@ -101,6 +105,7 @@ def main():
 	group.add_option("-R", "--showReservation", "--showreservation", dest="showReservation", help="Show current node reservations", action="store_true", default=False)
 	group.add_option("-A", "--showAllocation", "--showallocation", dest="showAllocation", help="Show current node allocation", action="store_true", default=False)
 	group.add_option("-S", "--showResources", dest="showResources", help="Show available resources to choose from", action="store_true", default=False)
+	group.add_option("--getResources", "--getresources", dest="getResources", help="Get available resources to choose from", action="store_true", default=False)
 	group.add_option("-p", "--procs", dest="numProcs", help="Set number of processors" )
 	group.add_option("-c", "--clock", dest="clockSpeed", help="Processor clock" )
 	group.add_option("--memory", dest="numMemory", help="Amount of memory (Bytes)" )
@@ -114,11 +119,12 @@ def main():
 	#  Admin Interface
 	group = optparse.OptionGroup(parser, "Admin Interface", "Administration Interface:")
 	group.add_option("--admin", dest="ADMIN", help="Enter Admin mode", action="store_true", default=False)
+	group.add_option("--setPortMode", "--setportmode", dest="setPortMode", help="Set port mode to access, trunk, or general")
 	group.add_option("--enableHostPort", "--enablehostport", dest="enableHostPort", help="Enable a switch port", action="store_true", default=False)
 	group.add_option("--disableHostPort", "--disablehostport", dest="disableHostPort", help="Disable a switch port", action="store_true", default=False)
-	group.add_option("--destroyVlan", "--destroyvlan", dest="removeVlanId", help="Remove vlan from all switches")
+	group.add_option("--destroyVlan", "--destroyvlan", dest="destroyVlanId", help="Remove vlan from all switches")
 	group.add_option("--createVlan", "--createvlan", dest="createVlanId", help="Create a vlan on all switches")
-	group.add_option("--addNodeToVlan", "--addnodetovlan", dest="add2Vlan", help="Add node to a vlan")
+	group.add_option("--addNodeToVlan", "--addnodetovlan", dest="add2Vlan", help="Add node to a vlan (:tagged)")
 	group.add_option("--removeNodeFromVlan", "--removenodefromvlan", dest="removeFromVlan", help="Remove node from a vlan")
 	group.add_option("--setNativeVlan", "--setnativevlan", dest="setNative", help="Configure native vlan")
 	group.add_option("--restoreNativeVlan", "--restorenativevlan", dest="restoreNative", help="Restore native vlan", action="store_true", default=False)
@@ -127,6 +133,8 @@ def main():
 	group.add_option("--interactiveSwitchConfig", "--interactiveswitchconfig", dest="interactiveSwitchConfig", help="Interactively configure a switch.  switchhname")
 	group.add_option("--showSwitchConfig", "--showswitchconfig", dest="showSwitchConfig", help="Show switch config for node", action="store_true", default=False)
 	group.add_option("--register", dest="register", help="Register hardware to Zoni", action="store_true", default=False)
+	group.add_option("--labelPort", dest="labelPort", help="Label switch port", action="store_true", default=False)
+	group.add_option("--saveConfig", dest="saveConfig", help="SWITCHNAME - Save Switch Config")
 	parser.add_option_group(group)
 
 
@@ -144,16 +152,18 @@ def main():
 	group.add_option("--addDomain", "--adddomain", dest="addDomain", help="Add new domain to Zoni", action="store_true", default=False)
 	group.add_option("--removeDomain", "--removedomain", dest="removeDomain", help="remove a domain from Zoni", action="store_true", default=False)
 	group.add_option("-V", "--showVlans", "--showvlans", dest="showVlans", help="Show an from Zoni", action="store_true", default=False)
-	group.add_option("--addVlan", "--addvlan", dest="addVlan", help="Add new vlan to Zoni", action="store_true", default=False)
-	group.add_option("--removeVlan", "--removevlan", dest="removeVlan", help="Remove an from Zoni", action="store_true", default=False)
+	#group.add_option("--addVlan", "--addvlan", dest="addVlan", help="Add new vlan to Zoni", action="store_true", default=False)
+	#group.add_option("--removeVlan", "--removevlan", dest="removeVlan", help="Remove an from Zoni", action="store_true", default=False)
 	group.add_option("--assignVlan", "--assignvlan", dest="assignVlan", help="Assign vlan to a domain")
 	parser.add_option_group(group)
 
 	#  Allocation Interface
 	group = optparse.OptionGroup(parser, "Allocation Interface", "Change current systems allocations:")
+	#group.add_option("--addReservation", "--addreservation", dest="addReservation", help="Add a Reservation", action="store_true", default=False)
 	group.add_option("--addImage", "--addimage", dest="addImage", help="Add image to Zoni - amd64-image:dist:dist_ver")
 	group.add_option("--delImage", "--delimage", dest="delImage", help="Delete PXE image")
 	#group.add_option("--addPxeImage", "--addpxeimage", dest="imageName", help="Add PXE image to database", action="store_true", default=False)
+	group.add_option("--assignImage", "--assignimage", dest="assignImage", help="Assign image to resource")
 	group.add_option("--imageName", "--imagename", dest="imageName", help="Assign image to resource")
 
 	group.add_option("--allocateNode", "--allocatenode", dest="allocateNode", help="Assign node to a user", action="store_true", default=False)
@@ -165,12 +175,15 @@ def main():
 	group.add_option("--releaseNode", "--releasenode", dest="releaseNode", help="Release current node allocation", action="store_true", default=False)
 	group.add_option("--reservationDuration", "--reservationduration", dest="reservationDuration", help="Specify duration of node reservation - YYYYMMDD format")
 	group.add_option("-r", "--reservationId", "--reservationid", dest="reservationId", help="Reservation ID")
-	group.add_option("--addReservation", "--addreservation", dest="addReservation", help="Add a Reservation", action="store_true", default=False)
 	group.add_option("--updateReservation", "--updatereservation", dest="updateReservation", help="Update Reservation", action="store_true", default=False)
 	group.add_option("--delReservation", "--delreservation", dest="delReservation", help="Delete Reservation")
 	group.add_option("--rgasstest", dest="rgasstest", help="Debug testing function", action="store_true", default=False)
 	parser.add_option_group(group)
 
+	group = optparse.OptionGroup(parser, "Reservation Interface", "Change current systems reservations:")
+	group.add_option("--createReservation", "--createreservation", dest="createReservation", help="Create a new Reservation", action="store_true", default=False)
+	parser.add_option_group(group)
+
 	#  Zoni Helpers
 	group = optparse.OptionGroup(parser, "Zoni Helpers", "Helper functions:")
 	group.add_option("--addDns", dest="addDns", help="Add a DNS entry", action="store_true", default=False)
@@ -187,42 +200,42 @@ def main():
 	cmdargs = {}
 
 	#  setup db connection
-	query = zoni.data.resourcequerysql.ResourceQuerySql(configs, options.verbosity)
+	#print "starting tread"
+	#threading.Thread(daemon=True, target=self.dbKeepAlive()).start()
+	#print "after tread"
+
+	data = instantiateImplementation("zoni.data.resourcequerysql.ResourceQuerySql", configs, options.verbosity)
+	reservation = instantiateImplementation("zoni.data.reservation.reservationMysql", configs, data, options.verbosity)
+	#query = zoni.data.resourcequerysql.ResourceQuerySql(configs, options.verbosity)
 
 	#  Get host info
 	host=None
 	if options.nodeName:
-		host = query.getHostInfo(options.nodeName)
+		host = data.getHostInfo(options.nodeName)
 		#print host
 	
 
 	#  Hardware control
-	if options.hardwareType:
-
-		if (options.hardwareType) and options.hardwareType not in configs['hardware_control']:
-			mesg = "Non support hardware type specified\n"
-			mesg += "Supported types:\n"
-			mesg += str(configs['hardware_control'])
-			mesg += "\n\n"
-			sys.stdout.write(mesg)
-			exit()
-
-		if (options.hardwareType) and options.nodeName:
-			#host = query.getHostInfo(options.nodeName)
-			if options.hardwareType == "ipmi":
-				hw = Ipmi(options.nodeName, host["ipmi_user"], host["ipmi_password"])
-
-			if options.hardwareType == "pdu":
-				hw = raritanDominionPx(configs, host)
-
-			if options.hardwareType == "drac":
-				#  Check if node has drac card
-				if "drac_name" in host:
-					hw = dellDrac(host)
-				else:
-					mesg = "Host (" + options.nodeName + ") does not have a DRAC card!!\n"
-					sys.stdout.write(mesg)
-					exit(1)
+	if options.hardwareType and options.nodeName:
+		host = data.getHostInfo(options.nodeName)
+		if options.hardwareType == "ipmi":
+		#hardware = zoni.hardware.systemmanagement.SystemManagement(configs,data)
+			hw = Ipmi(configs, options.nodeName, host)
+#
+		if options.hardwareType == "pdu":
+			hw = raritanDominionPx(configs, options.nodeName, host)
+#
+		if options.hardwareType == "drac":
+			##  Check if node has drac card
+			if "drac_name" in host:
+				hw= dellDrac(configs, options.nodeName, host)
+			else:
+				mesg = "Host (" + options.nodeName + ") does not have a DRAC card!!\n"
+				sys.stdout.write(mesg)
+				exit(1)
+		if (options.REBOOTNODE or options.POWERCYCLE  or options.POWEROFF or options.POWEROFFSOFT or \
+			options.POWERON or options.POWERSTATUS or options.CONSOLE or \
+			options.POWERRESET) and options.nodeName:
 
 			if options.verbosity:
 				hw.setVerbose(True)
@@ -236,6 +249,9 @@ def main():
 			if options.POWEROFF:
 				hw.powerOff()
 				exit()
+			if options.POWEROFFSOFT:
+				hw.powerOffSoft()
+				exit()
 			if options.POWERON:
 				hw.powerOn()
 				exit()
@@ -249,20 +265,51 @@ def main():
 				hw.activateConsole()
 				exit()
 			hw.getPowerStatus()
+			exit()
+	else:
+		hw = zoni.hardware.systemmanagement.SystemManagement(configs,data)
 
+	if (options.REBOOTNODE or options.POWERCYCLE  or options.POWEROFF or options.POWEROFFSOFT or \
+		options.POWERON or options.POWERSTATUS or options.CONSOLE or \
+		options.POWERRESET) and options.nodeName:
 
-		if (options.hardwareType) and not options.nodeName:
-			mesg = "\nMISSSING OPTION:  Node name required -n or --nodeName\n"
-			parser.print_help();
-			sys.stderr.write(mesg)
+		if options.verbosity:
+			hw.setVerbose(True)
+
+		if options.REBOOTNODE:
+			hw.powerReset(options.nodeName)
+			exit()
+		if options.POWERCYCLE: 
+			hw.powerCycle(options.nodeName)
+			exit()
+		if options.POWEROFFSOFT:
+			hw.powerOffSoft(options.nodeName)
+			exit()
+		if options.POWEROFF:
+			hw.powerOff(options.nodeName)
+			exit()
+		if options.POWERON:
+			hw.powerOn(options.nodeName)
+			exit()
+		if options.POWERRESET:
+			hw.powerReset(options.nodeName)
+			exit()
+		if options.POWERSTATUS:
+			hw.getPowerStatus(options.nodeName)
+			exit()
+		if options.CONSOLE:
+			hw.activateConsole(options.nodeName)
 			exit()
+		hw.getPowerStatus(options.nodeName)
+
+
 
 	if (options.REBOOTNODE or options.POWERCYCLE  or options.POWEROFF or \
 		options.POWERON or options.POWERSTATUS or options.CONSOLE or \
-		options.POWERRESET) and not options.hardwareType:
+		options.POWERRESET) and not options.nodeName:
 		parser.print_help()
-		usage = "\nMISSING OPTION: When specifying hardware parameters, you need the --hw option\n"
-		print usage
+		mesg = "\nMISSSING OPTION:  Node name required -n or --nodeName\n"
+		print mesg
 		exit()
 
 	#  Query Interface
@@ -285,6 +332,13 @@ def main():
 			parser.print_help()	
 			exit()
 
+	if options.getResources:
+		print "ALL resources"
+		print data.getAvailableResources()
+		key = "3Lf7Qy1oJZue1q/e3ZQbfg=="
+		print "Tashi Resources"
+		print data.getMyResources(key)
+
 	#  Show current allocations 
 	if (options.showAllocation) or (options.show and re.match(".lloca.*", args[0])):
 		if options.uid:
@@ -292,7 +346,7 @@ def main():
 		else: 
 			nameorid = options.userName
 
-		query.showAllocation(nameorid)
+		data.showAllocation(nameorid)
 		exit()
 
 	#  Show current reservation
@@ -302,20 +356,20 @@ def main():
 		else: 
 			nameorid = options.userName
 
-		query.showReservation(nameorid)
+		data.showReservation(nameorid)
 
 	#  Print all Resources
 	if options.showResources or (options.show and re.match(".esour.*", args[0])):
-		query.showResources(cmdargs)
+		data.showResources(cmdargs)
 
 	#  Show PXE images
 	#if (options.show and re.match(".esour.*", args[0])):
 	if options.showPxeImages or (options.show and re.match("pxei.*", args[0])):
-		query.showPxeImages()
+		data.showPxeImages()
 
 	#  Show machine to PXE image mapping
 	if options.showPxeImageMap or (options.show and re.match("pxem.*", args[0])):
-		query.showPxeImagesToSystemMap(cmdargs)
+		data.showPxeImagesToSystemMap(cmdargs)
 
 	if (len(sys.argv) == 1):
 		parser.print_help()
@@ -324,37 +378,46 @@ def main():
 
 	#  Delete reservation
 	if (options.delReservation):
-		query.removeReservation(options.delReservation)
+		data.removeReservation(options.delReservation)
 		exit()
 
 	#  Specify usermanagement, ldap or files
-	usermgt = usermanagement.ldap()
+	if configs['userManagement'] == "ldap":
+		usermgt = usermanagement.ldap()
+	elif configs['userManagement'] == "files":
+		usermgt = usermanagement.files()
+	else:
+		print "User management problem"
+		exit()
 
 
 	if (options.rgasstest):
+		#data.getHardwareCapabilities(options.nodeName)
 		#pdu = raritanDominionPx(host)
 		#print pdu
 		#bootit = pxe.Pxe(configs, options.verbosity)
-		#bootit.createPxeUpdateFile(query.getPxeImages())
+		#bootit.createPxeUpdateFile(data.getPxeImages())
 		#bootit.updatePxe()
 		#print "host is ", host
 		#drac = dellDrac("drac-r2r1c3", 1)
+		drac = dellDrac(configs, options.nodeName, host)
 		#drac.getPowerStatus()
 		#drac.powerOff()
 		#drac.powerOn()
 		#drac.powerCycle()
-		#drac.powerReset()
+		drac.setVerbose(options.verbosity)
+		drac.powerReset()
 		#drac.getPowerStatus()
-		print "host is ", host
-		pdu = raritanDominionPx(configs, host)
-		print "pdu", pdu
-		pdu.getPowerStatus()
-		exit()
+		#print "host is ", host
+		#pdu = raritanDominionPx(configs, options.nodeName, host)
+		#print "pdu", pdu
+		#pdu.getPowerStatus()
+		#exit()
 
 	#  Create a reservation for a user
-	if (options.addReservation):
+	if (options.createReservation):
 		if not (options.userName or options.uid):
-			mesg = "ERROR:  AddReservation requires the following arguments...\n"
+			mesg = "ERROR:  CreateReservation requires the following arguments...\n"
 			if not (options.userName or options.uid):
 				mesg += "  Username:  --userName=username or --uid 1000\n"
 
@@ -364,19 +427,23 @@ def main():
 			exit()
 
 		userId = options.uid
-		if not options.uid:
+		if not userId:
 			userId = usermgt.getUserId(options.userName)
 
-		reservationId = query.addReservation(userId, options.reservationDuration, options.myNotes + " " + str(string.join(args[0:len(args)])))
+		if userId:
+			reservationId = reservation.createReservation(userId, options.reservationDuration, options.myNotes + " " + str(string.join(args[0:len(args)])))
 
+		else:
+			print "user doesn't exist"
+			exit()
 
 	#  Allocate node to user
 	if (options.allocateNode):
 		if options.reservationId and options.domain and options.vlanInfo and options.nodeName and options.imageName:
-			host = query.getHostInfo(options.nodeName)
+			host = data.getHostInfo(options.nodeName)
 			#  optparse does not pass multiple args that are quoted anymore?  
 			#  Used to work with python 2.5.2.  Doesn't work with python 2.6.5.  
-			query.allocateNode(options.reservationId, options.domain, host['sys_id'], options.vlanInfo, options.imageName, options.myNotes + " " + str(string.join(args[0:len(args)])))
+			data.allocateNode(options.reservationId, options.domain, host['sys_id'], options.vlanInfo, options.imageName, options.myNotes + " " + str(string.join(args[0:len(args)])))
 		else:
 			mesg = "USAGE: %s --allocateNode --nodeName nodeName --domain domainname --reservationId ID --vlanInfo vlanNums:info, --imageName imagename [--notes]\n" % (sys.argv[0])
 			mesg += "Options\n"
@@ -405,7 +472,7 @@ def main():
 			exit()
 
 		print host['sys_id']
-		query.allocateNode(options.reservationId, host['sys_id'], options.hostName,  vlanNum, options.ipAddr, options.Notes)
+		data.allocateNode(options.reservationId, host['sys_id'], options.hostName,  vlanNum, options.ipAddr, options.Notes)
 		exit()
 
 	#  Update allocation
@@ -430,7 +497,7 @@ def main():
 				userId = usermgt.getUserId(options.userName)
 
 		print options.reservationId, userId, options.reservationDuration, options.vlanIsolate, options.Notes
-		query.updateReservation(options.reservationId, userId, options.reservationDuration, options.vlanIsolate, options.Notes)
+		data.updateReservation(options.reservationId, userId, options.reservationDuration, options.vlanIsolate, options.Notes)
 
 	#  Release node allocation
 	if (options.releaseNode):
@@ -441,71 +508,73 @@ def main():
 
 			sys.stderr.write(mesg)		
 			exit()
-		query.releaseNode(options.nodeName)
+		data.releaseNode(options.nodeName)
 		
 	#  Assign image to host
-	#if (options.assignImage):
-		#if not options.nodeName:
-			#usage = "Node not specified.  Please specify a node with --nodeName or -n"
-			#print usage
-			#exit()
-		#if query.assignImagetoHost(host, options.assignImage):
+	if (options.assignImage):
+		if not options.nodeName:
+			usage = "Node not specified.  Please specify a node with --nodeName or -n"
+			print usage
+			exit()
+		#  need to fix this later
+		#if data.assignImagetoHost(host, options.assignImage):
 			#print "ERROR"
 			#exit()
-#
+
 		#  Update PXE 
-		#bootit = pxe.Pxe(configs, options.verbosity)
-		#bootit.createPxeUpdateFile(query.getPxeImages())
+		bootit = Pxe(configs, data, options.verbosity)
+		bootit.setBootImage(host['mac_addr'], options.assignImage)
+		#bootit.createPxeUpdateFile(data.getPxeImages())
 		#bootit.updatePxe()
 		
 	
 	#  Add image to database
 	if (options.addImage):
-		query.addImage(options.addImage)
+		data.addImage(options.addImage)
 	#  Delete PXE image 
 	if (options.delImage):
-		query.delImage(options.delImage)
+		data.delImage(options.delImage)
 
 	#  Domain interface
 	if (options.showDomains):
-		query.showDomains()
+		data.showDomains()
 	if (options.addDomain):
 		if len(args) > 2 and options.reservationId:
-			query.addDomain(args[0], string.join(args[1:len(args)]), options.reservationId)
+			data.addDomain(args[0], string.join(args[1:len(args)]), options.reservationId)
 		else:
 			mesg = "USAGE: %s --addDomain domainname domaindesc --reservationId ID\n" % (sys.argv[0])
 			sys.stdout.write(mesg)
 			exit()
 	if (options.removeDomain):
 		if len(args) > 0:
-			query.removeDomain(args[0])
+			data.removeDomain(args[0])
 		else:
 			mesg = "USAGE: %s --removeDomain domainname \n" % (sys.argv[0])
 			sys.stdout.write(mesg)
 			exit()
 
 	if (options.showVlans):
-		query.showVlans()
-	if (options.addVlan):
-		print len(args)
-		if len(args) > 0:
-			query.addVlan(args[0], string.join(args[1:len(args)]))
-		else:
-			mesg = "USAGE: %s --addVlan vlanNumber [VlanDesc]\n" % (sys.argv[0])
-			sys.stdout.write(mesg)
-			exit()
-	if (options.removeVlan):
-		if len(args) > 1:
-			query.removeVlan(args[0])
-		else:
-			mesg = "USAGE: %s --removeVlan VlanNumber\n" % (sys.argv[0])
-			sys.stdout.write(mesg)
-			exit()
+		data.showVlans()
+	#if (options.addVlan):
+		#print len(args)
+		#if len(args) > 0:
+			#data.addVlan(args[0], string.join(args[1:len(args)]))
+		#else:
+			#mesg = "USAGE: %s --addVlan vlanNumber [VlanDesc]\n" % (sys.argv[0])
+			#sys.stdout.write(mesg)
+			#exit()
+	#if (options.removeVlan):
+		#if len(args) > 0:
+			#data.removeVlan(args[0])
+		#else:
+			#mesg = "USAGE: %s --removeVlan VlanNumber\n" % (sys.argv[0])
+			#sys.stdout.write(mesg)
+			#exit()
 
 	if (options.assignVlan):
 		print len(args)
 		if len(args) > 0:
-			query.assignVlan(options.assignVlan, args[0], options.forcefully)
+			data.assignVlan(options.assignVlan, args[0], options.forcefully)
 		else:
 			mesg = "USAGE: %s --assignVlan vlannum DomainName\n" % (sys.argv[0])
 			sys.stdout.write(mesg)
@@ -514,8 +583,9 @@ def main():
 	#  Admin Interface
 	#  snmpwalk -v2c -c zoni-domain sw0-r1r1 .1.3.6.1.2.1.17.7.1.4.3.1.5    
 	if (options.ADMIN):
+			
 
-		if not options.nodeName and not  options.createVlanId and not options.removeVlanId and not options.switchPort and not options.interactiveSwitchConfig:
+		if not options.nodeName and not  options.createVlanId and not options.destroyVlanId and not options.switchPort and not options.interactiveSwitchConfig and not options.saveConfig:
 			mesg = "\nERROR:  nodeName or switch not specified.  Please specify nodename with -n or --nodeName or --switchport\n"
 			parser.print_help()
 			sys.stderr.write(mesg)
@@ -523,34 +593,56 @@ def main():
 
 		#  We can specify port/switch combinations here
 		if options.switchPort:
-			host = query.getSwitchInfo(options.switchPort.split(":")[0])
+			host = data.getSwitchInfo(options.switchPort.split(":")[0])
 			if len(options.switchPort.split(":")) > 1:
 				host['hw_port'] = options.switchPort.split(":")[1]
 
 			host['location'] = options.switchPort
 
 		if options.interactiveSwitchConfig:
-			host = query.getSwitchInfo(options.interactiveSwitchConfig)
+			host = data.getSwitchInfo(options.interactiveSwitchConfig)
 
 		HwSwitch = HwDellSwitch
 		hwswitch = HwSwitch(configs, host)
 		if options.verbosity:
 			hwswitch.setVerbose(True)
 
-		#print "create vlan", options.createVlanId
-		if options.enableHostPort and options.nodeName:
+		if options.setPortMode:
+			hwswitch.setPortMode(options.setPortMode)
+
+		if options.saveConfig:
+			hwswitch.saveConfig(options.saveConfig, data)
+		if options.labelPort:
+			mydesc = None
+			if len(args) > 0:
+				mydesc = " ".join(["%s" % i for i in args])
+			hwswitch.labelPort(mydesc)
+			
+		if options.enableHostPort and (options.nodeName or options.switchPort):
 			hwswitch.enableHostPort()
 		if options.disableHostPort and (options.nodeName or options.switchPort):
 			hwswitch.disableHostPort()
+		#  Create a new vlan on all switches and add to db
 		if options.createVlanId:
-			hwswitch.createVlans(options.createVlanId, query.getAllSwitches(), query)
-		if options.removeVlanId:
-			hwswitch.removeVlans(options.removeVlanId, query.getAllSwitches(), query)
+			print options.createVlanId
+			hwswitch.createVlans(options.createVlanId, data.getAllSwitches(), data)
+			data.addVlan(options.createVlanId, string.join(args[1:len(args)]))
+		#  Remove vlan on all switches and remove from db
+		if options.destroyVlanId:
+			hwswitch.removeVlans(options.destroyVlanId, data.getAllSwitches(), data)
+			data.removeVlan(options.destroyVlanId)
 
 		if options.add2Vlan and (options.nodeName or options.switchPort):
-			hwswitch.addNodeToVlan(options.add2Vlan)
+			tag=None
+			vlan = options.add2Vlan
+			if ":" in options.add2Vlan:
+				print options.add2Vlan
+				vlan = options.add2Vlan.split(":")[0]
+				tag = options.add2Vlan.split(":")[1]
+
+			hwswitch.addNodeToVlan(vlan, tag)
 
-		if options.removeFromVlan and options.nodeName:
+		if options.removeFromVlan and (options.nodeName or options.switchPort): 
 			hwswitch.removeNodeFromVlan(options.removeFromVlan)
 		if options.setNative and (options.nodeName or options.switchPort):
 			hwswitch.setNativeVlan(options.setNative)
@@ -569,14 +661,14 @@ def main():
 	#  Register hardware
 	if options.register: 
 
-		supported_hardware = ['dell', 'raritan']
+		supported_hardware = ['dellswitch', 'raritan']
 		if len(args) < 3:
 			mesg = "ERROR:  Expecting username and ip address of hardware to be registered\n"
 			mesg += os.path.basename(sys.argv[0]) + " --register HARDWARE username ipaddr\n"
 			mesg += "Supported hardware " + str(supported_hardware) + "\n"
 			sys.stderr.write(mesg)
 		else:
-			if string.lower(args[0]) == "dell":
+			if string.lower(args[0]) == "dellswitch":
 				HwSwitch = HwDellSwitch
 				hw = HwSwitch(configs)
 			elif string.lower(args[0]) == "raritan":
@@ -594,7 +686,7 @@ def main():
 			data = hw.registerToZoni(args[1], password, args[2])
 
 			#  Register to DB
-			#query.registerHardware(data)
+			#data.registerHardware(data)
 			
 	#  Zoni Helper
 	if options.addDns or options.removeDns or options.addDhcp or options.removeDhcp or options.addCname or options.removeCname:
@@ -697,7 +789,7 @@ def main():
 		if options.addCname:
 			if len(args) < 2:
 				mesg = "ERROR:  Incorrect number of arguments\n"
-				mesg += "Example:  " + os.path.basename(sys.argv[0]) + " " + thisone + "cname existing_name"
+				mesg += "Example: %s %s cname existing_name" % (os.path.basename(sys.argv[0]), thisone) 
 				print mesg
 				exit()
 			hostName = args[1]
@@ -707,10 +799,10 @@ def main():
 			dhcpdns = DhcpDns(configs, verbose=options.verbosity)
 			dhcpdns.addCname(cname, hostName)
 			if dhcpdns.error: 
-				mesg = "[FAIL]  \n" + str(dhcpdns.error) + "\n" 
+				mesg = "[FAIL]  \n %s\n" % str(dhcpdns.error)
 				sys.stdout.write(mesg) 
 			else: 
-				mesg = "[SUCCESS]" + "\n" 
+				mesg = "[SUCCESS]\n"
 				sys.stdout.write(mesg) 
 
 if __name__ == "__main__":

Propchange: incubator/tashi/trunk/src/zoni/client/zoni-cli.py
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/zoni/data/resourcequerysql.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/data/resourcequerysql.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/zoni/data/resourcequerysql.py (original)
+++ incubator/tashi/trunk/src/zoni/data/resourcequerysql.py Fri Sep 30 13:47:21 2011
@@ -25,10 +25,12 @@ import MySQLdb
 import subprocess
 import traceback
 import logging
+import threading
+import time
 
 import usermanagement
 from zoni.data.infostore import InfoStore
-from zoni.extra.util import checkSuper
+from zoni.extra.util import checkSuper, createKey
 from zoni.agents.dhcpdns import DhcpDns
 
 class ResourceQuerySql(InfoStore):
@@ -39,32 +41,36 @@ class ResourceQuerySql(InfoStore):
 		self.user = config['dbUser']
 		self.passwd = config['dbPassword']
 		self.db = config['dbInst']
-		#self.log = logging.getLogger(os.path.basename(__name__))
+		self.port = config['dbPort']
+		self._isDb = 1
+		self.vlan_max = config['vlanMax']
+		if self.port == "":
+			self.port = 3306
 		self.log = logging.getLogger(__name__)
 		
-		self.tftpRootDir = config['tftpRootDir']
-		self.tftpImageDir = config['tftpImageDir']
-		self.tftpBootOptionsDir = config['tftpBootOptionsDir']
-
-
-		if config['dbPort'] == "":
-			config['dbPort'] = 3306
-
-		self.port = config['dbPort']
+		self.conn = self.createConn()
 
-		self.vlan_max = config['vlan_max']
-		#self.vlan_reserved = config['vlan_reserved']
 		
+	def createConn(self):
 		#  Connect to DB
 		try:
-			self.conn = MySQLdb.connect(host = self.host, port = self.port, user = self.user, passwd = self.passwd, db = self.db)
+			return MySQLdb.connect(host = self.host, port = self.port, user = self.user, passwd = self.passwd, db = self.db)
+			#return MySQLdb.connect(host = self.config['dbHost'], port = self.config['dbPort'], user = self.config['dbUser'], passwd = self.config['dbPassword'], db = self.config['dbInst'])
+
 		except MySQLdb.OperationalError, e:
 			if e[0] == 2005:
 				print "ERROR :" + str(e[1])
-				exit(1)
+				return 
 			else:
 				print "ERROR : ", e
-				exit(1)
+				return 
+
+	def keepAlive(self):
+		while True:
+			if not self.conn.open:
+				self.log.info("Reinitializing DB connection")
+				self.conn = self.createConn()
+			time.sleep(10)
 
 	def getNote(self):
 		return "Created by Zoni"
@@ -72,7 +78,7 @@ class ResourceQuerySql(InfoStore):
 	def addDomain(self, name, desc, reservationId):
 		#  Check if there is a reservation
 		query = "select * from reservationinfo where reservation_id = %s" % (reservationId)
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount < 1:
 			mesg = "Reservation does not exist : %s" % (reservationId)
 			self.log.error(mesg)
@@ -81,13 +87,14 @@ class ResourceQuerySql(InfoStore):
 		if desc == None:
 			desc = self.getNote()
 
-		print name
 		if self.__checkDup("domaininfo", "domain_name", name):
 			self.log.error("Domain (%s) already exists" % (name))
 			return -1
-		query = "insert into domaininfo (domain_name, domain_desc, reservation_id) values ('%s','%s', '%s')" % (name, desc, reservationId)
+		#  Create a key for the reservation
+		domainKey = createKey(name)
+		query = "insert into domaininfo (domain_name, domain_desc, domain_key, reservation_id) values ('%s','%s', '%s', '%s')" % (name, desc, domainKey, reservationId)
 		try:
-			result = self.__insertDb(query)
+			result = self.insertDb(query)
 			mesg = "Adding domain %s(%s)" % (name, desc)
 			self.log.info(mesg)
 		except Exception, e:
@@ -103,20 +110,29 @@ class ResourceQuerySql(InfoStore):
 		#  Need to remove any vlans attached to this domain
 
 	def showDomains(self):
-		query = "select domain_name, domain_desc from domaininfo"
-		result = self.__selectDb(query)
+		usermgt = eval("usermanagement.%s" % (self.config['userManagement']) + "()")
+		query = "select r.reservation_id, r.user_id, d.domain_name, d.domain_desc from domaininfo d, allocationinfo a, reservationinfo r where d.domain_id = a.domain_id and a.reservation_id = r.reservation_id"
+		result = self.selectDb(query)
 		desc = result.description
 		if result.rowcount > 0:
-			print "%s\t%s\n-------------------------------------" % (result.description[0][0], result.description[1][0])
+			print "%s\t%s\t%s\t%s" % (result.description[0][0], result.description[1][0], result.description[2][0], result.description[3][0])
+			print "------------------------------------------------------------"
 			for row in result.fetchall():
-				print "%s\t\t%s" % (row[0], row[1])
+				resName = usermgt.getUserName(row[1])
+				print "%s\t\t%s\t%s\t\t%s" % (row[0], resName, row[2], row[3])
 			return 0
 		else:
 			mesg = "No Domains exist"
 			self.log.info(mesg)
 			return -1
 
-	def addVlan(self, vnumber, desc=None):
+	def addVlan(self, vnum, desc=None):
+		vnumber = vnum
+		if ":" in vnum:
+			vnumber = vnum.split(":")[0]
+			desc = vnum.split(":")[1:len(vnumber)][0]
+			print vnumber, desc
+		
 		if desc == None:
 			desc = "Created by Zoni"
 		if int(vnumber) > self.vlan_max:
@@ -128,7 +144,7 @@ class ResourceQuerySql(InfoStore):
 			return -1
 		query = "insert into vlaninfo (vlan_num, vlan_desc) values ('%s','%s')" % (vnumber, desc)
 		try:
-			result = self.__insertDb(query)
+			result = self.insertDb(query)
 			mesg = "Adding vlan %s(%s)" % (vnumber, desc)
 			self.log.info(mesg)
 		except Exception, e:
@@ -152,7 +168,7 @@ class ResourceQuerySql(InfoStore):
 	def showVlans (self):
 		query = "select vlan_num, vlan_desc from vlaninfo order by vlan_num"
 		try:
-			result = self.__selectDb(query)
+			result = self.selectDb(query)
 			print "%s\t%s\n-------------------------------------" % (result.description[0][0], result.description[1][0])
 			for row in result.fetchall():
 				print "%s\t\t%s" % (row[0], row[1])
@@ -166,24 +182,29 @@ class ResourceQuerySql(InfoStore):
 		domainId = self.__getSomething("domain_id", "domaininfo", "domain_name", domain)
 		vlanId = self.__getSomething("vlan_id", "vlaninfo", "vlan_num", vlan)
 		query = "select * from domainmembermap m, vlaninfo v, domaininfo d where d.domain_id = '%s' and v.vlan_id = %s and v.vlan_id = m.vlan_id and m.domain_id = d.domain_id" % (int(domainId), int(vlanId))
-		if self.__selectDb(query).rowcount > 0:
+		if self.selectDb(query).rowcount > 0:
 			self.log.warning("Vlan %s already assigned to domain %s" % (vlan, domain));
 			return 0
 
 		# warning if vlan already assigned to another domain
 		query = "select * from domainmembermap where vlan_id = %s" % (vlanId)
-		if self.__selectDb(query).rowcount > 0:
+		if self.selectDb(query).rowcount > 0:
 			self.log.warning("Vlan %s already assigned to a domain" % (vlan));
 			if not force:
 				return -1
 
 		self.log.info("Assigning vlan %s to domain %s" % (vlan, domain))
 		query = "insert into domainmembermap (domain_id, vlan_id) values (%s, %s)" % (domainId, vlanId)
-		self.__insertDb(query)
+		self.insertDb(query)
 
 	def __getSomething(self, fieldname, table, critField, crit):
 		query = "select %s from %s where %s = '%s'" % (fieldname, table, critField, crit)
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
+		if result.rowcount == 0:
+			mesg = "No entry for '%s' found" % (crit)
+			self.log.error(mesg)
+			#return []
+			return -1
 		return result.fetchall()[0][0]
 
 
@@ -192,7 +213,7 @@ class ResourceQuerySql(InfoStore):
 		if (colname2 != None and value2 != None):
 			cond += " and %s = '%s'" % (colname2, value2)
 		query = "select * from %s %s" % (table, cond)
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount == 0:
 			return []
 		return result.fetchall()
@@ -248,10 +269,10 @@ class ResourceQuerySql(InfoStore):
 		queryopt = self.__create_queryopts(cmdargs)				
 				
 		#query = "show fields from sysinfo"
-		#results = self.__selectDb(query)
+		#results = self.selectDb(query)
 		
 		query = "select " + defaultFields + "from sysinfo " + queryopt
-		result = self.__selectDb(query)	
+		result = self.selectDb(query)	
 
 		line = ""
 		for i in defaultFields.split(","):
@@ -266,45 +287,95 @@ class ResourceQuerySql(InfoStore):
 			print line
 		print str(result.rowcount) + " systems returned"
 
-		#mysql -h rodimus -u reader irp-cluster -e "select * from sysinfo where location like 'r1%' and num_procs = 1"
+	def getAvailableResources(self):
+		#  Maybe should add a status flag?
+
+		query = "select sys_id from allocationinfo"
+		result = self.selectDb(query)
+		allocatedNodes = []
+		if result.rowcount:
+			for i in result.fetchall()[0]:
+				allocatedNodes.append(i)
+
+		query = "select sys_id, location, num_procs, num_cores, mem_total, clock_speed, proc_model from sysinfo where state_id = 0 or state_id = 1"
+		result = self.selectDb(query)
+		desc = result.description
+		res = {}
+		for i in result.fetchall():
+			sys_id = int(i[0])
+			if sys_id not in allocatedNodes:
+				location = i[1]
+				res[location] = res.get(location, {})
+				res[location][desc[0][0]] = sys_id
+				res[location][desc[1][0]] = location
+				res[location][desc[2][0]] = int(i[2])
+				res[location][desc[3][0]] = int(i[3])
+				res[location][desc[4][0]] = int(i[4])
+				res[location][desc[5][0]] = int(i[5])
+				res[location][desc[6][0]] = i[6]
+			
+		return res
+
+	def getMyResources(self, key):
+		query = "select s.sys_id, s.location, s.num_procs, s.num_cores, s.mem_total, s.clock_speed, s.proc_model from sysinfo s, allocationinfo a, domaininfo d where a.sys_id = s.sys_id and  a.domain_id = d.domain_id and d.domain_key = '%s'" % key
+		result = self.selectDb(query)
+		desc = result.description
+		res = {}
+		for i in result.fetchall():
+			sys_id = int(i[0])
+			location = i[1]
+			res[location] = res.get(location, {})
+			res[location][desc[0][0]] = sys_id
+			res[location][desc[1][0]] = location
+			res[location][desc[2][0]] = int(i[2])
+			res[location][desc[3][0]] = int(i[3])
+			res[location][desc[4][0]] = int(i[4])
+			res[location][desc[5][0]] = int(i[5])
+			res[location][desc[6][0]] = i[6]
+			
+		return res
+
+	def getDomainFromKey(self, key):
+		return self.__getSomething("domain_name", "domaininfo", "domain_key", key)
+
+	def getDomainIdFromKey(self, key):
+		return self.__getSomething("domain_id", "domaininfo", "domain_key", key)
 
+	def getKeyFromDomain(self, domain):
+		return self.__getSomething("domain_key", "domaininfo", "domain_name", domain)
+	
 	def getLocationFromSysId (self, nodeId):
 		query = "select location from sysinfo where sys_id = \"" + str(nodeId) + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		return result.fetchall()[0][0]
 
+	def getSysIdFromLocation(self, location):
+		return self.__getSomething("sys_id", "sysinfo", "location", location)
+
 	def getMacFromSysId(self, nodeId):
 		query = "select mac_addr from sysinfo where sys_id = \"" + str(nodeId) + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		return result.fetchall()[0][0]
 
 	def getIpFromSysId(self, nodeId):
 		query = "select ip_addr from sysinfo where sys_id = \"" + str(nodeId) + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		return result.fetchall()[0][0]
 		
 
 	def getAllSwitches(self):
 		switchList = []
 		query = "select hw_name from hardwareinfo where hw_type = \"switch\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		for switch in result.fetchall():
 			switchList.append(switch[0])
 
-		#  Use static list until we get all switches installed
-		#switchList =  ['sw1-r1r2', 'sw0-r1r1', 'sw0-r1r2', 'sw0-r1r3', 'sw0-r1r4', 'sw0-r2r3', 'sw0-r3r3', 'sw0-r3r2', 'sw0-r2r1c3', 'sw2-r1r2']
-		#switchList =  ['sw2-r1r2']
-		#switchList =  ['sw1-r1r2']
-
-
-		print switchList
-	
 		return switchList
 
 	def getAvailableVlan(self):
 		#  Get list of available vlans
 		query = "select vlan_num from vlaninfo where domain = 'private'"
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		for vlan in result.fetchall()[0]:
 			avail = self.isVlanAvailable(vlan)
 			if avail:
@@ -317,7 +388,7 @@ class ResourceQuerySql(InfoStore):
 	
 	def isVlanAvailable(self, vlan):
 		query = "select a.vlan_id, v.vlan_num from allocationinfo a, vlaninfo v where a.vlan_id = v.vlan_id and v.vlan_num = " + str(vlan)
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount > 1:
 			return 0
 		else:
@@ -325,7 +396,7 @@ class ResourceQuerySql(InfoStore):
 
 	def getVlanId(self, vlan):
 		query = "select vlan_id from vlaninfo where vlan_num = \"" +  str(vlan) + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		#print result.rowcount 
 		if result.rowcount > 0:
 			return result.fetchall()[0][0]
@@ -337,7 +408,7 @@ class ResourceQuerySql(InfoStore):
 	def isIpAvailable(self, ip_addr, vlan_id):
 		query = "select * from allocationinfo where ip_addr = \"" + str(ip_addr) + "\" and vlan_id = \"" + str(vlan_id) + "\""
 		#print "query ", query
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		#print "select row count is ", result.rowcount
 		if result.rowcount > 0:
 			return 0
@@ -348,7 +419,7 @@ class ResourceQuerySql(InfoStore):
 	def getDomainIp(self, vlan):
 		ip_start = 30
 		query = "select ip_network from vlaninfo where vlan_num = " + str(vlan)
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		ip_network = result.fetchall()[0][0]
 		v = ip_network.split(".")
 		ip_base = v[0] + "." + v[1] + "." + v[2]
@@ -358,7 +429,7 @@ class ResourceQuerySql(InfoStore):
 		#print "ip is ", ip_network 
 
 		query = "select a.ip_addr from allocationinfo a, vlaninfo v where a.vlan_id = v.vlan_id and v.vlan_num = " + str(vlan);
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		#print "row count is ", result.rowcount
 		if result.rowcount > 0:
 			for ip in xrange(ip_start, 255):
@@ -374,12 +445,6 @@ class ResourceQuerySql(InfoStore):
 		return ip_addr
 
 
-	#def showArchive(self):
-		#query = "select * from allocationarchive"
-		#result = self.__selectDb(query)
-		#for i in result:
-			#print i
-
 	def showAllocation(self, userId=None):
 		#from IPython.Shell import IPShellEmbed
 		#shell = IPShellEmbed(argv="")
@@ -406,14 +471,11 @@ class ResourceQuerySql(InfoStore):
 
 		query += "order by r.reservation_id asc, s.location"
 
-		print query
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		
-		print "NODE ALLOCATION"
-		print "---------------------------------------------------------------------------------"
+		print "NODE ALLOCATION\n"
 		if self.verbose:
-			#print "Res_id\tUser    \tNode    \tCores\tMemory  \tExpiration\t\tVLAN\tHOSTNAME    \tIPADDR    \t\tReservationNotes|AllocationNotes"
-			print "%-5s%-10s%-10s%-12s%-12s%-5s%-15s%-18s%-24s%s" % ("Res", "User", "Host", "Cores/Mem","Expiration", "Vlan", "Hostname", "IP Addr", "Boot Image Name", "Notes")
+			print "%-5s%-10s%-10s%-13s%-12s%-15s%-18s%-24s%-20s%s" % ("Res", "User", "Host", "Cores/Mem","Expiration", "Hostname", "IP Addr", "Boot Image Name", "Vlan Member", "Notes")
 		else:
 			print "%-10s%-10s%-13s%-12s%s" % ("User", "Node", "Cores/Mem","Expiration", "Notes")
 
@@ -429,18 +491,25 @@ class ResourceQuerySql(InfoStore):
 			rnotes = i[6]
 			resId= i[7]
 			hostname = i[8]
+			if hostname == None:
+				hostname = host
 			anotes = i[9]
 			image_name = i[10]
 			userName = usermgt.getUserName(uid)
 			combined_notes = str(rnotes) + "|" + str(anotes)
 			if self.verbose:
-				vlanId = 1000
+				query = "select vlan_num from vlaninfo v, domainmembermap m, domaininfo d where v.vlan_id = m.vlan_id and d.domain_id = m.domain_id and d.domain_name = '%s'" % (domain);
+				vlanRes = self.selectDb(query)
+				vlanList = []
+				for i in vlanRes.fetchall():
+					vlanList.append(str(i[0]))
+				
+				vlanMember = string.join(vlanList, ",")
 				ip_addr = "10.0.0.10"
-				print "%-5s%-10s%-10s%-2s/%-10s%-12s%-5s%-15s%-18s%-24s%s" % (resId, userName, host, cores, memory,expire, vlanId, hostname, ip_addr, image_name, combined_notes)
+				print "%-5s%-10s%-10s%-2s/%-10s%-12s%-15s%-18s%-24s%-20s%s" % (resId, userName, host, cores, memory,expire, hostname, ip_addr, image_name, vlanMember,combined_notes)
 			else:
 				print "%-10s%-10s%-2s/%-10s%-12s%s" % (userName, host, cores, memory,expire, combined_notes)
-		print "---------------------------------------------------------------------------------"
-		print str(result.rowcount) + " systems returned"
+		print "\n%s systems returned" % (str(result.rowcount))
 
 	def showReservation(self, userId=None):
 		#from IPython.Shell import IPShellEmbed
@@ -468,7 +537,7 @@ class ResourceQuerySql(InfoStore):
 
 		#query += "order by r.user_id, s.location"
 
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		
 		print "RESERVATIONS"
 		print "---------------------------------------------------------------------------------"
@@ -499,11 +568,10 @@ class ResourceQuerySql(InfoStore):
 
 	
 	def getPxeImages(self):
-		cursor = self.conn.cursor ()
-		line = "select image_name from imageinfo"
-		cursor.execute (line)
-		row = cursor.fetchall()
-		desc = cursor.description
+		query = "select image_name from imageinfo"
+		result = self.selectDb(query)
+		row = result.fetchall()
+		desc = result.description
 
 		imagelist = []
 		for i in row:
@@ -513,24 +581,37 @@ class ResourceQuerySql(InfoStore):
 		
 		
 	def showPxeImages(self):
-		cursor = self.conn.cursor ()
-		line = "select image_name, dist, dist_ver  from imageinfo"
-		cursor.execute (line)
-		row = cursor.fetchall()
-		desc = cursor.description
+		query = "select image_name, dist, dist_ver  from imageinfo"
+		result = self.selectDb(query)
+		row = result.fetchall()
+		desc = result.description
 
 		for i in row:
 			print i
 
-		cursor.close ()
+	def getKernelOptions(self,image):
+		val = {}
+		query = "select i.image_name, k.kernel_name, k.kernel_arch, n.initrd_name, n.initrd_options from imageinfo i, kernelinfo k, initrdinfo n where k.kernel_id = i.kernel_id and i.initrd_id = n.initrd_id and i.image_name = '%s'" % image
+		result = self.selectDb(query)
+		row = result.fetchone()
+		desc = result.description
+		val[desc[0][0]] = row[0]
+		val[desc[1][0]] = row[1]
+		val[desc[2][0]] = row[2]
+		val[desc[3][0]] = row[3]
+		val[desc[4][0]] = row[4]
+		return val
+			
+		
+
 
 	def showPxeImagesToSystemMap(self, cmdargs):
-		extra = "l.mac_addr = j.mac_addr and j.image_id = i.image_id"
+		extra = "j.image_id = i.image_id"
 		queryopt = self.__create_queryopts(cmdargs, extra=extra)
 
-		query = "select  l.location, j.mac_addr, i.image_name from sysinfo l , imageinfo i, imagemap j " + queryopt + " order by l.location"
+		query = "select  s.location, s.mac_addr, i.image_name from sysinfo s , imageinfo i, imagemap j " + queryopt + " order by s.location"
 		#print query
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 
 		for i in result.fetchall():
 			print i
@@ -548,13 +629,14 @@ class ResourceQuerySql(InfoStore):
 	def getHostInfo(self, node):
 		host = {}
 		query = "select sys_id, mac_addr, num_procs, num_cores, mem_total, clock_speed, sys_vendor, sys_model, proc_vendor, proc_model, proc_cache, cpu_flags, bios_rev, location, system_serial_number, ip_addr from sysinfo where location = \"" + node + "\"" 
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount > 1:
-			print "Multiple entries for system exist.  Please correct"
-			exit()
+			mesg = "Multiple entries for system exist.  Please correct"
+			self.log.info(mesg)
+			exit
 		if result.rowcount < 1:
 			mesg = "node does not exist :" + str(node) + "\n"
-			sys.stderr.write(mesg)
+			self.log.error(mesg)
 			exit()
 		
 		for i in result.fetchall():
@@ -582,10 +664,10 @@ class ResourceQuerySql(InfoStore):
 		
 		#  Get IPMI info
 		query = "select h.hw_userid, h.hw_password, h.hw_ipaddr from hardwareinfo h, portmap p, sysinfo s where p.sys_id = s.sys_id and h.hw_id = p.hw_id and h.hw_type = 'ipmi' and s.sys_id = " + str(host['sys_id']) + "" 
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount> 1:
 			print "Multiple entries for system exist.  Please correct"
-			exit()
+			return 
 		for i in result.fetchall():
 			host['ipmi_user'] = i[0]
 			host['ipmi_password'] = i[1]
@@ -593,7 +675,7 @@ class ResourceQuerySql(InfoStore):
 
 		#  Get image info
 		query = "select image_name from imagemap i, imageinfo j where i.image_id = j.image_id" 
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount == 0:
 			host['pxe_image_name'] = "None"
 		else:
@@ -602,7 +684,7 @@ class ResourceQuerySql(InfoStore):
 
 		#  Get switch info
 		query = "select h.hw_id, h.hw_name, h.hw_model, h.hw_ipaddr, h.hw_userid, h.hw_password, p.port_num from hardwareinfo h, portmap p where p.hw_id = h.hw_id and hw_type = 'switch' and sys_id = " +  str(host['sys_id'])
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		for i in result.fetchall():
 			host['hw_id'] = int(i[0])
 			host['hw_name'] = i[1]
@@ -614,7 +696,7 @@ class ResourceQuerySql(InfoStore):
 
 		#  Get drac info
 		query = "select h.hw_id, h.hw_name, h.hw_model, h.hw_ipaddr, h.hw_userid, h.hw_password, p.port_num from hardwareinfo h, portmap p where p.hw_id = h.hw_id and hw_type = 'drac' and sys_id = " +  str(host['sys_id'])
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount > 0:
 			for i in result.fetchall():
 				host['drac_id'] = int(i[0])
@@ -627,7 +709,7 @@ class ResourceQuerySql(InfoStore):
 
 		#  Get PDU info
 		query = "select h.hw_id, h.hw_name, h.hw_model, h.hw_ipaddr, h.hw_userid, h.hw_password, p.port_num from hardwareinfo h, portmap p where p.hw_id = h.hw_id and h.hw_type = 'pdu' and p.sys_id = " +  str(host['sys_id'])
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		for i in result.fetchall():
 			host['pdu_id'] = int(i[0])
 			host['pdu_name'] = i[1]
@@ -646,9 +728,7 @@ class ResourceQuerySql(InfoStore):
 		#  Get switch info
 		#switchList = self.getAllSwitches()
 		query = "select h.hw_id, h.hw_name, h.hw_model, h.hw_ipaddr, h.hw_userid, h.hw_password from hardwareinfo h where h.hw_name  = \"" +  str(switchName) + "\""
-		#print "query is ", query
-		result = self.__selectDb(query)
-		#desc = cursor.description
+		result = self.selectDb(query)
 		for i in result.fetchall():
 			host['hw_id'] = int(i[0])
 			host['hw_name'] = i[1]
@@ -659,6 +739,7 @@ class ResourceQuerySql(InfoStore):
 		return host
 
 	def __queryDb(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -673,6 +754,7 @@ class ResourceQuerySql(InfoStore):
 		return row
 
 	def execQuery(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -683,10 +765,11 @@ class ResourceQuerySql(InfoStore):
 			msg = "%s : %s" % (e[1], query)
 			self.log.error(msg)
 			#traceback.print_exc(sys.exc_info())
-			exit()
+			return 
 		return cursor
 
-	def __selectDb(self, query):
+	def selectDb(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -700,6 +783,7 @@ class ResourceQuerySql(InfoStore):
 		return cursor
 
 	def __deleteDb(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -713,6 +797,7 @@ class ResourceQuerySql(InfoStore):
 		return cursor
 
 	def __updateDb(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -725,7 +810,8 @@ class ResourceQuerySql(InfoStore):
 			return -1
 		return cursor
 
-	def __insertDb(self, query):
+	def insertDb(self, query):
+		self.conn.ping(True)
 		cursor = self.conn.cursor()
 		try:
 			cursor.execute (query)
@@ -756,7 +842,7 @@ class ResourceQuerySql(InfoStore):
 			else:
 				mesg = "ERROR: Invalid reservation duration"
 				self.log.error(mesg)
-				exit()
+				return 
 
 			mesg = "Updating reservationDuration :" + resDuration
 			self.log.info(mesg)
@@ -799,19 +885,18 @@ class ResourceQuerySql(InfoStore):
 		else:
 			mesg = "ERROR: Invalid reservation duration\n"
 			self.log.info(mesg)
-			exit()
+			return 
 
-		#  create reservation
 		#  Create the reservation
 		print userId, expireDate,reservationNotes
-		query = "insert into reservationinfo (user_id, reservation_expiration, notes) values (\"" + str(userId) + "\", " + str(expireDate) + ", \"" + str(reservationNotes) + "\")"
-		mesg = "Creating new reservation : " + query
+		query = "insert into reservationinfo (user_id, reservation_expiration, notes) values ('%s', '%s', '%s')" % (str(userId), str(expireDate), str(reservationNotes))
+		mesg = "Creating new reservation : %s" % query
 		self.log.info(mesg)
-		self.__insertDb(query)
+		self.insertDb(query)
 		#  Get the res_id
 		query = "select max(reservation_id) from reservationinfo"
-		res_id = self.__selectDb(query).fetchone()[0]
-		mesg = "  Reservation created - ID :" + str(res_id)
+		res_id = self.selectDb(query).fetchone()[0]
+		mesg = "  Reservation created - ID : %s" % str(res_id)
 		self.log.info(mesg)
 
 		return res_id
@@ -827,7 +912,7 @@ class ResourceQuerySql(InfoStore):
 				#str(user_id) + "\", \"" + str(reservation_type) + "\", \"" + \
 				#str(combined_notes) + "\")" 
 #
-		#self.__insertDb(query)
+		#self.insertDb(query)
 
 	def allocateNode(self, reservationId, domain, sysId, vlanInfo, imageName, notes=None):
 		print "reservationId", reservationId, domain, sysId, vlanInfo, imageName, notes
@@ -854,6 +939,12 @@ class ResourceQuerySql(InfoStore):
 			mesg = "Domain does not exist: %s(%s)" % (domainId, domain)
 			self.log.error(mesg)
 			return -1
+
+		imageId = self.__getSomething("image_id", "imageinfo", "image_name", imageName)
+		if len(self.__checkDup("imageinfo", "image_id", imageId)) == 0:
+			mesg = "Image does not exist: %s(%s)" % (imageName, imageId)
+			self.log.error(mesg)
+			return -1
 		
 		#  Check that all the vlans exist
 		for i in vlanInfo.split(","):
@@ -866,7 +957,7 @@ class ResourceQuerySql(InfoStore):
 		mesg = "allocateNode %s : domain %s : reservation %s(%s)" % (nodeName, domain, reservationId, resinfo[4])
 		self.log.info(mesg)
 		query = "insert into allocationinfo (sys_id, reservation_id, domain_id, notes) values ('%s', '%s', '%s', '%s')" % (sysId, reservationId, domainId, notes)
-		result = self.__insertDb(query)
+		result = self.insertDb(query)
 		allocationId = result.lastrowid
 
 		#  Parse vlan info and add to vlanmembermap
@@ -876,85 +967,57 @@ class ResourceQuerySql(InfoStore):
 			vId = self.getVlanId(v)
 			t = i.split(":")[1]
 			query = "insert into vlanmembermap (allocation_id, vlan_id, vlan_type) values ('%s', '%s', '%s')" % (allocationId, vId, t)
-			result = self.__insertDb(query)
+			result = self.insertDb(query)
 			mesg = "Adding vlan %s to node %s" % (v, nodeName)
 			self.log.info(mesg)
 
 		#  Insert into imagemap
-		image_id = self.__getSomething("image_id", "imageinfo", "image_name", imageName)
-		query = "insert into imagemap (allocation_id, image_id) values ('%s', '%s')" % (allocationId, image_id)
-		result = self.__insertDb(query)
+		query = "insert into imagemap (allocation_id, image_id) values ('%s', '%s')" % (allocationId, imageId)
+		result = self.insertDb(query)
+	
+		self.__updateSysState(sysId, 1)
+
+		
+	def __updateSysState(self, sysId, stateId):
+		query = "update sysinfo set state_id = '%s' where sys_id = '%s'" % (stateId, sysId)
+		return self.__updateDb(query)
 
 	def rgasstest(self, vlan_num):
 		query = "select * from vlaninfo where vlan_num = " + vlan_num
-		res = self.__selectDb(query).fetchall()
+		res = self.selectDb(query).fetchall()
 		print res
 		
 		
 			
 	def removeReservation(self, res):
+		mesg = "Removing reservation (%s)" % str(res)
+		self.log.info(mesg)
 		query = "delete from reservationinfo where reservation_id = " + str(res)
 		self.__updateDb(query)
 		query = "delete from allocationinfo where reservation_id = " + str(res)
 		self.__updateDb(query)
+
 		
-	@checkSuper
-	def releaseNode(self, nodeName):
+	def releaseNode(self, location):
 		#  Get the nodeId
-		query = "select sys_id, r.reservation_id, a.ip_addr, hostname, vlan_id, a.notes, r.notes,r.user_id from allocationinfo a, sysinfo s, reservationinfo r where a.sys_id = s.sys_id and a.reservation_id = r.reservation_id and location = \"" + nodeName + "\""
-		print query
-		result = self.__selectDb(query)
+		sysId = self.__getSomething("sys_id", "sysinfo", "location", location)
+		query = "select * from allocationinfo where sys_id = '%s'" % (sysId)
+		result = self.selectDb(query)
 		if result.rowcount == 0:
-			mesg = "ERROR:  Node not allocated\n"
-			sys.stderr.write(mesg)
-			exit(1)
+			mesg = "Node %s not allocated" % (location)
+			self.log.error(mesg)
+			return
 		if result.rowcount > 1:
-			mesg = "WARNING:  Node allocated multiple times (" + str(result.rowcount) + ")"
+			mesg = "Node %s allocated multiple times(%s)" % (location, str(result.rowcount))
 			self.log.warning(mesg)
+			return 
 
-		val = result.fetchone()
-		nodeId = int(val[0])
-		resId = int(val[1])
-		ip_addr = val[2]
-		hostName = val[3]
-		vlan_id = int(val[4])
-		allocation_notes = val[5]
-		reservation_notes = val[6]
-		user_id = val[7]
-
-		print "hostname is ", hostName
-		#  Assign IP address to node
-		dhcpdns = DhcpDns(self.config, verbose=1)
-		dnscheck = dhcpdns.removeDns(hostName)
-		dhcpdns.removeDhcp(hostName)
-
-		'''
-		query = "select reservation_id, notes from reservationinfo where sys_id = " + str(nodeId)
-		result = self.__selectDb(query)
-		for i in result:
-			print i
-		print result.rowcount
-		if result.rowcount == 0:
-			mesg = "No Reservation for this node.\n  Please check"
-			logit(self.logFile, mesg)
-			exit(1)
-		if result.rowcount > 1:
-			mesg = "WARNING:  Multiple reservations exist (" + str(result.rowcount) + ")"
-			logit(self.logFile, mesg)
-		
-		resId = int(result.fetchone()[0])
-		res_notes = int(result.fetchone()[1])
-		
-		print resId, res_notes
-		'''
-		
 		#  Eventually should add count =1 so deletes do get out of control
-		query = "delete from allocationinfo where reservation_id = " + str(resId) + " and sys_id = " + str(nodeId)
+		query = "delete from allocationinfo where sys_id = '%s'" % (sysId)
 		result = self.__deleteDb(query)
-
-		#  Archive node release
-		#reservation_type = "release"
-		#self.archiveAllocation(nodeId, ip_addr, hostName, vlan_id, user_id, reservation_type, reservation_notes, allocation_notes)
+		#  Set state to available
+		self.__updateSysState(sysId, 0)
+		return 
 
 	def addImage(self, imageName):
 		name = ""
@@ -969,11 +1032,11 @@ class ResourceQuerySql(InfoStore):
 			dist_ver = imageName.split(":")[2]
 
 		query = "select * from imageinfo where image_name = \"" + name + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount > 0:
 			mesg = "ERROR:  Image already exists\n"
 			sys.stderr.write(mesg)
-			exit()
+			return 
 		
 		if name == "":
 			mesg = "ERROR:  Image details not specified\n"
@@ -981,10 +1044,10 @@ class ResourceQuerySql(InfoStore):
 			mesg = "Example amd64-rgass-testing:Ubuntu:8.04\n"
 			mesg += "or amd64-rgass-testing::\n"
 			sys.stderr.write(mesg)
-			exit()
+			return 
 
 		query = "insert into imageinfo (image_name, dist, dist_ver) values(\"" + name + "\", \"" + dist + "\", \"" + dist_ver + "\")"
-		self.__insertDb(query)
+		self.insertDb(query)
 
 
 	def delImage(self, imageName):
@@ -993,7 +1056,7 @@ class ResourceQuerySql(InfoStore):
 		if result.rowcount == 0:
 			mesg = "ERROR:  No images match your entry\n"
 			sys.stderr.write(mesg)
-			exit()
+			return 
 
 	def assignImagetoHost(self, host, image):
 		#  imagemap db should be sys_id instead of mac_addr
@@ -1006,12 +1069,12 @@ class ResourceQuerySql(InfoStore):
 		if len(row) < 1: 
 			mesg = "ERROR: Image \"" + image + "\" does not exist"
 			self.log.error(mesg)
-			exit()
+			return 
 		new_image_id = str(row[0][0])
 
 		#  check for entry and delete in exists
 		query = "select * from imagemap where mac_addr = \"" + host['mac_addr'] + "\""
-		result = self.__selectDb(query)
+		result = self.selectDb(query)
 		if result.rowcount > 0:
 			query = "delete from imagemap where mac_addr = \"" + host['mac_addr'] + "\""
 			result = self.__deleteDb(query)
@@ -1019,10 +1082,11 @@ class ResourceQuerySql(InfoStore):
 
 		#  update the database entry with the new image for the host
 		query = "insert into imagemap (mac_addr, image_id) values (\"" + host['mac_addr'] + "\", " + new_image_id + ")"
-		self.__insertDb(query)
+		self.insertDb(query)
 		
 
 		#  Update tftp link
+		#  XXX move to pxe.py
 		mac_addr = "01-" + string.lower(string.replace(host['mac_addr'], ":", "-"))
 		maclink = self.tftpImageDir + "/" + mac_addr
 		#print "mac link is ", maclink
@@ -1055,6 +1119,33 @@ class ResourceQuerySql(InfoStore):
 
 		return 0
 
+
+	def getHardwareCapabilities(self, nodeName):
+		'''  getHardwareCapabilities return a list of lists with
+			[0] = hw method
+			[1] = hw method userid
+			[2] = hw method password  '''
+
+		sysId = self.getSysIdFromLocation(nodeName)	
+		query = "select h.hw_type, h.hw_userid, h.hw_password from hardwareinfo h, portmap p where p.hw_id = h.hw_id and p.sys_id = '%s'" % sysId
+		result = self.selectDb(query)
+		cap = []
+		val = []
+		for i in result.fetchall():
+			if i[0] in self.config['hardwareControl']:
+				val.append(i)
+
+		# order the hardware capabilities according to order in config file
+		for i in [j for j in self.config['hardwareControl']]:
+			for j in val:
+				if i in j:	
+					cap.append(j)
+		return cap
+
+	#  print out data in a consistent format
+	def __showIt(data):
+		pass
+
 	
 	def registerHardware(self, data):
 
@@ -1084,7 +1175,7 @@ class ResourceQuerySql(InfoStore):
 					statement += "'" + i + "') "
 				count += 1
 			try:
-				self.__insertDb(statement)
+				self.insertDb(statement)
 				mesg = "Device (%s) registered successfully\n" % (data['hw_name'])
 				self.log.info(mesg)
 			except Exception, e:

Propchange: incubator/tashi/trunk/src/zoni/data/resourcequerysql.py
            ('svn:mergeinfo' removed)

Modified: incubator/tashi/trunk/src/zoni/data/usermanagement.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/data/usermanagement.py?rev=1177661&r1=1177660&r2=1177661&view=diff
==============================================================================
--- incubator/tashi/trunk/src/zoni/data/usermanagement.py (original)
+++ incubator/tashi/trunk/src/zoni/data/usermanagement.py Fri Sep 30 13:47:21 2011
@@ -111,11 +111,31 @@ class ldap(UserManagementInterface):
 
 class files(UserManagementInterface):
 	def __init__(self):
-		raise NotImplementedError
+		pass
 
 
-	def getUserId(self):
-		raise NotImplementedError
+	def getUserId(self, userName=None):
+		if userName == None:
+			return os.getuid()
+		cmd = "cat /etc/passwd "
+		a = os.popen(cmd)
+		for line in a.readlines():
+			if userName in line :
+				return line.split(":")[2]
+		return 0
+
+
+	def getUserName(self, userId=None):
+		if userId == None:
+			return os.getenv('USERNAME')
+		cmd = "cat /etc/passwd "
+		a = os.popen(cmd)
+		for line in a.readlines():
+			if userName in line :
+				return line.split(":")[0]
+
+		return 0
+
 
 	def getGroupId(self):
-		raise NotImplementedError
+		pass

Propchange: incubator/tashi/trunk/src/zoni/data/usermanagement.py
            ('svn:mergeinfo' removed)

Propchange: incubator/tashi/trunk/src/zoni/data/usermanagementinterface.py
            ('svn:mergeinfo' removed)