[Et-mgmt-commits-list] [SCM] virt-factory branch, master now at v0.0.3-199-gdd2ebc7

Michael DeHaan mdehaan at redhat.com
Thu Aug 23 21:24:03 UTC 2007


Hello,

This is an automated email from the git hooks/update script, it was
generated because a ref change was pushed to the repository.

Updating branch, master,
       via  dd2ebc76267e42f9f0633c11fb0de864fd9e10ed (commit)
       via  e787ef8163e73b43bddb28c95cccbee6b679bff2 (commit)
      from  713d42d7bcc636168c41d4328cee979b1d3c577d (commit)

- Log -----------------------------------------------------------------
commit dd2ebc76267e42f9f0633c11fb0de864fd9e10ed
Merge: e787ef8... 713d42d...
Author: Michael DeHaan <mdehaan at redhat.com>
Date:   Thu Aug 23 17:19:10 2007 -0400

    Merge branch 'master' of git+ssh://g-mdehaan@et.redhat.com/git/virt-factory

commit e787ef8163e73b43bddb28c95cccbee6b679bff2
Author: Michael DeHaan <mdehaan at redhat.com>
Date:   Thu Aug 23 17:19:00 2007 -0400

    Add logging to node status process (for now, will want to put this on logrotate
    eventually)
-----------------------------------------------------------------------

Diffstat:
 nodes/modules/virt.py         |    9 ------
 nodes/nodes/amqp_utils.py     |   20 ++++++++++++-
 nodes/nodes/server.py         |   64 ++++++++++++++++++++++++++++++++++++++--
 nodes/nodes/virt_utils.py     |    6 +++-
 service/modules/deployment.py |    2 +-
 5 files changed, 85 insertions(+), 16 deletions(-)

diff --git a/nodes/modules/virt.py b/nodes/modules/virt.py
index b6f85d7..90fc869 100755
--- a/nodes/modules/virt.py
+++ b/nodes/modules/virt.py
@@ -97,15 +97,6 @@ class Virt(web_svc.WebSvc):
             raise VirtException(comment="koan returned %d" % rc)
  
     #=======================================================================
-
-    def find_vm(self, mac_address):
-        # FIXME: should not be a reason to duplicate this here?
-        self.get_conn()
-        if self.conn is None:
-            raise VirtException(comment="no connection")
-        return self.conn.find_vm(mac_address)
-    
-    #=======================================================================
    
     def shutdown(self, mac_address):
         """
diff --git a/nodes/nodes/amqp_utils.py b/nodes/nodes/amqp_utils.py
index 44d47cb..2152ac8 100644
--- a/nodes/nodes/amqp_utils.py
+++ b/nodes/nodes/amqp_utils.py
@@ -28,7 +28,7 @@ import socket
 from busrpc.rpc import lookup_service
 from busrpc.crypto import CertManager
 import busrpc.qpid_transport
-
+import config_data
 
 class VirtFactoryAmqpConnection():
 
@@ -55,4 +55,22 @@ class VirtFactoryAmqpConnection():
         return data.strip()
    
     
+# this class is for AMQP communication to the parent server
+# borrowed from vf_register's source
+
+class Server:
+    def __init__(self, client=None, host=None):
+        transport = busrpc.qpid_transport.QpidTransport(host=host)
+        transport.connect()
+
+        # no crypto for now
+        #cm = CertManager('/var/lib/virt-factory/qpidcert', client)
+        cm = None
+        self.rpc_interface = lookup_service("rpc", transport, host=host, server_name="busrpc.virt-factory", cert_mgr=cm, use_bridge=False)
+        if self.rpc_interface == None:
+            print "Lookup failed :("
+            sys.exit(-1)
+
+    def __getattr__(self, name):
+        return self.rpc_interface.__getattr__(name)
 
diff --git a/nodes/nodes/server.py b/nodes/nodes/server.py
index 033085a..1179ed6 100755
--- a/nodes/nodes/server.py
+++ b/nodes/nodes/server.py
@@ -18,10 +18,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 import os
 import socket
 
-
 from rhpl.translate import _, N_, textdomain, utf8
 I18N_DOMAIN = "vf_node_server"
-
+SLEEP_INTERVAL = 15 
 SERVE_ON = (None,None)
 
 # FIXME: this app writes a logfile in /var/log/virt-factory/svclog -- package should use logrotate
@@ -35,6 +34,8 @@ import config_data
 import logger
 import module_loader
 import utils
+import virt_utils
+import amqp_utils
 
 from busrpc.services import RPCDispatcher
 from busrpc.config import DeploymentConfig
@@ -53,6 +54,9 @@ class Singleton(object):
             type._the_instance.init(*args, **kwargs)
         return type._the_instance
 
+def make_logger():
+        return logger.Logger().logger
+
 class XmlRpcInterface(Singleton):
 
     def init(self):
@@ -63,7 +67,7 @@ class XmlRpcInterface(Singleton):
         config_obj = config_data.Config()
         self.config = config_obj.get()
        
-        self.logger = logger.Logger().logger
+        self.logger = make_logger()
 
         self.__setup_handlers()
        
@@ -161,6 +165,52 @@ def serve_qpid(config_path):
          dispatcher.stop()
      print "Exiting..."
 
+def serve_status():
+
+     # serve monitoring status for the current node, and
+     # if applicable, any sub-nodes (guests)
+
+     logger = make_logger()
+
+     # establish upstream qpid connection
+     logger.info("STATUS FORK: init amqp")
+     amqp_conn = amqp_utils.VirtFactoryAmqpConnection()
+     logger.info("STATUS FORK: connect")
+     amqp_conn.connect()
+
+     while True:
+         try:
+             logger.info("STATUS FORK: loop")
+             try:
+                 # reconnect each time to avoid errors
+                 logger.info("STATUS FORK: connect to libvirt")
+                 virt_conn = virt_utils.VirtFactoryLibvirtConnection()
+             except:
+                 logger.info("STATUS FORK: could not connect to libvirt")
+                 continue         
+
+             vms = virt_conn.find_vm(-1)
+             for vm in vms:
+                 status = virt_conn.get_status2(vm)
+                 args = {
+                     "mac_address" : vm.name(),
+                     "state"       : status
+                 }
+                 logger.info("sending status: %s" % args)
+                 amqp_conn.server.deployment_set_state("UNSET", args)
+         
+             time.sleep(SLEEP_INTERVAL)
+         except:
+             (t, v, tb) = sys.exc_info()
+             logger.info("Exception occured: %s" % t )
+             logger.info("Exception value: %s" % v)
+             logger.info("Exception Info:\n%s" % string.join(traceback.format_list(traceback.extract_tb(tb))))
+             # FIXME
+             raise
+
+
+
+
 def main(argv):
     """
     Start things up.
@@ -173,8 +223,14 @@ def main(argv):
         utils.daemonize("/var/run/vf_node_server.pid")
     else:
         print _("serving...\n")
-    serve_qpid("/etc/virt-factory-nodes/qpid.conf")
 
+    pid = os.fork()
+    if pid == 0:
+        serve_qpid("/etc/virt-factory-nodes/qpid.conf")
+    else:
+        # FIXME: should probably sleep to allow AMQP to initialize
+        # in case of conflict???
+        serve_status()
 
 if __name__ == "__main__":
     _("test") # make gettext be quiet when there are no strings
diff --git a/nodes/nodes/virt_utils.py b/nodes/nodes/virt_utils.py
index e89adce..d6d8df8 100644
--- a/nodes/nodes/virt_utils.py
+++ b/nodes/nodes/virt_utils.py
@@ -109,7 +109,11 @@ class VirtFactoryLibvirtConnection():
 
     def undefine(self, mac_address):
         return self.find_vm(mac_address).undefine()
-   
+
+    def get_status2(self, vm):
+        state = vm.info()[1]
+        return VIRT_STATE_NAME_MAP.get(state,"unknown")  
+ 
     def get_status(self, mac_address):
         state = self.find_vm(mac_address).info()[1]
         return VIRT_STATE_NAME_MAP.get(state,"unknown")
diff --git a/service/modules/deployment.py b/service/modules/deployment.py
index a3454f8..689b646 100755
--- a/service/modules/deployment.py
+++ b/service/modules/deployment.py
@@ -390,8 +390,8 @@ class Deployment(web_svc.AuthWebSvc):
         deployment = db.Deployment.get(session, { "id" : id })
         results = self.expand(deployment)
 
-        self.logger.info("your deployment is: %s" % results)
         results["state"] = args["state"]
+        self.logger.info("setting deployment status: %s" % results)
         self.edit(token, results)
 
         return success(results)

hooks/update
---
Git Source Code Management System
hooks/update refs/heads/master \
  713d42d7bcc636168c41d4328cee979b1d3c577d \
  dd2ebc76267e42f9f0633c11fb0de864fd9e10ed




More information about the Et-mgmt-commits-list mailing list