index.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import { ProviderTypes } from '@src/@types/Providers'
  15. import DefaultConnectionSchemaPlugin from './default/ConnectionSchemaPlugin'
  16. import AzureConnectionSchemaPlugin from './azure/ConnectionSchemaPlugin'
  17. import OpenstackConnectionSchemaPlugin from './openstack/ConnectionSchemaPlugin'
  18. import OciConnectionSchemaPlugin from './oci/ConnectionSchemaPlugin'
  19. import KubevirtConnectionSchemaPlugin from './kubevirt/ConnectionSchemaPlugin'
  20. import DefaultContentPlugin from './default/ContentPlugin'
  21. import AzureContentPlugin from './azure/ContentPlugin'
  22. import OpenstackContentPlugin from './openstack/ContentPlugin'
  23. import DefaultOptionsSchemaPlugin from './default/OptionsSchemaPlugin'
  24. import AwsOptionsSchemaPlugin from './aws/OptionsSchemaPlugin'
  25. import OvmOptionsSchemaPlugin from './ovm/OptionsSchemaPlugin'
  26. import VmwareOptionsSchemaPlugin from './vmware_vsphere/OptionsSchemaPlugin'
  27. import OpenstackOptionsSchemaPlugin from './openstack/OptionsSchemaPlugin'
  28. import OvirtOptionsSchemaPlugin from './ovirt/OptionsSchemaPlugin'
  29. import AzureOptionsSchemaPlugin from './azure/OptionsSchemaPlugin'
  30. import DefaultInstanceInfoPlugin from './default/InstanceInfoPlugin'
  31. import OciInstanceInfoPlugin from './oci/InstanceInfoPlugin'
  32. import DefaultMinionPoolSchemaPlugin from './default/MinionPoolSchemaPlugin'
  33. import OpenstackMinionPoolSchemaPlugin from './openstack/MinionPoolSchemaPlugin'
  34. const hasKey = <O>(obj: O, key: keyof any): key is keyof O => key in obj
  35. export const ConnectionSchemaPlugin = {
  36. for: (provider: ProviderTypes) => {
  37. const map = {
  38. default: new DefaultConnectionSchemaPlugin(),
  39. azure: new AzureConnectionSchemaPlugin(),
  40. openstack: new OpenstackConnectionSchemaPlugin(),
  41. oci: new OciConnectionSchemaPlugin(),
  42. kubevirt: new KubevirtConnectionSchemaPlugin(),
  43. }
  44. if (hasKey(map, provider)) {
  45. return map[provider]
  46. }
  47. return map.default
  48. },
  49. }
  50. export const OptionsSchemaPlugin = {
  51. for: (provider: ProviderTypes) => {
  52. const map = {
  53. default: new DefaultOptionsSchemaPlugin(),
  54. aws: new AwsOptionsSchemaPlugin(),
  55. oracle_vm: new OvmOptionsSchemaPlugin(),
  56. openstack: new OpenstackOptionsSchemaPlugin(),
  57. vmware_vsphere: new VmwareOptionsSchemaPlugin(),
  58. ovirt: new OvirtOptionsSchemaPlugin(),
  59. azure: new AzureOptionsSchemaPlugin(),
  60. }
  61. if (hasKey(map, provider)) {
  62. return map[provider]
  63. }
  64. return map.default
  65. },
  66. }
  67. export const ContentPlugin = {
  68. for: (provider: ProviderTypes) => {
  69. const map = {
  70. default: DefaultContentPlugin,
  71. azure: AzureContentPlugin,
  72. openstack: OpenstackContentPlugin,
  73. }
  74. if (hasKey(map, provider)) {
  75. return map[provider]
  76. }
  77. return map.default
  78. },
  79. }
  80. export const InstanceInfoPlugin = {
  81. for: (provider: ProviderTypes) => {
  82. const map = {
  83. default: new DefaultInstanceInfoPlugin(),
  84. oci: new OciInstanceInfoPlugin(),
  85. }
  86. if (hasKey(map, provider)) {
  87. return map[provider]
  88. }
  89. return map.default
  90. },
  91. }
  92. export const MinionPoolSchemaPlugin = {
  93. for: (provider: ProviderTypes) => {
  94. const map = {
  95. default: new DefaultMinionPoolSchemaPlugin(),
  96. openstack: new OpenstackMinionPoolSchemaPlugin(),
  97. }
  98. if (hasKey(map, provider)) {
  99. return map[provider]
  100. }
  101. return map.default
  102. },
  103. }