summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-03-18 08:01:07 +0000
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-03-18 08:01:07 +0000
commitdde92454697b23a02abd573feeea13fec0bd8a9a (patch)
tree7d082acbb041b340e586cf5cd1bb65de6613cbd8 /nova/virt
parentd1958f61e5573b6a4101564e6e4b1969000eccca (diff)
parentabe147f756f13d4f968aa075d709e5c6643d310a (diff)
merge trunk
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/libvirt_conn.py52
-rw-r--r--nova/virt/xenapi/vm_utils.py8
-rw-r--r--nova/virt/xenapi/vmops.py42
3 files changed, 62 insertions, 40 deletions
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 7994e9547..e80b9fbdf 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -502,7 +502,7 @@ class LibvirtConnection(object):
cmd = 'netcat', '0.0.0.0', port, '-w', '1'
try:
stdout, stderr = utils.execute(*cmd, process_input='')
- except ProcessExecutionError:
+ except exception.ProcessExecutionError:
return port
raise Exception(_('Unable to find an open port'))
@@ -984,32 +984,44 @@ class LibvirtConnection(object):
xml = self._conn.getCapabilities()
xml = libxml2.parseDoc(xml)
- nodes = xml.xpathEval('//cpu')
+ nodes = xml.xpathEval('//host/cpu')
if len(nodes) != 1:
raise exception.Invalid(_("Invalid xml. '<cpu>' must be 1,"
"but %d\n") % len(nodes)
+ xml.serialize())
cpu_info = dict()
- cpu_info['arch'] = xml.xpathEval('//cpu/arch')[0].getContent()
- cpu_info['model'] = xml.xpathEval('//cpu/model')[0].getContent()
- cpu_info['vendor'] = xml.xpathEval('//cpu/vendor')[0].getContent()
- topology_node = xml.xpathEval('//cpu/topology')[0].get_properties()
+ arch_nodes = xml.xpathEval('//host/cpu/arch')
+ if arch_nodes:
+ cpu_info['arch'] = arch_nodes[0].getContent()
+
+ model_nodes = xml.xpathEval('//host/cpu/model')
+ if model_nodes:
+ cpu_info['model'] = model_nodes[0].getContent()
+
+ vendor_nodes = xml.xpathEval('//host/cpu/vendor')
+ if vendor_nodes:
+ cpu_info['vendor'] = vendor_nodes[0].getContent()
+
+ topology_nodes = xml.xpathEval('//host/cpu/topology')
topology = dict()
- while topology_node != None:
- name = topology_node.get_name()
- topology[name] = topology_node.getContent()
- topology_node = topology_node.get_next()
-
- keys = ['cores', 'sockets', 'threads']
- tkeys = topology.keys()
- if list(set(tkeys)) != list(set(keys)):
- ks = ', '.join(keys)
- raise exception.Invalid(_("Invalid xml: topology(%(topology)s) "
- "must have %(ks)s") % locals())
-
- feature_nodes = xml.xpathEval('//cpu/feature')
+ if topology_nodes:
+ topology_node = topology_nodes[0].get_properties()
+ while topology_node:
+ name = topology_node.get_name()
+ topology[name] = topology_node.getContent()
+ topology_node = topology_node.get_next()
+
+ keys = ['cores', 'sockets', 'threads']
+ tkeys = topology.keys()
+ if set(tkeys) != set(keys):
+ ks = ', '.join(keys)
+ raise exception.Invalid(_("Invalid xml: topology"
+ "(%(topology)s) must have "
+ "%(ks)s") % locals())
+
+ feature_nodes = xml.xpathEval('//host/cpu/feature')
features = list()
for nodes in feature_nodes:
features.append(nodes.get_properties().getContent())
@@ -1597,6 +1609,8 @@ class IptablesFirewallDriver(FirewallDriver):
self.iptables.ipv4['filter'].add_chain('sg-fallback')
self.iptables.ipv4['filter'].add_rule('sg-fallback', '-j DROP')
+ self.iptables.ipv6['filter'].add_chain('sg-fallback')
+ self.iptables.ipv6['filter'].add_rule('sg-fallback', '-j DROP')
def setup_basic_filtering(self, instance):
"""Use NWFilter from libvirt for this."""
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index e308072fb..7e976e37a 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -233,7 +233,8 @@ class VMHelper(HelperBase):
raise StorageError(_('Unable to destroy VBD %s') % vbd_ref)
@classmethod
- def create_vif(cls, session, vm_ref, network_ref, mac_address, dev="0"):
+ def create_vif(cls, session, vm_ref, network_ref, mac_address,
+ dev="0", rxtx_cap=0):
"""Create a VIF record. Returns a Deferred that gives the new
VIF reference."""
vif_rec = {}
@@ -244,8 +245,9 @@ class VMHelper(HelperBase):
vif_rec['MAC'] = mac_address
vif_rec['MTU'] = '1500'
vif_rec['other_config'] = {}
- vif_rec['qos_algorithm_type'] = ''
- vif_rec['qos_algorithm_params'] = {}
+ vif_rec['qos_algorithm_type'] = "ratelimit" if rxtx_cap else ''
+ vif_rec['qos_algorithm_params'] = \
+ {"kbps": str(rxtx_cap * 1024)} if rxtx_cap else {}
LOG.debug(_('Creating VIF for VM %(vm_ref)s,'
' network %(network_ref)s.') % locals())
vif_ref = session.call_xenapi('VIF.create', vif_rec)
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index b82efc512..e3160e71e 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -19,6 +19,7 @@
Management class for VM-related functions (spawn, reboot, etc).
"""
+import base64
import json
import M2Crypto
import os
@@ -136,19 +137,20 @@ class VMOps(object):
LOG.info(_('Spawning VM %(instance_name)s created %(vm_ref)s.')
% locals())
- def _inject_onset_files():
- onset_files = instance.onset_files
- if onset_files:
+ def _inject_files():
+ injected_files = instance.injected_files
+ if injected_files:
# Check if this is a JSON-encoded string and convert if needed.
- if isinstance(onset_files, basestring):
+ if isinstance(injected_files, basestring):
try:
- onset_files = json.loads(onset_files)
+ injected_files = json.loads(injected_files)
except ValueError:
- LOG.exception(_("Invalid value for onset_files: '%s'")
- % onset_files)
- onset_files = []
+ LOG.exception(
+ _("Invalid value for injected_files: '%s'")
+ % injected_files)
+ injected_files = []
# Inject any files, if specified
- for path, contents in instance.onset_files:
+ for path, contents in instance.injected_files:
LOG.debug(_("Injecting file path: '%s'") % path)
self.inject_file(instance, path, contents)
# NOTE(armando): Do we really need to do this in virt?
@@ -164,7 +166,7 @@ class VMOps(object):
if state == power_state.RUNNING:
LOG.debug(_('Instance %s: booted'), instance_name)
timer.stop()
- _inject_onset_files()
+ _inject_files()
return True
except Exception, exc:
LOG.warn(exc)
@@ -408,17 +410,16 @@ class VMOps(object):
raise RuntimeError(resp_dict['message'])
return resp_dict['message']
- def inject_file(self, instance, b64_path, b64_contents):
+ def inject_file(self, instance, path, contents):
"""Write a file to the VM instance. The path to which it is to be
- written and the contents of the file need to be supplied; both should
+ written and the contents of the file need to be supplied; both will
be base64-encoded to prevent errors with non-ASCII characters being
transmitted. If the agent does not support file injection, or the user
has disabled it, a NotImplementedError will be raised.
"""
- # Files/paths *should* be base64-encoded at this point, but
- # double-check to make sure.
- b64_path = utils.ensure_b64_encoding(b64_path)
- b64_contents = utils.ensure_b64_encoding(b64_contents)
+ # Files/paths must be base64-encoded for transmission to agent
+ b64_path = base64.b64encode(path)
+ b64_contents = base64.b64encode(contents)
# Need to uniquely identify this request.
transaction_id = str(uuid.uuid4())
@@ -743,8 +744,12 @@ class VMOps(object):
Creates vifs for an instance
"""
- vm_ref = self._get_vm_opaque_ref(instance.id)
+ vm_ref = self._get_vm_opaque_ref(instance['id'])
+ admin_context = context.get_admin_context()
+ flavor = db.instance_type_get_by_name(admin_context,
+ instance.instance_type)
logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref)
+ rxtx_cap = flavor['rxtx_cap']
if networks is None:
networks = db.network_get_all_by_instance(admin_context,
instance['id'])
@@ -772,7 +777,8 @@ class VMOps(object):
device = "0"
VMHelper.create_vif(self._session, vm_ref, network_ref,
- instance.mac_address, device)
+ instance.mac_address, device,
+ rxtx_cap=rxtx_cap)
def reset_network(self, instance):
"""