@@ -89,9 +89,14 @@ def __init__(self, filename):
8989
9090 def load (self ):
9191 self .new_config = []
92- for line in open (self .filename ):
93- self .new_config .append (line )
94- logging .debug ("Reading file %s" % self .filename )
92+ try :
93+ for line in open (self .filename ):
94+ self .new_config .append (line )
95+ except IOError :
96+ logging .debug ("File %s does not exist" % self .filename )
97+ return
98+ else :
99+ logging .debug ("Reading file %s" % self .filename )
95100
96101 def is_changed (self ):
97102 return self .changed
@@ -243,6 +248,30 @@ def find(self):
243248 self .pid .append (re .split ("\s+" , i )[1 ])
244249 return len (self .pid ) > 0
245250
251+ class CsPassword (object ):
252+ """
253+ Update the password cache
254+
255+ A stupid step really as we should just rewrite the password server to
256+ use the databag
257+ """
258+ cache = "/var/cache/cloud/passwords"
259+
260+ def __init__ (self ):
261+ db = dataBag ()
262+ db .setKey ("vmpassword" )
263+ db .load ()
264+ dbag = db .getDataBag ()
265+ file = CsFile (self .cache )
266+ for item in dbag :
267+ if item == "id" :
268+ continue
269+ self .update (file , item , dbag [item ])
270+ file .commit ()
271+
272+ def update (self , file , ip , password ):
273+ file .search ("%s=" % ip , "%s=%s" % (ip , password ))
274+
246275class CsApp :
247276 def __init__ (self , ip ):
248277 self .dev = ip .getDevice ()
@@ -615,7 +644,6 @@ def arpPing(self):
615644 # Delete any ips that are configured but not in the bag
616645 def compare (self , bag ):
617646 if len (self .iplist ) > 0 and (not self .dev in bag .keys () or len (bag [self .dev ]) == 0 ):
618- print "Gets here"
619647 # Remove all IPs on this device
620648 logging .info ("Will remove all configured addresses on device %s" , self .dev )
621649 self .delete ("all" )
@@ -625,7 +653,6 @@ def compare(self, bag):
625653 # This condition should not really happen but did :)
626654 # It means an apache file got orphaned after a guest network address was deleted
627655 if len (self .iplist ) == 0 and (not self .dev in bag .keys () or len (bag [self .dev ]) == 0 ):
628- print self .dev
629656 app = CsApache (self )
630657 app .remove ()
631658
@@ -660,6 +687,8 @@ def main(argv):
660687 format = '%(asctime)s %(message)s' )
661688
662689 # we need to parse the cmd_line often, cloudstack might change it between reboots
690+
691+ # TODO - Take this out --------------------------------------------------------------------- #
663692 cmdLine = dataBag ()
664693 cmdLine .setKey ("cmd_line" )
665694 cmdLine .load ()
@@ -683,6 +712,7 @@ def main(argv):
683712 controlIp ["nic_dev_id" ] = 0
684713 controlIp ["nw_type" ] = "control"
685714 merge (dbag , controlIp )
715+ # ----------------------------------------------------------------------------------------- #
686716
687717
688718 for dev in CsDevice ('' ).list ():
@@ -704,6 +734,7 @@ def main(argv):
704734 logging .info ("Address %s on device %s not configured" , ip .ip (), dev )
705735 if CsDevice (dev ).waitfordevice ():
706736 ip .configure ()
737+ CsPassword ()
707738
708739if __name__ == "__main__" :
709740 main (sys .argv )
0 commit comments