diff options
| author | Arvind Somy <asomya@cisco.com> | 2011-06-17 15:12:01 -0400 |
|---|---|---|
| committer | Arvind Somy <asomya@cisco.com> | 2011-06-17 15:12:01 -0400 |
| commit | c3af5e65508fb325a4a8e350c9ed6d84d87e7cd8 (patch) | |
| tree | 2897cb3283e490d9b747da705fbc8c74aafca650 | |
| parent | faed18358f534ed7a743fcd168d649d06da092ab (diff) | |
Fix for lp:796834
- Fixes and enhancements to the ESX(i) guest_tool.py script.
| -rw-r--r-- | nova/virt/vmwareapi/vm_util.py | 4 | ||||
| -rw-r--r-- | nova/virt/vmwareapi/vmops.py | 5 | ||||
| -rw-r--r-- | tools/esx/guest_tool.py | 49 |
3 files changed, 53 insertions, 5 deletions
diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index d23472469..c823ac710 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -287,9 +287,9 @@ def get_dummy_vm_create_spec(client_factory, name, data_store_name): return config_spec
-def get_machine_id_change_spec(client_factory, mac, ip_addr, netmask, gateway):
+def get_machine_id_change_spec(client_factory, mac, ip_addr, netmask, gateway, broadcast, dns):
"""Builds the machine id change config spec."""
- machine_id_str = "%s;%s;%s;%s" % (mac, ip_addr, netmask, gateway)
+ machine_id_str = "%s;%s;%s;%s;%s;%s" % (mac, ip_addr, netmask, gateway, broadcast, dns)
virtual_machine_config_spec = \
client_factory.create('ns0:VirtualMachineConfigSpec')
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index d23edbdf8..9f2a36bf4 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -715,11 +715,14 @@ class VMWareVMOps(object): mac_addr = instance.mac_address
net_mask = network["netmask"]
gateway = network["gateway"]
+ broadcast = network["broadcast"]
+ dns = network["dns"]
ip_addr = db.instance_get_fixed_address(context.get_admin_context(),
instance['id'])
machine_id_chanfge_spec = \
vm_util.get_machine_id_change_spec(client_factory, mac_addr,
- ip_addr, net_mask, gateway)
+ ip_addr, net_mask, gateway,
+ broadcast, dns)
LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id "
"with ip - %(ip_addr)s") %
({'name': instance.name,
diff --git a/tools/esx/guest_tool.py b/tools/esx/guest_tool.py index 13b0f8d33..e126721d5 100644 --- a/tools/esx/guest_tool.py +++ b/tools/esx/guest_tool.py @@ -21,6 +21,7 @@ On Windows we require pyWin32 installed on Python. """
import array
+import gettext
import logging
import os
import platform
@@ -30,6 +31,8 @@ import subprocess import sys
import time
+_ = gettext.gettext
+
PLATFORM_WIN = 'win32'
PLATFORM_LINUX = 'linux2'
ARCH_32_BIT = '32bit'
@@ -314,6 +317,43 @@ def _set_rhel_networking(network_details=[]): dns_file.close()
_execute(['/sbin/service', 'network', 'restart'])
+def _set_ubuntu_networking(network_details=[]):
+ """ Set IPv4 network settings for Ubuntu """
+ all_dns_servers = []
+ for network_detail in network_details:
+ mac_address, ip_address, subnet_mask, gateway, broadcast,\
+ dns_servers = network_detail
+ all_dns_servers.extend(dns_servers)
+ adapter_name, current_ip_address = \
+ _get_linux_adapter_name_and_ip_address(mac_address)
+
+ if adapter_name and not ip_address == current_ip_address:
+ interface_file_name = \
+ '/etc/network/interfaces'
+ # Remove file
+ os.remove(interface_file_name)
+ # Touch file
+ _execute(['touch', interface_file_name])
+ interface_file = open(interface_file_name, 'w')
+ interface_file.write('\nauto %s' % adapter_name)
+ interface_file.write('\niface %s inet static' % adapter_name)
+ interface_file.write('\nbroadcast %s' % broadcast)
+ interface_file.write('\ngateway %s' % gateway)
+ interface_file.write('\nnetmask %s' % subnet_mask)
+ interface_file.write('\naddress %s' % ip_address)
+ interface_file.close()
+ if all_dns_servers:
+ dns_file_name = "/etc/resolv.conf"
+ os.remove(dns_file_name)
+ _execute(['touch', dns_file_name])
+ dns_file = open(dns_file_name, 'w')
+ dns_file.write("; generated by OpenStack guest tools")
+ unique_entries = _filter_duplicates(all_dns_servers)
+ for dns_server in unique_entries:
+ dns_file.write("\nnameserver %s" % dns_server)
+ dns_file.close()
+ print "\nRestarting networking....\n"
+ _execute(['/etc/init.d/networking', 'restart'])
def _linux_set_networking():
"""Set IP address for the Linux VM."""
@@ -330,8 +370,13 @@ def _linux_set_networking(): cmd = [vmware_tools_bin, '--cmd', 'machine.id.get']
network_details = _parse_network_details(_execute(cmd,
check_exit_code=False))
- # TODO(sateesh): For other distros like ubuntu, suse, debian, BSD, etc.
- _set_rhel_networking(network_details)
+ # TODO(sateesh): For other distros like suse, debian, BSD, etc.
+ if(platform.dist()[0] == 'Ubuntu') :
+ _set_ubuntu_networking(network_details)
+ elif (platform.dist()[0] == 'redhat') :
+ _set_rhel_networking(network_details)
+ else:
+ logging.warn(_("Distro '%s' not supported") % platform.dist()[0])
else:
logging.warn(_("VMware Tools is not installed"))
|
