On Tue, Apr 15, 2014 at 2:38 PM, Jose A. Lopes <[email protected]> wrote:

> ... so it can be reused by the Xen hypervisor.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  lib/hypervisor/hv_base.py         | 55
> ++++++++++++++++++++++++++++++++++++++-
>  lib/hypervisor/hv_kvm/__init__.py | 38 +++------------------------
>  2 files changed, 57 insertions(+), 36 deletions(-)
>
> diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
> index a945ef1..f7317fc 100644
> --- a/lib/hypervisor/hv_base.py
> +++ b/lib/hypervisor/hv_base.py
> @@ -42,9 +42,10 @@ import re
>  import logging
>
>
> +from ganeti import constants
>  from ganeti import errors
> +from ganeti import objects
>  from ganeti import utils
> -from ganeti import constants
>
>
>  def _IsCpuMaskWellFormed(cpu_mask):
> @@ -193,6 +194,58 @@ def GenerateTapName():
>    return "gnt.com.%d" % idx
>
>
> +def ConfigureNIC(cmd, instance, seq, nic, tap):
> +  """Run the network configuration script for a specified NIC
> +
> +  @type cmd: string
> +  @param cmd: command to run
> +  @type instance: instance object
> +  @param instance: instance we're acting on
> +  @type seq: int
> +  @param seq: nic sequence number
> +  @type nic: nic object
> +  @param nic: nic we're acting on
> +  @type tap: str
> +  @param tap: the host's tap interface this NIC corresponds to
> +
> +  """
> +  env = {
> +    "PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"],
> +    "INSTANCE": instance.name,
> +    "MAC": nic.mac,
> +    "MODE": nic.nicparams[constants.NIC_MODE],
> +    "INTERFACE": tap,
> +    "INTERFACE_INDEX": str(seq),
> +    "INTERFACE_UUID": nic.uuid,
> +    "TAGS": " ".join(instance.GetTags()),
> +  }
> +
> +  if nic.ip:
> +    env["IP"] = nic.ip
> +
> +  if nic.name:
> +    env["INTERFACE_NAME"] = nic.name
> +
> +  if nic.nicparams[constants.NIC_LINK]:
> +    env["LINK"] = nic.nicparams[constants.NIC_LINK]
> +
> +  if nic.nicparams[constants.NIC_VLAN]:
> +    env["VLAN"] = nic.nicparams[constants.NIC_VLAN]
> +
> +  if nic.network:
> +    n = objects.Network.FromDict(nic.netinfo)
> +    env.update(n.HooksDict())
> +
> +  if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
> +    env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
> +
> +  result = utils.RunCmd(cmd, env=env)
> +  if result.failed:
> +    raise errors.HypervisorError("Failed to configure interface %s: %s;"
> +                                 " network configuration script output:
> %s" %
> +                                 (tap, result.fail_reason, result.output))
> +
> +
>  class HvInstanceState(object):
>    RUNNING = 0
>    SHUTDOWN = 1
> diff --git a/lib/hypervisor/hv_kvm/__init__.py
> b/lib/hypervisor/hv_kvm/__init__.py
> index 34646d5..ac99fc5 100644
> --- a/lib/hypervisor/hv_kvm/__init__.py
> +++ b/lib/hypervisor/hv_kvm/__init__.py
> @@ -664,6 +664,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
>    def _ConfigureNIC(instance, seq, nic, tap):
>      """Run the network configuration script for a specified NIC
>
> +    See L{hv_base.ConfigureNIC}.
> +
>      @param instance: instance we're acting on
>      @type instance: instance object
>      @param seq: nic sequence number
> @@ -674,41 +676,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
>      @type tap: str
>
>      """
> -    env = {
> -      "PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"],
> -      "INSTANCE": instance.name,
> -      "MAC": nic.mac,
> -      "MODE": nic.nicparams[constants.NIC_MODE],
> -      "INTERFACE": tap,
> -      "INTERFACE_INDEX": str(seq),
> -      "INTERFACE_UUID": nic.uuid,
> -      "TAGS": " ".join(instance.GetTags()),
> -    }
> -
> -    if nic.ip:
> -      env["IP"] = nic.ip
> -
> -    if nic.name:
> -      env["INTERFACE_NAME"] = nic.name
> -
> -    if nic.nicparams[constants.NIC_LINK]:
> -      env["LINK"] = nic.nicparams[constants.NIC_LINK]
> -
> -    if nic.nicparams[constants.NIC_VLAN]:
> -      env["VLAN"] = nic.nicparams[constants.NIC_VLAN]
> -
> -    if nic.network:
> -      n = objects.Network.FromDict(nic.netinfo)
> -      env.update(n.HooksDict())
> -
> -    if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
> -      env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
> -
> -    result = utils.RunCmd([pathutils.KVM_IFUP, tap], env=env)
> -    if result.failed:
> -      raise errors.HypervisorError("Failed to configure interface %s: %s;"
> -                                   " network configuration script output:
> %s" %
> -                                   (tap, result.fail_reason,
> result.output))
> +    hv_base.ConfigureNIC([pathutils.KVM_IFUP, tap], instance, seq, nic,
> tap)
>
>    @staticmethod
>    def _VerifyAffinityPackage():
> --
> 1.9.1.423.g4596e3a
>
>
LGTM, thanks

Reply via email to