[ovs-dev] [PATCH] ovs-external-ids: Better handle VIFs from recently resumed VMs

Reid Price reid at nicira.com
Tue Oct 26 01:15:30 UTC 2010


Does this script handle interfaces that are not vifs?  If it doesn't, you
can probably
drop the if_name portion altogether.  Looks good, made one suggestion to
catch
the exact XenAPI.Failure exception in-line.

  -Reid

On Mon, Oct 25, 2010 at 5:57 PM, Justin Pettit <jpettit at nicira.com> wrote:

> XAPI doesn't provide a way to look up a VIF entry based on the name, so
> we have to locate it by other methods.  Previously, we were breaking up
> the name into the domid and device number.  Unfortunately, it can take
> XAPI a few seconds to update the domid of the VM, when resuming from a
> suspend.  Since we have the VIF UUID, we can just look up the needed
> information directly based on that.
>
> Bug #3930
> ---
>  .../usr_share_openvswitch_scripts_ovs-external-ids |   26
> +++++++++----------
>  1 files changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-external-ids
> b/xenserver/usr_share_openvswitch_scripts_ovs-external-ids
> index 13c644f..1717a3f 100755
> --- a/xenserver/usr_share_openvswitch_scripts_ovs-external-ids
> +++ b/xenserver/usr_share_openvswitch_scripts_ovs-external-ids
> @@ -88,26 +88,24 @@ def get_bridge_id(br_name, default=None):
>  # same as "xs-vif-uuid".  This may be overridden by defining a
>  # "nicira-iface-id" key in the "other_config" field of the VIF
>  # record of XAPI.
> -def get_iface_id(if_name, default=None):
> +def get_iface_id(if_name, xs_vif_uuid):
>     if not if_name.startswith("vif"):
> -        return default
> -
> -    domain,device = if_name.strip("vif").split(".")
> +        # Treat whatever was passed into 'xs_vif_uuid' as a default
> +        # value for non-VIFs.
> +        return xs_vif_uuid
>
>     if not init_session():
>         s_log.warning("Failed to get interface id %s because"
>                 " XAPI session could not be initialized" % if_name)
> -        return default
> -
> -    for n in session.xenapi.VM.get_all():
> -        if session.xenapi.VM.get_domid(n) == domain:
> -            vifs = session.xenapi.VM.get_VIFs(n)
> -            for vif in vifs:
> -                rec = session.xenapi.VIF.get_record(vif)
> -                if rec['device'] == device:
> -                    return rec['other_config'].get('nicira-iface-id',
> default)
> -    return None
> +        return xs_vif_uuid
>
> +    try:
> +        vif = session.xenapi.VIF.get_by_uuid(xs_vif_uuid)
> +        rec = session.xenapi.VIF.get_record(vif)
> +        return rec['other_config'].get('nicira-iface-id', xs_vif_uuid)
> +    except:
> +        s_log.warning("Could not find XAPI entry for VIF %s" % if_name)
> +        return xs_vif_uuid
>

Probably want to catch the Failure directly, in case you end up killing in
the middle of that try, or there is some parsing error, etc, all of which
except will happily catch.

    try:
        vif = session.xenapi.VIF.get_by_uuid(xs_vif_uuid)
        oc = session.xenapi.VIF.get_other_config(vif)
        return oc.get('nicira-iface-id', xs_vif_uuid)
    except XenAPI.Failure:
        s_log.warning("Could not find XAPI entry for VIF %s" % if_name)
        return xs_vif_uuid

>
>  def set_external_id(table, record, key, value):
>     col = 'external-ids:"' + key + '"="' + value + '"'
> --
> 1.7.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20101025/7a6280a0/attachment-0003.html>


More information about the dev mailing list