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

Michael DeHaan mdehaan at redhat.com
Wed Aug 15 19:18:25 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  13e7db8f7a8daf06864e3b845dd7fe305556cd05 (commit)
       via  137ec61519b2e116fb8c0356a9d48610bf3f5d53 (commit)
      from  898c9c79e0889f837a792b42a86b4cb4294d0e6b (commit)

- Log -----------------------------------------------------------------
commit 13e7db8f7a8daf06864e3b845dd7fe305556cd05
Merge: 137ec61... 898c9c7...
Author: Michael DeHaan <mdehaan at redhat.com>
Date:   Wed Aug 15 15:14:07 2007 -0400

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

commit 137ec61519b2e116fb8c0356a9d48610bf3f5d53
Author: Michael DeHaan <mdehaan at redhat.com>
Date:   Wed Aug 15 15:13:52 2007 -0400

    Added flag to vf_register for --allow-bridge-config.  If specified, it will
    set up a virtual networking bridge (if one does not already exist) for the interface that was used to access the --serverurl.  This ensures that we bridge
    the right interface.  We will use this for the default PXE kickstart templates
    and it's up to the admin if they want to use this for existing systems.  It will generally DRT but they may want to set up the network manually.  If they do that, they'll have to check to see if koan/virtinst is happy later on down the pipe.
-----------------------------------------------------------------------

Diffstat:
 register/register/machine_info.py |   13 ++++-
 register/register/register.py     |  111 +++++++++++++++++++++++++++++++++----
 2 files changed, 112 insertions(+), 12 deletions(-)

diff --git a/register/register/machine_info.py b/register/register/machine_info.py
index 4606b4d..b140c4d 100755
--- a/register/register/machine_info.py
+++ b/register/register/machine_info.py
@@ -63,11 +63,22 @@ def findHostByRoute(server_url, proxy_url=None):
 def get_netinfo(server_url, proxy_url=None):
     machine_data = read_network(server_url, proxy_url)
     net_interfaces = read_network_interfaces()
+    
+    print "-- DEBUG(FIXME): %s" % net_interfaces
 
     ip_addr = machine_data['ipaddr']
     hwaddr = get_hwaddr_for_route(ip_addr, net_interfaces)
 
-    return {'ipaddr': ip_addr, 'hwaddr':hwaddr, 'hostname': machine_data['hostname']}
+    found_intf = None
+    for x in net_interfaces.keys():
+        if (type(net_interfaces[x]) == dict) and net_interfaces[x].get('ipaddr','MISSING') == ip_addr:
+            found_intf = x
+            break
+
+    if not found_intf:
+        raise "Unable to find interface for %s" % ip_addr
+
+    return {'ipaddr': ip_addr, 'hwaddr':hwaddr, 'hostname': machine_data['hostname'], 'interface' : found_intf}
 
 def get_hwaddr_for_route(ip_addr, net_interfaces):
     for intf in net_interfaces.keys():
diff --git a/register/register/register.py b/register/register/register.py
index 773283c..429b46c 100755
--- a/register/register/register.py
+++ b/register/register/register.py
@@ -62,8 +62,12 @@ class Register(object):
         self.server_host = self.server_host.split(':')[0]
         self.logger = logger.Logger().logger
         self.net_info = machine_info.get_netinfo(self.server_url)
+        self.my_hostname = self.net_info['hostname']
+        self.my_interface = self.net_info['interface'] 
+        self.my_mac = self.net_info['hwaddr']
         self.logger.info(self.net_info)
-        self.server = Server(client=self.net_info['hostname'], host=self.server_host)
+
+        self.server = Server(client=self.my_hostname, host=self.server_host)
         self.token = None
 
     # assume username/password exist, so no user creation race conditions to avoid
@@ -187,12 +191,93 @@ class Register(object):
         file.write("PUPPET_SERVER=%s\n" % server)
         file.close()
 
-    def register_system(self, regtoken, username, password, profile_name, virtual):
+    def fix_network_bridging(self):
+
+        """
+        For virtual systems the target interface used for communication
+        with the server must be a bridge and not a physical interface.
+        If it is NOT a bridge, fix it.  Otherwise we can't install
+        virtual nodes. 
+        """
+
+        # first, see if a configuration file for the chosen interface
+        # exists.  If not, this is bad, and we must quit now.
+
+        filename = "/etc/sysconfig/network-scripts/ifcfg-%s" % self.my_interface
+        if not os.path.exists(filename):
+           self.logger.info("Missing config file: %s" % filename)
+           sys.exit(1)
+
+        intf = self.my_interface
+
+        # now check to see if the configuration seems to specify that the
+        # given interface is /already/ a bridge. If so, we're happy,
+        # and can continue.
+        interface_spec = open(filename, "r")
+        interface_data = interface_spec.read()
+        interface_spec.close()
+
+        cmd = subprocess.Popen("/sbin/ifconfig", shell=True, stdout=subprocess.PIPE)
+        data = cmd.communicate()[0]
+        if data.find("xenbr0") != -1:
+            self.logger.info("- Looks like you have a xenbr0, assuming ok...")
+            return
+
+        if interface_data.find("Bridge") != -1:
+            # life is good
+            self.logger.info("- It looks like you already have a Bridge, assuming ok...")
+
+            return
+        else:
+            # we have to make a new network bridge and tell the current
+            # interface to use that bridge, the user will want to restart
+            # the network but we'll be doing this from kickstart most
+            # of the time so it's totally unneccessary.  Something to
+            # document, at worst...
+              
+            self.logger.info("- %s will no longer be a physical device" % intf)
+
+            filename2 = "/etc/sysconfig/network-scripts/ifcfg-p%s" % intf
+            self.logger.info("- new physical device: p%s" % intf)
+            # write the new physical config
+            physical_file = open(filename2,"w+")
+            physical_file.write("TYPE=Ethernet\n")
+            physical_file.write("HWADDR=%s\n" % self.my_mac.upper())
+            physical_file.write("DEVICE=p%s\n" % intf)
+            physical_file.write("BRIDGE=%s\n" % intf)
+            physical_file.write("ONBOOT=yes\n")
+
+            self.logger.info("- new network bridge: %s" % intf)
+            # write the new bridge config
+            bridge_file = open(filename,"w+")
+            bridge_file.write("DEVICE=%s\n" % intf)
+            bridge_file.write("ONBOOT=yes\n")
+            bridge_file.write("TYPE=Bridge\n")
+            bridge_file.write("BOOTPROTO=dhcp\n")
+
+            self.logger.info("- /sbin/service network restart or reboot to apply changes")
+
+            # all good
+            return
+
+    def register_system(self, regtoken, username, password, profile_name, virtual, bridge_config_ok):
         if regtoken:
             self.token = regtoken
         else:
             self.login(username, password)
 
+        if not virtual and bridge_config_ok:
+
+            # this may possibly be a virtual host (we aren't sure)
+            # but if so we'll need a network bridge.  If not, it will
+            # not hurt anything (unless possibly the admin already had
+            # bridging configured).  Too many corner cases so let's
+            # deal with that when we come to it.  we want this to be
+            # as easy to set up as possible.
+
+            print "- warning: reconfiguring networking as needed"
+            self.fix_network_bridging()
+
         try:
             rc = self.register(self.net_info['hostname'], self.net_info['ipaddr'], self.net_info['hwaddr'], profile_name, virtual)
         except socket.error:
@@ -218,12 +303,13 @@ def showHelp():
 
 def main(argv):
 
-    regtoken   = "UNSET"
-    username   = None
-    password   = None
-    server_url = None
-    profile_name = ""
-    virtual      = False
+    regtoken         = "UNSET"
+    username         = None
+    password         = None
+    server_url       = None
+    profile_name     = ""
+    virtual          = False
+    bridge_config_ok = False
 
     # ensure we have somewhere to save parameters to, the node daemon will want
     # to know them later.
@@ -232,14 +318,15 @@ def main(argv):
         os.makedirs("/etc/sysconfig/virt-factory")
 
     try:
-        opts, args = getopt.getopt(argv[1:], "ht:u:p:s:P:v", [
+        opts, args = getopt.getopt(argv[1:], "ht:u:p:s:P:vB", [
             "help", 
             "token=", 
             "username=",
             "password=", 
             "serverurl=",
             "profilename=",
-            "virtual"
+            "virtual",
+            "allow-bridge-config"
         ])
     except getopt.error, e:
         print _("Error parsing command list arguments: %s") % e
@@ -264,6 +351,8 @@ def main(argv):
             profile_name = val
         if opt in ["-v", "--virtual"]:
             virtual = True
+        if opt in ["-n", "--allow-bridge-config"]:
+            bridge_config_ok = True
 
     if server_url is None:
         print _("must specify --serverurl, ex: http://foo.example.com:5150")
@@ -280,7 +369,7 @@ def main(argv):
 
     reg_obj = Register(server_url)
     profile_name = reg_obj.fix_profile_name(profile_name)
-    return_status = reg_obj.register_system(regtoken, username, password, profile_name, virtual)
+    return_status = reg_obj.register_system(regtoken, username, password, profile_name, virtual, bridge_config_ok)
     sys.exit(return_status)
 
 

hooks/update
---
Git Source Code Management System
hooks/update refs/heads/master \
  898c9c79e0889f837a792b42a86b4cb4294d0e6b \
  13e7db8f7a8daf06864e3b845dd7fe305556cd05




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