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.
 
 
 
 
 
 

114 lines
3.1 KiB

  1. /*
  2. * virsh-completer-pool.c: virsh completer callbacks related to pools
  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-pool.h"
  22. #include "conf/storage_conf.h"
  23. #include "viralloc.h"
  24. #include "virsh-pool.h"
  25. #include "virsh.h"
  26. #include "virstring.h"
  27. char **
  28. virshStoragePoolNameCompleter(vshControl *ctl,
  29. const vshCmd *cmd G_GNUC_UNUSED,
  30. unsigned int flags)
  31. {
  32. virshControlPtr priv = ctl->privData;
  33. virStoragePoolPtr *pools = NULL;
  34. int npools = 0;
  35. size_t i = 0;
  36. char **ret = NULL;
  37. VIR_AUTOSTRINGLIST tmp = NULL;
  38. virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE |
  39. VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
  40. VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT,
  41. NULL);
  42. if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
  43. return NULL;
  44. if ((npools = virConnectListAllStoragePools(priv->conn, &pools, flags)) < 0)
  45. return NULL;
  46. if (VIR_ALLOC_N(tmp, npools + 1) < 0)
  47. goto cleanup;
  48. for (i = 0; i < npools; i++) {
  49. const char *name = virStoragePoolGetName(pools[i]);
  50. tmp[i] = g_strdup(name);
  51. }
  52. ret = g_steal_pointer(&tmp);
  53. cleanup:
  54. for (i = 0; i < npools; i++)
  55. virStoragePoolFree(pools[i]);
  56. VIR_FREE(pools);
  57. return ret;
  58. }
  59. char **
  60. virshPoolEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
  61. const vshCmd *cmd G_GNUC_UNUSED,
  62. unsigned int flags)
  63. {
  64. size_t i = 0;
  65. VIR_AUTOSTRINGLIST tmp = NULL;
  66. virCheckFlags(0, NULL);
  67. if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0)
  68. return NULL;
  69. for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++)
  70. tmp[i] = g_strdup(virshPoolEventCallbacks[i].name);
  71. return g_steal_pointer(&tmp);
  72. }
  73. char **
  74. virshPoolTypeCompleter(vshControl *ctl,
  75. const vshCmd *cmd,
  76. unsigned int flags)
  77. {
  78. VIR_AUTOSTRINGLIST tmp = NULL;
  79. const char *type_str = NULL;
  80. size_t i = 0;
  81. virCheckFlags(0, NULL);
  82. if (vshCommandOptStringQuiet(ctl, cmd, "type", &type_str) < 0)
  83. return NULL;
  84. if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0)
  85. return NULL;
  86. for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
  87. tmp[i] = g_strdup(virStoragePoolTypeToString(i));
  88. return virshCommaStringListComplete(type_str, (const char **)tmp);
  89. }