[libvirt] [PATCHv2 5/7] interface: expose network config transaction API to virsh

Daniel P. Berrange berrange at redhat.com
Thu May 26 08:31:31 UTC 2011


On Thu, May 19, 2011 at 04:51:27PM -0400, Laine Stump wrote:
> From: Michal Privoznik <mprivozn at redhat.com>
> 
> This implements the commands iface-begin, iface-commit, and iface-rollback,
> which simply call the corresponding functions in the libvirt API.
> ---
>  tools/virsh.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 103 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index c2f4de6..6d72c75 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -5118,6 +5118,103 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
>      return ret;
>  }
>  
> +/*
> + * "iface-begin" command
> + */
> +static const vshCmdInfo info_interface_begin[] = {
> +    {"help", N_("create a snapshot of current interfaces settings, "
> +                "which can be later commited (iface-commit) or "
> +                "restored (iface-rollback)")},
> +    {"desc", N_("Create a restore point for interfaces settings")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_interface_begin[] = {
> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdInterfaceBegin(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> +{
> +    bool ret = false;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        goto end;
> +
> +    if (virInterfaceChangeBegin(ctl->conn, 0) < 0) {
> +        vshError(ctl, "%s", _("Failed to begin network config change transaction"));
> +    } else {
> +        vshPrint(ctl, "%s", _("Network config change transaction started\n"));
> +        ret = true;
> +    }
> +
> +end:
> +    return ret;
> +}
> +
> +/*
> + * "iface-commit" command
> + */
> +static const vshCmdInfo info_interface_commit[] = {
> +    {"help", N_("commit changes made since iface-begin and free restore point")},
> +    {"desc", N_("commit changes and free restore point")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_interface_commit[] = {
> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdInterfaceCommit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> +{
> +    bool ret = false;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        goto end;
> +
> +    if (virInterfaceChangeCommit(ctl->conn, 0) < 0) {
> +        vshError(ctl, "%s", _("Failed to commit network config change transaction"));
> +    } else {
> +        vshPrint(ctl, "%s", _("Network config change transaction committed\n"));
> +        ret = true;
> +    }
> +
> +end:
> +    return ret;
> +}
> +
> +/*
> + * "iface-rollback" command
> + */
> +static const vshCmdInfo info_interface_rollback[] = {
> +    {"help", N_("rollback to previous saved configuration created via iface-begin")},
> +    {"desc", N_("rollback to previous restore point")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_interface_rollback[] = {
> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> +{
> +    bool ret = false;
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        goto end;
> +
> +    if (virInterfaceChangeRollback(ctl->conn, 0) < 0) {
> +        vshError(ctl, "%s", _("Failed to rollback network config change transaction"));
> +    } else {
> +        vshPrint(ctl, "%s", _("Network config change transaction rolled back\n"));
> +        ret = true;
> +    }
> +
> +end:
> +    return ret;
> +}


The code patterns in these methods are rather different from the
normal practice used in virsh. Also 'end:' is also not following
the hacking guidelines for naming conventions. These methods
should be updated to follow the normal coding pattern. eg as
per the cmdCapabilities() method style

   static bool
   cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
   {
       if (!vshConnectionUsability(ctl, ctl->conn))
           return false;
   
       if (virInterfaceChangeRollback(ctl->conn, 0) < 0) {
           vshError(ctl, "%s", _("Failed to rollback network config change transaction"));
           return false;
       }

       vshPrint(ctl, "%s", _("Network config change transaction rolled back\n"));
       return true;
   }


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list