Barring the OVS difference, it looks to me that you are perpetuating a
copy-paste crime. Would you mind abstracting what you can into a function?
Pretty please?


On Wed, Apr 9, 2014 at 9:53 AM, Jose A. Lopes <[email protected]> wrote:

> * add path to the 'xen-ifup-os' script that configures interfaces
> * fix if-elif construct
> * generate names of the form 'gnt.com.%d' for instance communication TAP
> interfaces
> * add 'vifname' property to the 'vif' field of the configuration of a
> domain
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  lib/hypervisor/hv_xen.py | 34 +++++++++++++++++++++++++++++++++-
>  lib/pathutils.py         |  1 +
>  2 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
> index 88ee37a..68bd95f 100644
> --- a/lib/hypervisor/hv_xen.py
> +++ b/lib/hypervisor/hv_xen.py
> @@ -365,6 +365,24 @@ def _QuoteCpuidField(data):
>    return "'%s'" % data if data.startswith("host") else data
>
>
> +def _ConfigureNIC(instance, seq, nic, tap):
> +  """Run the network configuration script for a specified NIC
> +
> +  See L{hv_base.ConfigureNIC}.
> +
> +  @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
> +
> +  """
> +  hv_base.ConfigureNIC(pathutils.XEN_IFUP_OS, instance, seq, nic, tap)
> +
> +
>  class XenHypervisor(hv_base.BaseHypervisor):
>    """Xen generic hypervisor interface
>
> @@ -661,6 +679,10 @@ class XenHypervisor(hv_base.BaseHypervisor):
>                                     (instance.name, result.fail_reason,
>                                      result.output, stashed_config))
>
> +    for nic_seq, nic in enumerate(instance.nics):
> +      if nic.name and nic.name.startswith("gnt.com."):
> +        _ConfigureNIC(instance, nic_seq, nic, nic.name)
> +
>    def StopInstance(self, instance, force=False, retry=False, name=None,
>                     timeout=None):
>      """Stop an instance.
> @@ -1185,10 +1207,15 @@ class XenPvmHypervisor(XenHypervisor):
>          nic_str += ", ip=%s" % ip
>        if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
>          nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK]
> -      if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_OVS:
> +      elif nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_OVS:
>          nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK]
>          if nic.nicparams[constants.NIC_VLAN]:
>            nic_str += "%s" % nic.nicparams[constants.NIC_VLAN]
> +      if nic.name and \
> +
>  nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX):
> +        tap = hv_base.GenerateTapName()
> +        nic_str += ", vifname=%s" % tap
> +        nic.name = tap
>        if hvp[constants.HV_VIF_SCRIPT]:
>          nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT]
>        vif_data.append("'%s'" % nic_str)
> @@ -1365,6 +1392,11 @@ class XenHvmHypervisor(XenHypervisor):
>          nic_str += ", ip=%s" % ip
>        if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
>          nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK]
> +      if nic.name and \
> +
>  nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX):
> +        tap = hv_base.GenerateTapName()
> +        nic_str += ", vifname=%s" % tap
> +        nic.name = tap
>        if hvp[constants.HV_VIF_SCRIPT]:
>          nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT]
>        vif_data.append("'%s'" % nic_str)
> diff --git a/lib/pathutils.py b/lib/pathutils.py
> index 6ef1ca7..67ac41d 100644
> --- a/lib/pathutils.py
> +++ b/lib/pathutils.py
> @@ -100,6 +100,7 @@ RAPI_USERS_FILE = DATA_DIR + "/rapi/users"
>  QUEUE_DIR = DATA_DIR + "/queue"
>  INTENT_TO_UPGRADE = DATA_DIR + "/intent-to-upgrade"
>  CONF_DIR = SYSCONFDIR + "/ganeti"
> +XEN_IFUP_OS = CONF_DIR + "/xen-ifup-os"
>  USER_SCRIPTS_DIR = CONF_DIR + "/scripts"
>  VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
>  HOOKS_BASE_DIR = CONF_DIR + "/hooks"
> --
> 1.9.1.423.g4596e3a
>
>

Reply via email to