You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

73 lines
2.0 KiB

  1. /*
  2. * virsh-completer-snapshot.c: virsh completer callbacks related to snapshots
  3. *
  4. * Copyright (C) 2019 Red Hat, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include "virsh-completer-snapshot.h"
  22. #include "viralloc.h"
  23. #include "virsh-util.h"
  24. #include "virsh.h"
  25. #include "virstring.h"
  26. char **
  27. virshSnapshotNameCompleter(vshControl *ctl,
  28. const vshCmd *cmd,
  29. unsigned int flags)
  30. {
  31. virshControlPtr priv = ctl->privData;
  32. virDomainPtr dom = NULL;
  33. virDomainSnapshotPtr *snapshots = NULL;
  34. int rc;
  35. int nsnapshots = 0;
  36. size_t i = 0;
  37. char **ret = NULL;
  38. VIR_AUTOSTRINGLIST tmp = NULL;
  39. virCheckFlags(0, NULL);
  40. if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
  41. return NULL;
  42. if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
  43. return NULL;
  44. if ((rc = virDomainListAllSnapshots(dom, &snapshots, flags)) < 0)
  45. goto cleanup;
  46. nsnapshots = rc;
  47. if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0)
  48. goto cleanup;
  49. for (i = 0; i < nsnapshots; i++) {
  50. const char *name = virDomainSnapshotGetName(snapshots[i]);
  51. tmp[i] = g_strdup(name);
  52. }
  53. ret = g_steal_pointer(&tmp);
  54. cleanup:
  55. virshDomainFree(dom);
  56. for (i = 0; i < nsnapshots; i++)
  57. virshDomainSnapshotFree(snapshots[i]);
  58. VIR_FREE(snapshots);
  59. return ret;
  60. }