From 5fd450382cd02dda8a8d282c24a6c25e79578fb2 Mon Sep 17 00:00:00 2001 From: stSolo Date: Mon, 3 Oct 2022 16:56:47 +0300 Subject: [PATCH] Merge 'dev' into 'main' --- .golangci.yml | 10 +- account.go | 9 - client.go | 129 ++-- compute.go | 9 - computeci.go | 9 - config/config.go | 20 +- disks.go | 9 - extnet.go | 9 - flipgroup.go | 9 - image.go | 9 - interfaces/caller.go | 14 +- internal/client/http-client.go | 59 +- internal/client/transport.go | 134 ++-- internal/validators/helper.go | 20 +- k8ci.go | 9 - k8s.go | 9 - kvmppc.go | 7 - kvmx86.go | 9 - lb.go | 7 - locatons.go | 7 - opts/decort_opts.go | 6 - opts/opts.go | 26 - pkg/cloudapi/account.go | 9 + pkg/cloudapi/account/account.go | 30 +- pkg/cloudapi/account/add_user.go | 126 ++-- pkg/cloudapi/account/audits.go | 97 ++- pkg/cloudapi/account/create.go | 119 ++- pkg/cloudapi/account/delete.go | 88 +-- pkg/cloudapi/account/delete_user.go | 105 ++- pkg/cloudapi/account/disable_enable.go | 142 ++-- pkg/cloudapi/account/get.go | 99 ++- .../account/get_consumed_account_units.go | 99 ++- .../get_consumed_cloud_units_by_type.go | 118 ++- pkg/cloudapi/account/get_consumption.go | 148 ++-- .../account/get_reserved_account_units.go | 99 ++- pkg/cloudapi/account/list.go | 73 +- pkg/cloudapi/account/list_computes.go | 99 ++- pkg/cloudapi/account/list_deleted.go | 73 +- pkg/cloudapi/account/list_disks.go | 99 ++- pkg/cloudapi/account/list_flipgroups.go | 99 ++- pkg/cloudapi/account/list_rg.go | 99 ++- pkg/cloudapi/account/list_templates.go | 101 ++- pkg/cloudapi/account/list_vins.go | 99 ++- pkg/cloudapi/account/models.go | 458 ++++++------ pkg/cloudapi/account/restore.go | 95 ++- pkg/cloudapi/account/update.go | 109 ++- pkg/cloudapi/account/update_user.go | 126 ++-- pkg/cloudapi/bservice/create.go | 8 +- pkg/cloudapi/bservice/delete.go | 8 +- pkg/cloudapi/bservice/disable.go | 8 +- pkg/cloudapi/bservice/enable.go | 8 +- pkg/cloudapi/bservice/get.go | 8 +- pkg/cloudapi/bservice/group_add.go | 10 +- pkg/cloudapi/bservice/group_compute_remove.go | 8 +- pkg/cloudapi/bservice/group_get.go | 8 +- pkg/cloudapi/bservice/group_parent_add.go | 8 +- pkg/cloudapi/bservice/group_parent_remove.go | 8 +- pkg/cloudapi/bservice/group_remove.go | 8 +- pkg/cloudapi/bservice/group_resize.go | 7 +- pkg/cloudapi/bservice/group_start.go | 8 +- pkg/cloudapi/bservice/group_stop.go | 8 +- pkg/cloudapi/bservice/group_update.go | 8 +- pkg/cloudapi/bservice/group_update_extnet.go | 14 +- pkg/cloudapi/bservice/group_update_vins.go | 8 +- pkg/cloudapi/bservice/list.go | 12 +- pkg/cloudapi/bservice/models.go | 2 +- pkg/cloudapi/bservice/restore.go | 8 +- pkg/cloudapi/bservice/snapshot_create.go | 8 +- pkg/cloudapi/bservice/snapshot_delete.go | 8 +- pkg/cloudapi/bservice/snapshot_list.go | 8 +- pkg/cloudapi/bservice/snapshot_rollback.go | 8 +- pkg/cloudapi/bservice/start.go | 8 +- pkg/cloudapi/bservice/stop.go | 8 +- pkg/cloudapi/cloudapi.go | 15 + pkg/cloudapi/compute.go | 9 + .../compute/affinity_group_check_start.go | 88 +-- pkg/cloudapi/compute/affinity_label_remove.go | 92 ++- pkg/cloudapi/compute/affinity_label_set.go | 100 ++- pkg/cloudapi/compute/affinity_relations.go | 98 ++- pkg/cloudapi/compute/affinity_rule_add.go | 173 +++-- pkg/cloudapi/compute/affinity_rule_remove.go | 173 +++-- pkg/cloudapi/compute/affinity_rules_clear.go | 92 ++- .../compute/anti_affinity_rule_add.go | 173 +++-- .../compute/anti_affinity_rule_remove.go | 173 +++-- .../compute/anti_affinity_rules_clear.go | 92 ++- pkg/cloudapi/compute/attach_gpu.go | 102 ++- pkg/cloudapi/compute/attach_pci_device.go | 102 ++- pkg/cloudapi/compute/audits.go | 80 +- pkg/cloudapi/compute/cd_eject.go | 90 +-- pkg/cloudapi/compute/cd_insert.go | 98 ++- pkg/cloudapi/compute/clone.go | 102 ++- pkg/cloudapi/compute/compute.go | 30 +- pkg/cloudapi/compute/create_template.go | 158 ++-- pkg/cloudapi/compute/delete.go | 94 ++- pkg/cloudapi/compute/detach_gpu.go | 94 ++- pkg/cloudapi/compute/detach_pci_device.go | 102 ++- pkg/cloudapi/compute/disable.go | 92 ++- pkg/cloudapi/compute/disk_add.go | 122 ++- pkg/cloudapi/compute/disk_attach.go | 102 ++- pkg/cloudapi/compute/disk_del.go | 104 ++- pkg/cloudapi/compute/disk_detach.go | 102 ++- pkg/cloudapi/compute/disk_qos.go | 112 ++- pkg/cloudapi/compute/disk_resize.go | 112 ++- pkg/cloudapi/compute/enable.go | 92 ++- pkg/cloudapi/compute/get.go | 94 ++- pkg/cloudapi/compute/get_audits.go | 94 ++- pkg/cloudapi/compute/get_console_url.go | 86 +-- pkg/cloudapi/compute/get_log.go | 132 ++-- pkg/cloudapi/compute/list.go | 74 +- pkg/cloudapi/compute/list_deleted.go | 72 +- pkg/cloudapi/compute/list_pci_device.go | 96 ++- pkg/cloudapi/compute/list_vgpu.go | 96 ++- pkg/cloudapi/compute/models.go | 694 +++++++++--------- pkg/cloudapi/compute/move_to_rg.go | 104 ++- pkg/cloudapi/compute/net_attach.go | 125 ++-- pkg/cloudapi/compute/net_detach.go | 94 ++- pkg/cloudapi/compute/pause.go | 90 +-- pkg/cloudapi/compute/pfw_add.go | 129 ++-- pkg/cloudapi/compute/pfw_del.go | 102 ++- pkg/cloudapi/compute/pfw_list.go | 96 ++- pkg/cloudapi/compute/pin_to_stack.go | 90 +-- pkg/cloudapi/compute/power_cycle.go | 90 +-- pkg/cloudapi/compute/reboot.go | 90 +-- pkg/cloudapi/compute/redeploy.go | 100 ++- pkg/cloudapi/compute/reset.go | 90 +-- pkg/cloudapi/compute/resize.go | 96 ++- pkg/cloudapi/compute/restore.go | 80 +- pkg/cloudapi/compute/resume.go | 90 +-- pkg/cloudapi/compute/snapshot_create.go | 94 ++- pkg/cloudapi/compute/snapshot_delete.go | 100 ++- pkg/cloudapi/compute/snapshot_list.go | 96 ++- pkg/cloudapi/compute/snapshot_rollback.go | 100 ++- pkg/cloudapi/compute/snapshot_usage.go | 98 ++- pkg/cloudapi/compute/start.go | 92 ++- pkg/cloudapi/compute/stop.go | 92 ++- pkg/cloudapi/compute/tag_add.go | 108 ++- pkg/cloudapi/compute/tag_remove.go | 98 ++- pkg/cloudapi/compute/unpin_from_stack.go | 90 +-- pkg/cloudapi/compute/update.go | 94 ++- pkg/cloudapi/compute/user_grant.go | 121 ++- pkg/cloudapi/compute/user_list.go | 88 +-- pkg/cloudapi/compute/user_revoke.go | 100 ++- pkg/cloudapi/compute/user_update.go | 121 ++- pkg/cloudapi/computeci.go | 9 + pkg/cloudapi/computeci/computeci.go | 30 +- pkg/cloudapi/computeci/get.go | 80 +- pkg/cloudapi/computeci/list.go | 58 +- pkg/cloudapi/computeci/models.go | 28 +- pkg/cloudapi/disks.go | 9 + pkg/cloudapi/disks/create.go | 144 ++-- pkg/cloudapi/disks/delete.go | 96 ++- pkg/cloudapi/disks/delete_disks.go | 99 ++- pkg/cloudapi/disks/disks.go | 30 +- pkg/cloudapi/disks/get.go | 99 ++- pkg/cloudapi/disks/limitio.go | 123 ++-- pkg/cloudapi/disks/list.go | 126 ++-- pkg/cloudapi/disks/list_types.go | 71 +- pkg/cloudapi/disks/list_unattached.go | 71 +- pkg/cloudapi/disks/models.go | 232 +++--- pkg/cloudapi/disks/rename.go | 105 ++- pkg/cloudapi/disks/resize.go | 160 ++-- pkg/cloudapi/disks/restore.go | 105 ++- pkg/cloudapi/disks/search.go | 75 +- pkg/cloudapi/disks/snapshot_delete.go | 105 ++- pkg/cloudapi/disks/snapshot_rollback.go | 107 ++- pkg/cloudapi/extnet.go | 9 + pkg/cloudapi/extnet/extnet.go | 30 +- pkg/cloudapi/extnet/get.go | 95 ++- pkg/cloudapi/extnet/get_default.go | 59 +- pkg/cloudapi/extnet/list.go | 73 +- pkg/cloudapi/extnet/list_computes.go | 87 +-- pkg/cloudapi/extnet/models.go | 160 ++-- pkg/cloudapi/flipgroup.go | 9 + pkg/cloudapi/flipgroup/compute_add.go | 88 ++- pkg/cloudapi/flipgroup/compute_remove.go | 88 ++- pkg/cloudapi/flipgroup/create.go | 125 ++-- pkg/cloudapi/flipgroup/delete.go | 80 +- pkg/cloudapi/flipgroup/edit.go | 84 ++- pkg/cloudapi/flipgroup/flipgroup.go | 30 +- pkg/cloudapi/flipgroup/get.go | 82 +-- pkg/cloudapi/flipgroup/list.go | 56 +- pkg/cloudapi/flipgroup/models.go | 80 +- pkg/cloudapi/image.go | 9 + pkg/cloudapi/image/create.go | 194 +++-- pkg/cloudapi/image/create_virtual.go | 105 ++- pkg/cloudapi/image/delete.go | 97 ++- pkg/cloudapi/image/get.go | 98 ++- pkg/cloudapi/image/image.go | 30 +- pkg/cloudapi/image/link.go | 103 ++- pkg/cloudapi/image/list.go | 74 +- pkg/cloudapi/image/models.go | 136 ++-- pkg/cloudapi/image/rename.go | 105 ++- pkg/cloudapi/k8ci.go | 9 + pkg/cloudapi/k8ci/get.go | 80 +- pkg/cloudapi/k8ci/k8ci.go | 30 +- pkg/cloudapi/k8ci/list.go | 58 +- pkg/cloudapi/k8ci/list_deleted.go | 56 +- pkg/cloudapi/k8ci/models.go | 30 +- pkg/cloudapi/k8s.go | 9 + pkg/cloudapi/k8s/create.go | 139 ++-- pkg/cloudapi/k8s/delete.go | 92 ++- pkg/cloudapi/k8s/delete_master_from_group.go | 108 ++- pkg/cloudapi/k8s/delete_worker_from_group.go | 108 ++- pkg/cloudapi/k8s/disable_enable.go | 138 ++-- pkg/cloudapi/k8s/find_group_by_label.go | 108 ++- pkg/cloudapi/k8s/get.go | 96 ++- pkg/cloudapi/k8s/get_config.go | 80 +- pkg/cloudapi/k8s/get_node_annotations.go | 88 +-- pkg/cloudapi/k8s/get_node_taints.go | 88 +-- pkg/cloudapi/k8s/k8s.go | 30 +- pkg/cloudapi/k8s/list.go | 74 +- pkg/cloudapi/k8s/list_deleted.go | 72 +- pkg/cloudapi/k8s/models.go | 238 +++--- pkg/cloudapi/k8s/restore.go | 90 +-- pkg/cloudapi/k8s/start.go | 90 +-- pkg/cloudapi/k8s/stop.go | 90 +-- pkg/cloudapi/k8s/update.go | 94 ++- pkg/cloudapi/k8s/worker_add.go | 110 ++- pkg/cloudapi/k8s/worker_reset.go | 110 ++- pkg/cloudapi/k8s/worker_restart.go | 110 ++- pkg/cloudapi/k8s/workers_group_add.go | 138 ++-- pkg/cloudapi/k8s/workers_group_delete.go | 100 ++- pkg/cloudapi/k8s/workers_group_get_by_name.go | 106 ++- pkg/cloudapi/kvmppc.go | 7 + pkg/cloudapi/kvmppc/create.go | 149 ++-- pkg/cloudapi/kvmppc/create_blank.go | 151 ++-- pkg/cloudapi/kvmppc/kvmppc.go | 30 +- pkg/cloudapi/kvmx86.go | 9 + pkg/cloudapi/kvmx86/create.go | 149 ++-- pkg/cloudapi/kvmx86/create_blank.go | 151 ++-- pkg/cloudapi/kvmx86/kvmx86.go | 30 +- pkg/cloudapi/lb.go | 7 + pkg/cloudapi/lb/backend_create.go | 121 ++- pkg/cloudapi/lb/backend_delete.go | 103 ++- pkg/cloudapi/lb/backend_server_add.go | 151 ++-- pkg/cloudapi/lb/backend_server_delete.go | 113 ++- pkg/cloudapi/lb/backend_server_update.go | 151 ++-- pkg/cloudapi/lb/backend_update.go | 121 ++- pkg/cloudapi/lb/config_reset.go | 93 ++- pkg/cloudapi/lb/create.go | 117 ++- pkg/cloudapi/lb/delete.go | 95 ++- pkg/cloudapi/lb/disable_enable.go | 144 ++-- pkg/cloudapi/lb/frontend_bind.go | 107 ++- pkg/cloudapi/lb/frontend_bind_delete.go | 103 ++- pkg/cloudapi/lb/frontend_bind_update.go | 107 ++- pkg/cloudapi/lb/frontend_create.go | 113 ++- pkg/cloudapi/lb/frontend_delete.go | 103 ++- pkg/cloudapi/lb/get.go | 97 ++- pkg/cloudapi/lb/lb.go | 30 +- pkg/cloudapi/lb/list.go | 73 +- pkg/cloudapi/lb/list_deleted.go | 71 +- pkg/cloudapi/lb/models.go | 178 ++--- pkg/cloudapi/lb/restart.go | 93 ++- pkg/cloudapi/lb/restore.go | 93 ++- pkg/cloudapi/lb/update.go | 101 ++- pkg/cloudapi/locations/get_url.go | 47 +- pkg/cloudapi/locations/list.go | 73 +- pkg/cloudapi/locations/locations.go | 30 +- pkg/cloudapi/locations/models.go | 28 +- pkg/cloudapi/locatons.go | 7 + pkg/cloudapi/rg.go | 7 + pkg/cloudapi/rg/access_grant.go | 7 +- pkg/cloudapi/rg/access_revoke.go | 8 +- pkg/cloudapi/rg/affinity_group_computes.go | 8 +- pkg/cloudapi/rg/affinity_groups_get.go | 8 +- pkg/cloudapi/rg/affinity_groups_list.go | 8 +- pkg/cloudapi/rg/audits.go | 8 +- pkg/cloudapi/rg/create.go | 8 +- pkg/cloudapi/rg/delete.go | 8 +- pkg/cloudapi/rg/disable.go | 8 +- pkg/cloudapi/rg/enable.go | 8 +- pkg/cloudapi/rg/get.go | 8 +- pkg/cloudapi/rg/list.go | 8 +- pkg/cloudapi/rg/list_computes.go | 8 +- pkg/cloudapi/rg/list_deleted.go | 8 +- pkg/cloudapi/rg/list_lb.go | 8 +- pkg/cloudapi/rg/list_pfw.go | 8 +- pkg/cloudapi/rg/list_vins.go | 14 +- pkg/cloudapi/rg/models.go | 42 +- pkg/cloudapi/rg/restore.go | 8 +- pkg/cloudapi/rg/set_def_net.go | 7 +- pkg/cloudapi/rg/update.go | 8 +- pkg/cloudapi/rg/usage.go | 8 +- pkg/cloudapi/sizes.go | 9 + pkg/cloudapi/sizes/list.go | 60 +- pkg/cloudapi/sizes/models.go | 24 +- pkg/cloudapi/sizes/sizes.go | 30 +- pkg/cloudapi/tasks.go | 9 + pkg/cloudapi/tasks/get.go | 99 ++- pkg/cloudapi/tasks/list.go | 73 +- pkg/cloudapi/tasks/models.go | 102 +-- pkg/cloudapi/tasks/tasks.go | 30 +- pkg/cloudapi/vins.go | 9 + pkg/cloudapi/vins/audits.go | 97 ++- pkg/cloudapi/vins/create_in_account.go | 111 ++- pkg/cloudapi/vins/create_in_rg.go | 113 ++- pkg/cloudapi/vins/delete.go | 97 ++- pkg/cloudapi/vins/disable_enable.go | 148 ++-- pkg/cloudapi/vins/extnet_connect.go | 97 ++- pkg/cloudapi/vins/extnet_disconnect.go | 93 ++- pkg/cloudapi/vins/extnet_list.go | 87 +-- pkg/cloudapi/vins/get.go | 99 ++- pkg/cloudapi/vins/ip_list.go | 97 ++- pkg/cloudapi/vins/ip_release.go | 99 ++- pkg/cloudapi/vins/ip_reserve.go | 99 ++- pkg/cloudapi/vins/list.go | 73 +- pkg/cloudapi/vins/list_deleted.go | 71 +- pkg/cloudapi/vins/models.go | 542 +++++++------- pkg/cloudapi/vins/nat_rule_add.go | 129 ++-- pkg/cloudapi/vins/nat_rule_del.go | 105 ++- pkg/cloudapi/vins/nat_rule_list.go | 83 +-- pkg/cloudapi/vins/restore.go | 95 ++- pkg/cloudapi/vins/search.go | 75 +- pkg/cloudapi/vins/vins.go | 30 +- pkg/cloudapi/vins/vnfdev_redeploy.go | 95 ++- pkg/cloudapi/vins/vnfdev_restart.go | 95 ++- pkg/cloudbroker/account.go | 9 + pkg/cloudbroker/account/account.go | 13 + pkg/cloudbroker/account/add_user.go | 58 ++ pkg/cloudbroker/account/audits.go | 40 + pkg/cloudbroker/account/create.go | 53 ++ pkg/cloudbroker/account/delete.go | 39 + pkg/cloudbroker/account/delete_accounts.go | 39 + pkg/cloudbroker/account/delete_user.go | 45 ++ pkg/cloudbroker/account/disable.go | 44 ++ pkg/cloudbroker/account/disable_accounts.go | 34 + pkg/cloudbroker/account/enable.go | 44 ++ pkg/cloudbroker/account/enable_accounts.go | 34 + pkg/cloudbroker/account/get.go | 41 ++ pkg/cloudbroker/account/list.go | 28 + pkg/cloudbroker/account/list_computes.go | 43 ++ pkg/cloudbroker/account/list_deleted.go | 29 + pkg/cloudbroker/account/list_disks.go | 43 ++ pkg/cloudbroker/account/list_flip_groups.go | 43 ++ pkg/cloudbroker/account/list_rg.go | 43 ++ pkg/cloudbroker/account/list_vins.go | 43 ++ pkg/cloudbroker/account/models.go | 214 ++++++ pkg/cloudbroker/account/restore.go | 39 + pkg/cloudbroker/account/update.go | 52 ++ pkg/cloudbroker/account/update_user.go | 49 ++ pkg/cloudbroker/cloudbroker.go | 13 + pkg/cloudbroker/compute.go | 9 + pkg/cloudbroker/computeci.go | 9 + pkg/cloudbroker/disks.go | 9 + pkg/cloudbroker/disks/create.go | 64 ++ pkg/cloudbroker/disks/delete.go | 44 ++ pkg/cloudbroker/disks/delete_disks.go | 46 ++ pkg/cloudbroker/disks/disks.go | 13 + pkg/cloudbroker/disks/get.go | 43 ++ pkg/cloudbroker/disks/limit_io.go | 55 ++ pkg/cloudbroker/disks/list.go | 32 + pkg/cloudbroker/disks/list_deleted.go | 41 ++ pkg/cloudbroker/disks/list_types.go | 30 + pkg/cloudbroker/disks/list_unattached.go | 39 + pkg/cloudbroker/disks/models.go | 101 +++ pkg/cloudbroker/disks/rename.go | 47 ++ pkg/cloudbroker/disks/resize.go | 67 ++ pkg/cloudbroker/disks/restore.go | 46 ++ pkg/cloudbroker/disks/search.go | 34 + pkg/cloudbroker/disks/snapshot_delete.go | 46 ++ pkg/cloudbroker/disks/snapshot_rollback.go | 50 ++ pkg/cloudbroker/extnet.go | 9 + pkg/cloudbroker/flipgroup.go | 9 + pkg/cloudbroker/image.go | 9 + pkg/cloudbroker/image/computeci_set.go | 45 ++ pkg/cloudbroker/image/computeci_unset.go | 41 ++ pkg/cloudbroker/image/create_cdrom_image.go | 68 ++ pkg/cloudbroker/image/create_image.go | 78 ++ pkg/cloudbroker/image/create_virtual.go | 45 ++ pkg/cloudbroker/image/delete.go | 46 ++ pkg/cloudbroker/image/delete_cdrom_image.go | 42 ++ pkg/cloudbroker/image/delete_images.go | 46 ++ pkg/cloudbroker/image/disable.go | 41 ++ pkg/cloudbroker/image/edit.go | 47 ++ pkg/cloudbroker/image/enable.go | 41 ++ pkg/cloudbroker/image/get.go | 43 ++ pkg/cloudbroker/image/image.go | 13 + pkg/cloudbroker/image/link.go | 45 ++ pkg/cloudbroker/image/list.go | 32 + pkg/cloudbroker/image/list_stacks.go | 45 ++ pkg/cloudbroker/image/models.go | 82 +++ pkg/cloudbroker/image/rename.go | 45 ++ pkg/cloudbroker/image/share.go | 45 ++ pkg/cloudbroker/image/sync_create_image.go | 89 +++ pkg/cloudbroker/image/update_nodes.go | 42 ++ pkg/cloudbroker/k8ci.go | 9 + pkg/cloudbroker/k8s.go | 9 + pkg/cloudbroker/kvmppc.go | 7 + pkg/cloudbroker/kvmx86.go | 9 + pkg/cloudbroker/lb.go | 7 + pkg/cloudbroker/locatons.go | 7 + pkg/cloudbroker/rg.go | 7 + pkg/cloudbroker/sizes.go | 9 + pkg/cloudbroker/tasks.go | 9 + pkg/cloudbroker/vins.go | 9 + rg.go | 7 - sizes.go | 9 - tasks.go | 9 - typed/typed.go | 6 - vins.go | 9 - 400 files changed, 14394 insertions(+), 13407 deletions(-) delete mode 100644 account.go delete mode 100644 compute.go delete mode 100644 computeci.go delete mode 100644 disks.go delete mode 100644 extnet.go delete mode 100644 flipgroup.go delete mode 100644 image.go delete mode 100644 k8ci.go delete mode 100644 k8s.go delete mode 100644 kvmppc.go delete mode 100644 kvmx86.go delete mode 100644 lb.go delete mode 100644 locatons.go delete mode 100644 opts/decort_opts.go delete mode 100644 opts/opts.go create mode 100644 pkg/cloudapi/account.go create mode 100644 pkg/cloudapi/cloudapi.go create mode 100644 pkg/cloudapi/compute.go create mode 100644 pkg/cloudapi/computeci.go create mode 100644 pkg/cloudapi/disks.go create mode 100644 pkg/cloudapi/extnet.go create mode 100644 pkg/cloudapi/flipgroup.go create mode 100644 pkg/cloudapi/image.go create mode 100644 pkg/cloudapi/k8ci.go create mode 100644 pkg/cloudapi/k8s.go create mode 100644 pkg/cloudapi/kvmppc.go create mode 100644 pkg/cloudapi/kvmx86.go create mode 100644 pkg/cloudapi/lb.go create mode 100644 pkg/cloudapi/locatons.go create mode 100644 pkg/cloudapi/rg.go create mode 100644 pkg/cloudapi/sizes.go create mode 100644 pkg/cloudapi/tasks.go create mode 100644 pkg/cloudapi/vins.go create mode 100644 pkg/cloudbroker/account.go create mode 100644 pkg/cloudbroker/account/account.go create mode 100644 pkg/cloudbroker/account/add_user.go create mode 100644 pkg/cloudbroker/account/audits.go create mode 100644 pkg/cloudbroker/account/create.go create mode 100644 pkg/cloudbroker/account/delete.go create mode 100644 pkg/cloudbroker/account/delete_accounts.go create mode 100644 pkg/cloudbroker/account/delete_user.go create mode 100644 pkg/cloudbroker/account/disable.go create mode 100644 pkg/cloudbroker/account/disable_accounts.go create mode 100644 pkg/cloudbroker/account/enable.go create mode 100644 pkg/cloudbroker/account/enable_accounts.go create mode 100644 pkg/cloudbroker/account/get.go create mode 100644 pkg/cloudbroker/account/list.go create mode 100644 pkg/cloudbroker/account/list_computes.go create mode 100644 pkg/cloudbroker/account/list_deleted.go create mode 100644 pkg/cloudbroker/account/list_disks.go create mode 100644 pkg/cloudbroker/account/list_flip_groups.go create mode 100644 pkg/cloudbroker/account/list_rg.go create mode 100644 pkg/cloudbroker/account/list_vins.go create mode 100644 pkg/cloudbroker/account/models.go create mode 100644 pkg/cloudbroker/account/restore.go create mode 100644 pkg/cloudbroker/account/update.go create mode 100644 pkg/cloudbroker/account/update_user.go create mode 100644 pkg/cloudbroker/cloudbroker.go create mode 100644 pkg/cloudbroker/compute.go create mode 100644 pkg/cloudbroker/computeci.go create mode 100644 pkg/cloudbroker/disks.go create mode 100644 pkg/cloudbroker/disks/create.go create mode 100644 pkg/cloudbroker/disks/delete.go create mode 100644 pkg/cloudbroker/disks/delete_disks.go create mode 100644 pkg/cloudbroker/disks/disks.go create mode 100644 pkg/cloudbroker/disks/get.go create mode 100644 pkg/cloudbroker/disks/limit_io.go create mode 100644 pkg/cloudbroker/disks/list.go create mode 100644 pkg/cloudbroker/disks/list_deleted.go create mode 100644 pkg/cloudbroker/disks/list_types.go create mode 100644 pkg/cloudbroker/disks/list_unattached.go create mode 100644 pkg/cloudbroker/disks/models.go create mode 100644 pkg/cloudbroker/disks/rename.go create mode 100644 pkg/cloudbroker/disks/resize.go create mode 100644 pkg/cloudbroker/disks/restore.go create mode 100644 pkg/cloudbroker/disks/search.go create mode 100644 pkg/cloudbroker/disks/snapshot_delete.go create mode 100644 pkg/cloudbroker/disks/snapshot_rollback.go create mode 100644 pkg/cloudbroker/extnet.go create mode 100644 pkg/cloudbroker/flipgroup.go create mode 100644 pkg/cloudbroker/image.go create mode 100644 pkg/cloudbroker/image/computeci_set.go create mode 100644 pkg/cloudbroker/image/computeci_unset.go create mode 100644 pkg/cloudbroker/image/create_cdrom_image.go create mode 100644 pkg/cloudbroker/image/create_image.go create mode 100644 pkg/cloudbroker/image/create_virtual.go create mode 100644 pkg/cloudbroker/image/delete.go create mode 100644 pkg/cloudbroker/image/delete_cdrom_image.go create mode 100644 pkg/cloudbroker/image/delete_images.go create mode 100644 pkg/cloudbroker/image/disable.go create mode 100644 pkg/cloudbroker/image/edit.go create mode 100644 pkg/cloudbroker/image/enable.go create mode 100644 pkg/cloudbroker/image/get.go create mode 100644 pkg/cloudbroker/image/image.go create mode 100644 pkg/cloudbroker/image/link.go create mode 100644 pkg/cloudbroker/image/list.go create mode 100644 pkg/cloudbroker/image/list_stacks.go create mode 100644 pkg/cloudbroker/image/models.go create mode 100644 pkg/cloudbroker/image/rename.go create mode 100644 pkg/cloudbroker/image/share.go create mode 100644 pkg/cloudbroker/image/sync_create_image.go create mode 100644 pkg/cloudbroker/image/update_nodes.go create mode 100644 pkg/cloudbroker/k8ci.go create mode 100644 pkg/cloudbroker/k8s.go create mode 100644 pkg/cloudbroker/kvmppc.go create mode 100644 pkg/cloudbroker/kvmx86.go create mode 100644 pkg/cloudbroker/lb.go create mode 100644 pkg/cloudbroker/locatons.go create mode 100644 pkg/cloudbroker/rg.go create mode 100644 pkg/cloudbroker/sizes.go create mode 100644 pkg/cloudbroker/tasks.go create mode 100644 pkg/cloudbroker/vins.go delete mode 100644 rg.go delete mode 100644 sizes.go delete mode 100644 tasks.go delete mode 100644 typed/typed.go delete mode 100644 vins.go diff --git a/.golangci.yml b/.golangci.yml index e0b92a5..c74c72f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,18 +4,20 @@ linters: - decorder - dogsled - errorlint + - exhaustive - exportloopref - - gocognit + - exhaustive + #- gocognit - goconst - - gocyclo + #- gocyclo - gosec - - ifshort - makezero - - nestif + #- nestif - nilerr - prealloc - unconvert - unparam + - noctx issues: max-same-issues: 0 diff --git a/account.go b/account.go deleted file mode 100644 index 76fbcbf..0000000 --- a/account.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/account" -) - -func (dc *Client) Account() *account.Account { - return account.New(dc) -} diff --git a/client.go b/client.go index 5798077..e7c85ea 100644 --- a/client.go +++ b/client.go @@ -1,59 +1,70 @@ -package decortsdk - -import ( - "context" - "errors" - "io" - "net/http" - "strings" - - "github.com/google/go-querystring/query" - "github.com/rudecs/decort-sdk/config" - "github.com/rudecs/decort-sdk/internal/client" -) - -type Client struct { - decortUrl string - client *http.Client -} - -func New(cfg config.Config) *Client { - if cfg.Retries == 0 { - cfg.Retries = 5 - } - - return &Client{ - decortUrl: cfg.DecortURL, - client: client.NewHttpClient(cfg), - } -} - -func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) { - values, err := query.Values(params) - if err != nil { - return nil, err - } - - body := strings.NewReader(values.Encode()) - req, err := http.NewRequestWithContext(ctx, method, dc.decortUrl+"/restmachine"+url, body) - if err != nil { - return nil, err - } - - resp, err := dc.client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - respBytes, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - if resp.StatusCode != 200 { - return nil, errors.New(string(respBytes)) - } - - return respBytes, nil -} +package decortsdk + +import ( + "context" + "errors" + "io" + "net/http" + "strings" + + "github.com/rudecs/decort-sdk/pkg/cloudapi" + "github.com/rudecs/decort-sdk/pkg/cloudbroker" + + "github.com/google/go-querystring/query" + "github.com/rudecs/decort-sdk/config" + "github.com/rudecs/decort-sdk/internal/client" +) + +type Client struct { + decortURL string + client *http.Client +} + +func New(cfg config.Config) *Client { + if cfg.Retries == 0 { + cfg.Retries = 5 + } + + return &Client{ + decortURL: cfg.DecortURL, + client: client.NewHttpClient(cfg), + } +} + +func (dc *Client) CloudApi() *cloudapi.CloudApi { + return cloudapi.New(dc) +} + +func (dc *Client) CloudBroker() *cloudbroker.CloudBroker { + return cloudbroker.New(dc) +} + +func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) { + values, err := query.Values(params) + if err != nil { + return nil, err + } + + body := strings.NewReader(values.Encode()) + req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, body) + if err != nil { + return nil, err + } + + resp, err := dc.client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + respBytes, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + if resp.StatusCode != 200 { + return nil, errors.New(string(respBytes)) + } + + return respBytes, nil +} diff --git a/compute.go b/compute.go deleted file mode 100644 index a91e59f..0000000 --- a/compute.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/compute" -) - -func (dc *Client) Compute() *compute.Compute { - return compute.New(dc) -} diff --git a/computeci.go b/computeci.go deleted file mode 100644 index c2bf581..0000000 --- a/computeci.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/computeci" -) - -func (dc *Client) ComputeCI() *computeci.ComputeCI { - return computeci.New(dc) -} diff --git a/config/config.go b/config/config.go index 9efdf42..f5681bb 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,10 @@ -package config - -type Config struct { - AppID string - AppSecret string - SSOURL string - DecortURL string - Retries uint64 - SSLSkipVerify bool -} +package config + +type Config struct { + AppID string + AppSecret string + SSOURL string + DecortURL string + Retries uint64 + SSLSkipVerify bool +} diff --git a/disks.go b/disks.go deleted file mode 100644 index 655f481..0000000 --- a/disks.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/disks" -) - -func (dc *Client) Disks() *disks.Disks { - return disks.New(dc) -} diff --git a/extnet.go b/extnet.go deleted file mode 100644 index 3722006..0000000 --- a/extnet.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/extnet" -) - -func (dc *Client) Extnet() *extnet.Extnet { - return extnet.New(dc) -} diff --git a/flipgroup.go b/flipgroup.go deleted file mode 100644 index 05ea111..0000000 --- a/flipgroup.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup" -) - -func (dc *Client) FlipGroup() *flipgroup.FlipGroup { - return flipgroup.New(dc) -} diff --git a/image.go b/image.go deleted file mode 100644 index 952315c..0000000 --- a/image.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/image" -) - -func (dc *Client) Image() *image.Image { - return image.New(dc) -} diff --git a/interfaces/caller.go b/interfaces/caller.go index 7dbcdfe..4c987b3 100644 --- a/interfaces/caller.go +++ b/interfaces/caller.go @@ -1,7 +1,7 @@ -package interfaces - -import "context" - -type Caller interface { - DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) -} +package interfaces + +import "context" + +type Caller interface { + DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) +} diff --git a/internal/client/http-client.go b/internal/client/http-client.go index 3404aaa..fa88772 100644 --- a/internal/client/http-client.go +++ b/internal/client/http-client.go @@ -1,27 +1,32 @@ -package client - -import ( - "crypto/tls" - "net/http" - "time" - - "github.com/rudecs/decort-sdk/config" -) - -func NewHttpClient(cfg config.Config) *http.Client { - - transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SSLSkipVerify}} - - return &http.Client{ - Transport: &transport{ - base: transCfg, - retries: cfg.Retries, - clientId: cfg.AppID, - clientSecret: cfg.AppSecret, - ssoUrl: cfg.SSOURL, - //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, - - Timeout: 5 * time.Minute, - } -} +package client + +import ( + "crypto/tls" + "net/http" + "time" + + "github.com/rudecs/decort-sdk/config" +) + +func NewHttpClient(cfg config.Config) *http.Client { + + transCfg := &http.Transport{ + TLSClientConfig: &tls.Config{ + //nolint:gosec + InsecureSkipVerify: cfg.SSLSkipVerify, + }, + } + + return &http.Client{ + Transport: &transport{ + base: transCfg, + retries: cfg.Retries, + clientID: cfg.AppID, + clientSecret: cfg.AppSecret, + SSOURL: cfg.SSOURL, + //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + + Timeout: 5 * time.Minute, + } +} diff --git a/internal/client/transport.go b/internal/client/transport.go index d487ff2..9c470ae 100644 --- a/internal/client/transport.go +++ b/internal/client/transport.go @@ -1,67 +1,67 @@ -package client - -import ( - "fmt" - "io" - "net/http" - "strings" - "time" -) - -type transport struct { - base http.RoundTripper - retries uint64 - clientId string - clientSecret string - token string - ssoUrl string - expiryTime time.Time -} - -func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { - if t.token == "" || time.Now().After(t.expiryTime) { - body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientId, t.clientSecret) - bodyReader := strings.NewReader(body) - - req, _ := http.NewRequest("POST", t.ssoUrl+"/v1/oauth/access_token", bodyReader) - req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - - resp, err := t.base.RoundTrip(req) - if err != nil { - return nil, fmt.Errorf("cannot get token: %v", err) - } - - tokenBytes, _ := io.ReadAll(resp.Body) - resp.Body.Close() - - if resp.StatusCode != 200 { - return nil, fmt.Errorf("cannot get token: %s", tokenBytes) - } - - token := string(tokenBytes) - - t.token = token - t.expiryTime = time.Now().AddDate(0, 0, 1) - } - - req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - req.Header.Add("Authorization", "bearer "+t.token) - req.Header.Set("Accept", "application/json") - - var resp *http.Response - var err error - for i := uint64(0); i < t.retries; i++ { - resp, err = t.base.RoundTrip(req) - if err == nil { - if resp.StatusCode == 200 { - return resp, nil - } - respBytes, _ := io.ReadAll(resp.Body) - err = fmt.Errorf("%s", respBytes) - resp.Body.Close() - } - //logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries) - time.Sleep(time.Second * 5) - } - return nil, fmt.Errorf("could not execute request: %v", err) -} +package client + +import ( + "fmt" + "io" + "net/http" + "strings" + "time" +) + +type transport struct { + base http.RoundTripper + retries uint64 + clientID string + clientSecret string + token string + SSOURL string + expiryTime time.Time +} + +func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { + if t.token == "" || time.Now().After(t.expiryTime) { + body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret) + bodyReader := strings.NewReader(body) + + req, _ := http.NewRequestWithContext(req.Context(), "POST", t.SSOURL+"/v1/oauth/access_token", bodyReader) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + + resp, err := t.base.RoundTrip(req) + if err != nil { + return nil, fmt.Errorf("cannot get token: %w", err) + } + + tokenBytes, _ := io.ReadAll(resp.Body) + resp.Body.Close() + + if resp.StatusCode != 200 { + return nil, fmt.Errorf("cannot get token: %s", tokenBytes) + } + + token := string(tokenBytes) + + t.token = token + t.expiryTime = time.Now().AddDate(0, 0, 1) + } + + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + req.Header.Add("Authorization", "bearer "+t.token) + req.Header.Set("Accept", "application/json") + + var resp *http.Response + var err error + for i := uint64(0); i < t.retries; i++ { + resp, err = t.base.RoundTrip(req) + if err == nil { + if resp.StatusCode == 200 { + return resp, nil + } + respBytes, _ := io.ReadAll(resp.Body) + err = fmt.Errorf("%s", respBytes) + resp.Body.Close() + } + //logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries) + time.Sleep(time.Second * 5) + } + return nil, fmt.Errorf("could not execute request: %w", err) +} diff --git a/internal/validators/helper.go b/internal/validators/helper.go index 737c1ba..e639ab8 100644 --- a/internal/validators/helper.go +++ b/internal/validators/helper.go @@ -1,10 +1,10 @@ -package validators - -func StringInSlice(str string, target []string) bool { - for _, v := range target { - if v == str { - return true - } - } - return false -} +package validators + +func StringInSlice(str string, target []string) bool { + for _, v := range target { + if v == str { + return true + } + } + return false +} diff --git a/k8ci.go b/k8ci.go deleted file mode 100644 index 0073921..0000000 --- a/k8ci.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci" -) - -func (dc *Client) K8CI() *k8ci.K8CI { - return k8ci.New(dc) -} diff --git a/k8s.go b/k8s.go deleted file mode 100644 index 53aebbf..0000000 --- a/k8s.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/k8s" -) - -func (dc *Client) K8S() *k8s.K8S { - return k8s.New(dc) -} diff --git a/kvmppc.go b/kvmppc.go deleted file mode 100644 index 65a9744..0000000 --- a/kvmppc.go +++ /dev/null @@ -1,7 +0,0 @@ -package decortsdk - -import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc" - -func (dc *Client) KVMPPC() *kvmppc.KVMPPC { - return kvmppc.New(dc) -} diff --git a/kvmx86.go b/kvmx86.go deleted file mode 100644 index cf1500c..0000000 --- a/kvmx86.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86" -) - -func (dc *Client) KVMX86() *kvmx86.KVMX86 { - return kvmx86.New(dc) -} diff --git a/lb.go b/lb.go deleted file mode 100644 index 34a264d..0000000 --- a/lb.go +++ /dev/null @@ -1,7 +0,0 @@ -package decortsdk - -import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb" - -func (dc *Client) LB() *lb.LB { - return lb.New(dc) -} diff --git a/locatons.go b/locatons.go deleted file mode 100644 index 2c72ce2..0000000 --- a/locatons.go +++ /dev/null @@ -1,7 +0,0 @@ -package decortsdk - -import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations" - -func (dc *Client) Locations() *locations.Locations { - return locations.New(dc) -} diff --git a/opts/decort_opts.go b/opts/decort_opts.go deleted file mode 100644 index 4d9f1e7..0000000 --- a/opts/decort_opts.go +++ /dev/null @@ -1,6 +0,0 @@ -package opts - -type DecortOpts struct { - Type string - Value string -} diff --git a/opts/opts.go b/opts/opts.go deleted file mode 100644 index c5c76f6..0000000 --- a/opts/opts.go +++ /dev/null @@ -1,26 +0,0 @@ -package opts - -import "github.com/rudecs/decort-sdk/typed" - -type Opts struct { - IsAdmin bool - AdminValue string -} - -func New(options []DecortOpts) *Opts { - if len(options) == 0 { - return nil - } - - option := &Opts{} - - for _, v := range options { - if v.Type == typed.TypeAdmin { - option.IsAdmin = true - option.AdminValue = v.Value - } - - } - - return option -} diff --git a/pkg/cloudapi/account.go b/pkg/cloudapi/account.go new file mode 100644 index 0000000..79bff01 --- /dev/null +++ b/pkg/cloudapi/account.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/account" +) + +func (ca *CloudApi) Account() *account.Account { + return account.New(ca.client) +} diff --git a/pkg/cloudapi/account/account.go b/pkg/cloudapi/account/account.go index 93d53f4..a01d8a8 100644 --- a/pkg/cloudapi/account/account.go +++ b/pkg/cloudapi/account/account.go @@ -1,15 +1,15 @@ -package account - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Account struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Account { - return &Account{ - client, - } -} +package account + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Account struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Account { + return &Account{ + client, + } +} diff --git a/pkg/cloudapi/account/add_user.go b/pkg/cloudapi/account/add_user.go index d5256be..fedb31d 100644 --- a/pkg/cloudapi/account/add_user.go +++ b/pkg/cloudapi/account/add_user.go @@ -1,68 +1,58 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AddUserRequest struct { - AccountId uint64 `url:"accountId"` - UserId string `url:"userId"` - AccessType string `url:"accesstype"` -} - -func (arq AddUserRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - if arq.UserId == "" { - return errors.New("validation-error: field UserId can not be empty") - } - - if arq.AccessType == "" { - return errors.New("validation-error: field AccessType can not be empty") - } - - isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"}) - if !isValid { - return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") - } - - return nil -} - -func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/addUser" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AddUserRequest struct { + AccountID uint64 `url:"accountId"` + UserID string `url:"userId"` + AccessType string `url:"accesstype"` +} + +func (arq AddUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.UserID == "" { + return errors.New("validation-error: field UserID can not be empty") + } + + if arq.AccessType == "" { + return errors.New("validation-error: field AccessType can not be empty") + } + + isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"}) + if !isValid { + return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") + } + + return nil +} + +func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/addUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/account/audits.go b/pkg/cloudapi/account/audits.go index 1757666..b8d0b93 100644 --- a/pkg/cloudapi/account/audits.go +++ b/pkg/cloudapi/account/audits.go @@ -1,54 +1,43 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AuditsRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq AuditsRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/audits" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - auditsRaw, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - audits := AccountAuditsList{} - - err = json.Unmarshal([]byte(auditsRaw), &audits) - if err != nil { - return nil, err - } - - return audits, nil -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AuditsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq AuditsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/audits" + + auditsRaw, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + audits := AccountAuditsList{} + + err = json.Unmarshal(auditsRaw, &audits) + if err != nil { + return nil, err + } + + return audits, nil +} diff --git a/pkg/cloudapi/account/create.go b/pkg/cloudapi/account/create.go index 412dd8f..542b50c 100644 --- a/pkg/cloudapi/account/create.go +++ b/pkg/cloudapi/account/create.go @@ -1,65 +1,54 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - Name string `url:"name"` - Username string `url:"username"` - EmailAddress string `url:"emailaddress,omitempty"` - MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"` - MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"` - MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"` - MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"` - MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"` - SendAccessEmails bool `url:"sendAccessEmails,omitempty"` - GpuUnits uint `url:"gpu_units,omitempty"` -} - -func (arq CreateRequest) Validate() error { - if arq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if arq.Username == "" { - return errors.New("validation-error: field Username can not be empty") - } - - return nil -} - -func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/account/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + Name string `url:"name"` + Username string `url:"username"` + EmailAddress string `url:"emailaddress,omitempty"` + MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"` + SendAccessEmails bool `url:"sendAccessEmails,omitempty"` + GPUUnits uint64 `url:"gpu_units,omitempty"` +} + +func (arq CreateRequest) Validate() error { + if arq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if arq.Username == "" { + return errors.New("validation-error: field Username can not be empty") + } + + return nil +} + +func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/account/create" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/account/delete.go b/pkg/cloudapi/account/delete.go index 38d3531..7673095 100644 --- a/pkg/cloudapi/account/delete.go +++ b/pkg/cloudapi/account/delete.go @@ -1,52 +1,36 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - AccountId uint64 `url:"accountId"` - Permanently bool `url:"permanently,omitempty"` -} - -func (arq DeleteRequest) Validate() error { - - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId must be set") - } - return nil -} - -func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/delete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" +) + +type DeleteRequest struct { + AccountID uint64 `url:"accountId"` + Permanently bool `url:"permanently,omitempty"` +} + +func (arq DeleteRequest) Validate() error { + + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + return nil +} + +func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/delete" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudapi/account/delete_user.go b/pkg/cloudapi/account/delete_user.go index 54abdb9..409c144 100644 --- a/pkg/cloudapi/account/delete_user.go +++ b/pkg/cloudapi/account/delete_user.go @@ -1,58 +1,47 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteUserRequest struct { - AccountId uint64 `url:"accountId"` - UserId string `url:"userId"` - RecursiveDelete bool `url:"recursivedelete,omitempty"` -} - -func (arq DeleteUserRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - if arq.UserId == "" { - return errors.New("validation-error: field UserId can not be empty") - } - - return nil -} - -func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/deleteUser" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteUserRequest struct { + AccountID uint64 `url:"accountId"` + UserID string `url:"userId"` + RecursiveDelete bool `url:"recursivedelete,omitempty"` +} + +func (arq DeleteUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.UserID == "" { + return errors.New("validation-error: field UserID can not be empty") + } + + return nil +} + +func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/deleteUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/account/disable_enable.go b/pkg/cloudapi/account/disable_enable.go index 58b0ea0..8b2a938 100644 --- a/pkg/cloudapi/account/disable_enable.go +++ b/pkg/cloudapi/account/disable_enable.go @@ -1,80 +1,62 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisabelEnableRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq DisabelEnableRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/disable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} - -func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/enable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisabelEnableRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq DisabelEnableRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/disable" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} + +func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/enable" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/account/get.go b/pkg/cloudapi/account/get.go index 6512d4f..c7dd5d5 100644 --- a/pkg/cloudapi/account/get.go +++ b/pkg/cloudapi/account/get.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq GetRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - account := &AccountWithResources{} - - err = json.Unmarshal(res, &account) - if err != nil { - return nil, err - } - - return account, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq GetRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/get" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + account := &AccountWithResources{} + + err = json.Unmarshal(res, &account) + if err != nil { + return nil, err + } + + return account, nil + +} diff --git a/pkg/cloudapi/account/get_consumed_account_units.go b/pkg/cloudapi/account/get_consumed_account_units.go index 14a3e79..5c31f0e 100644 --- a/pkg/cloudapi/account/get_consumed_account_units.go +++ b/pkg/cloudapi/account/get_consumed_account_units.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetConsumedAccountUnitsRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq GetConsumedAccountUnitsRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/getConsumedAccountUnits" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - rl := &ResourceLimits{} - - err = json.Unmarshal(res, &rl) - if err != nil { - return nil, err - } - - return rl, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetConsumedAccountUnitsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq GetConsumedAccountUnitsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/getConsumedAccountUnits" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + rl := &ResourceLimits{} + + err = json.Unmarshal(res, &rl) + if err != nil { + return nil, err + } + + return rl, nil + +} diff --git a/pkg/cloudapi/account/get_consumed_cloud_units_by_type.go b/pkg/cloudapi/account/get_consumed_cloud_units_by_type.go index e6a432c..1735446 100644 --- a/pkg/cloudapi/account/get_consumed_cloud_units_by_type.go +++ b/pkg/cloudapi/account/get_consumed_cloud_units_by_type.go @@ -1,64 +1,54 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetConsumedCloudUnitsByTypeRequest struct { - AccountId uint64 `url:"accountId"` - CUType string `url:"cutype"` -} - -func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - if arq.CUType == "" { - return errors.New("validation-error: field CUType can not be empty") - } - - isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"}) - if !isValid { - return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP") - } - - return nil -} - -func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/account/getConsumedCloudUnitsByType" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseFloat(string(res), 64) - if err != nil { - return 0, err - } - - return result, nil - -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type GetConsumedCloudUnitsByTypeRequest struct { + AccountID uint64 `url:"accountId"` + CUType string `url:"cutype"` +} + +func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.CUType == "" { + return errors.New("validation-error: field CUType can not be empty") + } + + isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"}) + if !isValid { + return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP") + } + + return nil +} + +func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/account/getConsumedCloudUnitsByType" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseFloat(string(res), 64) + if err != nil { + return 0, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/account/get_consumption.go b/pkg/cloudapi/account/get_consumption.go index c97cb86..6d375aa 100644 --- a/pkg/cloudapi/account/get_consumption.go +++ b/pkg/cloudapi/account/get_consumption.go @@ -1,83 +1,65 @@ -package account - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetConsumtionRequest struct { - AccountId uint64 `url:"accountId"` - Start uint64 `url:"start"` - End uint64 `url:"end"` -} - -func (arq GetConsumtionRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - if arq.Start == 0 { - return errors.New("validation-error: field Start can not be empty or equal to 0") - } - - if arq.End == 0 { - return errors.New("validation-error: field End can not be empty or equal to 0") - } - - return nil -} - -func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/account/getConsumtion" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil - -} - -func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/account/getConsumtion" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.GET, url, req) - if err != nil { - return "", err - } - - return string(res), nil - -} +package account + +import ( + "context" + "errors" + "net/http" +) + +type GetConsumtionRequest struct { + AccountID uint64 `url:"accountId"` + Start uint64 `url:"start"` + End uint64 `url:"end"` +} + +func (arq GetConsumtionRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.Start == 0 { + return errors.New("validation-error: field Start can not be empty or equal to 0") + } + + if arq.End == 0 { + return errors.New("validation-error: field End can not be empty or equal to 0") + } + + return nil +} + +func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/account/getConsumtion" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil + +} + +func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/account/getConsumtion" + prefix := "/cloudapi" + + url = prefix + url + res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req) + if err != nil { + return "", err + } + + return string(res), nil + +} diff --git a/pkg/cloudapi/account/get_reserved_account_units.go b/pkg/cloudapi/account/get_reserved_account_units.go index 37caf7a..316c833 100644 --- a/pkg/cloudapi/account/get_reserved_account_units.go +++ b/pkg/cloudapi/account/get_reserved_account_units.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetReservedAccountUnitsRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq GetReservedAccountUnitsRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/getReservedAccountUnits" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - rl := &ResourceLimits{} - - err = json.Unmarshal(res, &rl) - if err != nil { - return nil, err - } - - return rl, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetReservedAccountUnitsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq GetReservedAccountUnitsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/getReservedAccountUnits" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + rl := &ResourceLimits{} + + err = json.Unmarshal(res, &rl) + if err != nil { + return nil, err + } + + return rl, nil + +} diff --git a/pkg/cloudapi/account/list.go b/pkg/cloudapi/account/list.go index e083c69..b37daf3 100644 --- a/pkg/cloudapi/account/list.go +++ b/pkg/cloudapi/account/list.go @@ -1,42 +1,31 @@ -package account - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) { - url := "/account/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountList := AccountCloudApiList{} - - err = json.Unmarshal(res, &accountList) - if err != nil { - return nil, err - } - - return accountList, nil - -} +package account + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList, error) { + url := "/cloudapi/account/list" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountList := AccountCloudApiList{} + + err = json.Unmarshal(res, &accountList) + if err != nil { + return nil, err + } + + return accountList, nil + +} diff --git a/pkg/cloudapi/account/list_computes.go b/pkg/cloudapi/account/list_computes.go index fa29a88..e46b4ad 100644 --- a/pkg/cloudapi/account/list_computes.go +++ b/pkg/cloudapi/account/list_computes.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListComputesRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq ListComputesRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listComputes" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountComputesList := AccountComputesList{} - - err = json.Unmarshal(res, &accountComputesList) - if err != nil { - return nil, err - } - - return accountComputesList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListComputesRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListComputesRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (AccountComputesList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listComputes" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountComputesList := AccountComputesList{} + + err = json.Unmarshal(res, &accountComputesList) + if err != nil { + return nil, err + } + + return accountComputesList, nil + +} diff --git a/pkg/cloudapi/account/list_deleted.go b/pkg/cloudapi/account/list_deleted.go index 972c164..a067061 100644 --- a/pkg/cloudapi/account/list_deleted.go +++ b/pkg/cloudapi/account/list_deleted.go @@ -1,42 +1,31 @@ -package account - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) { - url := "/account/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountList := AccountCloudApiList{} - - err = json.Unmarshal(res, &accountList) - if err != nil { - return nil, err - } - - return accountList, nil - -} +package account + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (AccountCloudApiList, error) { + url := "/cloudapi/account/listDeleted" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountList := AccountCloudApiList{} + + err = json.Unmarshal(res, &accountList) + if err != nil { + return nil, err + } + + return accountList, nil + +} diff --git a/pkg/cloudapi/account/list_disks.go b/pkg/cloudapi/account/list_disks.go index c239163..cabbd94 100644 --- a/pkg/cloudapi/account/list_disks.go +++ b/pkg/cloudapi/account/list_disks.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDisksRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq ListDisksRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listDisks" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountDisksList := AccountDisksList{} - - err = json.Unmarshal(res, &accountDisksList) - if err != nil { - return nil, err - } - - return accountDisksList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListDisksRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListDisksRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDisksList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listDisks" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountDisksList := AccountDisksList{} + + err = json.Unmarshal(res, &accountDisksList) + if err != nil { + return nil, err + } + + return accountDisksList, nil + +} diff --git a/pkg/cloudapi/account/list_flipgroups.go b/pkg/cloudapi/account/list_flipgroups.go index 04c864e..cb7fe93 100644 --- a/pkg/cloudapi/account/list_flipgroups.go +++ b/pkg/cloudapi/account/list_flipgroups.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListFlipGroupsRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq ListFlipGroupsRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listFlipGroups" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountFlipGroupsList := AccountFlipGroupsList{} - - err = json.Unmarshal(res, &accountFlipGroupsList) - if err != nil { - return nil, err - } - - return accountFlipGroupsList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListFlipGroupsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListFlipGroupsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (AccountFlipGroupsList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listFlipGroups" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountFlipGroupsList := AccountFlipGroupsList{} + + err = json.Unmarshal(res, &accountFlipGroupsList) + if err != nil { + return nil, err + } + + return accountFlipGroupsList, nil + +} diff --git a/pkg/cloudapi/account/list_rg.go b/pkg/cloudapi/account/list_rg.go index cc32dbc..879ec70 100644 --- a/pkg/cloudapi/account/list_rg.go +++ b/pkg/cloudapi/account/list_rg.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRGRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq ListRGRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listRG" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountRGList := AccountRGList{} - - err = json.Unmarshal(res, &accountRGList) - if err != nil { - return nil, err - } - - return accountRGList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListRGRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListRGRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listRG" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountRGList := AccountRGList{} + + err = json.Unmarshal(res, &accountRGList) + if err != nil { + return nil, err + } + + return accountRGList, nil + +} diff --git a/pkg/cloudapi/account/list_templates.go b/pkg/cloudapi/account/list_templates.go index 96420e7..fdcf480 100644 --- a/pkg/cloudapi/account/list_templates.go +++ b/pkg/cloudapi/account/list_templates.go @@ -1,56 +1,45 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListTemplatesRequest struct { - AccountId uint64 `url:"accountId"` - IncludeDeleted bool `url:"includedeleted"` -} - -func (arq ListTemplatesRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listTemplates" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountTemplatesList := AccountTemplatesList{} - - err = json.Unmarshal(res, &accountTemplatesList) - if err != nil { - return nil, err - } - - return accountTemplatesList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListTemplatesRequest struct { + AccountID uint64 `url:"accountId"` + IncludeDeleted bool `url:"includedeleted"` +} + +func (arq ListTemplatesRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (AccountTemplatesList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listTemplates" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountTemplatesList := AccountTemplatesList{} + + err = json.Unmarshal(res, &accountTemplatesList) + if err != nil { + return nil, err + } + + return accountTemplatesList, nil + +} diff --git a/pkg/cloudapi/account/list_vins.go b/pkg/cloudapi/account/list_vins.go index e224274..394a5b3 100644 --- a/pkg/cloudapi/account/list_vins.go +++ b/pkg/cloudapi/account/list_vins.go @@ -1,55 +1,44 @@ -package account - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListVinsRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq ListVinsRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/account/listVins" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - accountVinsList := AccountVinsList{} - - err = json.Unmarshal(res, &accountVinsList) - if err != nil { - return nil, err - } - - return accountVinsList, nil - -} +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListVINSRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListVINSRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINSList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/account/listVins" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + accountVINSList := AccountVINSList{} + + err = json.Unmarshal(res, &accountVINSList) + if err != nil { + return nil, err + } + + return accountVINSList, nil + +} diff --git a/pkg/cloudapi/account/models.go b/pkg/cloudapi/account/models.go index 42b1757..84e62f8 100644 --- a/pkg/cloudapi/account/models.go +++ b/pkg/cloudapi/account/models.go @@ -1,229 +1,229 @@ -package account - -type AccountAclRecord struct { - IsExplicit bool `json:"explicit"` - GUID string `json:"guid"` - Rights string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UgroupID string `json:"userGroupId"` - CanBeDeleted bool `json:"canBeDeleted"` -} - -type ResourceLimits struct { - CUC float64 `json:"CU_C"` - CUD float64 `json:"CU_D"` - CUI float64 `json:"CU_I"` - CUM float64 `json:"CU_M"` - CUNP float64 `json:"CU_NP"` - GpuUnits float64 `json:"gpu_units"` -} - -type AccountRecord struct { - DCLocation string `json:"DCLocation"` - CKey string `jspn:"_ckey"` - Meta []interface{} `json:"_meta"` - Acl []AccountAclRecord `json:"acl"` - Company string `json:"company"` - CompanyUrl string `json:"companyurl"` - CreatedBy string `jspn:"createdBy"` - CreatedTime int `json:"createdTime"` - DeactiovationTime float64 `json:"deactivationTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - DisplayName string `json:"displayname"` - GUID int `json:"guid"` - ID int `json:"id"` - Name string `json:"name"` - ResourceLimits ResourceLimits `json:"resourceLimits"` - SendAccessEmails bool `json:"sendAccessEmails"` - ServiceAccount bool `json:"serviceAccount"` - Status string `json:"status"` - UpdatedTime int `json:"updatedTime"` - Version int `json:"version"` - Vins []int `json:"vins"` -} - -type AccountList []AccountRecord - -type AccountCloudApi struct { - Acl []AccountAclRecord `json:"acl"` - CreatedTime int `json:"createdTime"` - DeletedTime int `json:"deletedTime"` - ID int `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountCloudApiList []AccountCloudApi - -type Resource struct { - CPU int `json:"cpu"` - Disksize int `json:"disksize"` - Extips int `json:"extips"` - Exttraffic int `json:"exttraffic"` - GPU int `json:"gpu"` - RAM int `json:"ram"` -} - -type Resources struct { - Current Resource `json:"Current"` - Reserved Resource `json:"Reserved"` -} - -type Computes struct { - Started int `json:"started"` - Stopped int `json:"stopped"` -} - -type Machines struct { - Running int `json:"running"` - Halted int `json:"halted"` -} - -type AccountWithResources struct { - Account - Resources Resources `json:"Resources"` - Computes Computes `json:"computes"` - Machines Machines `json:"machines"` - Vinses int `json:"vinses"` -} - -type AccountCompute struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - CPUs int `json:"cpus"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ComputeId int `json:"id"` - ComputeName string `json:"name"` - RAM int `json:"ram"` - Registered bool `json:"registered"` - RGId int `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - TotalDisksSize int `json:"totalDisksSize"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - UserManaged bool `json:"userManaged"` - VinsConnected int `json:"vinsConnected"` -} - -type AccountComputesList []AccountCompute - -type AccountDisk struct { - ID int `json:"id"` - Name string `json:"name"` - Pool string `json:"pool"` - SepId int `json:"sepId"` - SizeMax int `json:"sizeMax"` - Type string `json:"type"` -} - -type AccountDisksList []AccountDisk - -type AccountVin struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - Computes int `json:"computes"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ExternalIP string `json:"externalIP"` - ID int `json:"id"` - Name string `json:"name"` - Network string `json:"network"` - PriVnfDevId int `json:"priVnfDevId"` - RGId int `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountVinsList []AccountVin - -type AccountAudit struct { - Call string `json:"call"` - ResponseTime float64 `json:"responsetime"` - StatusCode int `json:"statuscode"` - Timestamp float64 `json:"timestamp"` - User string `json:"user"` -} - -type AccountAuditsList []AccountAudit - -type AccountRGComputes struct { - Started int `json:"Started"` - Stopped int `json:"Stopped"` -} - -type AccountRGResources struct { - Consumed Resource `json:"Consumed"` - Limits Resource `json:"Limits"` - Reserved Resource `json:"Reserved"` -} - -type AccountRG struct { - Computes AccountRGComputes `json:"Computes"` - Resources AccountRGResources `json:"Resources"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - RGID int `json:"id"` - Milestones int `json:"milestones"` - RGName string `json:"name"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - Vinses int `json:"vinses"` -} - -type AccountRGList []AccountRG - -type AccountTemplate struct { - UNCPath string `json:"UNCPath"` - AccountId int `json:"accountId"` - Description string `json:"desc"` - ID int `json:"id"` - Name string `json:"name"` - Public bool `json:"public"` - Size int `json:"size"` - Status string `json:"status"` - Type string `json:"type"` - Username string `json:"username"` -} - -type AccountTemplatesList []AccountTemplate - -type AccountFlipGroup struct { - AccountId int `json:"accountId"` - ClientType string `json:"clientType"` - ConnType string `json:"connType"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DefaultGW string `json:"defaultGW"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - Description string `json:"desc"` - GID int `json:"gid"` - GUID int `json:"guid"` - ID int `json:"id"` - IP string `json:"ip"` - Milestones int `json:"milestones"` - Name string `json:"name"` - NetID int `json:"netId"` - NetType string `json:"netType"` - NetMask int `json:"netmask"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountFlipGroupsList []AccountFlipGroup +package account + +type AccountACLRecord struct { + IsExplicit bool `json:"explicit"` + GUID string `json:"guid"` + Rights string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UgroupID string `json:"userGroupId"` + CanBeDeleted bool `json:"canBeDeleted"` +} + +type ResourceLimits struct { + CUC float64 `json:"CU_C"` + CUD float64 `json:"CU_D"` + CUI float64 `json:"CU_I"` + CUM float64 `json:"CU_M"` + CUNP float64 `json:"CU_NP"` + GPUUnits float64 `json:"gpu_units"` +} + +type AccountRecord struct { + DCLocation string `json:"DCLocation"` + CKey string `jspn:"_ckey"` + Meta []interface{} `json:"_meta"` + ACL []AccountACLRecord `json:"acl"` + Company string `json:"company"` + CompanyURL string `json:"companyurl"` + CreatedBy string `jspn:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeactiovationTime float64 `json:"deactivationTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + DisplayName string `json:"displayname"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + Name string `json:"name"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + SendAccessEmails bool `json:"sendAccessEmails"` + ServiceAccount bool `json:"serviceAccount"` + Status string `json:"status"` + UpdatedTime uint64 `json:"updatedTime"` + Version uint64 `json:"version"` + VINS []uint64 `json:"vins"` +} + +type AccountList []AccountRecord + +type AccountCloudApi struct { + ACL []AccountACLRecord `json:"acl"` + CreatedTime uint64 `json:"createdTime"` + DeletedTime uint64 `json:"deletedTime"` + ID uint64 `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type AccountCloudApiList []AccountCloudApi + +type Resource struct { + CPU int64 `json:"cpu"` + DiskSize int64 `json:"disksize"` + ExtIPs int64 `json:"extips"` + ExtTraffic int64 `json:"exttraffic"` + GPU int64 `json:"gpu"` + RAM int64 `json:"ram"` +} + +type Resources struct { + Current Resource `json:"Current"` + Reserved Resource `json:"Reserved"` +} + +type Computes struct { + Started uint64 `json:"started"` + Stopped uint64 `json:"stopped"` +} + +type Machines struct { + Running uint64 `json:"running"` + Halted uint64 `json:"halted"` +} + +type AccountWithResources struct { + Account + Resources Resources `json:"Resources"` + Computes Computes `json:"computes"` + Machines Machines `json:"machines"` + VINSes uint64 `json:"vinses"` +} + +type AccountCompute struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + CPUs uint64 `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ComputeID uint64 `json:"id"` + ComputeName string `json:"name"` + RAM uint64 `json:"ram"` + Registered bool `json:"registered"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TotalDisksSize uint64 `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + VINSConnected uint64 `json:"vinsConnected"` +} + +type AccountComputesList []AccountCompute + +type AccountDisk struct { + ID uint64 `json:"id"` + Name string `json:"name"` + Pool string `json:"pool"` + SepID uint64 `json:"sepId"` + SizeMax uint64 `json:"sizeMax"` + Type string `json:"type"` +} + +type AccountDisksList []AccountDisk + +type AccountVIN struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + Computes uint64 `json:"computes"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID uint64 `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + PriVnfDevID uint64 `json:"priVnfDevId"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type AccountVINSList []AccountVIN + +type AccountAudit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode uint64 `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type AccountAuditsList []AccountAudit + +type AccountRGComputes struct { + Started uint64 `json:"Started"` + Stopped uint64 `json:"Stopped"` +} + +type AccountRGResources struct { + Consumed Resource `json:"Consumed"` + Limits Resource `json:"Limits"` + Reserved Resource `json:"Reserved"` +} + +type AccountRG struct { + Computes AccountRGComputes `json:"Computes"` + Resources AccountRGResources `json:"Resources"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + RGID uint64 `json:"id"` + Milestones uint64 `json:"milestones"` + RGName string `json:"name"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINSes uint64 `json:"vinses"` +} + +type AccountRGList []AccountRG + +type AccountTemplate struct { + UNCPath string `json:"UNCPath"` + AccountID uint64 `json:"accountId"` + Description string `json:"desc"` + ID uint64 `json:"id"` + Name string `json:"name"` + Public bool `json:"public"` + Size uint64 `json:"size"` + Status string `json:"status"` + Type string `json:"type"` + Username string `json:"username"` +} + +type AccountTemplatesList []AccountTemplate + +type AccountFlipGroup struct { + AccountID uint64 `json:"accountId"` + ClientType string `json:"clientType"` + ConnType string `json:"connType"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefaultGW string `json:"defaultGW"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + IP string `json:"ip"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetType string `json:"netType"` + NetMask uint64 `json:"netmask"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type AccountFlipGroupsList []AccountFlipGroup diff --git a/pkg/cloudapi/account/restore.go b/pkg/cloudapi/account/restore.go index 8352faa..bc14300 100644 --- a/pkg/cloudapi/account/restore.go +++ b/pkg/cloudapi/account/restore.go @@ -1,53 +1,42 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (arq RestoreRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/restore" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq RestoreRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/restore" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/account/update.go b/pkg/cloudapi/account/update.go index e9a82f7..5efeefb 100644 --- a/pkg/cloudapi/account/update.go +++ b/pkg/cloudapi/account/update.go @@ -1,60 +1,49 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UpdateRequest struct { - AccountId uint64 `url:"accountId"` - Name string `url:"name,omitempty"` - MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"` - MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"` - MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"` - MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"` - MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"` - SendAccessEmails bool `url:"sendAccessEmails,omitempty"` - GpuUnits uint `url:"gpu_units,omitempty"` -} - -func (arq UpdateRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/update" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + AccountID uint64 `url:"accountId"` + Name string `url:"name,omitempty"` + MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"` + SendAccessEmails bool `url:"sendAccessEmails,omitempty"` + GPUUnits uint64 `url:"gpu_units,omitempty"` +} + +func (arq UpdateRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/update" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/account/update_user.go b/pkg/cloudapi/account/update_user.go index f96aeab..8949dc2 100644 --- a/pkg/cloudapi/account/update_user.go +++ b/pkg/cloudapi/account/update_user.go @@ -1,68 +1,58 @@ -package account - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UpdateUserRequest struct { - AccountId uint64 `url:"accountId"` - UserId string `url:"userId"` - AccessType string `url:"accesstype"` -} - -func (arq UpdateUserRequest) Validate() error { - if arq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - if arq.UserId == "" { - return errors.New("validation-error: field UserId can not be empty") - } - - if arq.AccessType == "" { - return errors.New("validation-error: field AccessType can not be empty") - } - - isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"}) - if !isValid { - return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") - } - - return nil -} - -func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/account/updateUser" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := a.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package account + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type UpdateUserRequest struct { + AccountID uint64 `url:"accountId"` + UserID string `url:"userId"` + AccessType string `url:"accesstype"` +} + +func (arq UpdateUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.UserID == "" { + return errors.New("validation-error: field UserID can not be empty") + } + + if arq.AccessType == "" { + return errors.New("validation-error: field AccessType can not be empty") + } + + isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"}) + if !isValid { + return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") + } + + return nil +} + +func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/account/updateUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/bservice/create.go b/pkg/cloudapi/bservice/create.go index ee398c1..1196457 100644 --- a/pkg/cloudapi/bservice/create.go +++ b/pkg/cloudapi/bservice/create.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type CreateRequest struct { @@ -28,13 +26,13 @@ func (bsrq CreateRequest) Validate() error { return nil } -func (b BService) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { +func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) { if err := req.Validate(); err != nil { return 0, err } url := "/cloudapi/bservice/create" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return 0, err } diff --git a/pkg/cloudapi/bservice/delete.go b/pkg/cloudapi/bservice/delete.go index d54845f..4568f45 100644 --- a/pkg/cloudapi/bservice/delete.go +++ b/pkg/cloudapi/bservice/delete.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type DeleteRequest struct { @@ -22,13 +20,13 @@ func (bsrq DeleteRequest) Validate() error { return nil } -func (b BService) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/delete" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/disable.go b/pkg/cloudapi/bservice/disable.go index 76b7adc..86b3e40 100644 --- a/pkg/cloudapi/bservice/disable.go +++ b/pkg/cloudapi/bservice/disable.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type DisableRequest struct { @@ -21,13 +19,13 @@ func (bsrq DisableRequest) Validate() error { return nil } -func (b BService) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/delete" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/enable.go b/pkg/cloudapi/bservice/enable.go index 8cc0fa9..356d49b 100644 --- a/pkg/cloudapi/bservice/enable.go +++ b/pkg/cloudapi/bservice/enable.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type EnableRequest struct { @@ -21,13 +19,13 @@ func (bsrq EnableRequest) Validate() error { return nil } -func (b BService) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/enable" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/get.go b/pkg/cloudapi/bservice/get.go index 48c012b..413d24d 100644 --- a/pkg/cloudapi/bservice/get.go +++ b/pkg/cloudapi/bservice/get.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type GetRequest struct { @@ -21,13 +19,13 @@ func (bsrq GetRequest) Validate() error { return nil } -func (b BService) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*BasicService, error) { +func (b BService) Get(ctx context.Context, req GetRequest) (*BasicService, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/bservice/get" - bsRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + bsRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/bservice/group_add.go b/pkg/cloudapi/bservice/group_add.go index 2ed02f2..6e38ad0 100644 --- a/pkg/cloudapi/bservice/group_add.go +++ b/pkg/cloudapi/bservice/group_add.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupAddRequest struct { @@ -20,7 +18,7 @@ type GroupAddRequest struct { Driver string `url:"driver"` Role string `url:"role,omitempty"` VINSes []uint64 `url:"vinses,omitempty"` - Extnets []uint64 `url:"extnets,omitempty"` + ExtNets []uint64 `url:"extnets,omitempty"` TimeoutStart uint64 `url:"timeoutStart"` } @@ -60,13 +58,13 @@ func (bsrq GroupAddRequest) Validate() error { return nil } -func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest, options ...opts.DecortOpts) (uint64, error) { +func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) { if err := req.Validate(); err != nil { return 0, err } url := "/cloudapi/bservice/groupAdd" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return 0, err } diff --git a/pkg/cloudapi/bservice/group_compute_remove.go b/pkg/cloudapi/bservice/group_compute_remove.go index 0635587..c903508 100644 --- a/pkg/cloudapi/bservice/group_compute_remove.go +++ b/pkg/cloudapi/bservice/group_compute_remove.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupComputeRemoveRequest struct { @@ -31,13 +29,13 @@ func (bsrq GroupComputeRemoveRequest) Validate() error { return nil } -func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupComputeRemove" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_get.go b/pkg/cloudapi/bservice/group_get.go index 8230e7c..25987e9 100644 --- a/pkg/cloudapi/bservice/group_get.go +++ b/pkg/cloudapi/bservice/group_get.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type GroupGetRequest struct { @@ -26,13 +24,13 @@ func (bsrq GroupGetRequest) Validate() error { return nil } -func (b BService) GroupGet(ctx context.Context, req GroupGetRequest, options ...opts.DecortOpts) (*Group, error) { +func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*Group, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/bservice/groupGet" - groupRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + groupRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/bservice/group_parent_add.go b/pkg/cloudapi/bservice/group_parent_add.go index 02ce409..2e1f666 100644 --- a/pkg/cloudapi/bservice/group_parent_add.go +++ b/pkg/cloudapi/bservice/group_parent_add.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupParentAddRequest struct { @@ -31,13 +29,13 @@ func (bsrq GroupParentAddRequest) Validate() error { return nil } -func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupParentAdd" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_parent_remove.go b/pkg/cloudapi/bservice/group_parent_remove.go index a57e63e..afc77d1 100644 --- a/pkg/cloudapi/bservice/group_parent_remove.go +++ b/pkg/cloudapi/bservice/group_parent_remove.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupParentRemoveRequest struct { @@ -31,13 +29,13 @@ func (bsrq GroupParentRemoveRequest) Validate() error { return nil } -func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupParentRemove" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_remove.go b/pkg/cloudapi/bservice/group_remove.go index c200ce3..ef2df93 100644 --- a/pkg/cloudapi/bservice/group_remove.go +++ b/pkg/cloudapi/bservice/group_remove.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupRemoveRequest struct { @@ -26,13 +24,13 @@ func (bsrq GroupRemoveRequest) Validate() error { return nil } -func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupRemove" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err diff --git a/pkg/cloudapi/bservice/group_resize.go b/pkg/cloudapi/bservice/group_resize.go index 1588e85..ba420d4 100644 --- a/pkg/cloudapi/bservice/group_resize.go +++ b/pkg/cloudapi/bservice/group_resize.go @@ -3,11 +3,10 @@ package bservice import ( "context" "errors" + "net/http" "strconv" "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupResizeRequest struct { @@ -37,13 +36,13 @@ func (bsrq GroupResizeRequest) Validate() error { return nil } -func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest, options ...opts.DecortOpts) (uint64, error) { +func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) { if err := req.Validate(); err != nil { return 0, err } url := "/cloudapi/bservice/groupResize" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return 0, err } diff --git a/pkg/cloudapi/bservice/group_start.go b/pkg/cloudapi/bservice/group_start.go index 3d52c6a..35b6629 100644 --- a/pkg/cloudapi/bservice/group_start.go +++ b/pkg/cloudapi/bservice/group_start.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupStartRequest struct { @@ -26,13 +24,13 @@ func (bsrq GroupStartRequest) Validate() error { return nil } -func (b BService) GroupStart(ctx context.Context, req GroupStartRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupStart" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_stop.go b/pkg/cloudapi/bservice/group_stop.go index 82e268a..155d8fa 100644 --- a/pkg/cloudapi/bservice/group_stop.go +++ b/pkg/cloudapi/bservice/group_stop.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupStopRequest struct { @@ -27,13 +25,13 @@ func (bsrq GroupStopRequest) Validate() error { return nil } -func (b BService) GroupStop(ctx context.Context, req GroupStopRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupStop" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_update.go b/pkg/cloudapi/bservice/group_update.go index 1771ed5..184cf80 100644 --- a/pkg/cloudapi/bservice/group_update.go +++ b/pkg/cloudapi/bservice/group_update.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupUpdateRequest struct { @@ -32,13 +30,13 @@ func (bsrq GroupUpdateRequest) Validate() error { return nil } -func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupUpdate" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_update_extnet.go b/pkg/cloudapi/bservice/group_update_extnet.go index 8353e14..d10b267 100644 --- a/pkg/cloudapi/bservice/group_update_extnet.go +++ b/pkg/cloudapi/bservice/group_update_extnet.go @@ -3,19 +3,17 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) -type GroupUpdateExtnetRequest struct { +type GroupUpdateExtNetRequest struct { ServiceID uint64 `url:"serviceId"` CompGroupID uint64 `url:"compgroupId"` - Extnets []uint64 `url:"extnets,omitempty"` + ExtNets []uint64 `url:"extnets,omitempty"` } -func (bsrq GroupUpdateExtnetRequest) Validate() error { +func (bsrq GroupUpdateExtNetRequest) Validate() error { if bsrq.ServiceID == 0 { return errors.New("field ServiceID can not be empty or equal to 0") } @@ -27,13 +25,13 @@ func (bsrq GroupUpdateExtnetRequest) Validate() error { return nil } -func (b BService) GroupUpdateExtnet(ctx context.Context, req GroupUpdateExtnetRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupUpdateExtnet" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/group_update_vins.go b/pkg/cloudapi/bservice/group_update_vins.go index a0ed7b5..799aa6d 100644 --- a/pkg/cloudapi/bservice/group_update_vins.go +++ b/pkg/cloudapi/bservice/group_update_vins.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type GroupUpdateVINSRequest struct { @@ -27,13 +25,13 @@ func (bsrq GroupUpdateVINSRequest) Validate() error { return nil } -func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/groupUpdateVins" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/list.go b/pkg/cloudapi/bservice/list.go index fa12389..a2e4853 100644 --- a/pkg/cloudapi/bservice/list.go +++ b/pkg/cloudapi/bservice/list.go @@ -3,9 +3,7 @@ package bservice import ( "context" "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListRequest struct { @@ -15,9 +13,9 @@ type ListRequest struct { Size uint64 `url:"size,omitempty"` } -func (b BService) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) { +func (b BService) List(ctx context.Context, req ListRequest) (BasicServiceList, error) { url := "/cloudapi/bservice/list" - bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } @@ -30,9 +28,9 @@ func (b BService) List(ctx context.Context, req ListRequest, options ...opts.Dec return bsList, nil } -func (b BService) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) { +func (b BService) ListDeleted(ctx context.Context, req ListRequest) (BasicServiceList, error) { url := "/cloudapi/bservice/listDeleted" - bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/bservice/models.go b/pkg/cloudapi/bservice/models.go index 3d866f1..d6cbdfb 100644 --- a/pkg/cloudapi/bservice/models.go +++ b/pkg/cloudapi/bservice/models.go @@ -60,7 +60,7 @@ type Group struct { DeletedTime uint64 `json:"deletedTime"` Disk uint64 `json:"disk"` Driver string `json:"driver"` - Extnets []uint64 `json:"extnets"` + ExtNets []uint64 `json:"extnets"` GID uint64 `json:"gid"` GUID uint64 `json:"guid"` ID uint64 `json:"id"` diff --git a/pkg/cloudapi/bservice/restore.go b/pkg/cloudapi/bservice/restore.go index add6205..a7ecac2 100644 --- a/pkg/cloudapi/bservice/restore.go +++ b/pkg/cloudapi/bservice/restore.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type RestoreRequest struct { @@ -21,13 +19,13 @@ func (bsrq RestoreRequest) Validate() error { return nil } -func (b BService) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/restore" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/snapshot_create.go b/pkg/cloudapi/bservice/snapshot_create.go index b0bac96..babe1bc 100644 --- a/pkg/cloudapi/bservice/snapshot_create.go +++ b/pkg/cloudapi/bservice/snapshot_create.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type SnapshotCreateRequest struct { @@ -26,13 +24,13 @@ func (bsrq SnapshotCreateRequest) Validate() error { return nil } -func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/snapshotCreate" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/snapshot_delete.go b/pkg/cloudapi/bservice/snapshot_delete.go index aa5b551..2531369 100644 --- a/pkg/cloudapi/bservice/snapshot_delete.go +++ b/pkg/cloudapi/bservice/snapshot_delete.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type SnapshotDeleteRequest struct { @@ -26,13 +24,13 @@ func (bsrq SnapshotDeleteRequest) Validate() error { return nil } -func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/snapshotDelete" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/snapshot_list.go b/pkg/cloudapi/bservice/snapshot_list.go index 9d2027d..2a1417b 100644 --- a/pkg/cloudapi/bservice/snapshot_list.go +++ b/pkg/cloudapi/bservice/snapshot_list.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type SnapshotListRequest struct { @@ -21,13 +19,13 @@ func (bsrq SnapshotListRequest) Validate() error { return nil } -func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) ([]Snapshot, error) { +func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) ([]Snapshot, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/bservice/snapshotList" - snapshotListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + snapshotListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/bservice/snapshot_rollback.go b/pkg/cloudapi/bservice/snapshot_rollback.go index 20d9ead..2fa2903 100644 --- a/pkg/cloudapi/bservice/snapshot_rollback.go +++ b/pkg/cloudapi/bservice/snapshot_rollback.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type SnapshotRollbackRequest struct { @@ -26,13 +24,13 @@ func (bsrq SnapshotRollbackRequest) Validate() error { return nil } -func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/snapshotRollback" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/start.go b/pkg/cloudapi/bservice/start.go index 5d3a910..59a3662 100644 --- a/pkg/cloudapi/bservice/start.go +++ b/pkg/cloudapi/bservice/start.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type StartRequest struct { @@ -21,13 +19,13 @@ func (bsrq StartRequest) Validate() error { return nil } -func (b BService) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/start" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/bservice/stop.go b/pkg/cloudapi/bservice/stop.go index b1f8cbd..497ebb2 100644 --- a/pkg/cloudapi/bservice/stop.go +++ b/pkg/cloudapi/bservice/stop.go @@ -3,10 +3,8 @@ package bservice import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type StopRequest struct { @@ -21,13 +19,13 @@ func (bsrq StopRequest) Validate() error { return nil } -func (b BService) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) { +func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/bservice/stop" - res, err := b.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/cloudapi.go b/pkg/cloudapi/cloudapi.go new file mode 100644 index 0000000..501bf37 --- /dev/null +++ b/pkg/cloudapi/cloudapi.go @@ -0,0 +1,15 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type CloudApi struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *CloudApi { + return &CloudApi{ + client: client, + } +} diff --git a/pkg/cloudapi/compute.go b/pkg/cloudapi/compute.go new file mode 100644 index 0000000..010d4f7 --- /dev/null +++ b/pkg/cloudapi/compute.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/compute" +) + +func (ca *CloudApi) Compute() *compute.Compute { + return compute.New(ca.client) +} diff --git a/pkg/cloudapi/compute/affinity_group_check_start.go b/pkg/cloudapi/compute/affinity_group_check_start.go index 8289107..108641b 100644 --- a/pkg/cloudapi/compute/affinity_group_check_start.go +++ b/pkg/cloudapi/compute/affinity_group_check_start.go @@ -1,49 +1,39 @@ -package compute - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityGroupCheckStartRequest struct { - RGID uint64 `url:"rgId"` - AffinityLabel string `url:"affinityLabel"` -} - -func (crq AffinityGroupCheckStartRequest) Validate() error { - if crq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - if crq.AffinityLabel == "" { - return errors.New("validation-error: field AffinityLabel can not be empty") - } - - return nil -} - -func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/affinityGroupCheckStart" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package compute + +import ( + "context" + "errors" + "net/http" +) + +type AffinityGroupCheckStartRequest struct { + RGID uint64 `url:"rgId"` + AffinityLabel string `url:"affinityLabel"` +} + +func (crq AffinityGroupCheckStartRequest) Validate() error { + if crq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if crq.AffinityLabel == "" { + return errors.New("validation-error: field AffinityLabel can not be empty") + } + + return nil +} + +func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/compute/affinityGroupCheckStart" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/compute/affinity_label_remove.go b/pkg/cloudapi/compute/affinity_label_remove.go index 34837ff..521faa6 100644 --- a/pkg/cloudapi/compute/affinity_label_remove.go +++ b/pkg/cloudapi/compute/affinity_label_remove.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityLabelRemoveRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq AffinityLabelRemoveRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/affinityLabelRemove" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AffinityLabelRemoveRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq AffinityLabelRemoveRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/affinityLabelRemove" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/affinity_label_set.go b/pkg/cloudapi/compute/affinity_label_set.go index 055d052..b1bfab4 100644 --- a/pkg/cloudapi/compute/affinity_label_set.go +++ b/pkg/cloudapi/compute/affinity_label_set.go @@ -1,55 +1,45 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityLabelSetRequest struct { - ComputeId uint64 `url:"computeId"` - AffinityLabel string `url:"affinityLabel"` -} - -func (crq AffinityLabelSetRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.AffinityLabel == "" { - return errors.New("validation-error: field AffinityLabel can not be empty") - } - - return nil -} - -func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/affinityLabelSet" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AffinityLabelSetRequest struct { + ComputeID uint64 `url:"computeId"` + AffinityLabel string `url:"affinityLabel"` +} + +func (crq AffinityLabelSetRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.AffinityLabel == "" { + return errors.New("validation-error: field AffinityLabel can not be empty") + } + + return nil +} + +func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/affinityLabelSet" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/affinity_relations.go b/pkg/cloudapi/compute/affinity_relations.go index 097fdd1..2ad8731 100644 --- a/pkg/cloudapi/compute/affinity_relations.go +++ b/pkg/cloudapi/compute/affinity_relations.go @@ -1,54 +1,44 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityRelationsRequest struct { - ComputeId uint64 `url:"computeId"` - AffinityLabel string `url:"affinityLabel"` -} - -func (crq AffinityRelationsRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest, options ...opts.DecortOpts) (*AffinityRelations, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/affinityRelations" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - relations := &AffinityRelations{} - - err = json.Unmarshal([]byte(res), relations) - if err != nil { - return nil, err - } - - return relations, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AffinityRelationsRequest struct { + ComputeID uint64 `url:"computeId"` + AffinityLabel string `url:"affinityLabel"` +} + +func (crq AffinityRelationsRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*AffinityRelations, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/affinityRelations" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + relations := &AffinityRelations{} + + err = json.Unmarshal(res, relations) + if err != nil { + return nil, err + } + + return relations, nil +} diff --git a/pkg/cloudapi/compute/affinity_rule_add.go b/pkg/cloudapi/compute/affinity_rule_add.go index cf35f34..a1d52dd 100644 --- a/pkg/cloudapi/compute/affinity_rule_add.go +++ b/pkg/cloudapi/compute/affinity_rule_add.go @@ -1,91 +1,82 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityRuleAddRequest struct { - ComputeId uint64 `url:"computeId"` - Topology string `url:"topology"` - Policy string `url:"policy"` - Mode string `url:"mode"` - Key string `url:"key"` - Value string `url:"value"` -} - -func (crq AffinityRuleAddRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Topology == "" { - return errors.New("validation-error: field Topology can not be empty") - } - - validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) - if !validator { - return errors.New("validation-error: field Topology can be only compute or node") - } - - if crq.Policy == "" { - return errors.New("validation-error: field Policy can not be empty") - } - - validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) - if !validator { - return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") - } - - if crq.Mode == "" { - return errors.New("validation-error: field Mode can not be empty") - } - - validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) - if !validator { - return errors.New("validation-error: field Mode can be only EQ, NE or ANY") - } - - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - if crq.Value == "" { - return errors.New("validation-error: field Value can not be empty") - } - - return nil -} - -func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/affinityRuleAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AffinityRuleAddRequest struct { + ComputeID uint64 `url:"computeId"` + Topology string `url:"topology"` + Policy string `url:"policy"` + Mode string `url:"mode"` + Key string `url:"key"` + Value string `url:"value"` +} + +func (crq AffinityRuleAddRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Topology == "" { + return errors.New("validation-error: field Topology can not be empty") + } + + validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) + if !validator { + return errors.New("validation-error: field Topology can be only compute or node") + } + + if crq.Policy == "" { + return errors.New("validation-error: field Policy can not be empty") + } + + validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) + if !validator { + return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") + } + + if crq.Mode == "" { + return errors.New("validation-error: field Mode can not be empty") + } + + validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) + if !validator { + return errors.New("validation-error: field Mode can be only EQ, NE or ANY") + } + + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + if crq.Value == "" { + return errors.New("validation-error: field Value can not be empty") + } + + return nil +} + +func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/affinityRuleAdd" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/affinity_rule_remove.go b/pkg/cloudapi/compute/affinity_rule_remove.go index 2b2ed19..37b4676 100644 --- a/pkg/cloudapi/compute/affinity_rule_remove.go +++ b/pkg/cloudapi/compute/affinity_rule_remove.go @@ -1,91 +1,82 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityRuleRemoveRequest struct { - ComputeId uint64 `url:"computeId"` - Topology string `url:"topology"` - Policy string `url:"policy"` - Mode string `url:"mode"` - Key string `url:"key"` - Value string `url:"value"` -} - -func (crq AffinityRuleRemoveRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Topology == "" { - return errors.New("validation-error: field Topology can not be empty") - } - - validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) - if !validator { - return errors.New("validation-error: field Topology can be only compute or node") - } - - if crq.Policy == "" { - return errors.New("validation-error: field Policy can not be empty") - } - - validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) - if !validator { - return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") - } - - if crq.Mode == "" { - return errors.New("validation-error: field Mode can not be empty") - } - - validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) - if !validator { - return errors.New("validation-error: field Mode can be only EQ, NE or ANY") - } - - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - if crq.Value == "" { - return errors.New("validation-error: field Value can not be empty") - } - - return nil -} - -func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/affinityRuleRemove" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AffinityRuleRemoveRequest struct { + ComputeID uint64 `url:"computeId"` + Topology string `url:"topology"` + Policy string `url:"policy"` + Mode string `url:"mode"` + Key string `url:"key"` + Value string `url:"value"` +} + +func (crq AffinityRuleRemoveRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Topology == "" { + return errors.New("validation-error: field Topology can not be empty") + } + + validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) + if !validator { + return errors.New("validation-error: field Topology can be only compute or node") + } + + if crq.Policy == "" { + return errors.New("validation-error: field Policy can not be empty") + } + + validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) + if !validator { + return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") + } + + if crq.Mode == "" { + return errors.New("validation-error: field Mode can not be empty") + } + + validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) + if !validator { + return errors.New("validation-error: field Mode can be only EQ, NE or ANY") + } + + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + if crq.Value == "" { + return errors.New("validation-error: field Value can not be empty") + } + + return nil +} + +func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/affinityRuleRemove" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/affinity_rules_clear.go b/pkg/cloudapi/compute/affinity_rules_clear.go index a37fd1a..4ed565f 100644 --- a/pkg/cloudapi/compute/affinity_rules_clear.go +++ b/pkg/cloudapi/compute/affinity_rules_clear.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AffinityRulesClearRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq AffinityRulesClearRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/affinityRulesClear" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AffinityRulesClearRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq AffinityRulesClearRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/affinityRulesClear" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/anti_affinity_rule_add.go b/pkg/cloudapi/compute/anti_affinity_rule_add.go index d64e40c..366ab45 100644 --- a/pkg/cloudapi/compute/anti_affinity_rule_add.go +++ b/pkg/cloudapi/compute/anti_affinity_rule_add.go @@ -1,91 +1,82 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AntiAffinityRuleAddRequest struct { - ComputeId uint64 `url:"computeId"` - Topology string `url:"topology"` - Policy string `url:"policy"` - Mode string `url:"mode"` - Key string `url:"key"` - Value string `url:"value"` -} - -func (crq AntiAffinityRuleAddRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Topology == "" { - return errors.New("validation-error: field Topology can not be empty") - } - - validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) - if !validator { - return errors.New("validation-error: field Topology can be only compute or node") - } - - if crq.Policy == "" { - return errors.New("validation-error: field Policy can not be empty") - } - - validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) - if !validator { - return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") - } - - if crq.Mode == "" { - return errors.New("validation-error: field Mode can not be empty") - } - - validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) - if !validator { - return errors.New("validation-error: field Mode can be only EQ, NE or ANY") - } - - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - if crq.Value == "" { - return errors.New("validation-error: field Value can not be empty") - } - - return nil -} - -func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/antiAffinityRuleAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AntiAffinityRuleAddRequest struct { + ComputeID uint64 `url:"computeId"` + Topology string `url:"topology"` + Policy string `url:"policy"` + Mode string `url:"mode"` + Key string `url:"key"` + Value string `url:"value"` +} + +func (crq AntiAffinityRuleAddRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Topology == "" { + return errors.New("validation-error: field Topology can not be empty") + } + + validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) + if !validator { + return errors.New("validation-error: field Topology can be only compute or node") + } + + if crq.Policy == "" { + return errors.New("validation-error: field Policy can not be empty") + } + + validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) + if !validator { + return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") + } + + if crq.Mode == "" { + return errors.New("validation-error: field Mode can not be empty") + } + + validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) + if !validator { + return errors.New("validation-error: field Mode can be only EQ, NE or ANY") + } + + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + if crq.Value == "" { + return errors.New("validation-error: field Value can not be empty") + } + + return nil +} + +func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/antiAffinityRuleAdd" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/anti_affinity_rule_remove.go b/pkg/cloudapi/compute/anti_affinity_rule_remove.go index 4f9637d..031334d 100644 --- a/pkg/cloudapi/compute/anti_affinity_rule_remove.go +++ b/pkg/cloudapi/compute/anti_affinity_rule_remove.go @@ -1,91 +1,82 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AntiAffinityRuleRemoveRequest struct { - ComputeId uint64 `url:"computeId"` - Topology string `url:"topology"` - Policy string `url:"policy"` - Mode string `url:"mode"` - Key string `url:"key"` - Value string `url:"value"` -} - -func (crq AntiAffinityRuleRemoveRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Topology == "" { - return errors.New("validation-error: field Topology can not be empty") - } - - validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) - if !validator { - return errors.New("validation-error: field Topology can be only compute or node") - } - - if crq.Policy == "" { - return errors.New("validation-error: field Policy can not be empty") - } - - validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) - if !validator { - return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") - } - - if crq.Mode == "" { - return errors.New("validation-error: field Mode can not be empty") - } - - validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) - if !validator { - return errors.New("validation-error: field Mode can be only EQ, NE or ANY") - } - - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - if crq.Value == "" { - return errors.New("validation-error: field Value can not be empty") - } - - return nil -} - -func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/antiAffinityRuleRemove" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AntiAffinityRuleRemoveRequest struct { + ComputeID uint64 `url:"computeId"` + Topology string `url:"topology"` + Policy string `url:"policy"` + Mode string `url:"mode"` + Key string `url:"key"` + Value string `url:"value"` +} + +func (crq AntiAffinityRuleRemoveRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Topology == "" { + return errors.New("validation-error: field Topology can not be empty") + } + + validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"}) + if !validator { + return errors.New("validation-error: field Topology can be only compute or node") + } + + if crq.Policy == "" { + return errors.New("validation-error: field Policy can not be empty") + } + + validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"}) + if !validator { + return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED") + } + + if crq.Mode == "" { + return errors.New("validation-error: field Mode can not be empty") + } + + validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"}) + if !validator { + return errors.New("validation-error: field Mode can be only EQ, NE or ANY") + } + + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + if crq.Value == "" { + return errors.New("validation-error: field Value can not be empty") + } + + return nil +} + +func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/antiAffinityRuleRemove" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/anti_affinity_rules_clear.go b/pkg/cloudapi/compute/anti_affinity_rules_clear.go index 989e49c..ac58234 100644 --- a/pkg/cloudapi/compute/anti_affinity_rules_clear.go +++ b/pkg/cloudapi/compute/anti_affinity_rules_clear.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AntiAffinityRulesClearRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq AntiAffinityRulesClearRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/antiAffinityRulesClear" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AntiAffinityRulesClearRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq AntiAffinityRulesClearRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/antiAffinityRulesClear" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/attach_gpu.go b/pkg/cloudapi/compute/attach_gpu.go index 4d1e963..634d131 100644 --- a/pkg/cloudapi/compute/attach_gpu.go +++ b/pkg/cloudapi/compute/attach_gpu.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AttachGPURequest struct { - ComputeId uint64 `url:"computeId"` - VGPUID uint64 `url:"vgpuId"` -} - -func (crq AttachGPURequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.VGPUID == 0 { - return errors.New("validation-error: field VGPUID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/compute/attachGpu" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AttachGPURequest struct { + ComputeID uint64 `url:"computeId"` + VGPUID uint64 `url:"vgpuId"` +} + +func (crq AttachGPURequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.VGPUID == 0 { + return errors.New("validation-error: field VGPUID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/compute/attachGpu" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/attach_pci_device.go b/pkg/cloudapi/compute/attach_pci_device.go index 1dc4bed..58f2630 100644 --- a/pkg/cloudapi/compute/attach_pci_device.go +++ b/pkg/cloudapi/compute/attach_pci_device.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AttachPciDeviceRequest struct { - ComputeId uint64 `url:"computeId"` - DeviceID uint64 `url:"deviceId"` -} - -func (crq AttachPciDeviceRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DeviceID == 0 { - return errors.New("validation-error: field DeviceID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/attachPciDevice" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type AttachPciDeviceRequest struct { + ComputeID uint64 `url:"computeId"` + DeviceID uint64 `url:"deviceId"` +} + +func (crq AttachPciDeviceRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DeviceID == 0 { + return errors.New("validation-error: field DeviceID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/attachPciDevice" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/audits.go b/pkg/cloudapi/compute/audits.go index 0f15277..e4b9d0e 100644 --- a/pkg/cloudapi/compute/audits.go +++ b/pkg/cloudapi/compute/audits.go @@ -1,41 +1,39 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AuditsRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq AuditsRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) { - if err := req.Validate(); err != nil { - return nil, err - } - - url := "/cloudapi/compute/audits" - auditListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - auditList := AuditList{} - if err := json.Unmarshal(auditListRaw, &auditList); err != nil { - return nil, err - } - - return auditList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AuditsRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq AuditsRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudapi/compute/audits" + auditListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + auditList := AuditList{} + if err := json.Unmarshal(auditListRaw, &auditList); err != nil { + return nil, err + } + + return auditList, nil +} diff --git a/pkg/cloudapi/compute/cd_eject.go b/pkg/cloudapi/compute/cd_eject.go index a6bf7d3..3c8e7db 100644 --- a/pkg/cloudapi/compute/cd_eject.go +++ b/pkg/cloudapi/compute/cd_eject.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CDEjectRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq CDEjectRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) CDEject(ctx context.Context, req CDEjectRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/cdEject" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CDEjectRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq CDEjectRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/cdEject" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/cd_insert.go b/pkg/cloudapi/compute/cd_insert.go index 7e5ddcf..3eaf174 100644 --- a/pkg/cloudapi/compute/cd_insert.go +++ b/pkg/cloudapi/compute/cd_insert.go @@ -1,54 +1,44 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CDInsertRequest struct { - ComputeId uint64 `url:"computeId"` - CDROMID uint64 `url:"cdromId"` -} - -func (crq CDInsertRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.CDROMID == 0 { - return errors.New("validation-error: field CDROMID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/cdInsert" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CDInsertRequest struct { + ComputeID uint64 `url:"computeId"` + CDROMID uint64 `url:"cdromId"` +} + +func (crq CDInsertRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.CDROMID == 0 { + return errors.New("validation-error: field CDROMID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/cdInsert" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/clone.go b/pkg/cloudapi/compute/clone.go index 3b219c9..6e84a31 100644 --- a/pkg/cloudapi/compute/clone.go +++ b/pkg/cloudapi/compute/clone.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CloneRequest struct { - ComputeId uint64 `url:"computeId"` - Name string `url:"name"` - SnapshotTimestamp uint64 `url:"snapshotTimestamp"` - SnapshotName string `url:"snapshotName"` -} - -func (crq CloneRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Name == "" { - return errors.New("validation-error: field Name can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Clone(ctx context.Context, req CloneRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/compute/clone" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CloneRequest struct { + ComputeID uint64 `url:"computeId"` + Name string `url:"name"` + SnapshotTimestamp uint64 `url:"snapshotTimestamp"` + SnapshotName string `url:"snapshotName"` +} + +func (crq CloneRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Name == "" { + return errors.New("validation-error: field Name can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/compute/clone" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/compute.go b/pkg/cloudapi/compute/compute.go index 73f0a90..4ebedce 100644 --- a/pkg/cloudapi/compute/compute.go +++ b/pkg/cloudapi/compute/compute.go @@ -1,15 +1,15 @@ -package compute - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Compute struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Compute { - return &Compute{ - client, - } -} +package compute + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Compute struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Compute { + return &Compute{ + client, + } +} diff --git a/pkg/cloudapi/compute/create_template.go b/pkg/cloudapi/compute/create_template.go index f05c071..49b39ec 100644 --- a/pkg/cloudapi/compute/create_template.go +++ b/pkg/cloudapi/compute/create_template.go @@ -1,88 +1,70 @@ -package compute - -import ( - "context" - "errors" - "strconv" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateTemplateRequest struct { - ComputeId uint64 `url:"computeId"` - Name string `url:"name"` - Async bool `url:"async"` -} - -func (crq CreateTemplateRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - return nil -} - -func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - req.Async = false - - url := "/compute/createTemplate" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, nil - } - - return result, nil -} - -func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - req.Async = true - - url := "/compute/createTemplate" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - result := strings.ReplaceAll(string(res), "\"", "") - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + "strings" +) + +type CreateTemplateRequest struct { + ComputeID uint64 `url:"computeId"` + Name string `url:"name"` + Async bool `url:"async"` +} + +func (crq CreateTemplateRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + return nil +} + +func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + req.Async = false + + url := "/cloudapi/compute/createTemplate" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} + +func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + req.Async = true + + url := "/cloudapi/compute/createTemplate" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + result := strings.ReplaceAll(string(res), "\"", "") + + return result, nil +} diff --git a/pkg/cloudapi/compute/delete.go b/pkg/cloudapi/compute/delete.go index 3570ff6..c17fd1a 100644 --- a/pkg/cloudapi/compute/delete.go +++ b/pkg/cloudapi/compute/delete.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - ComputeId uint64 `url:"computeId"` - Permanently bool `url:"permanently,omitempty"` - DetachDisks bool `url:"detachDisks,omitempty"` -} - -func (crq DeleteRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/delete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + ComputeID uint64 `url:"computeId"` + Permanently bool `url:"permanently,omitempty"` + DetachDisks bool `url:"detachDisks,omitempty"` +} + +func (crq DeleteRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/delete" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/detach_gpu.go b/pkg/cloudapi/compute/detach_gpu.go index 132f77e..6b69381 100644 --- a/pkg/cloudapi/compute/detach_gpu.go +++ b/pkg/cloudapi/compute/detach_gpu.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DetachGPURequest struct { - ComputeId uint64 `url:"computeId"` - VGPUID int64 `url:"vgpuId,omitempty"` -} - -func (crq DetachGPURequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/detachGpu" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DetachGPURequest struct { + ComputeID uint64 `url:"computeId"` + VGPUID int64 `url:"vgpuId,omitempty"` +} + +func (crq DetachGPURequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/detachGpu" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/detach_pci_device.go b/pkg/cloudapi/compute/detach_pci_device.go index 2731e0d..8ecc361 100644 --- a/pkg/cloudapi/compute/detach_pci_device.go +++ b/pkg/cloudapi/compute/detach_pci_device.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DetachPciDeviceRequest struct { - ComputeId uint64 `url:"computeId"` - DeviceID uint64 `url:"deviceId"` -} - -func (crq DetachPciDeviceRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DeviceID == 0 { - return errors.New("validation-error: field DeviceID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/detachPciDevice" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DetachPciDeviceRequest struct { + ComputeID uint64 `url:"computeId"` + DeviceID uint64 `url:"deviceId"` +} + +func (crq DetachPciDeviceRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DeviceID == 0 { + return errors.New("validation-error: field DeviceID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/detachPciDevice" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disable.go b/pkg/cloudapi/compute/disable.go index efc3795..014104b 100644 --- a/pkg/cloudapi/compute/disable.go +++ b/pkg/cloudapi/compute/disable.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisableRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq DisableRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/disable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisableRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq DisableRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/disable" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_add.go b/pkg/cloudapi/compute/disk_add.go index ba118fa..8a01fa8 100644 --- a/pkg/cloudapi/compute/disk_add.go +++ b/pkg/cloudapi/compute/disk_add.go @@ -1,66 +1,56 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskAddRequest struct { - ComputeId uint64 `url:"computeId"` - DiskName string `url:"diskName"` - Size uint64 `url:"size"` - DiskType string `url:"diskType,omitempty"` - SepID uint64 `url:"sepId,omitempty"` - Pool string `url:"pool,omitempty"` - Description string `url:"desc,omitempty"` - ImageID uint64 `url:"imageId,omitempty"` -} - -func (crq DiskAddRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Size == 0 { - return errors.New("validation-error: field Size can not be empty or equal to 0") - } - - if crq.DiskName == "" { - return errors.New("validation-error: field DiskName can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/compute/diskAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskAddRequest struct { + ComputeID uint64 `url:"computeId"` + DiskName string `url:"diskName"` + Size uint64 `url:"size"` + DiskType string `url:"diskType,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + Description string `url:"desc,omitempty"` + ImageID uint64 `url:"imageId,omitempty"` +} + +func (crq DiskAddRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Size == 0 { + return errors.New("validation-error: field Size can not be empty or equal to 0") + } + + if crq.DiskName == "" { + return errors.New("validation-error: field DiskName can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/compute/diskAdd" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_attach.go b/pkg/cloudapi/compute/disk_attach.go index e37e238..ee93e1c 100644 --- a/pkg/cloudapi/compute/disk_attach.go +++ b/pkg/cloudapi/compute/disk_attach.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskAttachRequest struct { - ComputeId uint64 `url:"computeId"` - DiskID uint64 `url:"diskId"` -} - -func (crq DiskAttachRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DiskID == 0 { - return errors.New("validation-error: field DiskID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/diskAttach" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskAttachRequest struct { + ComputeID uint64 `url:"computeId"` + DiskID uint64 `url:"diskId"` +} + +func (crq DiskAttachRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/diskAttach" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_del.go b/pkg/cloudapi/compute/disk_del.go index e162117..cf8f7bb 100644 --- a/pkg/cloudapi/compute/disk_del.go +++ b/pkg/cloudapi/compute/disk_del.go @@ -1,57 +1,47 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskDelRequest struct { - ComputeId uint64 `url:"computeId"` - DiskID uint64 `url:"diskId"` - Permanently bool `url:"permanently"` -} - -func (crq DiskDelRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DiskID == 0 { - return errors.New("validation-error: field DiskID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/diskDel" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskDelRequest struct { + ComputeID uint64 `url:"computeId"` + DiskID uint64 `url:"diskId"` + Permanently bool `url:"permanently"` +} + +func (crq DiskDelRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/diskDel" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_detach.go b/pkg/cloudapi/compute/disk_detach.go index 696a2c9..1d699ea 100644 --- a/pkg/cloudapi/compute/disk_detach.go +++ b/pkg/cloudapi/compute/disk_detach.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskDetachRequest struct { - ComputeId uint64 `url:"computeId"` - DiskID uint64 `url:"diskId"` -} - -func (crq DiskDetachRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DiskID == 0 { - return errors.New("validation-error: field DiskID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/diskDetach" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskDetachRequest struct { + ComputeID uint64 `url:"computeId"` + DiskID uint64 `url:"diskId"` +} + +func (crq DiskDetachRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/diskDetach" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_qos.go b/pkg/cloudapi/compute/disk_qos.go index 5c0466a..b23457f 100644 --- a/pkg/cloudapi/compute/disk_qos.go +++ b/pkg/cloudapi/compute/disk_qos.go @@ -1,61 +1,51 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskQOSRequest struct { - ComputeId uint64 `url:"computeId"` - DiskID uint64 `url:"diskId"` - Limits string `url:"limits"` -} - -func (crq DiskQOSRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DiskID == 0 { - return errors.New("validation-error: field DiskID can not be empty or equal to 0") - } - - if crq.Limits == "" { - return errors.New("validation-error: field Limits can not be empty") - } - - return nil -} - -func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/diskQos" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskQOSRequest struct { + ComputeID uint64 `url:"computeId"` + DiskID uint64 `url:"diskId"` + Limits string `url:"limits"` +} + +func (crq DiskQOSRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if crq.Limits == "" { + return errors.New("validation-error: field Limits can not be empty") + } + + return nil +} + +func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/diskQos" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/disk_resize.go b/pkg/cloudapi/compute/disk_resize.go index f95a67c..ca06a77 100644 --- a/pkg/cloudapi/compute/disk_resize.go +++ b/pkg/cloudapi/compute/disk_resize.go @@ -1,61 +1,51 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DiskResizeRequest struct { - ComputeId uint64 `url:"computeId"` - DiskID uint64 `url:"diskId"` - Size uint64 `url:"size"` -} - -func (crq DiskResizeRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.DiskID == 0 { - return errors.New("validation-error: field DiskID can not be empty or equal to 0") - } - - if crq.Size == 0 { - return errors.New("validation-error: field Size can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/diskResize" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DiskResizeRequest struct { + ComputeID uint64 `url:"computeId"` + DiskID uint64 `url:"diskId"` + Size uint64 `url:"size"` +} + +func (crq DiskResizeRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if crq.Size == 0 { + return errors.New("validation-error: field Size can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/diskResize" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/enable.go b/pkg/cloudapi/compute/enable.go index db52dc2..df7dd18 100644 --- a/pkg/cloudapi/compute/enable.go +++ b/pkg/cloudapi/compute/enable.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type EnableRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq EnableRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/enable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EnableRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq EnableRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/enable" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/get.go b/pkg/cloudapi/compute/get.go index 54c545c..dab033e 100644 --- a/pkg/cloudapi/compute/get.go +++ b/pkg/cloudapi/compute/get.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq GetRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ComputeRecord, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/get" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - compute := &ComputeRecord{} - err = json.Unmarshal(res, compute) - if err != nil { - return nil, err - } - - return compute, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq GetRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Get(ctx context.Context, req GetRequest) (*ComputeRecord, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/get" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + compute := &ComputeRecord{} + err = json.Unmarshal(res, compute) + if err != nil { + return nil, err + } + + return compute, nil +} diff --git a/pkg/cloudapi/compute/get_audits.go b/pkg/cloudapi/compute/get_audits.go index 3c47a73..18a4460 100644 --- a/pkg/cloudapi/compute/get_audits.go +++ b/pkg/cloudapi/compute/get_audits.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetAuditsRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq GetAuditsRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest, options ...opts.DecortOpts) (AuditShortList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/getAudits" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - auditsList := AuditShortList{} - err = json.Unmarshal(res, &auditsList) - if err != nil { - return nil, err - } - - return auditsList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetAuditsRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq GetAuditsRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (AuditShortList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/getAudits" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + auditsList := AuditShortList{} + err = json.Unmarshal(res, &auditsList) + if err != nil { + return nil, err + } + + return auditsList, nil +} diff --git a/pkg/cloudapi/compute/get_console_url.go b/pkg/cloudapi/compute/get_console_url.go index 12b1ed6..bc4d98f 100644 --- a/pkg/cloudapi/compute/get_console_url.go +++ b/pkg/cloudapi/compute/get_console_url.go @@ -1,48 +1,38 @@ -package compute - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetConsoleURLRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq GetConsoleURLRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/getConsoleUrl" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - result := strings.ReplaceAll(string(res), "\"", "") - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type GetConsoleURLRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq GetConsoleURLRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/compute/getConsoleUrl" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + result := strings.ReplaceAll(string(res), "\"", "") + + return result, nil +} diff --git a/pkg/cloudapi/compute/get_log.go b/pkg/cloudapi/compute/get_log.go index e8263f7..9699063 100644 --- a/pkg/cloudapi/compute/get_log.go +++ b/pkg/cloudapi/compute/get_log.go @@ -1,74 +1,58 @@ -package compute - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetLogRequest struct { - ComputeId uint64 `url:"computeId"` - Path string `url:"path"` -} - -func (crq GetLogRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Path == "" { - return errors.New("validation-error: field Path can not be empty") - } - - return nil -} - -func (c Compute) GetLog(ctx context.Context, req GetLogRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/getLog" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} - -func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/getLog" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.GET, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package compute + +import ( + "context" + "errors" + "net/http" +) + +type GetLogRequest struct { + ComputeID uint64 `url:"computeId"` + Path string `url:"path"` +} + +func (crq GetLogRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Path == "" { + return errors.New("validation-error: field Path can not be empty") + } + + return nil +} + +func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/compute/getLog" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} + +func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/compute/getLog" + prefix := "/cloudapi" + + url = prefix + url + res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/compute/list.go b/pkg/cloudapi/compute/list.go index 77f724c..bbd22a6 100644 --- a/pkg/cloudapi/compute/list.go +++ b/pkg/cloudapi/compute/list.go @@ -1,42 +1,32 @@ -package compute - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDeleted bool `url:"includedeleted,omitempty"` - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (c Compute) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ComputeList, error) { - - url := "/compute/list" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - computeList := ComputeList{} - - err = json.Unmarshal(res, &computeList) - if err != nil { - return nil, err - } - - return computeList, nil -} +package compute + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includedeleted,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (c Compute) List(ctx context.Context, req ListRequest) (ComputeList, error) { + + url := "/cloudapi/compute/list" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computeList := ComputeList{} + + err = json.Unmarshal(res, &computeList) + if err != nil { + return nil, err + } + + return computeList, nil +} diff --git a/pkg/cloudapi/compute/list_deleted.go b/pkg/cloudapi/compute/list_deleted.go index af85954..c327921 100644 --- a/pkg/cloudapi/compute/list_deleted.go +++ b/pkg/cloudapi/compute/list_deleted.go @@ -1,41 +1,31 @@ -package compute - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (ComputeList, error) { - - url := "/compute/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - computeList := ComputeList{} - - err = json.Unmarshal(res, &computeList) - if err != nil { - return nil, err - } - - return computeList, nil -} +package compute + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ComputeList, error) { + + url := "/cloudapi/compute/listDeleted" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computeList := ComputeList{} + + err = json.Unmarshal(res, &computeList) + if err != nil { + return nil, err + } + + return computeList, nil +} diff --git a/pkg/cloudapi/compute/list_pci_device.go b/pkg/cloudapi/compute/list_pci_device.go index 9f80863..fb0f097 100644 --- a/pkg/cloudapi/compute/list_pci_device.go +++ b/pkg/cloudapi/compute/list_pci_device.go @@ -1,53 +1,43 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListPCIDeviceRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq ListPCIDeviceRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest, options ...opts.DecortOpts) ([]interface{}, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/listPciDevice" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - pciDeviceList := []interface{}{} - - err = json.Unmarshal(res, &pciDeviceList) - if err != nil { - return nil, err - } - - return pciDeviceList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListPCIDeviceRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq ListPCIDeviceRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/listPciDevice" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + pciDeviceList := []interface{}{} + + err = json.Unmarshal(res, &pciDeviceList) + if err != nil { + return nil, err + } + + return pciDeviceList, nil +} diff --git a/pkg/cloudapi/compute/list_vgpu.go b/pkg/cloudapi/compute/list_vgpu.go index dfe1996..dbbe0a0 100644 --- a/pkg/cloudapi/compute/list_vgpu.go +++ b/pkg/cloudapi/compute/list_vgpu.go @@ -1,53 +1,43 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListVGPURequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq ListVGPURequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest, options ...opts.DecortOpts) ([]interface{}, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/listVgpu" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - pciDeviceList := []interface{}{} - - err = json.Unmarshal(res, &pciDeviceList) - if err != nil { - return nil, err - } - - return pciDeviceList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListVGPURequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq ListVGPURequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/listVgpu" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + pciDeviceList := []interface{}{} + + err = json.Unmarshal(res, &pciDeviceList) + if err != nil { + return nil, err + } + + return pciDeviceList, nil +} diff --git a/pkg/cloudapi/compute/models.go b/pkg/cloudapi/compute/models.go index 8f7532e..e5fba38 100644 --- a/pkg/cloudapi/compute/models.go +++ b/pkg/cloudapi/compute/models.go @@ -1,347 +1,347 @@ -package compute - -//ACL for compute -type UserList struct { - AccountACL ACLList `json:"accountACL"` - ComputeACL ACLList `json:"computeACL"` - RGACL ACLList `json:"rgACL"` -} - -type ACL struct { - Explicit bool `json:"explicit"` - GUID string `json:"guid"` - Rigth string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UserGroupId string `json:"userGroupId"` -} - -type ACLList []ACL - -type SnapshotUsage struct { - Count uint64 `json:"count,omitempty"` - Stored float64 `json:"stored"` - Label string `json:"label,omitempty"` - Timestamp uint64 `json:"timestamp,omitempty"` -} - -type SnapshotUsageList []SnapshotUsage - -type Snapshot struct { - Disks []uint64 `json:"disks"` - GUID string `json:"guid"` - Label string `json:"label"` - Timestamp uint64 `json:"timestamp"` -} - -type SnapshotList []Snapshot - -type PFW struct { - ID uint64 `json:"id"` - LocalIP string `json:"localIp"` - LocalPort uint64 `json:"localPort"` - Protocol string `json:"protocol"` - PublicPortEnd uint64 `json:"publicPortEnd"` - PublicPortStart uint64 `json:"publicPortStart"` - VMID uint64 `json:"vmId"` -} - -type PFWList []PFW - -type AffinityRelations struct { - OtherNode []interface{} `json:"otherNode"` - OtherNodeIndirect []interface{} `json:"otherNodeIndirect"` - OtherNodeIndirectSoft []interface{} `json:"otherNodeIndirectSoft"` - OtherNodeSoft []interface{} `json:"otherNodeSoft"` - SameNode []interface{} `json:"sameNode"` - SameNodeSoft []interface{} `json:"sameNodeSoft"` -} - -type NetAttach struct { - ConnID uint64 `json:"connId"` - ConnType string `json:"connType"` - DefGW string `json:"defGw"` - FlipGroupID uint64 `json:"flipgroupId"` - GUID string `json:"guid"` - IPAddress string `json:"ipAddress"` - ListenSSH bool `json:"listenSsh"` - MAC string `json:"mac"` - Name string `json:"name"` - NetID uint64 `json:"netId"` - NetMask uint64 `json:"netMask"` - NetType string `json:"netType"` - PCISlot uint64 `json:"pciSlot"` - QOS QOS `json:"qos"` - Target string `json:"target"` - Type string `json:"type"` - VNFS []uint64 `json:"vnfs"` -} - -type Audit struct { - Call string `json:"call"` - ResponseTime float64 `json:"responsetime"` - StatusCode uint64 `json:"statuscode"` - Timestamp float64 `json:"timestamp"` - User string `json:"user"` -} - -type AuditList []Audit - -type AuditShort struct { - Epoch float64 `json:"epoch"` - Message string `json:"message"` -} - -type AuditShortList []AuditShort - -type Rule struct { - GUID string `json:"guid"` - Key string `json:"key"` - Mode string `json:"mode"` - Policy string `json:"policy"` - Topology string `json:"topology"` - Value string `json:"value"` -} - -type RuleList []Rule - -type ComputeRecord struct { - ACL UserList `json:"ACL"` - AccountID uint64 `json:"accountId"` - AccountName string `json:"accountName"` - AffinityLabel string `json:"affinityLabel"` - AffinityRules RuleList `json:"affinityRules"` - AffinityWeight uint64 `json:"affinityWeight"` - AntiAffinityRules RuleList `json:"antiAffinityRules"` - Architecture string `json:"arch"` - BootOrder []string `json:"bootOrder"` - BootDiskSize uint64 `json:"bootdiskSize"` - CloneReference uint64 `json:"cloneReference"` - Clones []uint64 `json:"clones"` - ComputeCIID uint64 `json:"computeciId"` - CPU uint64 `json:"cpus"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - CustomFields map[string]interface{} `json:"customFields"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - Devices interface{} `json:"devices"` - Disks ComputeDiskList `json:"disks"` - Driver string `json:"driver"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - ImageID uint64 `json:"imageId"` - ImageName string `json:"imageName"` - Intefaces IntefaceList `json:"interfaces"` - LockStatus string `json:"lockStatus"` - ManagerID uint64 `json:"managerId"` - ManagerType string `json:"managerType"` - MigrationJob uint64 `json:"migrationjob"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - NatableVinsID uint64 `json:"natableVinsId"` - NatableVinsIP string `json:"natableVinsIp"` - NatableVinsName string `json:"natableVinsName"` - NatableVinsNetwork string `json:"natableVinsNetwork"` - NatableVinsNetworkName string `json:"natableVinsNetworkName"` - OSUsers OSUserList `json:"osUsers"` - Pinned bool `json:"pinned"` - RAM uint64 `json:"ram"` - ReferenceID string `json:"referenceId"` - Registered bool `json:"registered"` - ResName string `json:"resName"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - SnapSets SnapSetList `json:"snapSets"` - StatelessSepID uint64 `json:"statelessSepId"` - StatelessSepType string `json:"statelessSepType"` - Status string `json:"status"` - Tags map[string]string `json:"tags"` - TechStatus string `json:"techStatus"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - UserManaged bool `json:"userManaged"` - Userdata interface{} `json:"userdata"` - VGPUs []uint64 `json:"vgpus"` - VirtualImageID uint64 `json:"virtualImageId"` - VirtualImageName string `json:"virtualImageName"` -} - -type OSUser struct { - GUID string `json:"guid"` - Login string `json:"login"` - Password string `json:"password"` - PubKey string `json:"pubkey"` -} - -type OSUserList []OSUser - -type SnapSet struct { - Disks []uint64 `json:"disks"` - GUID string `json:"guid"` - Label string `json:"label"` - Timestamp uint64 `json:"timestamp"` -} - -type SnapSetList []SnapSet - -type VNFInterface struct { - ConnId uint64 `json:"connId"` - ConnType string `json:"connType"` - DefGW string `json:"defGw"` - FlipGroupId uint64 `json:"flipgroupId"` - GUID string `json:"guid"` - IPAddress string `json:"ipAddress"` - ListenSSH bool `json:"listenSsh"` - MAC string `json:"mac"` - Name string `json:"name"` - NetId uint64 `json:"netId"` - NetMask uint64 `json:"netMask"` - NetType string `json:"netType"` - PCISlot uint64 `json:"pciSlot"` - QOS QOS `json:"qos"` - Target string `json:"target"` - Type string `json:"type"` - VNFS []uint64 `json:"vnfs"` -} - -type QOS struct { - ERate uint64 `json:"eRate"` - GUID string `json:"guid"` - InBurst uint64 `json:"inBurst"` - InRate uint64 `json:"inRate"` -} - -type IntefaceList []VNFInterface - -type ComputeDiskList []ComputeDisk - -type ComputeDisk struct { - Ckey string `json:"_ckey"` - Acl map[string]interface{} `json:"acl"` - AccountID int `json:"accountId"` - Bootpartition uint64 `json:"bootPartition"` - CreatedTime uint64 `json:"createdTime"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - DestructionTime uint64 `json:"destructionTime"` - DiskPath string `json:"diskPath"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - ImageID uint64 `json:"imageId"` - Images []uint64 `json:"images"` - IOTune IOTune `json:"iotune"` - IQN string `json:"iqn"` - Login string `json:"login"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - Order uint64 `json:"order"` - Params string `json:"params"` - ParentID uint64 `json:"parentId"` - Passwd string `json:"passwd"` - PciSlot uint64 `json:"pciSlot"` - Pool string `json:"pool"` - PurgeTime uint64 `json:"purgeTime"` - RealityDeviceNumber uint64 `json:"realityDeviceNumber"` - ResID string `json:"resId"` - Role string `json:"role"` - SepID int `json:"sepId"` // NOTE: absent from compute/get output - SizeMax int `json:"sizeMax"` - SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space - Snapshots SnapshotExtendList `json:"snapshots"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - VMID int `json:"vmid"` -} - -type SnapshotExtend struct { - Guid string `json:"guid"` - Label string `json:"label"` - ResId string `json:"resId"` - SnapSetGuid string `json:"snapSetGuid"` - SnapSetTime uint64 `json:"snapSetTime"` - TimeStamp uint64 `json:"timestamp"` -} - -type SnapshotExtendList []SnapshotExtend - -type IOTune struct { - ReadBytesSec int `json:"read_bytes_sec"` - ReadBytesSecMax int `json:"read_bytes_sec_max"` - ReadIopsSec int `json:"read_iops_sec"` - ReadIopsSecMax int `json:"read_iops_sec_max"` - SizeIopsSec int `json:"size_iops_sec"` - TotalBytesSec int `json:"total_bytes_sec"` - TotalBytesSecMax int `json:"total_bytes_sec_max"` - TotalIopsSec int `json:"total_iops_sec"` - TotalIopsSecMax int `json:"total_iops_sec_max"` - WriteBytesSec int `json:"write_bytes_sec"` - WriteBytesSecMax int `json:"write_bytes_sec_max"` - WriteIopsSec int `json:"write_iops_sec"` - WriteIopsSecMax int `json:"write_iops_sec_max"` -} - -type ComputeItem struct { - ACL []interface{} `json:"ACL"` - AccountID uint64 `json:"accountId"` - AccountName string `json:"accountName"` - AffinityLabel string `json:"affinityLabel"` - AffinityRules RuleList `json:"affinityRules"` - AffinityWeight uint64 `json:"affinityWeight"` - AntiAffinityRules RuleList `json:"antiAffinityRules"` - Architecture string `json:"arch"` - BootOrder []string `json:"bootOrder"` - BootDiskSize uint64 `json:"bootdiskSize"` - CloneReference uint64 `json:"cloneReference"` - Clones []uint64 `json:"clones"` - ComputeCIID uint64 `json:"computeciId"` - CPU uint64 `json:"cpus"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - CustomFields map[string]interface{} `json:"customFields"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - Devices interface{} `json:"devices"` - Disks []uint64 `json:"disks"` - Driver string `json:"driver"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - ImageID uint64 `json:"imageId"` - ImageName string `json:"imageName"` - Intefaces IntefaceList `json:"interfaces"` - LockStatus string `json:"lockStatus"` - ManagerID uint64 `json:"managerId"` - ManagerType string `json:"managerType"` - MigrationJob uint64 `json:"migrationjob"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - Pinned bool `json:"pinned"` - RAM uint64 `json:"ram"` - ReferenceID string `json:"referenceId"` - Registered bool `json:"registered"` - ResName string `json:"resName"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - SnapSets SnapSetList `json:"snapSets"` - StatelessSepID uint64 `json:"statelessSepId"` - StatelessSepType string `json:"statelessSepType"` - Status string `json:"status"` - Tags map[string]string `json:"tags"` - TechStatus string `json:"techStatus"` - TotalDiskSize uint64 `json:"totalDisksSize"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - UserManaged bool `json:"userManaged"` - Userdata interface{} `json:"userdata"` - VGPUs []uint64 `json:"vgpus"` - VirtualImageID uint64 `json:"virtualImageId"` - VirtualImageName string `json:"virtualImageName"` -} - -type ComputeList []ComputeItem +package compute + +// ACL for compute +type UserList struct { + AccountACL ACLList `json:"accountACL"` + ComputeACL ACLList `json:"computeACL"` + RGACL ACLList `json:"rgACL"` +} + +type ACL struct { + Explicit bool `json:"explicit"` + GUID string `json:"guid"` + Right string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UserGroupID string `json:"userGroupId"` +} + +type ACLList []ACL + +type SnapshotUsage struct { + Count uint64 `json:"count,omitempty"` + Stored float64 `json:"stored"` + Label string `json:"label,omitempty"` + Timestamp uint64 `json:"timestamp,omitempty"` +} + +type SnapshotUsageList []SnapshotUsage + +type Snapshot struct { + Disks []uint64 `json:"disks"` + GUID string `json:"guid"` + Label string `json:"label"` + Timestamp uint64 `json:"timestamp"` +} + +type SnapshotList []Snapshot + +type PFW struct { + ID uint64 `json:"id"` + LocalIP string `json:"localIp"` + LocalPort uint64 `json:"localPort"` + Protocol string `json:"protocol"` + PublicPortEnd uint64 `json:"publicPortEnd"` + PublicPortStart uint64 `json:"publicPortStart"` + VMID uint64 `json:"vmId"` +} + +type PFWList []PFW + +type AffinityRelations struct { + OtherNode []interface{} `json:"otherNode"` + OtherNodeIndirect []interface{} `json:"otherNodeIndirect"` + OtherNodeIndirectSoft []interface{} `json:"otherNodeIndirectSoft"` + OtherNodeSoft []interface{} `json:"otherNodeSoft"` + SameNode []interface{} `json:"sameNode"` + SameNodeSoft []interface{} `json:"sameNodeSoft"` +} + +type NetAttach struct { + ConnID uint64 `json:"connId"` + ConnType string `json:"connType"` + DefGW string `json:"defGw"` + FlipGroupID uint64 `json:"flipgroupId"` + GUID string `json:"guid"` + IPAddress string `json:"ipAddress"` + ListenSSH bool `json:"listenSsh"` + MAC string `json:"mac"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetMask uint64 `json:"netMask"` + NetType string `json:"netType"` + PCISlot uint64 `json:"pciSlot"` + QOS QOS `json:"qos"` + Target string `json:"target"` + Type string `json:"type"` + VNFS []uint64 `json:"vnfs"` +} + +type Audit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode uint64 `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type AuditList []Audit + +type AuditShort struct { + Epoch float64 `json:"epoch"` + Message string `json:"message"` +} + +type AuditShortList []AuditShort + +type Rule struct { + GUID string `json:"guid"` + Key string `json:"key"` + Mode string `json:"mode"` + Policy string `json:"policy"` + Topology string `json:"topology"` + Value string `json:"value"` +} + +type RuleList []Rule + +type ComputeRecord struct { + ACL UserList `json:"ACL"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + AffinityLabel string `json:"affinityLabel"` + AffinityRules RuleList `json:"affinityRules"` + AffinityWeight uint64 `json:"affinityWeight"` + AntiAffinityRules RuleList `json:"antiAffinityRules"` + Architecture string `json:"arch"` + BootOrder []string `json:"bootOrder"` + BootDiskSize uint64 `json:"bootdiskSize"` + CloneReference uint64 `json:"cloneReference"` + Clones []uint64 `json:"clones"` + ComputeCIID uint64 `json:"computeciId"` + CPU uint64 `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + CustomFields map[string]interface{} `json:"customFields"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + Devices interface{} `json:"devices"` + Disks ComputeDiskList `json:"disks"` + Driver string `json:"driver"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + ImageName string `json:"imageName"` + Intefaces IntefaceList `json:"interfaces"` + LockStatus string `json:"lockStatus"` + ManagerID uint64 `json:"managerId"` + ManagerType string `json:"managerType"` + MigrationJob uint64 `json:"migrationjob"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + NatableVINSID uint64 `json:"natableVinsId"` + NatableVINSIP string `json:"natableVinsIp"` + NatableVINSName string `json:"natableVinsName"` + NatableVINSNetwork string `json:"natableVinsNetwork"` + NatableVINSNetworkName string `json:"natableVinsNetworkName"` + OSUsers OSUserList `json:"osUsers"` + Pinned bool `json:"pinned"` + RAM uint64 `json:"ram"` + ReferenceID string `json:"referenceId"` + Registered bool `json:"registered"` + ResName string `json:"resName"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + SnapSets SnapSetList `json:"snapSets"` + StatelessSepID uint64 `json:"statelessSepId"` + StatelessSepType string `json:"statelessSepType"` + Status string `json:"status"` + Tags map[string]string `json:"tags"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + Userdata interface{} `json:"userdata"` + VGPUs []uint64 `json:"vgpus"` + VirtualImageID uint64 `json:"virtualImageId"` + VirtualImageName string `json:"virtualImageName"` +} + +type OSUser struct { + GUID string `json:"guid"` + Login string `json:"login"` + Password string `json:"password"` + PubKey string `json:"pubkey"` +} + +type OSUserList []OSUser + +type SnapSet struct { + Disks []uint64 `json:"disks"` + GUID string `json:"guid"` + Label string `json:"label"` + Timestamp uint64 `json:"timestamp"` +} + +type SnapSetList []SnapSet + +type VNFInterface struct { + ConnID uint64 `json:"connId"` + ConnType string `json:"connType"` + DefGW string `json:"defGw"` + FlipGroupID uint64 `json:"flipgroupId"` + GUID string `json:"guid"` + IPAddress string `json:"ipAddress"` + ListenSSH bool `json:"listenSsh"` + MAC string `json:"mac"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetMask uint64 `json:"netMask"` + NetType string `json:"netType"` + PCISlot uint64 `json:"pciSlot"` + QOS QOS `json:"qos"` + Target string `json:"target"` + Type string `json:"type"` + VNFS []uint64 `json:"vnfs"` +} + +type QOS struct { + ERate uint64 `json:"eRate"` + GUID string `json:"guid"` + InBurst uint64 `json:"inBurst"` + InRate uint64 `json:"inRate"` +} + +type IntefaceList []VNFInterface + +type ComputeDiskList []ComputeDisk + +type ComputeDisk struct { + Ckey string `json:"_ckey"` + ACL map[string]interface{} `json:"acl"` + AccountID uint64 `json:"accountId"` + Bootpartition uint64 `json:"bootPartition"` + CreatedTime uint64 `json:"createdTime"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + DiskPath string `json:"diskPath"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Images []uint64 `json:"images"` + IOTune IOTune `json:"iotune"` + IQN string `json:"iqn"` + Login string `json:"login"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Order uint64 `json:"order"` + Params string `json:"params"` + ParentID uint64 `json:"parentId"` + Passwd string `json:"passwd"` + PciSlot uint64 `json:"pciSlot"` + Pool string `json:"pool"` + PurgeTime uint64 `json:"purgeTime"` + RealityDeviceNumber uint64 `json:"realityDeviceNumber"` + ResID string `json:"resId"` + Role string `json:"role"` + SepID uint64 `json:"sepId"` // NOTE: absent from compute/get output + SizeMax uint64 `json:"sizeMax"` + SizeUsed uint64 `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space + Snapshots SnapshotExtendList `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + VMID uint64 `json:"vmid"` +} + +type SnapshotExtend struct { + Guid string `json:"guid"` + Label string `json:"label"` + ResID string `json:"resId"` + SnapSetGuid string `json:"snapSetGuid"` + SnapSetTime uint64 `json:"snapSetTime"` + TimeStamp uint64 `json:"timestamp"` +} + +type SnapshotExtendList []SnapshotExtend + +type IOTune struct { + ReadBytesSec uint64 `json:"read_bytes_sec"` + ReadBytesSecMax uint64 `json:"read_bytes_sec_max"` + ReadIopsSec uint64 `json:"read_iops_sec"` + ReadIopsSecMax uint64 `json:"read_iops_sec_max"` + SizeIopsSec uint64 `json:"size_iops_sec"` + TotalBytesSec uint64 `json:"total_bytes_sec"` + TotalBytesSecMax uint64 `json:"total_bytes_sec_max"` + TotalIopsSec uint64 `json:"total_iops_sec"` + TotalIopsSecMax uint64 `json:"total_iops_sec_max"` + WriteBytesSec uint64 `json:"write_bytes_sec"` + WriteBytesSecMax uint64 `json:"write_bytes_sec_max"` + WriteIopsSec uint64 `json:"write_iops_sec"` + WriteIopsSecMax uint64 `json:"write_iops_sec_max"` +} + +type ComputeItem struct { + ACL []interface{} `json:"ACL"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + AffinityLabel string `json:"affinityLabel"` + AffinityRules RuleList `json:"affinityRules"` + AffinityWeight uint64 `json:"affinityWeight"` + AntiAffinityRules RuleList `json:"antiAffinityRules"` + Architecture string `json:"arch"` + BootOrder []string `json:"bootOrder"` + BootDiskSize uint64 `json:"bootdiskSize"` + CloneReference uint64 `json:"cloneReference"` + Clones []uint64 `json:"clones"` + ComputeCIID uint64 `json:"computeciId"` + CPU uint64 `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + CustomFields map[string]interface{} `json:"customFields"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + Devices interface{} `json:"devices"` + Disks []uint64 `json:"disks"` + Driver string `json:"driver"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + ImageName string `json:"imageName"` + Intefaces IntefaceList `json:"interfaces"` + LockStatus string `json:"lockStatus"` + ManagerID uint64 `json:"managerId"` + ManagerType string `json:"managerType"` + MigrationJob uint64 `json:"migrationjob"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Pinned bool `json:"pinned"` + RAM uint64 `json:"ram"` + ReferenceID string `json:"referenceId"` + Registered bool `json:"registered"` + ResName string `json:"resName"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + SnapSets SnapSetList `json:"snapSets"` + StatelessSepID uint64 `json:"statelessSepId"` + StatelessSepType string `json:"statelessSepType"` + Status string `json:"status"` + Tags map[string]string `json:"tags"` + TechStatus string `json:"techStatus"` + TotalDiskSize uint64 `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + Userdata interface{} `json:"userdata"` + VGPUs []uint64 `json:"vgpus"` + VirtualImageID uint64 `json:"virtualImageId"` + VirtualImageName string `json:"virtualImageName"` +} + +type ComputeList []ComputeItem diff --git a/pkg/cloudapi/compute/move_to_rg.go b/pkg/cloudapi/compute/move_to_rg.go index ef412e7..5fc0803 100644 --- a/pkg/cloudapi/compute/move_to_rg.go +++ b/pkg/cloudapi/compute/move_to_rg.go @@ -1,57 +1,47 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type MoveToRGRequest struct { - ComputeId uint64 `url:"computeId"` - RGID uint64 `url:"rgId"` - Name string `url:"name,omitempty"` - Autostart bool `url:"autostart,omitempty"` - ForceStop bool `url:"forceStop,omitempty"` -} - -func (crq MoveToRGRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/moveToRg" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type MoveToRGRequest struct { + ComputeID uint64 `url:"computeId"` + RGID uint64 `url:"rgId"` + Name string `url:"name,omitempty"` + Autostart bool `url:"autostart,omitempty"` + ForceStop bool `url:"forceStop,omitempty"` +} + +func (crq MoveToRGRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/moveToRg" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/net_attach.go b/pkg/cloudapi/compute/net_attach.go index b89caba..416542d 100644 --- a/pkg/cloudapi/compute/net_attach.go +++ b/pkg/cloudapi/compute/net_attach.go @@ -1,67 +1,58 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type NetAttachRequest struct { - ComputeId uint64 `url:"computeId"` - NetType string `url:"netType"` - NetID uint64 `url:"netId"` - IPAddr string `url:"ipAddr,omitempty"` -} - -func (crq NetAttachRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.NetType == "" { - return errors.New("validation-error: field NetType can not be empty") - } - validator := validators.StringInSlice(crq.NetType, []string{"EXTNET", "VINS"}) - if !validator { - return errors.New("validation-error: field NetType can be only EXTNET or VINS") - } - - if crq.NetID == 0 { - return errors.New("validation-error: field NetID can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest, options ...opts.DecortOpts) (*NetAttach, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/netAttach" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - netAttach := &NetAttach{} - err = json.Unmarshal(res, netAttach) - if err != nil { - return nil, err - } - - return netAttach, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type NetAttachRequest struct { + ComputeID uint64 `url:"computeId"` + NetType string `url:"netType"` + NetID uint64 `url:"netId"` + IPAddr string `url:"ipAddr,omitempty"` +} + +func (crq NetAttachRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.NetType == "" { + return errors.New("validation-error: field NetType can not be empty") + } + validator := validators.StringInSlice(crq.NetType, []string{"EXTNET", "VINS"}) + if !validator { + return errors.New("validation-error: field NetType can be only EXTNET or VINS") + } + + if crq.NetID == 0 { + return errors.New("validation-error: field NetID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*NetAttach, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/netAttach" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + netAttach := &NetAttach{} + err = json.Unmarshal(res, netAttach) + if err != nil { + return nil, err + } + + return netAttach, nil +} diff --git a/pkg/cloudapi/compute/net_detach.go b/pkg/cloudapi/compute/net_detach.go index cb209b6..c5b4f05 100644 --- a/pkg/cloudapi/compute/net_detach.go +++ b/pkg/cloudapi/compute/net_detach.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type NetDetachRequest struct { - ComputeId uint64 `url:"computeId"` - IPAddr string `url:"ipAddr,omitempty"` - MAC string `url:"mac,omitempty"` -} - -func (crq NetDetachRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/netDetach" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type NetDetachRequest struct { + ComputeID uint64 `url:"computeId"` + IPAddr string `url:"ipAddr,omitempty"` + MAC string `url:"mac,omitempty"` +} + +func (crq NetDetachRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/netDetach" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/pause.go b/pkg/cloudapi/compute/pause.go index bd0b809..0e90c6f 100644 --- a/pkg/cloudapi/compute/pause.go +++ b/pkg/cloudapi/compute/pause.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PauseRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq PauseRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Pause(ctx context.Context, req PauseRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/pause" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type PauseRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq PauseRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Pause(ctx context.Context, req PauseRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/pause" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/pfw_add.go b/pkg/cloudapi/compute/pfw_add.go index 1ac4c49..1aa1bf5 100644 --- a/pkg/cloudapi/compute/pfw_add.go +++ b/pkg/cloudapi/compute/pfw_add.go @@ -1,69 +1,60 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PFWAddRequest struct { - ComputeId uint64 `url:"computeId"` - PublicPortStart uint64 `url:"publicPortStart"` - PublicPortEnd uint64 `url:"publicPortEnd,omitempty"` - LocalBasePort uint64 `url:"localBasePort"` - Proto string `url:"proto"` -} - -func (crq PFWAddRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.PublicPortStart == 0 { - return errors.New("validation-error: field PublicPortStart can not be empty or equal to 0") - } - if crq.LocalBasePort == 0 { - return errors.New("validation-error: field LocalBasePort can not be empty or equal to 0") - } - if crq.Proto == "" { - return errors.New("validation-error: field Proto can not be empty") - } - validator := validators.StringInSlice(crq.Proto, []string{"tcp", "udp"}) - if !validator { - return errors.New("validation-error: field Proto can be only tcp or udp") - } - - return nil -} - -func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/compute/pfwAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type PFWAddRequest struct { + ComputeID uint64 `url:"computeId"` + PublicPortStart uint64 `url:"publicPortStart"` + PublicPortEnd uint64 `url:"publicPortEnd,omitempty"` + LocalBasePort uint64 `url:"localBasePort"` + Proto string `url:"proto"` +} + +func (crq PFWAddRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.PublicPortStart == 0 { + return errors.New("validation-error: field PublicPortStart can not be empty or equal to 0") + } + if crq.LocalBasePort == 0 { + return errors.New("validation-error: field LocalBasePort can not be empty or equal to 0") + } + if crq.Proto == "" { + return errors.New("validation-error: field Proto can not be empty") + } + validator := validators.StringInSlice(crq.Proto, []string{"tcp", "udp"}) + if !validator { + return errors.New("validation-error: field Proto can be only tcp or udp") + } + + return nil +} + +func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/compute/pfwAdd" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/pfw_del.go b/pkg/cloudapi/compute/pfw_del.go index 9f9ecdb..bed1d20 100644 --- a/pkg/cloudapi/compute/pfw_del.go +++ b/pkg/cloudapi/compute/pfw_del.go @@ -1,56 +1,46 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PFWDelRequest struct { - ComputeId uint64 `url:"computeId"` - PFWId uint64 `url:"ruleId,omitempty"` - PublicPortStart uint64 `url:"publicPortStart,omitempty"` - PublicPortEnd uint64 `url:"publicPortEnd,omitempty"` - LocalBasePort uint64 `url:"localBasePort,omitempty"` - Proto string `url:"proto,omitempty"` -} - -func (crq PFWDelRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/pfwDel" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type PFWDelRequest struct { + ComputeID uint64 `url:"computeId"` + PFWID uint64 `url:"ruleId,omitempty"` + PublicPortStart uint64 `url:"publicPortStart,omitempty"` + PublicPortEnd uint64 `url:"publicPortEnd,omitempty"` + LocalBasePort uint64 `url:"localBasePort,omitempty"` + Proto string `url:"proto,omitempty"` +} + +func (crq PFWDelRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/pfwDel" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/pfw_list.go b/pkg/cloudapi/compute/pfw_list.go index 69fb55c..3e92dde 100644 --- a/pkg/cloudapi/compute/pfw_list.go +++ b/pkg/cloudapi/compute/pfw_list.go @@ -1,53 +1,43 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PFWListRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq PFWListRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) PFWList(ctx context.Context, req PFWListRequest, options ...opts.DecortOpts) (PFWList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/pfwList" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - pfwList := PFWList{} - - err = json.Unmarshal(res, &pfwList) - if err != nil { - return nil, err - } - - return pfwList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type PFWListRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq PFWListRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (PFWList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/pfwList" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + pfwList := PFWList{} + + err = json.Unmarshal(res, &pfwList) + if err != nil { + return nil, err + } + + return pfwList, nil +} diff --git a/pkg/cloudapi/compute/pin_to_stack.go b/pkg/cloudapi/compute/pin_to_stack.go index 606f91c..c5cc926 100644 --- a/pkg/cloudapi/compute/pin_to_stack.go +++ b/pkg/cloudapi/compute/pin_to_stack.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PinToStackRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq PinToStackRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/compute/pinToStack" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type PinToStackRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq PinToStackRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/compute/pinToStack" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/power_cycle.go b/pkg/cloudapi/compute/power_cycle.go index 5cc0091..8ec13bc 100644 --- a/pkg/cloudapi/compute/power_cycle.go +++ b/pkg/cloudapi/compute/power_cycle.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type PowerCycleRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq PowerCycleRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/powerCycle" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type PowerCycleRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq PowerCycleRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/powerCycle" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/reboot.go b/pkg/cloudapi/compute/reboot.go index e350776..290d56f 100644 --- a/pkg/cloudapi/compute/reboot.go +++ b/pkg/cloudapi/compute/reboot.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RebootRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq RebootRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Reboot(ctx context.Context, req RebootRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/reboot" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RebootRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq RebootRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Reboot(ctx context.Context, req RebootRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/reboot" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/redeploy.go b/pkg/cloudapi/compute/redeploy.go index d105c8a..b16cdb4 100644 --- a/pkg/cloudapi/compute/redeploy.go +++ b/pkg/cloudapi/compute/redeploy.go @@ -1,55 +1,45 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RedeployRequest struct { - ComputeId uint64 `url:"computeId"` - ImageId uint64 `url:"imageId,omitempty"` - DiskSize uint64 `url:"diskSize,omitempty"` - DataDisks string `url:"dataDisks,omitempty"` - AutoStart bool `url:"autoStart,omitempty"` - ForceStop bool `url:"forceStop,omitempty"` -} - -func (crq RedeployRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Redeploy(ctx context.Context, req RedeployRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/redeploy" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RedeployRequest struct { + ComputeID uint64 `url:"computeId"` + ImageID uint64 `url:"imageId,omitempty"` + DiskSize uint64 `url:"diskSize,omitempty"` + DataDisks string `url:"dataDisks,omitempty"` + AutoStart bool `url:"autoStart,omitempty"` + ForceStop bool `url:"forceStop,omitempty"` +} + +func (crq RedeployRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/redeploy" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/reset.go b/pkg/cloudapi/compute/reset.go index 7757649..81c86db 100644 --- a/pkg/cloudapi/compute/reset.go +++ b/pkg/cloudapi/compute/reset.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ResetRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq ResetRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Reset(ctx context.Context, req ResetRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/reset" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ResetRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq ResetRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Reset(ctx context.Context, req ResetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/reset" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/resize.go b/pkg/cloudapi/compute/resize.go index 7a6f4a8..6dc1e49 100644 --- a/pkg/cloudapi/compute/resize.go +++ b/pkg/cloudapi/compute/resize.go @@ -1,53 +1,43 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ResizeRequest struct { - ComputeId uint64 `url:"computeId"` - Force bool `url:"force,omitempty"` - CPU uint64 `url:"cpu,omitempty"` - RAM uint64 `url:"ram,omitempty"` -} - -func (crq ResizeRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Resize(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/resize" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ResizeRequest struct { + ComputeID uint64 `url:"computeId"` + Force bool `url:"force,omitempty"` + CPU uint64 `url:"cpu,omitempty"` + RAM uint64 `url:"ram,omitempty"` +} + +func (crq ResizeRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/resize" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/restore.go b/pkg/cloudapi/compute/restore.go index 904f59f..f9799e2 100644 --- a/pkg/cloudapi/compute/restore.go +++ b/pkg/cloudapi/compute/restore.go @@ -1,45 +1,35 @@ -package compute - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq RestoreRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/restore" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package compute + +import ( + "context" + "errors" + "net/http" +) + +type RestoreRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq RestoreRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Restore(ctx context.Context, req RestoreRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/compute/restore" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/compute/resume.go b/pkg/cloudapi/compute/resume.go index c9f1011..6415f7f 100644 --- a/pkg/cloudapi/compute/resume.go +++ b/pkg/cloudapi/compute/resume.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ResumeRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq ResumeRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Resume(ctx context.Context, req ResumeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/resume" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ResumeRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq ResumeRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Resume(ctx context.Context, req ResumeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/resume" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/snapshot_create.go b/pkg/cloudapi/compute/snapshot_create.go index b139fb5..f64ad82 100644 --- a/pkg/cloudapi/compute/snapshot_create.go +++ b/pkg/cloudapi/compute/snapshot_create.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotCreateRequest struct { - ComputeId uint64 `url:"computeId"` - Label string `url:"label"` -} - -func (crq SnapshotCreateRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Label == "" { - return errors.New("validation-error: field Label can not be empty") - } - - return nil -} - -func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/compute/snapshotCreate" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - result := strings.ReplaceAll(string(res), "\"", "") - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type SnapshotCreateRequest struct { + ComputeID uint64 `url:"computeId"` + Label string `url:"label"` +} + +func (crq SnapshotCreateRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Label == "" { + return errors.New("validation-error: field Label can not be empty") + } + + return nil +} + +func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/compute/snapshotCreate" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + result := strings.ReplaceAll(string(res), "\"", "") + + return result, nil +} diff --git a/pkg/cloudapi/compute/snapshot_delete.go b/pkg/cloudapi/compute/snapshot_delete.go index d157f59..cd94ec5 100644 --- a/pkg/cloudapi/compute/snapshot_delete.go +++ b/pkg/cloudapi/compute/snapshot_delete.go @@ -1,55 +1,45 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotDeleteRequest struct { - ComputeId uint64 `url:"computeId"` - Label string `url:"label"` -} - -func (crq SnapshotDeleteRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Label == "" { - return errors.New("validation-error: field Label can not be empty") - } - - return nil -} - -func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/snapshotDelete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotDeleteRequest struct { + ComputeID uint64 `url:"computeId"` + Label string `url:"label"` +} + +func (crq SnapshotDeleteRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Label == "" { + return errors.New("validation-error: field Label can not be empty") + } + + return nil +} + +func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/snapshotDelete" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/snapshot_list.go b/pkg/cloudapi/compute/snapshot_list.go index 0161384..55230cf 100644 --- a/pkg/cloudapi/compute/snapshot_list.go +++ b/pkg/cloudapi/compute/snapshot_list.go @@ -1,53 +1,43 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotListRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq SnapshotListRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) (SnapshotList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/snapshotList" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - snapshotList := SnapshotList{} - - err = json.Unmarshal(res, &snapshotList) - if err != nil { - return nil, err - } - - return snapshotList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type SnapshotListRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq SnapshotListRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (SnapshotList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/snapshotList" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + snapshotList := SnapshotList{} + + err = json.Unmarshal(res, &snapshotList) + if err != nil { + return nil, err + } + + return snapshotList, nil +} diff --git a/pkg/cloudapi/compute/snapshot_rollback.go b/pkg/cloudapi/compute/snapshot_rollback.go index 25d5934..62ae6cc 100644 --- a/pkg/cloudapi/compute/snapshot_rollback.go +++ b/pkg/cloudapi/compute/snapshot_rollback.go @@ -1,55 +1,45 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotRollbackRequest struct { - ComputeId uint64 `url:"computeId"` - Label string `url:"label"` -} - -func (crq SnapshotRollbackRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Label == "" { - return errors.New("validation-error: field Label can not be empty") - } - - return nil -} - -func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/snapshotRollback" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotRollbackRequest struct { + ComputeID uint64 `url:"computeId"` + Label string `url:"label"` +} + +func (crq SnapshotRollbackRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Label == "" { + return errors.New("validation-error: field Label can not be empty") + } + + return nil +} + +func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/snapshotRollback" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/compute/snapshot_usage.go b/pkg/cloudapi/compute/snapshot_usage.go index bd77670..1568a30 100644 --- a/pkg/cloudapi/compute/snapshot_usage.go +++ b/pkg/cloudapi/compute/snapshot_usage.go @@ -1,54 +1,44 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotUsageRequest struct { - ComputeId uint64 `url:"computeId"` - Label string `url:"label,omitempty"` -} - -func (crq SnapshotUsageRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest, options ...opts.DecortOpts) (SnapshotUsageList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/compute/snapshotUsage" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - snapshotUsage := SnapshotUsageList{} - - err = json.Unmarshal(res, &snapshotUsage) - if err != nil { - return nil, err - } - - return snapshotUsage, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type SnapshotUsageRequest struct { + ComputeID uint64 `url:"computeId"` + Label string `url:"label,omitempty"` +} + +func (crq SnapshotUsageRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (SnapshotUsageList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/compute/snapshotUsage" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + snapshotUsage := SnapshotUsageList{} + + err = json.Unmarshal(res, &snapshotUsage) + if err != nil { + return nil, err + } + + return snapshotUsage, nil +} diff --git a/pkg/cloudapi/compute/start.go b/pkg/cloudapi/compute/start.go index 5b75870..5facbc9 100644 --- a/pkg/cloudapi/compute/start.go +++ b/pkg/cloudapi/compute/start.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type StartRequest struct { - ComputeId uint64 `url:"computeId"` - AltBootId uint64 `url:"altBootId,omitempty"` -} - -func (crq StartRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/start" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type StartRequest struct { + ComputeID uint64 `url:"computeId"` + AltBootID uint64 `url:"altBootId,omitempty"` +} + +func (crq StartRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Start(ctx context.Context, req StartRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/start" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/stop.go b/pkg/cloudapi/compute/stop.go index 1a8e379..9ebc460 100644 --- a/pkg/cloudapi/compute/stop.go +++ b/pkg/cloudapi/compute/stop.go @@ -1,51 +1,41 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type StopRequest struct { - ComputeId uint64 `url:"computeId"` - Force bool `url:"force,omitempty"` -} - -func (crq StopRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/stop" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type StopRequest struct { + ComputeID uint64 `url:"computeId"` + Force bool `url:"force,omitempty"` +} + +func (crq StopRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Stop(ctx context.Context, req StopRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/stop" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/tag_add.go b/pkg/cloudapi/compute/tag_add.go index 41126e3..32fb418 100644 --- a/pkg/cloudapi/compute/tag_add.go +++ b/pkg/cloudapi/compute/tag_add.go @@ -1,59 +1,49 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type TagAddRequest struct { - ComputeId uint64 `url:"computeId"` - Key string `url:"key"` - Value string `url:"value"` -} - -func (crq TagAddRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - if crq.Value == "" { - return errors.New("validation-error: field Value can not be empty") - } - - return nil -} - -func (c Compute) TagAdd(ctx context.Context, req TagAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/tagAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type TagAddRequest struct { + ComputeID uint64 `url:"computeId"` + Key string `url:"key"` + Value string `url:"value"` +} + +func (crq TagAddRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + if crq.Value == "" { + return errors.New("validation-error: field Value can not be empty") + } + + return nil +} + +func (c Compute) TagAdd(ctx context.Context, req TagAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/tagAdd" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/tag_remove.go b/pkg/cloudapi/compute/tag_remove.go index f18480f..4cfebec 100644 --- a/pkg/cloudapi/compute/tag_remove.go +++ b/pkg/cloudapi/compute/tag_remove.go @@ -1,54 +1,44 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type TagRemoveRequest struct { - ComputeId uint64 `url:"computeId"` - Key string `url:"key"` -} - -func (crq TagRemoveRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - if crq.Key == "" { - return errors.New("validation-error: field Key can not be empty") - } - - return nil -} - -func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/tagRemove" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type TagRemoveRequest struct { + ComputeID uint64 `url:"computeId"` + Key string `url:"key"` +} + +func (crq TagRemoveRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + if crq.Key == "" { + return errors.New("validation-error: field Key can not be empty") + } + + return nil +} + +func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/tagRemove" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/unpin_from_stack.go b/pkg/cloudapi/compute/unpin_from_stack.go index 4a0810e..b4d9eb2 100644 --- a/pkg/cloudapi/compute/unpin_from_stack.go +++ b/pkg/cloudapi/compute/unpin_from_stack.go @@ -1,50 +1,40 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UnpinFromStackRequest struct { - ComputeId uint64 `url:"computeId"` -} - -func (crq UnpinFromStackRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/unpinFromStack" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UnpinFromStackRequest struct { + ComputeID uint64 `url:"computeId"` +} + +func (crq UnpinFromStackRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/unpinFromStack" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/update.go b/pkg/cloudapi/compute/update.go index 2fd6c10..9b53f58 100644 --- a/pkg/cloudapi/compute/update.go +++ b/pkg/cloudapi/compute/update.go @@ -1,52 +1,42 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UpdateRequest struct { - ComputeId uint64 `url:"computeId"` - Name string `url:"name,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (crq UpdateRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/update" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + ComputeID uint64 `url:"computeId"` + Name string `url:"name,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (crq UpdateRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/update" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/user_grant.go b/pkg/cloudapi/compute/user_grant.go index 8b9b683..413d65a 100644 --- a/pkg/cloudapi/compute/user_grant.go +++ b/pkg/cloudapi/compute/user_grant.go @@ -1,65 +1,56 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UserGrantRequest struct { - ComputeId uint64 `url:"computeId"` - Username string `url:"userName"` - AccessType string `url:"accesstype"` -} - -func (crq UserGrantRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Username == "" { - return errors.New("validation-error: field Username can not be empty") - } - - if crq.AccessType == "" { - return errors.New("validation-error: field AccessType can not be empty") - } - validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"}) - if !validator { - return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") - } - - return nil -} - -func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/userGrant" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type UserGrantRequest struct { + ComputeID uint64 `url:"computeId"` + Username string `url:"userName"` + AccessType string `url:"accesstype"` +} + +func (crq UserGrantRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Username == "" { + return errors.New("validation-error: field UserName can not be empty") + } + + if crq.AccessType == "" { + return errors.New("validation-error: field AccessType can not be empty") + } + validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"}) + if !validator { + return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") + } + + return nil +} + +func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/userGrant" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/user_list.go b/pkg/cloudapi/compute/user_list.go index e72cdd3..8e4b83a 100644 --- a/pkg/cloudapi/compute/user_list.go +++ b/pkg/cloudapi/compute/user_list.go @@ -1,49 +1,39 @@ -package compute - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UserListRequest struct { - ComputeId uint64 `url:"computeId "` -} - -func (crq UserListRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - return nil -} - -func (c Compute) UserList(ctx context.Context, req UserListRequest, options ...opts.DecortOpts) (*UserList, error) { - - url := "/compute/userList" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - userList := &UserList{} - - err = json.Unmarshal(res, userList) - if err != nil { - return nil, err - } - - return userList, nil -} +package compute + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type UserListRequest struct { + ComputeID uint64 `url:"computeId "` +} + +func (crq UserListRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (c Compute) UserList(ctx context.Context, req UserListRequest) (*UserList, error) { + + url := "/cloudapi/compute/userList" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + userList := &UserList{} + + err = json.Unmarshal(res, userList) + if err != nil { + return nil, err + } + + return userList, nil +} diff --git a/pkg/cloudapi/compute/user_revoke.go b/pkg/cloudapi/compute/user_revoke.go index 54e82d1..4b7bbd5 100644 --- a/pkg/cloudapi/compute/user_revoke.go +++ b/pkg/cloudapi/compute/user_revoke.go @@ -1,55 +1,45 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UserRevokeRequest struct { - ComputeId uint64 `url:"computeId"` - Username string `url:"userName"` -} - -func (crq UserRevokeRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Username == "" { - return errors.New("validation-error: field Username can not be empty") - } - - return nil -} - -func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/userRevoke" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UserRevokeRequest struct { + ComputeID uint64 `url:"computeId"` + Username string `url:"userName"` +} + +func (crq UserRevokeRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Username == "" { + return errors.New("validation-error: field UserName can not be empty") + } + + return nil +} + +func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/userRevoke" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/compute/user_update.go b/pkg/cloudapi/compute/user_update.go index b69d2b5..c8d2c77 100644 --- a/pkg/cloudapi/compute/user_update.go +++ b/pkg/cloudapi/compute/user_update.go @@ -1,65 +1,56 @@ -package compute - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UserUpdateRequest struct { - ComputeId uint64 `url:"computeId"` - Username string `url:"userName"` - AccessType string `url:"accesstype"` -} - -func (crq UserUpdateRequest) Validate() error { - if crq.ComputeId == 0 { - return errors.New("validation-error: field ComputeId can not be empty or equal to 0") - } - - if crq.Username == "" { - return errors.New("validation-error: field Username can not be empty") - } - - if crq.AccessType == "" { - return errors.New("validation-error: field AccessType can not be empty") - } - validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"}) - if !validator { - return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") - } - - return nil -} - -func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/compute/userUpdate" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package compute + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type UserUpdateRequest struct { + ComputeID uint64 `url:"computeId"` + Username string `url:"userName"` + AccessType string `url:"accesstype"` +} + +func (crq UserUpdateRequest) Validate() error { + if crq.ComputeID == 0 { + return errors.New("validation-error: field ComputeID can not be empty or equal to 0") + } + + if crq.Username == "" { + return errors.New("validation-error: field UserName can not be empty") + } + + if crq.AccessType == "" { + return errors.New("validation-error: field AccessType can not be empty") + } + validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"}) + if !validator { + return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") + } + + return nil +} + +func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/compute/userUpdate" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/computeci.go b/pkg/cloudapi/computeci.go new file mode 100644 index 0000000..e534b8d --- /dev/null +++ b/pkg/cloudapi/computeci.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/computeci" +) + +func (ca *CloudApi) ComputeCI() *computeci.ComputeCI { + return computeci.New(ca.client) +} diff --git a/pkg/cloudapi/computeci/computeci.go b/pkg/cloudapi/computeci/computeci.go index 12a99ff..d22e349 100644 --- a/pkg/cloudapi/computeci/computeci.go +++ b/pkg/cloudapi/computeci/computeci.go @@ -1,15 +1,15 @@ -package computeci - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type ComputeCI struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *ComputeCI { - return &ComputeCI{ - client, - } -} +package computeci + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type ComputeCI struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *ComputeCI { + return &ComputeCI{ + client, + } +} diff --git a/pkg/cloudapi/computeci/get.go b/pkg/cloudapi/computeci/get.go index 0c0b840..8c274b6 100644 --- a/pkg/cloudapi/computeci/get.go +++ b/pkg/cloudapi/computeci/get.go @@ -1,41 +1,39 @@ -package computeci - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - ComputeCIID uint64 `url:"computeciId"` -} - -func (krq GetRequest) Validate() error { - if krq.ComputeCIID == 0 { - return errors.New("field ComputeCIID can not be empty or equal to 0") - } - - return nil -} - -func (c ComputeCI) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ComputeCIRecord, error) { - if err := req.Validate(); err != nil { - return nil, err - } - - url := "/cloudapi/computeci/get" - computeciRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - computeci := &ComputeCIRecord{} - if err := json.Unmarshal(computeciRaw, computeci); err != nil { - return nil, err - } - - return computeci, nil -} +package computeci + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + ComputeCIID uint64 `url:"computeciId"` +} + +func (krq GetRequest) Validate() error { + if krq.ComputeCIID == 0 { + return errors.New("field ComputeCIID can not be empty or equal to 0") + } + + return nil +} + +func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ComputeCIRecord, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudapi/computeci/get" + computeciRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computeci := &ComputeCIRecord{} + if err := json.Unmarshal(computeciRaw, computeci); err != nil { + return nil, err + } + + return computeci, nil +} diff --git a/pkg/cloudapi/computeci/list.go b/pkg/cloudapi/computeci/list.go index e7f9dcf..cded5b0 100644 --- a/pkg/cloudapi/computeci/list.go +++ b/pkg/cloudapi/computeci/list.go @@ -1,30 +1,28 @@ -package computeci - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDeleted bool `url:"includeDeleted,omitempty"` - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (c ComputeCI) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ComputeCIList, error) { - url := "/cloudapi/computeci/list" - computeciListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - computeciList := ComputeCIList{} - if err := json.Unmarshal(computeciListRaw, &computeciList); err != nil { - return nil, err - } - - return computeciList, nil -} +package computeci + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includeDeleted,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (c ComputeCI) List(ctx context.Context, req ListRequest) (ComputeCIList, error) { + url := "/cloudapi/computeci/list" + computeciListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + computeciList := ComputeCIList{} + if err := json.Unmarshal(computeciListRaw, &computeciList); err != nil { + return nil, err + } + + return computeciList, nil +} diff --git a/pkg/cloudapi/computeci/models.go b/pkg/cloudapi/computeci/models.go index 6a5e63c..48f1d22 100644 --- a/pkg/cloudapi/computeci/models.go +++ b/pkg/cloudapi/computeci/models.go @@ -1,14 +1,14 @@ -package computeci - -type ComputeCIRecord struct { - CustomFields map[string]interface{} `json:"customFields"` - Description string `json:"desc"` - Drivers []string `json:"drivers"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - Template string `jsnn:"template"` -} - -type ComputeCIList []ComputeCIRecord +package computeci + +type ComputeCIRecord struct { + CustomFields map[string]interface{} `json:"customFields"` + Description string `json:"desc"` + Drivers []string `json:"drivers"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + Template string `jsnn:"template"` +} + +type ComputeCIList []ComputeCIRecord diff --git a/pkg/cloudapi/disks.go b/pkg/cloudapi/disks.go new file mode 100644 index 0000000..28d33a7 --- /dev/null +++ b/pkg/cloudapi/disks.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/disks" +) + +func (ca *CloudApi) Disks() *disks.Disks { + return disks.New(ca.client) +} diff --git a/pkg/cloudapi/disks/create.go b/pkg/cloudapi/disks/create.go index 8e03ac9..aabf921 100644 --- a/pkg/cloudapi/disks/create.go +++ b/pkg/cloudapi/disks/create.go @@ -1,77 +1,67 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - AccountId uint64 `url:"accountId"` - GID uint64 `url:"gid"` - Name string `url:"name"` - Description string `url:"description,omitempty"` - Size uint64 `url:"size,omitempty"` - Type string `url:"type"` - SSDSize uint64 `url:"ssdSize,omitempty"` - IOps uint64 `url:"iops"` - SepId uint64 `url:"sep_id,omitempty"` - Pool string `url:"pool,omitempty"` -} - -func (drq CreateRequest) Validate() error { - if drq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - if drq.GID == 0 { - return errors.New("validation-error: field Gid can not be empty or equal to 0") - } - if drq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"}) - if !validType { - return errors.New("validation-error: field Type must be set as B, D or T") - } - - if drq.IOps == 0 { - return errors.New("validation-error: field IOps must be set") - } - - return nil -} - -func (d Disks) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/disks/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type CreateRequest struct { + AccountID uint64 `url:"accountId"` + GID uint64 `url:"gid"` + Name string `url:"name"` + Description string `url:"description,omitempty"` + Size uint64 `url:"size,omitempty"` + Type string `url:"type"` + SSDSize uint64 `url:"ssdSize,omitempty"` + IOps uint64 `url:"iops"` + SepID uint64 `url:"sep_id,omitempty"` + Pool string `url:"pool,omitempty"` +} + +func (drq CreateRequest) Validate() error { + if drq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + if drq.GID == 0 { + return errors.New("validation-error: field GID can not be empty or equal to 0") + } + if drq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"}) + if !validType { + return errors.New("validation-error: field Type must be set as B, D or T") + } + + if drq.IOps == 0 { + return errors.New("validation-error: field IOps must be set") + } + + return nil +} + +func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/disks/create" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil + +} diff --git a/pkg/cloudapi/disks/delete.go b/pkg/cloudapi/disks/delete.go index 94c3ecd..c3349b4 100644 --- a/pkg/cloudapi/disks/delete.go +++ b/pkg/cloudapi/disks/delete.go @@ -1,53 +1,43 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - DiskId uint64 `url:"diskId"` - Detach bool `url:"detach,omitempty"` - Permanently bool `url:"permanently,omitempty"` - Reason string `url:"reason,omitempty"` -} - -func (d DeleteRequest) Validate() error { - - if d.DiskId == 0 { - return errors.New("validation-error: field DiskId must be set") - } - return nil -} - -func (d Disks) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/delete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + DiskID uint64 `url:"diskId"` + Detach bool `url:"detach,omitempty"` + Permanently bool `url:"permanently,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (d DeleteRequest) Validate() error { + + if d.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + return nil +} + +func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/delete" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/disks/delete_disks.go b/pkg/cloudapi/disks/delete_disks.go index ae3a778..931d9dd 100644 --- a/pkg/cloudapi/disks/delete_disks.go +++ b/pkg/cloudapi/disks/delete_disks.go @@ -1,55 +1,44 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisksDeleteRequest struct { - DisksIds []uint64 `url:"diskIds"` - Reason string `url:"reason"` - Permanently bool `url:"permanently"` -} - -func (drq DisksDeleteRequest) Validate() error { - if len(drq.DisksIds) == 0 { - return errors.New("validation-error: field DisksIds must include one or more disks ids") - } - - return nil -} - -func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/deleteDisks" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisksDeleteRequest struct { + DisksIDs []uint64 `url:"diskIds"` + Reason string `url:"reason"` + Permanently bool `url:"permanently"` +} + +func (drq DisksDeleteRequest) Validate() error { + if len(drq.DisksIDs) == 0 { + return errors.New("validation-error: field DisksIDs must include one or more disks ids") + } + + return nil +} + +func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/deleteDisks" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/disks.go b/pkg/cloudapi/disks/disks.go index 13a5d2d..ce07806 100644 --- a/pkg/cloudapi/disks/disks.go +++ b/pkg/cloudapi/disks/disks.go @@ -1,15 +1,15 @@ -package disks - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Disks struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Disks { - return &Disks{ - client, - } -} +package disks + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Disks struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Disks { + return &Disks{ + client, + } +} diff --git a/pkg/cloudapi/disks/get.go b/pkg/cloudapi/disks/get.go index 6663699..4897f8a 100644 --- a/pkg/cloudapi/disks/get.go +++ b/pkg/cloudapi/disks/get.go @@ -1,55 +1,44 @@ -package disks - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - DiskId uint64 `url:"diskId"` -} - -func (drq GetRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - return nil -} - -func (d Disks) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*DiskRecord, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/disks/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - disk := &DiskRecord{} - - err = json.Unmarshal(res, disk) - if err != nil { - return nil, err - } - - return disk, nil - -} +package disks + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + DiskID uint64 `url:"diskId"` +} + +func (drq GetRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +func (d Disks) Get(ctx context.Context, req GetRequest) (*DiskRecord, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/disks/get" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + disk := &DiskRecord{} + + err = json.Unmarshal(res, disk) + if err != nil { + return nil, err + } + + return disk, nil + +} diff --git a/pkg/cloudapi/disks/limitio.go b/pkg/cloudapi/disks/limitio.go index 23e66a2..8cab664 100644 --- a/pkg/cloudapi/disks/limitio.go +++ b/pkg/cloudapi/disks/limitio.go @@ -1,67 +1,56 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type LimitIORequest struct { - DiskId uint64 `url:"diskId"` - IOps uint64 `url:"iops"` - TotalBytesSec uint64 `url:"total_bytes_sec"` - ReadBytesSec uint64 `url:"read_bytes_sec"` - WriteBytesSec uint64 `url:"write_bytes_sec"` - TotalIOpsSec uint64 `url:"total_iops_sec"` - ReadIOpsSec uint64 `url:"read_iops_sec"` - WriteIOpsSec uint64 `url:"write_iops_sec"` - TotalBytesSecMax uint64 `url:"total_bytes_sec_max"` - ReadBytesSecMax uint64 `url:"read_bytes_sec_max"` - WriteBytesSecMax uint64 `url:"write_bytes_sec_max"` - TotalIOpsSecMax uint64 `url:"total_iops_sec_max"` - ReadIOpsSecMax uint64 `url:"read_iops_sec_max"` - WriteIOpsSecMax uint64 `url:"write_iops_sec_max"` - SizeIOpsSec uint64 `url:"size_iops_sec"` -} - -func (drq LimitIORequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - return nil -} - -func (d Disks) LimitIO(ctx context.Context, req LimitIORequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/limitIO" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type LimitIORequest struct { + DiskID uint64 `url:"diskId"` + IOps uint64 `url:"iops"` + TotalBytesSec uint64 `url:"total_bytes_sec"` + ReadBytesSec uint64 `url:"read_bytes_sec"` + WriteBytesSec uint64 `url:"write_bytes_sec"` + TotalIOpsSec uint64 `url:"total_iops_sec"` + ReadIOpsSec uint64 `url:"read_iops_sec"` + WriteIOpsSec uint64 `url:"write_iops_sec"` + TotalBytesSecMax uint64 `url:"total_bytes_sec_max"` + ReadBytesSecMax uint64 `url:"read_bytes_sec_max"` + WriteBytesSecMax uint64 `url:"write_bytes_sec_max"` + TotalIOpsSecMax uint64 `url:"total_iops_sec_max"` + ReadIOpsSecMax uint64 `url:"read_iops_sec_max"` + WriteIOpsSecMax uint64 `url:"write_iops_sec_max"` + SizeIOpsSec uint64 `url:"size_iops_sec"` +} + +func (drq LimitIORequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/limitIO" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/list.go b/pkg/cloudapi/disks/list.go index 8b33aab..358c242 100644 --- a/pkg/cloudapi/disks/list.go +++ b/pkg/cloudapi/disks/list.go @@ -1,72 +1,54 @@ -package disks - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - AccountId uint64 `url:"accountId,omitempty"` - Type string `url:"type,omitempty"` - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (d Disks) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (DiskList, error) { - url := "/disks/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - diskList := DiskList{} - - err = json.Unmarshal(res, &diskList) - if err != nil { - return nil, err - } - - return diskList, nil - -} - -func (d Disks) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (DiskList, error) { - url := "/disks/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - diskList := DiskList{} - - err = json.Unmarshal(res, &diskList) - if err != nil { - return nil, err - } - - return diskList, nil - -} +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + AccountID uint64 `url:"accountId,omitempty"` + Type string `url:"type,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (d Disks) List(ctx context.Context, req ListRequest) (DiskList, error) { + url := "/cloudapi/disks/list" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := DiskList{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} + +func (d Disks) ListDeleted(ctx context.Context, req ListRequest) (DiskList, error) { + url := "/disks/listDeleted" + prefix := "/cloudapi" + + url = prefix + url + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := DiskList{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} diff --git a/pkg/cloudapi/disks/list_types.go b/pkg/cloudapi/disks/list_types.go index e95afcd..08047dc 100644 --- a/pkg/cloudapi/disks/list_types.go +++ b/pkg/cloudapi/disks/list_types.go @@ -1,41 +1,30 @@ -package disks - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListTypesRequest struct { - Detailed bool `url:"detailed"` -} - -func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest, options ...opts.DecortOpts) ([]interface{}, error) { - url := "/disks/listTypes" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - typesList := make([]interface{}, 0) - - err = json.Unmarshal(res, &typesList) - if err != nil { - return nil, err - } - - return typesList, nil - -} +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListTypesRequest struct { + Detailed bool `url:"detailed"` +} + +func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) { + url := "/cloudapi/disks/listTypes" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + typesList := make([]interface{}, 0) + + err = json.Unmarshal(res, &typesList) + if err != nil { + return nil, err + } + + return typesList, nil + +} diff --git a/pkg/cloudapi/disks/list_unattached.go b/pkg/cloudapi/disks/list_unattached.go index fff0e96..622a073 100644 --- a/pkg/cloudapi/disks/list_unattached.go +++ b/pkg/cloudapi/disks/list_unattached.go @@ -1,41 +1,30 @@ -package disks - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListUnattachedRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest, options ...opts.DecortOpts) (DiskList, error) { - url := "/disks/listUnattached" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - diskList := DiskList{} - - err = json.Unmarshal(res, &diskList) - if err != nil { - return nil, err - } - - return diskList, nil - -} +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListUnattachedRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (DiskList, error) { + url := "/cloudapi/disks/listUnattached" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := DiskList{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} diff --git a/pkg/cloudapi/disks/models.go b/pkg/cloudapi/disks/models.go index 05815af..9ad69bf 100644 --- a/pkg/cloudapi/disks/models.go +++ b/pkg/cloudapi/disks/models.go @@ -1,116 +1,116 @@ -package disks - -type Disk struct { - Acl map[string]interface{} `json:"acl"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - BootPartition int `json:"bootPartition"` - CreatedTime uint64 `json:"createdTime"` - ComputeID int `json:"computeId"` - ComputeName string `json:"computeName"` - DeletedTime uint64 `json:"deletedTime"` - DeviceName string `json:"devicename"` - Description string `json:"desc"` - DestructionTime uint64 `json:"destructionTime"` - GID uint64 `json:"gid"` - ID uint64 `json:"id"` - ImageID uint64 `json:"imageId"` - Images []uint64 `json:"images"` - IOTune IOTune `json:"iotune"` - MachineId int `json:"machineId"` - MachineName string `json:"machineName"` - Name string `json:"name"` - Order int `json:"order"` - Params string `json:"params"` - ParentId uint64 `json:"parentId"` - PciSlot uint64 `json:"pciSlot"` - Pool string `json:"pool"` - PurgeTime uint64 `json:"purgeTime"` - ResID string `json:"resId"` - ResName string `json:"resName"` - Role string `json:"role"` - SepType string `json:"sepType"` - SepID int `json:"sepId"` // NOTE: absent from compute/get output - SizeMax int `json:"sizeMax"` - Snapshots []Snapshot `json:"snapshots"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - VMID int `json:"vmid"` -} - -type Snapshot struct { - Guid string `json:"guid"` - Label string `json:"label"` - ResId string `json:"resId"` - SnapSetGuid string `json:"snapSetGuid"` - SnapSetTime uint64 `json:"snapSetTime"` - TimeStamp uint64 `json:"timestamp"` -} - -type SnapshotList []Snapshot - -type IOTune struct { - ReadBytesSec int `json:"read_bytes_sec"` - ReadBytesSecMax int `json:"read_bytes_sec_max"` - ReadIopsSec int `json:"read_iops_sec"` - ReadIopsSecMax int `json:"read_iops_sec_max"` - SizeIopsSec int `json:"size_iops_sec"` - TotalBytesSec int `json:"total_bytes_sec"` - TotalBytesSecMax int `json:"total_bytes_sec_max"` - TotalIopsSec int `json:"total_iops_sec"` - TotalIopsSecMax int `json:"total_iops_sec_max"` - WriteBytesSec int `json:"write_bytes_sec"` - WriteBytesSecMax int `json:"write_bytes_sec_max"` - WriteIopsSec int `json:"write_iops_sec"` - WriteIopsSecMax int `json:"write_iops_sec_max"` -} - -type DiskList []Disk - -type DisksTypesListCoomon []string - -type DisksTypesListDetailed struct { - Pools []Pool `json:"pools"` - SepId uint64 `json:"sepId"` -} - -type Pool struct { - Name string `json:"name"` - Types []string `json:"types"` -} - -type DiskRecord struct { - Acl map[string]interface{} `json:"acl"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - CreatedTime uint64 `json:"createdTime"` - DeletedTime uint64 `json:"deletedTime"` - DeviceName string `json:"devicename"` - Description string `json:"desc"` - DestructionTime uint64 `json:"destructionTime"` - GID int `json:"gid"` - ID uint `json:"id"` - ImageID int `json:"imageId"` - Images []int `json:"images"` - IOTune IOTune `json:"iotune"` - Name string `json:"name"` - Order int `json:"order"` - Params string `json:"params"` - ParentId int `json:"parentId"` - PciSlot int `json:"pciSlot"` - Pool string `json:"pool"` - PurgeTime uint64 `json:"purgeTime"` - ResID string `json:"resId"` - ResName string `json:"resName"` - Role string `json:"role"` - SepType string `json:"sepType"` - SepID int `json:"sepId"` // NOTE: absent from compute/get output - SizeMax int `json:"sizeMax"` - SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space - Snapshots []Snapshot `json:"snapshots"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - VMID int `json:"vmid"` -} +package disks + +type Disk struct { + ACL map[string]interface{} `json:"acl"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + BootPartition uint64 `json:"bootPartition"` + CreatedTime uint64 `json:"createdTime"` + ComputeID uint64 `json:"computeId"` + ComputeName string `json:"computeName"` + DeletedTime uint64 `json:"deletedTime"` + DeviceName string `json:"devicename"` + Description string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + GID uint64 `json:"gid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Images []uint64 `json:"images"` + IOTune IOTune `json:"iotune"` + MachineID uint64 `json:"machineId"` + MachineName string `json:"machineName"` + Name string `json:"name"` + Order uint64 `json:"order"` + Params string `json:"params"` + ParentID uint64 `json:"parentId"` + PciSlot uint64 `json:"pciSlot"` + Pool string `json:"pool"` + PurgeTime uint64 `json:"purgeTime"` + ResID string `json:"resId"` + ResName string `json:"resName"` + Role string `json:"role"` + SepType string `json:"sepType"` + SepID uint64 `json:"sepId"` // NOTE: absent from compute/get output + SizeMax uint64 `json:"sizeMax"` + Snapshots []Snapshot `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + VMID uint64 `json:"vmid"` +} + +type Snapshot struct { + Guid string `json:"guid"` + Label string `json:"label"` + ResID string `json:"resId"` + SnapSetGuid string `json:"snapSetGuid"` + SnapSetTime uint64 `json:"snapSetTime"` + TimeStamp uint64 `json:"timestamp"` +} + +type SnapshotList []Snapshot + +type IOTune struct { + ReadBytesSec uint64 `json:"read_bytes_sec"` + ReadBytesSecMax uint64 `json:"read_bytes_sec_max"` + ReadIopsSec uint64 `json:"read_iops_sec"` + ReadIopsSecMax uint64 `json:"read_iops_sec_max"` + SizeIopsSec uint64 `json:"size_iops_sec"` + TotalBytesSec uint64 `json:"total_bytes_sec"` + TotalBytesSecMax uint64 `json:"total_bytes_sec_max"` + TotalIopsSec uint64 `json:"total_iops_sec"` + TotalIopsSecMax uint64 `json:"total_iops_sec_max"` + WriteBytesSec uint64 `json:"write_bytes_sec"` + WriteBytesSecMax uint64 `json:"write_bytes_sec_max"` + WriteIopsSec uint64 `json:"write_iops_sec"` + WriteIopsSecMax uint64 `json:"write_iops_sec_max"` +} + +type DiskList []Disk + +type DisksTypesListCoomon []string + +type DisksTypesListDetailed struct { + Pools []Pool `json:"pools"` + SepID uint64 `json:"sepId"` +} + +type Pool struct { + Name string `json:"name"` + Types []string `json:"types"` +} + +type DiskRecord struct { + ACL map[string]interface{} `json:"acl"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + CreatedTime uint64 `json:"createdTime"` + DeletedTime uint64 `json:"deletedTime"` + DeviceName string `json:"devicename"` + Description string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + GID uint64 `json:"gid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Images []uint64 `json:"images"` + IOTune IOTune `json:"iotune"` + Name string `json:"name"` + Order uint64 `json:"order"` + Params string `json:"params"` + ParentID uint64 `json:"parentId"` + PciSlot uint64 `json:"pciSlot"` + Pool string `json:"pool"` + PurgeTime uint64 `json:"purgeTime"` + ResID string `json:"resId"` + ResName string `json:"resName"` + Role string `json:"role"` + SepType string `json:"sepType"` + SepID uint64 `json:"sepId"` // NOTE: absent from compute/get output + SizeMax uint64 `json:"sizeMax"` + SizeUsed uint64 `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space + Snapshots []Snapshot `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + VMID uint64 `json:"vmid"` +} diff --git a/pkg/cloudapi/disks/rename.go b/pkg/cloudapi/disks/rename.go index 7b193b5..4a1a56b 100644 --- a/pkg/cloudapi/disks/rename.go +++ b/pkg/cloudapi/disks/rename.go @@ -1,58 +1,47 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RenameRequest struct { - DiskId uint64 `url:"diskId"` - Name string `url:"name"` -} - -func (drq RenameRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - if drq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - return nil -} - -func (d Disks) Rename(ctx context.Context, req RenameRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/rename" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RenameRequest struct { + DiskID uint64 `url:"diskId"` + Name string `url:"name"` +} + +func (drq RenameRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if drq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + return nil +} + +func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/rename" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/resize.go b/pkg/cloudapi/disks/resize.go index c7120c0..50feb23 100644 --- a/pkg/cloudapi/disks/resize.go +++ b/pkg/cloudapi/disks/resize.go @@ -1,89 +1,71 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ResizeRequest struct { - DiskId uint64 `url:"diskId"` - Size uint64 `url:"size"` -} - -func (drq ResizeRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - if drq.Size == 0 { - return errors.New("validation-error: field Size can not be empty or equal to 0") - } - - return nil -} - -func (d Disks) Resize(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/resize" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} - -func (d Disks) Resize2(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/resize2" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ResizeRequest struct { + DiskID uint64 `url:"diskId"` + Size uint64 `url:"size"` +} + +func (drq ResizeRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if drq.Size == 0 { + return errors.New("validation-error: field Size can not be empty or equal to 0") + } + + return nil +} + +func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/resize" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} + +func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/disks/resize2" + prefix := "/cloudapi" + + url = prefix + url + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/restore.go b/pkg/cloudapi/disks/restore.go index ad205ba..31f364f 100644 --- a/pkg/cloudapi/disks/restore.go +++ b/pkg/cloudapi/disks/restore.go @@ -1,58 +1,47 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - DiskId uint64 `url:"diskId"` - Reason string `url:"reason"` -} - -func (drq RestoreRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - if drq.Reason == "" { - return errors.New("validation-error: field Reason can not be empty") - } - - return nil -} - -func (d Disks) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/restore" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + DiskID uint64 `url:"diskId"` + Reason string `url:"reason"` +} + +func (drq RestoreRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if drq.Reason == "" { + return errors.New("validation-error: field Reason can not be empty") + } + + return nil +} + +func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/restore" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/search.go b/pkg/cloudapi/disks/search.go index 68565c0..a5dc26a 100644 --- a/pkg/cloudapi/disks/search.go +++ b/pkg/cloudapi/disks/search.go @@ -1,43 +1,32 @@ -package disks - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SearchRequest struct { - AccountId uint64 `url:"accountId,omitempty"` - Name string `url:"name,omitempty"` - ShowAll bool `url:"show_all,omitempty"` -} - -func (d Disks) Search(ctx context.Context, req SearchRequest, options ...opts.DecortOpts) (DiskList, error) { - url := "/disks/search" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - diskList := DiskList{} - - err = json.Unmarshal(res, &diskList) - if err != nil { - return nil, err - } - - return diskList, nil - -} +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type SearchRequest struct { + AccountID uint64 `url:"accountId,omitempty"` + Name string `url:"name,omitempty"` + ShowAll bool `url:"show_all,omitempty"` +} + +func (d Disks) Search(ctx context.Context, req SearchRequest) (DiskList, error) { + url := "/cloudapi/disks/search" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := DiskList{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} diff --git a/pkg/cloudapi/disks/snapshot_delete.go b/pkg/cloudapi/disks/snapshot_delete.go index 2f5a87c..03db348 100644 --- a/pkg/cloudapi/disks/snapshot_delete.go +++ b/pkg/cloudapi/disks/snapshot_delete.go @@ -1,58 +1,47 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotDeleteRequest struct { - DiskId uint64 `url:"diskId"` - Label string `url:"label"` -} - -func (drq SnapshotDeleteRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - if drq.Label == "" { - return errors.New("validation-error: field Label can not be empty") - } - - return nil -} - -func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/snapshotDelete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotDeleteRequest struct { + DiskID uint64 `url:"diskId"` + Label string `url:"label"` +} + +func (drq SnapshotDeleteRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if drq.Label == "" { + return errors.New("validation-error: field Label can not be empty") + } + + return nil +} + +func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/snapshotDelete" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/disks/snapshot_rollback.go b/pkg/cloudapi/disks/snapshot_rollback.go index 909c148..2b91a2c 100644 --- a/pkg/cloudapi/disks/snapshot_rollback.go +++ b/pkg/cloudapi/disks/snapshot_rollback.go @@ -1,59 +1,48 @@ -package disks - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SnapshotRollbackRequest struct { - DiskId uint64 `url:"diskId"` - Label string `url:"label"` - TimeStamp uint64 `url:"timestamp"` -} - -func (drq SnapshotRollbackRequest) Validate() error { - if drq.DiskId == 0 { - return errors.New("validation-error: field DiskId can not be empty or equal to 0") - } - - if drq.Label == "" && drq.TimeStamp == 0 { - return errors.New("validation-error: field Label or field TimeStamp can not be empty") - } - - return nil -} - -func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/disks/snapshotRollback" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := d.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotRollbackRequest struct { + DiskID uint64 `url:"diskId"` + Label string `url:"label"` + TimeStamp uint64 `url:"timestamp"` +} + +func (drq SnapshotRollbackRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + if drq.Label == "" && drq.TimeStamp == 0 { + return errors.New("validation-error: field Label or field TimeStamp can not be empty") + } + + return nil +} + +func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/disks/snapshotRollback" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/extnet.go b/pkg/cloudapi/extnet.go new file mode 100644 index 0000000..d03508a --- /dev/null +++ b/pkg/cloudapi/extnet.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/extnet" +) + +func (ca *CloudApi) ExtNet() *extnet.ExtNet { + return extnet.New(ca.client) +} diff --git a/pkg/cloudapi/extnet/extnet.go b/pkg/cloudapi/extnet/extnet.go index aaf36aa..88a0d14 100644 --- a/pkg/cloudapi/extnet/extnet.go +++ b/pkg/cloudapi/extnet/extnet.go @@ -1,15 +1,15 @@ -package extnet - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Extnet struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Extnet { - return &Extnet{ - client, - } -} +package extnet + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type ExtNet struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *ExtNet { + return &ExtNet{ + client, + } +} diff --git a/pkg/cloudapi/extnet/get.go b/pkg/cloudapi/extnet/get.go index 7070456..a3f67a0 100644 --- a/pkg/cloudapi/extnet/get.go +++ b/pkg/cloudapi/extnet/get.go @@ -1,53 +1,42 @@ -package extnet - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - NetId uint64 `url:"net_id"` -} - -func (erq GetRequest) Validate() error { - if erq.NetId == 0 { - return errors.New("validation-error: field NetId can not be empty or equal to 0") - } - return nil -} - -func (e Extnet) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ExtnetDetailed, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/extnet/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - extnetRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - extnet := &ExtnetDetailed{} - err = json.Unmarshal(extnetRaw, &extnet) - if err != nil { - return nil, err - } - - return extnet, nil - -} +package extnet + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + NetID uint64 `url:"net_id"` +} + +func (erq GetRequest) Validate() error { + if erq.NetID == 0 { + return errors.New("validation-error: field NetID can not be empty or equal to 0") + } + return nil +} + +func (e ExtNet) Get(ctx context.Context, req GetRequest) (*ExtNetDetailed, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/extnet/get" + + extnetRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + extnet := &ExtNetDetailed{} + err = json.Unmarshal(extnetRaw, &extnet) + if err != nil { + return nil, err + } + + return extnet, nil + +} diff --git a/pkg/cloudapi/extnet/get_default.go b/pkg/cloudapi/extnet/get_default.go index 4dcb68a..1f7e948 100644 --- a/pkg/cloudapi/extnet/get_default.go +++ b/pkg/cloudapi/extnet/get_default.go @@ -1,35 +1,24 @@ -package extnet - -import ( - "context" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -func (e Extnet) GetDefault(ctx context.Context, options ...opts.DecortOpts) (uint64, error) { - url := "/extnet/getDefault" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := e.client.DecortApiCall(ctx, typed.POST, url, nil) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil - -} +package extnet + +import ( + "context" + "net/http" + "strconv" +) + +func (e ExtNet) GetDefault(ctx context.Context) (uint64, error) { + url := "/cloudapi/extnet/getDefault" + + res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, nil) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/extnet/list.go b/pkg/cloudapi/extnet/list.go index 20a25ee..d987726 100644 --- a/pkg/cloudapi/extnet/list.go +++ b/pkg/cloudapi/extnet/list.go @@ -1,42 +1,31 @@ -package extnet - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - AccountId uint64 `url:"accountId"` - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (e Extnet) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ExtnetList, error) { - url := "/extnet/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - extnetListRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - extnetList := ExtnetList{} - err = json.Unmarshal(extnetListRaw, &extnetList) - if err != nil { - return nil, err - } - - return extnetList, nil - -} +package extnet + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + AccountID uint64 `url:"accountId"` + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (e ExtNet) List(ctx context.Context, req ListRequest) (ExtNetList, error) { + url := "/cloudapi/extnet/list" + + extnetListRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + extnetList := ExtNetList{} + err = json.Unmarshal(extnetListRaw, &extnetList) + if err != nil { + return nil, err + } + + return extnetList, nil + +} diff --git a/pkg/cloudapi/extnet/list_computes.go b/pkg/cloudapi/extnet/list_computes.go index aa7a854..855e527 100644 --- a/pkg/cloudapi/extnet/list_computes.go +++ b/pkg/cloudapi/extnet/list_computes.go @@ -1,49 +1,38 @@ -package extnet - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListComputesRequest struct { - AccountId uint64 `url:"accountId"` -} - -func (erq ListComputesRequest) Validate() error { - if erq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (e Extnet) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (ExtnetComputesList, error) { - url := "/extnet/listComputes" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - extnetComputesListRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - extnetComputesList := ExtnetComputesList{} - err = json.Unmarshal(extnetComputesListRaw, &extnetComputesList) - if err != nil { - return nil, err - } - - return extnetComputesList, nil - -} +package extnet + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListComputesRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (erq ListComputesRequest) Validate() error { + if erq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ExtNetComputesList, error) { + url := "/cloudapi/extnet/listComputes" + + extnetComputesListRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + extnetComputesList := ExtNetComputesList{} + err = json.Unmarshal(extnetComputesListRaw, &extnetComputesList) + if err != nil { + return nil, err + } + + return extnetComputesList, nil + +} diff --git a/pkg/cloudapi/extnet/models.go b/pkg/cloudapi/extnet/models.go index be6b2f0..32a703d 100644 --- a/pkg/cloudapi/extnet/models.go +++ b/pkg/cloudapi/extnet/models.go @@ -1,80 +1,80 @@ -package extnet - -type ExtnetRecord struct { - ID int `json:"id"` - IPCidr string `json:"ipcidr"` - Name string `json:"name"` -} -type ExtnetExtend struct { - ExtnetRecord - IPAddr string `json:"ipaddr"` -} - -type ExtnetList []ExtnetRecord -type ExtnetExtendList []ExtnetExtend - -type ExtnetComputes struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - Extnets ExtnetExtendList `json:"extnets"` - ID int `json:"id"` - Name string `json:"name"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` -} - -type ExtnetComputesList []ExtnetComputes - -type ExtnetQos struct { - ERate int `json:"eRate"` - GUID string `json:"guid"` - InBurst int `json:"inBurst"` - InRate int `json:"inRate"` -} - -type ExtnetReservation struct { - ClientType string `json:"clientType"` - Description string `json:"desc"` - DomainName string `json:"domainname"` - HostName string `json:"hostname"` - IP string `json:"ip"` - MAC string `json:"mac"` - Type string `json:"type"` - VMID int `json:"vmId"` -} - -type ExtnetReservations []ExtnetReservation - -type ExtnetVNFS struct { - DHCP int `json:"dhcp"` -} - -type ExtnetDetailed struct { - CKey string `json:"_ckey"` - Meta []interface{} `json:"_meta"` - CheckIPs []string `json:"checkIPs"` - CheckIps []string `json:"checkIps"` - Default bool `json:"default"` - DefaultQos ExtnetQos `json:"defaultQos"` - Description string `json:"desc"` - Dns []string `json:"dns"` - Excluded []string `json:"excluded"` - FreeIps int `json:"free_ips"` - Gateway string `json:"gateway"` - GID int `json:"gid"` - GUID int `json:"guid"` - ID int `json:"id"` - IPCidr string `json:"ipcidr"` - Milestones int `json:"milestones"` - Name string `json:"name"` - Network string `json:"network"` - NetworkId int `json:"networkId"` - PreReservationsNum int `json:"preReservationsNum"` - Prefix int `json:"prefix"` - PriVnfDevId int `json:"priVnfDevId"` - Reservations ExtnetReservations `json:"reservations"` - SharedWith []int `json:"sharedWith"` - Status string `json:"status"` - VlanID int `json:"vlanId"` - VNFS ExtnetVNFS `json:"vnfs"` -} +package extnet + +type ExtNetRecord struct { + ID uint64 `json:"id"` + IPCidr string `json:"ipcidr"` + Name string `json:"name"` +} +type ExtNetExtend struct { + ExtNetRecord + IPAddr string `json:"ipaddr"` +} + +type ExtNetList []ExtNetRecord +type ExtNetExtendList []ExtNetExtend + +type ExtNetComputes struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + ExtNets ExtNetExtendList `json:"extnets"` + ID uint64 `json:"id"` + Name string `json:"name"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` +} + +type ExtNetComputesList []ExtNetComputes + +type ExtNetQos struct { + ERate uint64 `json:"eRate"` + GUID string `json:"guid"` + InBurst uint64 `json:"inBurst"` + InRate uint64 `json:"inRate"` +} + +type ExtNetReservation struct { + ClientType string `json:"clientType"` + Description string `json:"desc"` + DomainName string `json:"domainname"` + HostName string `json:"hostname"` + IP string `json:"ip"` + MAC string `json:"mac"` + Type string `json:"type"` + VMID uint64 `json:"vmId"` +} + +type ExtNetReservations []ExtNetReservation + +type ExtNetVNFS struct { + DHCP uint64 `json:"dhcp"` +} + +type ExtNetDetailed struct { + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + CheckIPs []string `json:"checkIPs"` + CheckIps []string `json:"checkIps"` + Default bool `json:"default"` + DefaultQos ExtNetQos `json:"defaultQos"` + Description string `json:"desc"` + Dns []string `json:"dns"` + Excluded []string `json:"excluded"` + FreeIps uint64 `json:"free_ips"` + Gateway string `json:"gateway"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + IPCidr string `json:"ipcidr"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Network string `json:"network"` + NetworkID uint64 `json:"networkId"` + PreReservationsNum uint64 `json:"preReservationsNum"` + Prefix uint64 `json:"prefix"` + PriVNFDevID uint64 `json:"priVnfDevId"` + Reservations ExtNetReservations `json:"reservations"` + SharedWith []uint64 `json:"sharedWith"` + Status string `json:"status"` + VlanID uint64 `json:"vlanId"` + VNFS ExtNetVNFS `json:"vnfs"` +} diff --git a/pkg/cloudapi/flipgroup.go b/pkg/cloudapi/flipgroup.go new file mode 100644 index 0000000..b15a3fb --- /dev/null +++ b/pkg/cloudapi/flipgroup.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup" +) + +func (ca *CloudApi) FlipGroup() *flipgroup.FlipGroup { + return flipgroup.New(ca.client) +} diff --git a/pkg/cloudapi/flipgroup/compute_add.go b/pkg/cloudapi/flipgroup/compute_add.go index 2f05d60..5138ece 100644 --- a/pkg/cloudapi/flipgroup/compute_add.go +++ b/pkg/cloudapi/flipgroup/compute_add.go @@ -1,45 +1,43 @@ -package flipgroup - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ComputeAddRequest struct { - FlipGroupID uint64 `url:"flipgroupId"` - ComputeID uint64 `url:"computeId"` -} - -func (frq ComputeAddRequest) Validate() error { - if frq.FlipGroupID == 0 { - return errors.New("field FlipGroupID can not be empty or equal to 0") - } - if frq.ComputeID == 0 { - return errors.New("field ComputeID can not be empty or equal to 0") - } - - return nil -} - -func (f FlipGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest, options ...opts.DecortOpts) (bool, error) { - if err := req.Validate(); err != nil { - return false, err - } - - url := "/cloudapi/flipgroup/computeAdd" - res, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package flipgroup + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ComputeAddRequest struct { + FlipGroupID uint64 `url:"flipgroupId"` + ComputeID uint64 `url:"computeId"` +} + +func (frq ComputeAddRequest) Validate() error { + if frq.FlipGroupID == 0 { + return errors.New("field FlipGroupID can not be empty or equal to 0") + } + if frq.ComputeID == 0 { + return errors.New("field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (f FlipGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest) (bool, error) { + if err := req.Validate(); err != nil { + return false, err + } + + url := "/cloudapi/flipgroup/computeAdd" + res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/flipgroup/compute_remove.go b/pkg/cloudapi/flipgroup/compute_remove.go index a135c5c..20a6a29 100644 --- a/pkg/cloudapi/flipgroup/compute_remove.go +++ b/pkg/cloudapi/flipgroup/compute_remove.go @@ -1,45 +1,43 @@ -package flipgroup - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ComputeRemoveRequest struct { - FlipGroupID uint64 `url:"flipgroupId"` - ComputeID uint64 `url:"computeId"` -} - -func (frq ComputeRemoveRequest) Validate() error { - if frq.FlipGroupID == 0 { - return errors.New("field FlipGroupID can not be empty or equal to 0") - } - if frq.ComputeID == 0 { - return errors.New("field ComputeID can not be empty or equal to 0") - } - - return nil -} - -func (f FlipGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest, options ...opts.DecortOpts) (bool, error) { - if err := req.Validate(); err != nil { - return false, err - } - - url := "/cloudapi/flipgroup/computeRemove" - res, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package flipgroup + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ComputeRemoveRequest struct { + FlipGroupID uint64 `url:"flipgroupId"` + ComputeID uint64 `url:"computeId"` +} + +func (frq ComputeRemoveRequest) Validate() error { + if frq.FlipGroupID == 0 { + return errors.New("field FlipGroupID can not be empty or equal to 0") + } + if frq.ComputeID == 0 { + return errors.New("field ComputeID can not be empty or equal to 0") + } + + return nil +} + +func (f FlipGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest) (bool, error) { + if err := req.Validate(); err != nil { + return false, err + } + + url := "/cloudapi/flipgroup/computeRemove" + res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/flipgroup/create.go b/pkg/cloudapi/flipgroup/create.go index 055fb77..70d48de 100644 --- a/pkg/cloudapi/flipgroup/create.go +++ b/pkg/cloudapi/flipgroup/create.go @@ -1,63 +1,62 @@ -package flipgroup - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - AccountID uint64 `url:"accountId"` - Name string `url:"name"` - NetType string `url:"netType"` - NetID uint64 `url:"netId"` - ClientType string `url:"clientType"` - IP string `url:"ip,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (frq CreateRequest) Validate() error { - if frq.AccountID == 0 { - return errors.New("field AccountID can not be empty or equal to 0") - } - if frq.NetID == 0 { - return errors.New("field NetID can not be empty or equal to 0") - } - if frq.Name == "" { - return errors.New("field Name can not be empty") - } - - validator := validators.StringInSlice(frq.NetType, []string{"EXTNET", "VINS"}) - if !validator { - return errors.New("field Name can be only EXTNET or VINS") - } - validator = validators.StringInSlice(frq.ClientType, []string{"compute", "node"}) - if !validator { - return errors.New("field Name can be only compute or node") - } - - return nil -} - -func (f FlipGroup) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (*FlipGroupRecord, error) { - if err := req.Validate(); err != nil { - return nil, err - } - - url := "/cloudapi/flipgroup/create" - fgRaw, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - fg := &FlipGroupRecord{} - if err := json.Unmarshal(fgRaw, fg); err != nil { - return nil, err - } - - return fg, nil -} +package flipgroup + +import ( + "context" + "encoding/json" + "errors" + "net/http" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type CreateRequest struct { + AccountID uint64 `url:"accountId"` + Name string `url:"name"` + NetType string `url:"netType"` + NetID uint64 `url:"netId"` + ClientType string `url:"clientType"` + IP string `url:"ip,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (frq CreateRequest) Validate() error { + if frq.AccountID == 0 { + return errors.New("field AccountID can not be empty or equal to 0") + } + if frq.NetID == 0 { + return errors.New("field NetID can not be empty or equal to 0") + } + if frq.Name == "" { + return errors.New("field Name can not be empty") + } + + validator := validators.StringInSlice(frq.NetType, []string{"EXTNET", "VINS"}) + if !validator { + return errors.New("field Name can be only EXTNET or VINS") + } + validator = validators.StringInSlice(frq.ClientType, []string{"compute", "node"}) + if !validator { + return errors.New("field Name can be only compute or node") + } + + return nil +} + +func (f FlipGroup) Create(ctx context.Context, req CreateRequest) (*FlipGroupRecord, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudapi/flipgroup/create" + fgRaw, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + fg := &FlipGroupRecord{} + if err := json.Unmarshal(fgRaw, fg); err != nil { + return nil, err + } + + return fg, nil +} diff --git a/pkg/cloudapi/flipgroup/delete.go b/pkg/cloudapi/flipgroup/delete.go index b9231b1..9cc30c5 100644 --- a/pkg/cloudapi/flipgroup/delete.go +++ b/pkg/cloudapi/flipgroup/delete.go @@ -1,41 +1,39 @@ -package flipgroup - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - FlipGroupID uint64 `url:"flipgroupId"` -} - -func (frq DeleteRequest) Validate() error { - if frq.FlipGroupID == 0 { - return errors.New("field FlipGroupID can not be empty or equal to 0") - } - - return nil -} - -func (f FlipGroup) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - if err := req.Validate(); err != nil { - return false, err - } - - url := "/cloudapi/flipgroup/delete" - res, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package flipgroup + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + FlipGroupID uint64 `url:"flipgroupId"` +} + +func (frq DeleteRequest) Validate() error { + if frq.FlipGroupID == 0 { + return errors.New("field FlipGroupID can not be empty or equal to 0") + } + + return nil +} + +func (f FlipGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + if err := req.Validate(); err != nil { + return false, err + } + + url := "/cloudapi/flipgroup/delete" + res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/flipgroup/edit.go b/pkg/cloudapi/flipgroup/edit.go index 434d174..c703d04 100644 --- a/pkg/cloudapi/flipgroup/edit.go +++ b/pkg/cloudapi/flipgroup/edit.go @@ -1,43 +1,41 @@ -package flipgroup - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type EditRequest struct { - FlipGroupID uint64 `url:"flipgroupId"` - Name string `url:"name,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (frq EditRequest) Validate() error { - if frq.FlipGroupID == 0 { - return errors.New("field FlipGroupID can not be empty or equal to 0") - } - - return nil -} - -func (f FlipGroup) Edit(ctx context.Context, req EditRequest, options ...opts.DecortOpts) (bool, error) { - if err := req.Validate(); err != nil { - return false, err - } - - url := "/cloudapi/flipgroup/edit" - res, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package flipgroup + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EditRequest struct { + FlipGroupID uint64 `url:"flipgroupId"` + Name string `url:"name,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (frq EditRequest) Validate() error { + if frq.FlipGroupID == 0 { + return errors.New("field FlipGroupID can not be empty or equal to 0") + } + + return nil +} + +func (f FlipGroup) Edit(ctx context.Context, req EditRequest) (bool, error) { + if err := req.Validate(); err != nil { + return false, err + } + + url := "/cloudapi/flipgroup/edit" + res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/flipgroup/flipgroup.go b/pkg/cloudapi/flipgroup/flipgroup.go index 810d2af..b51829e 100644 --- a/pkg/cloudapi/flipgroup/flipgroup.go +++ b/pkg/cloudapi/flipgroup/flipgroup.go @@ -1,15 +1,15 @@ -package flipgroup - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type FlipGroup struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *FlipGroup { - return &FlipGroup{ - client, - } -} +package flipgroup + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type FlipGroup struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *FlipGroup { + return &FlipGroup{ + client, + } +} diff --git a/pkg/cloudapi/flipgroup/get.go b/pkg/cloudapi/flipgroup/get.go index b9b0775..96a7501 100644 --- a/pkg/cloudapi/flipgroup/get.go +++ b/pkg/cloudapi/flipgroup/get.go @@ -1,42 +1,40 @@ -package flipgroup - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - FlipGroupID uint64 `url:"flipgroupId"` -} - -func (frq GetRequest) Validate() error { - if frq.FlipGroupID == 0 { - return errors.New("field FlipGroupID can not be empty or equal to 0") - } - - return nil -} - -func (f FlipGroup) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*FlipGroupItem, error) { - if err := req.Validate(); err != nil { - return nil, err - } - - url := "/cloudapi/flipgroup/get" - res, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - fg := &FlipGroupItem{} - err = json.Unmarshal(res, fg) - if err != nil { - return nil, err - } - - return fg, nil -} +package flipgroup + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + FlipGroupID uint64 `url:"flipgroupId"` +} + +func (frq GetRequest) Validate() error { + if frq.FlipGroupID == 0 { + return errors.New("field FlipGroupID can not be empty or equal to 0") + } + + return nil +} + +func (f FlipGroup) Get(ctx context.Context, req GetRequest) (*FlipGroupItem, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudapi/flipgroup/get" + res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + fg := &FlipGroupItem{} + err = json.Unmarshal(res, fg) + if err != nil { + return nil, err + } + + return fg, nil +} diff --git a/pkg/cloudapi/flipgroup/list.go b/pkg/cloudapi/flipgroup/list.go index e84642a..1add550 100644 --- a/pkg/cloudapi/flipgroup/list.go +++ b/pkg/cloudapi/flipgroup/list.go @@ -1,29 +1,27 @@ -package flipgroup - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (f FlipGroup) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (FlipGroupList, error) { - url := "/cloudapi/flipgroup/list" - fgListRaw, err := f.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - fgList := FlipGroupList{} - if err := json.Unmarshal(fgListRaw, &fgList); err != nil { - return nil, err - } - - return fgList, nil -} +package flipgroup + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (f FlipGroup) List(ctx context.Context, req ListRequest) (FlipGroupList, error) { + url := "/cloudapi/flipgroup/list" + fgListRaw, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + fgList := FlipGroupList{} + if err := json.Unmarshal(fgListRaw, &fgList); err != nil { + return nil, err + } + + return fgList, nil +} diff --git a/pkg/cloudapi/flipgroup/models.go b/pkg/cloudapi/flipgroup/models.go index 0d66d7e..097d4eb 100644 --- a/pkg/cloudapi/flipgroup/models.go +++ b/pkg/cloudapi/flipgroup/models.go @@ -1,40 +1,40 @@ -package flipgroup - -type FlipGroupRecord struct { - DefaultGW string `json:"defaultGW"` - ID uint64 `json:"id"` - IP string `json:"ip"` - Name string `json:"name"` - Netmask uint64 `json:"netmask"` -} - -type FlipGroupItem struct { - AccountID uint64 `json:"accountId"` - AccountName string `json:"accountName"` - ClientIds []uint64 `json:"clientIds"` - ClientType string `json:"clientType"` - ConnID uint64 `json:"connId"` - ConnType string `json:"connType"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DefaultGW string `json:"defaultGW"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - IP string `json:"ip"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - NetID uint64 `json:"netId"` - NetType string `json:"netType"` - Network string `json:"network"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` -} - -type FlipGroupList []FlipGroupItem +package flipgroup + +type FlipGroupRecord struct { + DefaultGW string `json:"defaultGW"` + ID uint64 `json:"id"` + IP string `json:"ip"` + Name string `json:"name"` + Netmask uint64 `json:"netmask"` +} + +type FlipGroupItem struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + ClientIDs []uint64 `json:"clientIds"` + ClientType string `json:"clientType"` + ConnID uint64 `json:"connId"` + ConnType string `json:"connType"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefaultGW string `json:"defaultGW"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + IP string `json:"ip"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetType string `json:"netType"` + Network string `json:"network"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type FlipGroupList []FlipGroupItem diff --git a/pkg/cloudapi/image.go b/pkg/cloudapi/image.go new file mode 100644 index 0000000..3ee7c12 --- /dev/null +++ b/pkg/cloudapi/image.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/image" +) + +func (ca *CloudApi) Image() *image.Image { + return image.New(ca.client) +} diff --git a/pkg/cloudapi/image/create.go b/pkg/cloudapi/image/create.go index 0d84208..628d7af 100644 --- a/pkg/cloudapi/image/create.go +++ b/pkg/cloudapi/image/create.go @@ -1,102 +1,92 @@ -package image - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - Name string `url:"name"` - URL string `url:"url"` - GID uint64 `url:"gid"` - BootType string `url:"boottype"` - ImageType string `url:"imagetype"` - Hotresize bool `url:"hotresize,omitempty"` - Username string `url:"username,omitempty"` - Password string `url:"password,omitempty"` - AccountId uint64 `url:"accountId,omitempty"` - UsernameDL string `url:"usernameDL,omitempty"` - PasswordDL string `url:"passwordDL,omitempty"` - SepId uint64 `url:"sepId,omitempty"` - Pool string `url:"poolName,omitempty"` - Architecture string `url:"architecture,omitempty"` - Drivers []string `url:"drivers"` -} - -func (irq CreateRequest) Validate() error { - if irq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if irq.URL == "" { - return errors.New("validation-error: field URL can not be empty") - } - - if irq.GID == 0 { - return errors.New("validation-error: field GID can not be empty or equal to 0") - } - if irq.BootType == "" { - return errors.New("validation-error: field BootType can not be empty") - } - - validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"}) - if !validate { - return errors.New("validation-error: field BootType can be bios or uefi") - } - if irq.ImageType == "" { - return errors.New("validation-error: field ImageType can not be empty") - } - - validate = validators.StringInSlice(irq.ImageType, []string{"bios", "uefi"}) - if !validate { - return errors.New("validation-error: field ImageType can be windows, linux or other") - } - - if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 { - return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements") - } - - for _, v := range irq.Drivers { - validate := validators.StringInSlice(v, []string{"KVM_X86"}) - if !validate { - return errors.New("validation-error: field Drivers can be KVM_X86 only") - } - } - - return nil -} - -func (i Image) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/image/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil - -} +package image + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type CreateRequest struct { + Name string `url:"name"` + URL string `url:"url"` + GID uint64 `url:"gid"` + BootType string `url:"boottype"` + ImageType string `url:"imagetype"` + Hotresize bool `url:"hotresize,omitempty"` + Username string `url:"username,omitempty"` + Password string `url:"password,omitempty"` + AccountID uint64 `url:"accountId,omitempty"` + UsernameDL string `url:"usernameDL,omitempty"` + PasswordDL string `url:"passwordDL,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"poolName,omitempty"` + Architecture string `url:"architecture,omitempty"` + Drivers []string `url:"drivers"` +} + +func (irq CreateRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if irq.URL == "" { + return errors.New("validation-error: field URL can not be empty") + } + + if irq.GID == 0 { + return errors.New("validation-error: field GID can not be empty or equal to 0") + } + if irq.BootType == "" { + return errors.New("validation-error: field BootType can not be empty") + } + + validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"}) + if !validate { + return errors.New("validation-error: field BootType can be bios or uefi") + } + if irq.ImageType == "" { + return errors.New("validation-error: field ImageType can not be empty") + } + + validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"}) + if !validate { + return errors.New("validation-error: field ImageType can be windows, linux or other") + } + + if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 { + return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements") + } + + for _, v := range irq.Drivers { + validate := validators.StringInSlice(v, []string{"KVM_X86"}) + if !validate { + return errors.New("validation-error: field Drivers can be KVM_X86 only") + } + } + + return nil +} + +func (i Image) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/image/create" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/image/create_virtual.go b/pkg/cloudapi/image/create_virtual.go index 541385b..d11c1bc 100644 --- a/pkg/cloudapi/image/create_virtual.go +++ b/pkg/cloudapi/image/create_virtual.go @@ -1,58 +1,47 @@ -package image - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateVirtualRequest struct { - Name string `url:"name"` - TargetId uint64 `url:"targetId"` -} - -func (irq CreateVirtualRequest) Validate() error { - if irq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if irq.TargetId == 0 { - return errors.New("validation-error: field TargetId can not be empty or equal to 0") - } - - return nil -} - -func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/image/createVirtual" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil - -} +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateVirtualRequest struct { + Name string `url:"name"` + TargetID uint64 `url:"targetId"` +} + +func (irq CreateVirtualRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if irq.TargetID == 0 { + return errors.New("validation-error: field TargetID can not be empty or equal to 0") + } + + return nil +} + +func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/image/createVirtual" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/image/delete.go b/pkg/cloudapi/image/delete.go index 215176e..e09a426 100644 --- a/pkg/cloudapi/image/delete.go +++ b/pkg/cloudapi/image/delete.go @@ -1,54 +1,43 @@ -package image - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - ImageId uint64 `url:"imageId"` - Permanently bool `url:"permanently"` -} - -func (irq DeleteRequest) Validate() error { - if irq.ImageId == 0 { - return errors.New("validation-error: field ImageId can not be empty or equal to 0") - } - - return nil -} - -func (i Image) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/image/delete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + ImageID uint64 `url:"imageId"` + Permanently bool `url:"permanently"` +} + +func (irq DeleteRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + + return nil +} + +func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/image/delete" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/image/get.go b/pkg/cloudapi/image/get.go index 133392d..b1a6681 100644 --- a/pkg/cloudapi/image/get.go +++ b/pkg/cloudapi/image/get.go @@ -1,54 +1,44 @@ -package image - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - ImageId uint64 `url:"imageId"` - ShowAll bool `url:"show_all,omitempty"` -} - -func (irq GetRequest) Validate() error { - if irq.ImageId == 0 { - return errors.New("validation-error: field ImageId can not be empty or equal to 0") - } - - return nil -} - -func (i Image) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ImageExtend, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/image/get" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - imageInfo := &ImageExtend{} - - err = json.Unmarshal(res, imageInfo) - if err != nil { - return nil, err - } - - return imageInfo, nil -} +package image + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + ImageID uint64 `url:"imageId"` + ShowAll bool `url:"show_all,omitempty"` +} + +func (irq GetRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + + return nil +} + +func (i Image) Get(ctx context.Context, req GetRequest) (*ImageExtend, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/image/get" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + imageInfo := &ImageExtend{} + + err = json.Unmarshal(res, imageInfo) + if err != nil { + return nil, err + } + + return imageInfo, nil +} diff --git a/pkg/cloudapi/image/image.go b/pkg/cloudapi/image/image.go index 455b3f9..d4221d2 100644 --- a/pkg/cloudapi/image/image.go +++ b/pkg/cloudapi/image/image.go @@ -1,15 +1,15 @@ -package image - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Image struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Image { - return &Image{ - client, - } -} +package image + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Image struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Image { + return &Image{ + client, + } +} diff --git a/pkg/cloudapi/image/link.go b/pkg/cloudapi/image/link.go index 0c923c6..fb256cf 100644 --- a/pkg/cloudapi/image/link.go +++ b/pkg/cloudapi/image/link.go @@ -1,57 +1,46 @@ -package image - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type LinkRequest struct { - ImageId uint64 `url:"imageId"` - TargetId uint64 `url:"targetId"` -} - -func (irq LinkRequest) Validate() error { - if irq.ImageId == 0 { - return errors.New("validation-error: field ImageId can not be empty or equal to 0") - } - if irq.TargetId == 0 { - return errors.New("validation-error: field TargetId can not be empty or equal to 0") - } - - return nil -} - -func (i Image) Link(ctx context.Context, req LinkRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/image/link" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type LinkRequest struct { + ImageID uint64 `url:"imageId"` + TargetID uint64 `url:"targetId"` +} + +func (irq LinkRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + if irq.TargetID == 0 { + return errors.New("validation-error: field TargetID can not be empty or equal to 0") + } + + return nil +} + +func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/image/link" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/image/list.go b/pkg/cloudapi/image/list.go index 17e7807..9cdfe79 100644 --- a/pkg/cloudapi/image/list.go +++ b/pkg/cloudapi/image/list.go @@ -1,42 +1,32 @@ -package image - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - AccountId uint64 `json:"accountId"` - Page uint64 `json:"page"` - Size uint64 `json:"size"` -} - -func (i Image) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ImageList, error) { - - url := "/image/list" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - imageList := ImageList{} - - err = json.Unmarshal(res, &imageList) - if err != nil { - return nil, err - } - - return imageList, nil -} +package image + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + AccountID uint64 `json:"accountId"` + Page uint64 `json:"page"` + Size uint64 `json:"size"` +} + +func (i Image) List(ctx context.Context, req ListRequest) (ImageList, error) { + + url := "/cloudapi/image/list" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + imageList := ImageList{} + + err = json.Unmarshal(res, &imageList) + if err != nil { + return nil, err + } + + return imageList, nil +} diff --git a/pkg/cloudapi/image/models.go b/pkg/cloudapi/image/models.go index 8b95f3b..2b03a25 100644 --- a/pkg/cloudapi/image/models.go +++ b/pkg/cloudapi/image/models.go @@ -1,68 +1,68 @@ -package image - -type ImageRecord struct { - AccountId uint64 `json:"accountId"` - Architecture string `json:"architecture"` - BootType string `json:"bootType"` - Bootable bool `json:"bootable"` - CDROM bool `json:"cdrom"` - Description string `json:"desc"` - Drivers []string `json:"drivers"` - HotResize bool `json:"hotResize"` - ID uint64 `json:"id"` - LinkTo uint64 `json:"linkTo"` - Name string `json:"name"` - Pool string `json:"pool"` - SepId uint64 `json:"sepId"` - Size uint64 `json:"size"` - Status string `json:"status"` - Type string `json:"type"` - Username string `json:"username"` - Virtual bool `json:"virtual"` -} - -type ImageList []ImageRecord - -type History struct { - GUID string `json:"guid"` - ID uint64 `json:"id"` - Timestamp uint64 `json:"timestamp"` -} - -type ImageExtend struct { - UNCPath string `json:"UNCPath"` - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - Acl interface{} `json:"acl"` - Architecture string `json:"architecture"` - BootType string `json:"bootType"` - Bootable bool `json:"bootable"` - ComputeCiId uint64 `json:"computeciId"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - Drivers []string `json:"drivers"` - Enabled bool `json:"enabled"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - History []History `json:"history"` - HotResize bool `json:"hotResize"` - ID uint64 `json:"id"` - LastModified uint64 `json:"lastModified"` - LinkTo uint64 `json:"linkTo"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - Password string `json:"password"` - Pool string `json:"pool"` - ProviderName string `json:"provider_name"` - PurgeAttempts int `json:"purgeAttempts"` - ResId string `json:"resId"` - RescueCD bool `json:"rescuecd"` - SepId uint64 `json:"sepId"` - SharedWith []int `json:"sharedWith"` - Size uint64 `json:"size"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - Username string `json:"username"` - Version string `json:"version"` -} +package image + +type ImageRecord struct { + AccountID uint64 `json:"accountId"` + Architecture string `json:"architecture"` + BootType string `json:"bootType"` + Bootable bool `json:"bootable"` + CDROM bool `json:"cdrom"` + Description string `json:"desc"` + Drivers []string `json:"drivers"` + HotResize bool `json:"hotResize"` + ID uint64 `json:"id"` + LinkTo uint64 `json:"linkTo"` + Name string `json:"name"` + Pool string `json:"pool"` + SepID uint64 `json:"sepId"` + Size uint64 `json:"size"` + Status string `json:"status"` + Type string `json:"type"` + Username string `json:"username"` + Virtual bool `json:"virtual"` +} + +type ImageList []ImageRecord + +type History struct { + GUID string `json:"guid"` + ID uint64 `json:"id"` + Timestamp uint64 `json:"timestamp"` +} + +type ImageExtend struct { + UNCPath string `json:"UNCPath"` + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + ACL interface{} `json:"acl"` + Architecture string `json:"architecture"` + BootType string `json:"bootType"` + Bootable bool `json:"bootable"` + ComputeCiID uint64 `json:"computeciId"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + Drivers []string `json:"drivers"` + Enabled bool `json:"enabled"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + History []History `json:"history"` + HotResize bool `json:"hotResize"` + ID uint64 `json:"id"` + LastModified uint64 `json:"lastModified"` + LinkTo uint64 `json:"linkTo"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Password string `json:"password"` + Pool string `json:"pool"` + ProviderName string `json:"provider_name"` + PurgeAttempts uint64 `json:"purgeAttempts"` + ResID string `json:"resId"` + RescueCD bool `json:"rescuecd"` + SepID uint64 `json:"sepId"` + SharedWith []uint64 `json:"sharedWith"` + Size uint64 `json:"size"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` +} diff --git a/pkg/cloudapi/image/rename.go b/pkg/cloudapi/image/rename.go index 152654a..918e75b 100644 --- a/pkg/cloudapi/image/rename.go +++ b/pkg/cloudapi/image/rename.go @@ -1,58 +1,47 @@ -package image - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RenameRequest struct { - ImageId uint64 `url:"imageId"` - Name string `url:"name"` -} - -func (irq RenameRequest) Validate() error { - if irq.ImageId == 0 { - return errors.New("validation-error: field ImageId can not be empty or equal to 0") - } - - if irq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - return nil -} - -func (i Image) Rename(ctx context.Context, req RenameRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/image/rename" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := i.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil - -} +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RenameRequest struct { + ImageID uint64 `url:"imageId"` + Name string `url:"name"` +} + +func (irq RenameRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + + if irq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + return nil +} + +func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/image/rename" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/k8ci.go b/pkg/cloudapi/k8ci.go new file mode 100644 index 0000000..b452b28 --- /dev/null +++ b/pkg/cloudapi/k8ci.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci" +) + +func (ca *CloudApi) K8CI() *k8ci.K8CI { + return k8ci.New(ca.client) +} diff --git a/pkg/cloudapi/k8ci/get.go b/pkg/cloudapi/k8ci/get.go index 4f5c06f..3fc1eb1 100644 --- a/pkg/cloudapi/k8ci/get.go +++ b/pkg/cloudapi/k8ci/get.go @@ -1,41 +1,39 @@ -package k8ci - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - K8CIID uint64 `url:"k8ciId"` -} - -func (krq GetRequest) Validate() error { - if krq.K8CIID == 0 { - return errors.New("field K8CIID can not be empty or equal to 0") - } - - return nil -} - -func (k K8CI) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*K8CIRecord, error) { - if err := req.Validate(); err != nil { - return nil, err - } - - url := "/cloudapi/k8ci/get" - k8ciRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8ci := &K8CIRecord{} - if err := json.Unmarshal(k8ciRaw, k8ci); err != nil { - return nil, err - } - - return k8ci, nil -} +package k8ci + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + K8CIID uint64 `url:"k8ciId"` +} + +func (krq GetRequest) Validate() error { + if krq.K8CIID == 0 { + return errors.New("field K8CIID can not be empty or equal to 0") + } + + return nil +} + +func (k K8CI) Get(ctx context.Context, req GetRequest) (*K8CIRecord, error) { + if err := req.Validate(); err != nil { + return nil, err + } + + url := "/cloudapi/k8ci/get" + k8ciRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8ci := &K8CIRecord{} + if err := json.Unmarshal(k8ciRaw, k8ci); err != nil { + return nil, err + } + + return k8ci, nil +} diff --git a/pkg/cloudapi/k8ci/k8ci.go b/pkg/cloudapi/k8ci/k8ci.go index 0e5a774..25cfd8f 100644 --- a/pkg/cloudapi/k8ci/k8ci.go +++ b/pkg/cloudapi/k8ci/k8ci.go @@ -1,15 +1,15 @@ -package k8ci - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type K8CI struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *K8CI { - return &K8CI{ - client, - } -} +package k8ci + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type K8CI struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *K8CI { + return &K8CI{ + client, + } +} diff --git a/pkg/cloudapi/k8ci/list.go b/pkg/cloudapi/k8ci/list.go index de4dc52..c80a0c1 100644 --- a/pkg/cloudapi/k8ci/list.go +++ b/pkg/cloudapi/k8ci/list.go @@ -1,30 +1,28 @@ -package k8ci - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDisabled bool `url:"includeDisabled,omitempty"` - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (k K8CI) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (K8CIList, error) { - url := "/cloudapi/k8ci/list" - k8ciListRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8ciList := K8CIList{} - if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil { - return nil, err - } - - return k8ciList, nil -} +package k8ci + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDisabled bool `url:"includeDisabled,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (k K8CI) List(ctx context.Context, req ListRequest) (K8CIList, error) { + url := "/cloudapi/k8ci/list" + k8ciListRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8ciList := K8CIList{} + if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil { + return nil, err + } + + return k8ciList, nil +} diff --git a/pkg/cloudapi/k8ci/list_deleted.go b/pkg/cloudapi/k8ci/list_deleted.go index 2051a2a..4b00f62 100644 --- a/pkg/cloudapi/k8ci/list_deleted.go +++ b/pkg/cloudapi/k8ci/list_deleted.go @@ -1,29 +1,27 @@ -package k8ci - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (K8CIList, error) { - url := "/cloudapi/k8ci/listDeleted" - k8ciListRaw, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8ciList := K8CIList{} - if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil { - return nil, err - } - - return k8ciList, nil -} +package k8ci + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (K8CIList, error) { + url := "/cloudapi/k8ci/listDeleted" + k8ciListRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8ciList := K8CIList{} + if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil { + return nil, err + } + + return k8ciList, nil +} diff --git a/pkg/cloudapi/k8ci/models.go b/pkg/cloudapi/k8ci/models.go index fcb1af0..34a7567 100644 --- a/pkg/cloudapi/k8ci/models.go +++ b/pkg/cloudapi/k8ci/models.go @@ -1,15 +1,15 @@ -package k8ci - -type K8CIItem struct { - CreatedTime uint64 `json:"createdTime"` - K8CIRecord -} - -type K8CIList []K8CIItem - -type K8CIRecord struct { - Description string `json:"desc"` - ID uint64 `json:"id"` - Name string `json:"name"` - Version string `json:"version"` -} +package k8ci + +type K8CIItem struct { + CreatedTime uint64 `json:"createdTime"` + K8CIRecord +} + +type K8CIList []K8CIItem + +type K8CIRecord struct { + Description string `json:"desc"` + ID uint64 `json:"id"` + Name string `json:"name"` + Version string `json:"version"` +} diff --git a/pkg/cloudapi/k8s.go b/pkg/cloudapi/k8s.go new file mode 100644 index 0000000..9f322d7 --- /dev/null +++ b/pkg/cloudapi/k8s.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/k8s" +) + +func (ca *CloudApi) K8S() *k8s.K8S { + return k8s.New(ca.client) +} diff --git a/pkg/cloudapi/k8s/create.go b/pkg/cloudapi/k8s/create.go index 64f90b1..846a663 100644 --- a/pkg/cloudapi/k8s/create.go +++ b/pkg/cloudapi/k8s/create.go @@ -1,75 +1,64 @@ -package k8s - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - Name string `url:"name"` - RGID uint64 `url:"rgId"` - K8SCIId uint64 `url:"k8ciId"` - WorkerGroupName string `url:"workerGroupName"` - Labels []string `url:"labels,omitempty"` - Taints []string `url:"taints,omitempty"` - Annotations []string `url:"annotations,omitempty"` - MasterNum uint `url:"masterNum,omitempty"` - MasterCPU uint `url:"masterCPU,omitempty"` - MasterRAM uint `url:"masterRam,omitempty"` - MasterDisk uint `url:"masterDisk,omitempty"` - WorkerNum uint `url:"workerNum,omitempty"` - WorkerCPU uint `url:"workerCPU,omitempty"` - WorkerRAM uint `url:"workerRam,omitempty"` - WorkerDisk uint `url:"workerDisk,omitempty"` - ExtnetId uint64 `url:"extnetId,omitempty"` - WithLB bool `url:"withLB,omitempty"` - Description string `url:"desc, omitempty"` -} - -func (krq CreateRequest) Validate() error { - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if krq.RGID == 0 { - return errors.New("validation-error: field RgId can not be empty or equal to 0") - } - if krq.K8SCIId == 0 { - return errors.New("validation-error: field K8SCIId can not be empty or equal to 0") - } - - if krq.WorkerGroupName == "" { - return errors.New("validation-error: field WorkerGroupName can not be empty") - } - - return nil -} - -func (k8s K8S) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/k8s/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return strings.ReplaceAll(string(res), "\"", ""), nil - -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type CreateRequest struct { + Name string `url:"name"` + RGID uint64 `url:"rgId"` + K8SCIID uint64 `url:"k8ciId"` + WorkerGroupName string `url:"workerGroupName"` + Labels []string `url:"labels,omitempty"` + Taints []string `url:"taints,omitempty"` + Annotations []string `url:"annotations,omitempty"` + MasterNum uint `url:"masterNum,omitempty"` + MasterCPU uint `url:"masterCPU,omitempty"` + MasterRAM uint `url:"masterRam,omitempty"` + MasterDisk uint `url:"masterDisk,omitempty"` + WorkerNum uint `url:"workerNum,omitempty"` + WorkerCPU uint `url:"workerCPU,omitempty"` + WorkerRAM uint `url:"workerRam,omitempty"` + WorkerDisk uint `url:"workerDisk,omitempty"` + ExtNetID uint64 `url:"extnetId,omitempty"` + WithLB bool `url:"withLB,omitempty"` + Description string `url:"desc, omitempty"` +} + +func (krq CreateRequest) Validate() error { + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if krq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if krq.K8SCIID == 0 { + return errors.New("validation-error: field K8SCIID can not be empty or equal to 0") + } + + if krq.WorkerGroupName == "" { + return errors.New("validation-error: field WorkerGroupName can not be empty") + } + + return nil +} + +func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/k8s/create" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return strings.ReplaceAll(string(res), "\"", ""), nil + +} diff --git a/pkg/cloudapi/k8s/delete.go b/pkg/cloudapi/k8s/delete.go index a2c4c73..fc2d42f 100644 --- a/pkg/cloudapi/k8s/delete.go +++ b/pkg/cloudapi/k8s/delete.go @@ -1,51 +1,41 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - K8SId uint64 `url:"k8sId"` - Permanently bool `url:"permanently"` -} - -func (krq DeleteRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/delete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + K8SID uint64 `url:"k8sId"` + Permanently bool `url:"permanently"` +} + +func (krq DeleteRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/delete" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/delete_master_from_group.go b/pkg/cloudapi/k8s/delete_master_from_group.go index 43b7c2b..3401fc9 100644 --- a/pkg/cloudapi/k8s/delete_master_from_group.go +++ b/pkg/cloudapi/k8s/delete_master_from_group.go @@ -1,59 +1,49 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteMasterFromGroupRequest struct { - K8SId uint64 `url:"k8sId"` - MasterGroupId uint64 `url:"masterGroupId"` - MasterIds []string `url:"masterIds"` -} - -func (krq DeleteMasterFromGroupRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - if krq.MasterGroupId == 0 { - return errors.New("validation-error: field MasterGroupId can not be empty or equal to 0") - } - - if len(krq.MasterIds) == 0 { - return errors.New("validation-error: field MasterIds can not be empty") - } - - return nil -} - -func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/deleteMasterFromGroup" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteMasterFromGroupRequest struct { + K8SID uint64 `url:"k8sId"` + MasterGroupID uint64 `url:"masterGroupId"` + MasterIDs []string `url:"masterIds"` +} + +func (krq DeleteMasterFromGroupRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + if krq.MasterGroupID == 0 { + return errors.New("validation-error: field MasterGroupID can not be empty or equal to 0") + } + + if len(krq.MasterIDs) == 0 { + return errors.New("validation-error: field MasterIDs can not be empty") + } + + return nil +} + +func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/deleteMasterFromGroup" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/delete_worker_from_group.go b/pkg/cloudapi/k8s/delete_worker_from_group.go index 447e1bf..020ea3d 100644 --- a/pkg/cloudapi/k8s/delete_worker_from_group.go +++ b/pkg/cloudapi/k8s/delete_worker_from_group.go @@ -1,59 +1,49 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteWorkerFromGroupRequest struct { - K8SId uint64 `url:"k8sId"` - WorkersGroupId uint64 `url:"workersGroupId"` - WorkerId uint64 `url:"workerId"` -} - -func (krq DeleteWorkerFromGroupRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - if krq.WorkersGroupId == 0 { - return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0") - } - - if krq.WorkerId == 0 { - return errors.New("validation-error: field WorkerId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/deleteWorkerFromGroup" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteWorkerFromGroupRequest struct { + K8SID uint64 `url:"k8sId"` + WorkersGroupID uint64 `url:"workersGroupId"` + WorkerID uint64 `url:"workerId"` +} + +func (krq DeleteWorkerFromGroupRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + if krq.WorkersGroupID == 0 { + return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0") + } + + if krq.WorkerID == 0 { + return errors.New("validation-error: field WorkerID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/deleteWorkerFromGroup" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/disable_enable.go b/pkg/cloudapi/k8s/disable_enable.go index f9f8321..c13207c 100644 --- a/pkg/cloudapi/k8s/disable_enable.go +++ b/pkg/cloudapi/k8s/disable_enable.go @@ -1,78 +1,60 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisabelEnableRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq DisabelEnableRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/disable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} - -func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/enable" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisabelEnableRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq DisabelEnableRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/disable" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} + +func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/enable" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/find_group_by_label.go b/pkg/cloudapi/k8s/find_group_by_label.go index c9760bf..5ac5377 100644 --- a/pkg/cloudapi/k8s/find_group_by_label.go +++ b/pkg/cloudapi/k8s/find_group_by_label.go @@ -1,59 +1,49 @@ -package k8s - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FindGroupByLabelRequest struct { - K8SId uint64 `url:"k8sId"` - Labels []string `url:"labels"` - Strict bool `url:"strict"` -} - -func (krq FindGroupByLabelRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if len(krq.Labels) == 0 { - return errors.New("validation-error: field Labels can not be empty") - } - - return nil -} - -func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest, options ...opts.DecortOpts) (K8SGroupList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/k8s/findGroupByLabel" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8sGroupList := K8SGroupList{} - - err = json.Unmarshal(res, &k8sGroupList) - if err != nil { - return nil, err - } - - return k8sGroupList, nil -} +package k8s + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type FindGroupByLabelRequest struct { + K8SID uint64 `url:"k8sId"` + Labels []string `url:"labels"` + Strict bool `url:"strict"` +} + +func (krq FindGroupByLabelRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if len(krq.Labels) == 0 { + return errors.New("validation-error: field Labels can not be empty") + } + + return nil +} + +func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (K8SGroupList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/k8s/findGroupByLabel" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8sGroupList := K8SGroupList{} + + err = json.Unmarshal(res, &k8sGroupList) + if err != nil { + return nil, err + } + + return k8sGroupList, nil +} diff --git a/pkg/cloudapi/k8s/get.go b/pkg/cloudapi/k8s/get.go index deea0ce..c12325c 100644 --- a/pkg/cloudapi/k8s/get.go +++ b/pkg/cloudapi/k8s/get.go @@ -1,53 +1,43 @@ -package k8s - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq GetRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*K8SRecord, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/k8s/get" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8sInfo := &K8SRecord{} - - err = json.Unmarshal(res, k8sInfo) - if err != nil { - return nil, err - } - - return k8sInfo, nil -} +package k8s + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq GetRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Get(ctx context.Context, req GetRequest) (*K8SRecord, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/k8s/get" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8sInfo := &K8SRecord{} + + err = json.Unmarshal(res, k8sInfo) + if err != nil { + return nil, err + } + + return k8sInfo, nil +} diff --git a/pkg/cloudapi/k8s/get_config.go b/pkg/cloudapi/k8s/get_config.go index f1fe5fe..05a7c4e 100644 --- a/pkg/cloudapi/k8s/get_config.go +++ b/pkg/cloudapi/k8s/get_config.go @@ -1,45 +1,35 @@ -package k8s - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetConfigRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq GetConfigRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) GetConfig(ctx context.Context, req GetConfigRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/k8s/getConfig" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package k8s + +import ( + "context" + "errors" + "net/http" +) + +type GetConfigRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq GetConfigRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) GetConfig(ctx context.Context, req GetConfigRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/k8s/getConfig" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/k8s/get_node_annotations.go b/pkg/cloudapi/k8s/get_node_annotations.go index b452df4..0e64434 100644 --- a/pkg/cloudapi/k8s/get_node_annotations.go +++ b/pkg/cloudapi/k8s/get_node_annotations.go @@ -1,49 +1,39 @@ -package k8s - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetNodeAnnotationsRequest struct { - K8SId uint64 `url:"k8sId"` - NodeId uint64 `url:"nodeId"` -} - -func (krq GetNodeAnnotationsRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - if krq.NodeId == 0 { - return errors.New("validation-error: field NodeId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/k8s/getNodeAnnotations" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package k8s + +import ( + "context" + "errors" + "net/http" +) + +type GetNodeAnnotationsRequest struct { + K8SID uint64 `url:"k8sId"` + NodeID uint64 `url:"nodeId"` +} + +func (krq GetNodeAnnotationsRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + if krq.NodeID == 0 { + return errors.New("validation-error: field NodeID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/k8s/getNodeAnnotations" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/k8s/get_node_taints.go b/pkg/cloudapi/k8s/get_node_taints.go index b38048a..4d3ff79 100644 --- a/pkg/cloudapi/k8s/get_node_taints.go +++ b/pkg/cloudapi/k8s/get_node_taints.go @@ -1,49 +1,39 @@ -package k8s - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetNodeTaintsRequest struct { - K8SId uint64 `url:"k8sId"` - NodeId uint64 `url:"nodeId"` -} - -func (krq GetNodeTaintsRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - if krq.NodeId == 0 { - return errors.New("validation-error: field NodeId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/k8s/getNodeTaints" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil -} +package k8s + +import ( + "context" + "errors" + "net/http" +) + +type GetNodeTaintsRequest struct { + K8SID uint64 `url:"k8sId"` + NodeID uint64 `url:"nodeId"` +} + +func (krq GetNodeTaintsRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + if krq.NodeID == 0 { + return errors.New("validation-error: field NodeID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/k8s/getNodeTaints" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/k8s/k8s.go b/pkg/cloudapi/k8s/k8s.go index ac40198..5ff017e 100644 --- a/pkg/cloudapi/k8s/k8s.go +++ b/pkg/cloudapi/k8s/k8s.go @@ -1,15 +1,15 @@ -package k8s - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type K8S struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *K8S { - return &K8S{ - client, - } -} +package k8s + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type K8S struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *K8S { + return &K8S{ + client, + } +} diff --git a/pkg/cloudapi/k8s/list.go b/pkg/cloudapi/k8s/list.go index a48e76b..2168358 100644 --- a/pkg/cloudapi/k8s/list.go +++ b/pkg/cloudapi/k8s/list.go @@ -1,42 +1,32 @@ -package k8s - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDeleted bool `url:"includedeleted"` - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (k8s K8S) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (K8SList, error) { - - url := "/k8s/list" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8sList := K8SList{} - - err = json.Unmarshal(res, &k8sList) - if err != nil { - return nil, err - } - - return k8sList, nil -} +package k8s + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includedeleted"` + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (k8s K8S) List(ctx context.Context, req ListRequest) (K8SList, error) { + + url := "/cloudapi/k8s/list" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8sList := K8SList{} + + err = json.Unmarshal(res, &k8sList) + if err != nil { + return nil, err + } + + return k8sList, nil +} diff --git a/pkg/cloudapi/k8s/list_deleted.go b/pkg/cloudapi/k8s/list_deleted.go index cb4fcea..b56e4bd 100644 --- a/pkg/cloudapi/k8s/list_deleted.go +++ b/pkg/cloudapi/k8s/list_deleted.go @@ -1,41 +1,31 @@ -package k8s - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (K8SList, error) { - - url := "/k8s/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - k8sList := K8SList{} - - err = json.Unmarshal(res, &k8sList) - if err != nil { - return nil, err - } - - return k8sList, nil -} +package k8s + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (K8SList, error) { + + url := "/cloudapi/k8s/listDeleted" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + k8sList := K8SList{} + + err = json.Unmarshal(res, &k8sList) + if err != nil { + return nil, err + } + + return k8sList, nil +} diff --git a/pkg/cloudapi/k8s/models.go b/pkg/cloudapi/k8s/models.go index 6f97992..c5e345b 100644 --- a/pkg/cloudapi/k8s/models.go +++ b/pkg/cloudapi/k8s/models.go @@ -1,119 +1,119 @@ -package k8s - -type K8SGroup struct { - Annotations []string `json:"annotations"` - CPU uint `json:"cpu"` - DetailedInfo DetailedInfoList `json:"detailedInfo"` - Disk uint `json:"disk"` - GUID string `json:"guid"` - ID uint64 `json:"id"` - Labels []string `json:"labels"` - Name string `json:"name"` - Num uint `json:"num"` - RAM uint `json:"ram"` - Taints []string `json:"taints"` -} - -type K8SGroupList []K8SGroup - -type DetailedInfo struct { - ID uint64 `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` -} - -type DetailedInfoList []DetailedInfo - -type K8SRecord struct { - ACL ACLGroup `json:"ACL"` - AccountId uint64 `json:"accountId"` - AccountName string `json:"accountName"` - BServiceId uint64 `json:"bserviceId"` - CIId uint64 `json:"ciId"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - ID uint64 `json:"id"` - K8CIName string `json:"k8ciName"` - K8SGroups K8SGroups `json:"k8sGroups"` - LBId uint64 `json:"lbId"` - Name string `json:"name"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` -} - -type K8SGroups struct { - Masters MasterGroup `json:"masters"` - Workers K8SGroupList `json:"workers"` -} - -type MasterGroup struct { - CPU uint `json:"cpu"` - DetailedInfo DetailedInfoList `json:"detailedInfo"` - Disk uint `json:"disk"` - ID uint64 `json:"id"` - Name string `json:"name"` - Num uint `json:"num"` - RAM uint `json:"ram"` -} - -type ACLGroup struct { - AccountAcl AclList `json:"accountAcl"` - K8SAcl AclList `json:"k8sAcl"` - RGAcl AclList `json:"rgAcl"` -} - -type Acl struct { - Explicit bool `json:"explicit"` - GUID string `json:"guid"` - Right string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UserGroupId string `json:"userGroupId"` -} - -type AclList []Acl - -type K8SItem struct { - AccountId uint64 `json:"accountId"` - AccountName string `json:"accountName"` - Acl []interface{} `json:"acl"` - BServiceId uint64 `json:"bserviceId"` - CIId uint64 `json:"ciId"` - Config interface{} `json:"config"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - ExtnetId uint64 `json:"extnetId"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - LBId uint64 `json:"lbId"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - ServiceAccount ServiceAccount `json:"serviceAccount"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - VinsId uint64 `json:"vinsId"` - WorkersGroup K8SGroupList `json:"workersGroups"` -} - -type ServiceAccount struct { - GUID string `json:"guid"` - Password string `json:"password"` - Username string `json:"username"` -} - -type K8SList []K8SItem +package k8s + +type K8SGroup struct { + Annotations []string `json:"annotations"` + CPU uint64 `json:"cpu"` + DetailedInfo DetailedInfoList `json:"detailedInfo"` + Disk uint64 `json:"disk"` + GUID string `json:"guid"` + ID uint64 `json:"id"` + Labels []string `json:"labels"` + Name string `json:"name"` + Num uint64 `json:"num"` + RAM uint64 `json:"ram"` + Taints []string `json:"taints"` +} + +type K8SGroupList []K8SGroup + +type DetailedInfo struct { + ID uint64 `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` +} + +type DetailedInfoList []DetailedInfo + +type K8SRecord struct { + ACL ACLGroup `json:"ACL"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + BServiceID uint64 `json:"bserviceId"` + CIID uint64 `json:"ciId"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ID uint64 `json:"id"` + K8CIName string `json:"k8ciName"` + K8SGroups K8SGroups `json:"k8sGroups"` + LBID uint64 `json:"lbId"` + Name string `json:"name"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type K8SGroups struct { + Masters MasterGroup `json:"masters"` + Workers K8SGroupList `json:"workers"` +} + +type MasterGroup struct { + CPU uint64 `json:"cpu"` + DetailedInfo DetailedInfoList `json:"detailedInfo"` + Disk uint64 `json:"disk"` + ID uint64 `json:"id"` + Name string `json:"name"` + Num uint64 `json:"num"` + RAM uint64 `json:"ram"` +} + +type ACLGroup struct { + AccountACL ACLList `json:"accountAcl"` + K8SACL ACLList `json:"k8sAcl"` + RGACL ACLList `json:"rgAcl"` +} + +type ACL struct { + Explicit bool `json:"explicit"` + GUID string `json:"guid"` + Right string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UserGroupID string `json:"userGroupId"` +} + +type ACLList []ACL + +type K8SItem struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + ACL []interface{} `json:"acl"` + BServiceID uint64 `json:"bserviceId"` + CIID uint64 `json:"ciId"` + Config interface{} `json:"config"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + ExtNetID uint64 `json:"extnetId"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LBID uint64 `json:"lbId"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + ServiceAccount ServiceAccount `json:"serviceAccount"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINSID uint64 `json:"vinsId"` + WorkersGroup K8SGroupList `json:"workersGroups"` +} + +type ServiceAccount struct { + GUID string `json:"guid"` + Password string `json:"password"` + Username string `json:"username"` +} + +type K8SList []K8SItem diff --git a/pkg/cloudapi/k8s/restore.go b/pkg/cloudapi/k8s/restore.go index eda1150..3aea1d9 100644 --- a/pkg/cloudapi/k8s/restore.go +++ b/pkg/cloudapi/k8s/restore.go @@ -1,50 +1,40 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq RestoreRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/restore" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq RestoreRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/restore" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/start.go b/pkg/cloudapi/k8s/start.go index 0114157..35f13cc 100644 --- a/pkg/cloudapi/k8s/start.go +++ b/pkg/cloudapi/k8s/start.go @@ -1,50 +1,40 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type StartRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq StartRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/start" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type StartRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq StartRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Start(ctx context.Context, req StartRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/start" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/stop.go b/pkg/cloudapi/k8s/stop.go index 339b96f..d124274 100644 --- a/pkg/cloudapi/k8s/stop.go +++ b/pkg/cloudapi/k8s/stop.go @@ -1,50 +1,40 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type StopRequest struct { - K8SId uint64 `url:"k8sId"` -} - -func (krq StopRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/stop" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type StopRequest struct { + K8SID uint64 `url:"k8sId"` +} + +func (krq StopRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Stop(ctx context.Context, req StopRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/stop" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/update.go b/pkg/cloudapi/k8s/update.go index 22ffb68..a347cb9 100644 --- a/pkg/cloudapi/k8s/update.go +++ b/pkg/cloudapi/k8s/update.go @@ -1,52 +1,42 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UpdateRequest struct { - K8SId uint64 `url:"k8sId"` - Name string `url:"name,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (krq UpdateRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/update" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + K8SID uint64 `url:"k8sId"` + Name string `url:"name,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (krq UpdateRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/update" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/worker_add.go b/pkg/cloudapi/k8s/worker_add.go index be75474..a787fc0 100644 --- a/pkg/cloudapi/k8s/worker_add.go +++ b/pkg/cloudapi/k8s/worker_add.go @@ -1,60 +1,50 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkerAddRequest struct { - K8SId uint64 `url:"k8sId"` - WorkersGroupId uint64 `url:"workersGroupId"` - Num uint `url:"num"` -} - -func (krq WorkerAddRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.WorkersGroupId == 0 { - return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0") - } - - if krq.Num == 0 { - return errors.New("validation-error: field Num can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/workerAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type WorkerAddRequest struct { + K8SID uint64 `url:"k8sId"` + WorkersGroupID uint64 `url:"workersGroupId"` + Num uint `url:"num"` +} + +func (krq WorkerAddRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.WorkersGroupID == 0 { + return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0") + } + + if krq.Num == 0 { + return errors.New("validation-error: field Num can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/workerAdd" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/worker_reset.go b/pkg/cloudapi/k8s/worker_reset.go index 58d7bdf..ffa7611 100644 --- a/pkg/cloudapi/k8s/worker_reset.go +++ b/pkg/cloudapi/k8s/worker_reset.go @@ -1,60 +1,50 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkerResetRequest struct { - K8SId uint64 `url:"k8sId"` - WorkersGroupId uint64 `url:"workersGroupId"` - WorkerId uint64 `url:"workerId"` -} - -func (krq WorkerResetRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.WorkersGroupId == 0 { - return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0") - } - - if krq.WorkerId == 0 { - return errors.New("validation-error: field WorkerId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/workerReset" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type WorkerResetRequest struct { + K8SID uint64 `url:"k8sId"` + WorkersGroupID uint64 `url:"workersGroupId"` + WorkerID uint64 `url:"workerId"` +} + +func (krq WorkerResetRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.WorkersGroupID == 0 { + return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0") + } + + if krq.WorkerID == 0 { + return errors.New("validation-error: field WorkerID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/workerReset" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/worker_restart.go b/pkg/cloudapi/k8s/worker_restart.go index cb21615..afc0329 100644 --- a/pkg/cloudapi/k8s/worker_restart.go +++ b/pkg/cloudapi/k8s/worker_restart.go @@ -1,60 +1,50 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkerRestartRequest struct { - K8SId uint64 `url:"k8sId"` - WorkersGroupId uint64 `url:"workersGroupId"` - WorkerId uint64 `url:"workerId"` -} - -func (krq WorkerRestartRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.WorkersGroupId == 0 { - return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0") - } - - if krq.WorkerId == 0 { - return errors.New("validation-error: field WorkerId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/workerRestart" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type WorkerRestartRequest struct { + K8SID uint64 `url:"k8sId"` + WorkersGroupID uint64 `url:"workersGroupId"` + WorkerID uint64 `url:"workerId"` +} + +func (krq WorkerRestartRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.WorkersGroupID == 0 { + return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0") + } + + if krq.WorkerID == 0 { + return errors.New("validation-error: field WorkerID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/workerRestart" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/workers_group_add.go b/pkg/cloudapi/k8s/workers_group_add.go index 73e7b5b..7e79284 100644 --- a/pkg/cloudapi/k8s/workers_group_add.go +++ b/pkg/cloudapi/k8s/workers_group_add.go @@ -1,74 +1,64 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkersGroupAddRequest struct { - K8SId uint64 `url:"k8sId"` - Name string `url:"name"` - Labels []string `url:"labels"` - Taints []string `url:"taints"` - Annotations []string `url:"annotations"` - WorkerNum uint `url:"workerNum"` - WorkerCpu uint `url:"workerCpu"` - WorkerRam uint `url:"workerRam"` - WorkerDisk uint `url:"workerDisk"` -} - -func (krq WorkersGroupAddRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if krq.WorkerNum == 0 { - return errors.New("validation-error: field WorkerNum can not be empty or equal to 0") - } - - if krq.WorkerCpu == 0 { - return errors.New("validation-error: field WorkerCpu can not be empty or equal to 0") - } - - if krq.WorkerRam < 1024 { - return errors.New("validation-error: field WorkerRam must be greater or equal 1024") - } - - return nil -} - -func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/workersGroupAdd" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type WorkersGroupAddRequest struct { + K8SID uint64 `url:"k8sId"` + Name string `url:"name"` + Labels []string `url:"labels"` + Taints []string `url:"taints"` + Annotations []string `url:"annotations"` + WorkerNum uint `url:"workerNum"` + WorkerCPU uint `url:"workerCpu"` + WorkerRam uint `url:"workerRam"` + WorkerDisk uint `url:"workerDisk"` +} + +func (krq WorkersGroupAddRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if krq.WorkerNum == 0 { + return errors.New("validation-error: field WorkerNum can not be empty or equal to 0") + } + + if krq.WorkerCPU == 0 { + return errors.New("validation-error: field WorkerCPU can not be empty or equal to 0") + } + + if krq.WorkerRam < 1024 { + return errors.New("validation-error: field WorkerRam must be greater or equal 1024") + } + + return nil +} + +func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/workersGroupAdd" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/workers_group_delete.go b/pkg/cloudapi/k8s/workers_group_delete.go index a626ded..d07f73c 100644 --- a/pkg/cloudapi/k8s/workers_group_delete.go +++ b/pkg/cloudapi/k8s/workers_group_delete.go @@ -1,55 +1,45 @@ -package k8s - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkersGroupDeleteRequest struct { - K8SId uint64 `url:"k8sId"` - WorkersGroupId uint64 `url:"workersGroupId"` -} - -func (krq WorkersGroupDeleteRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.WorkersGroupId == 0 { - return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0") - } - - return nil -} - -func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/k8s/workersGroupDelete" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - return result, nil -} +package k8s + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type WorkersGroupDeleteRequest struct { + K8SID uint64 `url:"k8sId"` + WorkersGroupID uint64 `url:"workersGroupId"` +} + +func (krq WorkersGroupDeleteRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.WorkersGroupID == 0 { + return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0") + } + + return nil +} + +func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/k8s/workersGroupDelete" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudapi/k8s/workers_group_get_by_name.go b/pkg/cloudapi/k8s/workers_group_get_by_name.go index 9d5166e..e187ce0 100644 --- a/pkg/cloudapi/k8s/workers_group_get_by_name.go +++ b/pkg/cloudapi/k8s/workers_group_get_by_name.go @@ -1,58 +1,48 @@ -package k8s - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type WorkersGroupGetByNameRequest struct { - K8SId uint64 `url:"k8sId"` - GroupName string `url:"groupName "` -} - -func (krq WorkersGroupGetByNameRequest) Validate() error { - if krq.K8SId == 0 { - return errors.New("validation-error: field K8SId can not be empty or equal to 0") - } - - if krq.GroupName == "" { - return errors.New("validation-error: field WorkersGroupId can not be empty") - } - - return nil -} - -func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest, options ...opts.DecortOpts) (*K8SGroup, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/k8s/workersGroupGetByName" - prefix := "/cloudapi" - - option := opts.New(options) - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - group := &K8SGroup{} - - err = json.Unmarshal(res, group) - if err != nil { - return nil, err - } - - return group, nil -} +package k8s + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type WorkersGroupGetByNameRequest struct { + K8SID uint64 `url:"k8sId"` + GroupName string `url:"groupName "` +} + +func (krq WorkersGroupGetByNameRequest) Validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + + if krq.GroupName == "" { + return errors.New("validation-error: field WorkersGroupID can not be empty") + } + + return nil +} + +func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*K8SGroup, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/k8s/workersGroupGetByName" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + group := &K8SGroup{} + + err = json.Unmarshal(res, group) + if err != nil { + return nil, err + } + + return group, nil +} diff --git a/pkg/cloudapi/kvmppc.go b/pkg/cloudapi/kvmppc.go new file mode 100644 index 0000000..72aabfd --- /dev/null +++ b/pkg/cloudapi/kvmppc.go @@ -0,0 +1,7 @@ +package cloudapi + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc" + +func (ca *CloudApi) KVMPPC() *kvmppc.KVMPPC { + return kvmppc.New(ca.client) +} diff --git a/pkg/cloudapi/kvmppc/create.go b/pkg/cloudapi/kvmppc/create.go index 0ca4eb3..444412a 100644 --- a/pkg/cloudapi/kvmppc/create.go +++ b/pkg/cloudapi/kvmppc/create.go @@ -1,79 +1,70 @@ -package kvmppc - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - RGID uint64 `url:"rgId"` - Name string `url:"name"` - CPU uint64 `url:"cpu"` - RAM uint64 `url:"ram"` - ImageID uint64 `url:"imageId"` - BootDisk uint64 `url:"bootDisk,omitempty"` - SepID uint64 `url:"sepId,omitempty"` - Pool string `url:"pool,omitempty"` - NetType string `url:"netType,omitempty"` - NetID uint64 `url:"netId,omitempty"` - IPAddr string `url:"ipAddr,omitempty"` - Userdata string `url:"userdata,omitempty"` - Description string `url:"desc,omitempty"` - Start bool `url:"start,omitempty"` - IS string `url:"IS,omitempty"` - IPAType string `url:"ipaType,omitempty"` -} - -func (krq CreateRequest) Validate() error { - if krq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if krq.CPU == 0 { - return errors.New("validation-error: field CPU can not be empty or equal to 0") - } - if krq.RAM == 0 { - return errors.New("validation-error: field RAM can not be empty or equal to 0") - } - if krq.ImageID == 0 { - return errors.New("validation-error: field ImageID can not be empty or equal to 0") - } - - return nil -} - -func (k KVMPPC) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/kvmppc/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil - -} +package kvmppc + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Userdata string `url:"userdata,omitempty"` + Description string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + IS string `url:"IS,omitempty"` + IPAType string `url:"ipaType,omitempty"` +} + +func (krq CreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU can not be empty or equal to 0") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM can not be empty or equal to 0") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + + return nil +} + +func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/kvmppc/create" + prefix := "/cloudapi" + + url = prefix + url + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil + +} diff --git a/pkg/cloudapi/kvmppc/create_blank.go b/pkg/cloudapi/kvmppc/create_blank.go index ae5249c..824300b 100644 --- a/pkg/cloudapi/kvmppc/create_blank.go +++ b/pkg/cloudapi/kvmppc/create_blank.go @@ -1,80 +1,71 @@ -package kvmppc - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateBlankRequest struct { - RGID uint64 `url:"rgId"` - Name string `url:"name"` - CPU uint64 `url:"cpu"` - RAM uint64 `url:"ram"` - BootDisk uint64 `url:"bootDisk"` - SepID uint64 `url:"sepId"` - Pool string `url:"pool"` - NetType string `url:"netType,omitempty"` - NetID uint64 `url:"netId,omitempty"` - IPAddr string `url:"ipAddr,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (krq CreateBlankRequest) Validate() error { - if krq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if krq.CPU == 0 { - return errors.New("validation-error: field CPU can not be empty or equal to 0") - } - if krq.RAM == 0 { - return errors.New("validation-error: field RAM can not be empty or equal to 0") - } - if krq.BootDisk == 0 { - return errors.New("validation-error: field BootDisk can not be empty or equal to 0") - } - if krq.SepID == 0 { - return errors.New("validation-error: field SepID can not be empty or equal to 0") - } - if krq.Pool == "" { - return errors.New("validation-error: field Pool can not be empty") - } - - return nil -} - -func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/kvmppc/createBlank" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil - -} +package kvmppc + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateBlankRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + BootDisk uint64 `url:"bootDisk"` + SepID uint64 `url:"sepId"` + Pool string `url:"pool"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (krq CreateBlankRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU can not be empty or equal to 0") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM can not be empty or equal to 0") + } + if krq.BootDisk == 0 { + return errors.New("validation-error: field BootDisk can not be empty or equal to 0") + } + if krq.SepID == 0 { + return errors.New("validation-error: field SepID can not be empty or equal to 0") + } + if krq.Pool == "" { + return errors.New("validation-error: field Pool can not be empty") + } + + return nil +} + +func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/kvmppc/createBlank" + prefix := "/cloudapi" + + url = prefix + url + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil + +} diff --git a/pkg/cloudapi/kvmppc/kvmppc.go b/pkg/cloudapi/kvmppc/kvmppc.go index e206e75..050b6d5 100644 --- a/pkg/cloudapi/kvmppc/kvmppc.go +++ b/pkg/cloudapi/kvmppc/kvmppc.go @@ -1,15 +1,15 @@ -package kvmppc - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type KVMPPC struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *KVMPPC { - return &KVMPPC{ - client, - } -} +package kvmppc + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type KVMPPC struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *KVMPPC { + return &KVMPPC{ + client, + } +} diff --git a/pkg/cloudapi/kvmx86.go b/pkg/cloudapi/kvmx86.go new file mode 100644 index 0000000..8c2bd72 --- /dev/null +++ b/pkg/cloudapi/kvmx86.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86" +) + +func (ca *CloudApi) KVMX86() *kvmx86.KVMX86 { + return kvmx86.New(ca.client) +} diff --git a/pkg/cloudapi/kvmx86/create.go b/pkg/cloudapi/kvmx86/create.go index fb1e8c0..cb728d1 100644 --- a/pkg/cloudapi/kvmx86/create.go +++ b/pkg/cloudapi/kvmx86/create.go @@ -1,79 +1,70 @@ -package kvmx86 - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - RGID uint64 `url:"rgId"` - Name string `url:"name"` - CPU uint64 `url:"cpu"` - RAM uint64 `url:"ram"` - ImageID uint64 `url:"imageId"` - BootDisk uint64 `url:"bootDisk,omitempty"` - SepID uint64 `url:"sepId,omitempty"` - Pool string `url:"pool,omitempty"` - NetType string `url:"netType,omitempty"` - NetID uint64 `url:"netId,omitempty"` - IPAddr string `url:"ipAddr,omitempty"` - Userdata string `url:"userdata,omitempty"` - Description string `url:"desc,omitempty"` - Start bool `url:"start,omitempty"` - IS string `url:"IS,omitempty"` - IPAType string `url:"ipaType,omitempty"` -} - -func (krq CreateRequest) Validate() error { - if krq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if krq.CPU == 0 { - return errors.New("validation-error: field CPU can not be empty or equal to 0") - } - if krq.RAM == 0 { - return errors.New("validation-error: field RAM can not be empty or equal to 0") - } - if krq.ImageID == 0 { - return errors.New("validation-error: field ImageID can not be empty or equal to 0") - } - - return nil -} - -func (k KVMX86) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/kvmx86/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil - -} +package kvmx86 + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + ImageID uint64 `url:"imageId"` + BootDisk uint64 `url:"bootDisk,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Userdata string `url:"userdata,omitempty"` + Description string `url:"desc,omitempty"` + Start bool `url:"start,omitempty"` + IS string `url:"IS,omitempty"` + IPAType string `url:"ipaType,omitempty"` +} + +func (krq CreateRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU can not be empty or equal to 0") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM can not be empty or equal to 0") + } + if krq.ImageID == 0 { + return errors.New("validation-error: field ImageID can not be empty or equal to 0") + } + + return nil +} + +func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/kvmx86/create" + prefix := "/cloudapi" + + url = prefix + url + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil + +} diff --git a/pkg/cloudapi/kvmx86/create_blank.go b/pkg/cloudapi/kvmx86/create_blank.go index 90de019..c9e114e 100644 --- a/pkg/cloudapi/kvmx86/create_blank.go +++ b/pkg/cloudapi/kvmx86/create_blank.go @@ -1,80 +1,71 @@ -package kvmx86 - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateBlankRequest struct { - RGID uint64 `url:"rgId"` - Name string `url:"name"` - CPU uint64 `url:"cpu"` - RAM uint64 `url:"ram"` - BootDisk uint64 `url:"bootDisk"` - SepID uint64 `url:"sepId"` - Pool string `url:"pool"` - NetType string `url:"netType,omitempty"` - NetID uint64 `url:"netId,omitempty"` - IPAddr string `url:"ipAddr,omitempty"` - Description string `url:"desc,omitempty"` -} - -func (krq CreateBlankRequest) Validate() error { - if krq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - if krq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - if krq.CPU == 0 { - return errors.New("validation-error: field CPU can not be empty or equal to 0") - } - if krq.RAM == 0 { - return errors.New("validation-error: field RAM can not be empty or equal to 0") - } - if krq.BootDisk == 0 { - return errors.New("validation-error: field BootDisk can not be empty or equal to 0") - } - if krq.SepID == 0 { - return errors.New("validation-error: field SepID can not be empty or equal to 0") - } - if krq.Pool == "" { - return errors.New("validation-error: field Pool can not be empty") - } - - return nil -} - -func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/kvmx86/createBlank" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := k.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - return result, nil - -} +package kvmx86 + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateBlankRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + CPU uint64 `url:"cpu"` + RAM uint64 `url:"ram"` + BootDisk uint64 `url:"bootDisk"` + SepID uint64 `url:"sepId"` + Pool string `url:"pool"` + NetType string `url:"netType,omitempty"` + NetID uint64 `url:"netId,omitempty"` + IPAddr string `url:"ipAddr,omitempty"` + Description string `url:"desc,omitempty"` +} + +func (krq CreateBlankRequest) Validate() error { + if krq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + if krq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + if krq.CPU == 0 { + return errors.New("validation-error: field CPU can not be empty or equal to 0") + } + if krq.RAM == 0 { + return errors.New("validation-error: field RAM can not be empty or equal to 0") + } + if krq.BootDisk == 0 { + return errors.New("validation-error: field BootDisk can not be empty or equal to 0") + } + if krq.SepID == 0 { + return errors.New("validation-error: field SepID can not be empty or equal to 0") + } + if krq.Pool == "" { + return errors.New("validation-error: field Pool can not be empty") + } + + return nil +} + +func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/kvmx86/createBlank" + prefix := "/cloudapi" + + url = prefix + url + res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + return result, nil + +} diff --git a/pkg/cloudapi/kvmx86/kvmx86.go b/pkg/cloudapi/kvmx86/kvmx86.go index 40cd87a..62ff0b1 100644 --- a/pkg/cloudapi/kvmx86/kvmx86.go +++ b/pkg/cloudapi/kvmx86/kvmx86.go @@ -1,15 +1,15 @@ -package kvmx86 - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type KVMX86 struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *KVMX86 { - return &KVMX86{ - client, - } -} +package kvmx86 + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type KVMX86 struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *KVMX86 { + return &KVMX86{ + client, + } +} diff --git a/pkg/cloudapi/lb.go b/pkg/cloudapi/lb.go new file mode 100644 index 0000000..6a4362c --- /dev/null +++ b/pkg/cloudapi/lb.go @@ -0,0 +1,7 @@ +package cloudapi + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb" + +func (ca *CloudApi) LB() *lb.LB { + return lb.New(ca.client) +} diff --git a/pkg/cloudapi/lb/backend_create.go b/pkg/cloudapi/lb/backend_create.go index fe56fcf..1d909a9 100644 --- a/pkg/cloudapi/lb/backend_create.go +++ b/pkg/cloudapi/lb/backend_create.go @@ -1,66 +1,55 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendCreateRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` - Algorithm string `url:"algorithm,omitempty"` - Inter uint64 `url:"inter,omitempty"` - DownInter uint64 `url:"downinter,omitempty"` - Rise uint `url:"rise,omitempty"` - Fall uint `url:"fall,omitempty"` - SlowStart uint64 `url:"slowstart,omitempty"` - MaxConn uint `url:"maxconn,omitempty"` - MaxQueue uint `url:"maxqueue,omitempty"` - Weight uint `url:"weight,omitempty"` -} - -func (lbrq BackendCreateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - return nil -} - -func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendCreate" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendCreateRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` + Algorithm string `url:"algorithm,omitempty"` + Inter uint64 `url:"inter,omitempty"` + DownInter uint64 `url:"downinter,omitempty"` + Rise uint `url:"rise,omitempty"` + Fall uint `url:"fall,omitempty"` + SlowStart uint64 `url:"slowstart,omitempty"` + MaxConn uint `url:"maxconn,omitempty"` + MaxQueue uint `url:"maxqueue,omitempty"` + Weight uint `url:"weight,omitempty"` +} + +func (lbrq BackendCreateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + return nil +} + +func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendCreate" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/backend_delete.go b/pkg/cloudapi/lb/backend_delete.go index 1ad68e6..158464e 100644 --- a/pkg/cloudapi/lb/backend_delete.go +++ b/pkg/cloudapi/lb/backend_delete.go @@ -1,57 +1,46 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendDeleteRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` -} - -func (lbrq BackendDeleteRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - return nil -} - -func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendDelete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendDeleteRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` +} + +func (lbrq BackendDeleteRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + return nil +} + +func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendDelete" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/backend_server_add.go b/pkg/cloudapi/lb/backend_server_add.go index e23f7b7..7c84509 100644 --- a/pkg/cloudapi/lb/backend_server_add.go +++ b/pkg/cloudapi/lb/backend_server_add.go @@ -1,81 +1,70 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendServerAddRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` - ServerName string `url:"serverName"` - Address string `url:"address"` - Port uint `url:"port"` - Check string `url:"check,omitempty"` - Inter uint64 `url:"inter,omitempty"` - DownInter uint64 `url:"downinter,omitempty"` - Rise uint `url:"rise,omitempty"` - Fall uint `url:"fall,omitempty"` - SlowStart uint64 `url:"slowstart,omitempty"` - MaxConn uint `url:"maxconn,omitempty"` - MaxQueue uint `url:"maxqueue,omitempty"` - Weight uint `url:"weight,omitempty"` -} - -func (lbrq BackendServerAddRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - if lbrq.ServerName == "" { - return errors.New("validation-error: field ServerName can not be empty") - } - - if lbrq.Address == "" { - return errors.New("validation-error: field Address can not be empty") - } - - if lbrq.Port == 0 { - return errors.New("validation-error: field Port can not be empty or equal to 0") - } - - return nil -} - -func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendServerAdd" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendServerAddRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` + ServerName string `url:"serverName"` + Address string `url:"address"` + Port uint `url:"port"` + Check string `url:"check,omitempty"` + Inter uint64 `url:"inter,omitempty"` + DownInter uint64 `url:"downinter,omitempty"` + Rise uint `url:"rise,omitempty"` + Fall uint `url:"fall,omitempty"` + SlowStart uint64 `url:"slowstart,omitempty"` + MaxConn uint `url:"maxconn,omitempty"` + MaxQueue uint `url:"maxqueue,omitempty"` + Weight uint `url:"weight,omitempty"` +} + +func (lbrq BackendServerAddRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + if lbrq.ServerName == "" { + return errors.New("validation-error: field ServerName can not be empty") + } + + if lbrq.Address == "" { + return errors.New("validation-error: field Address can not be empty") + } + + if lbrq.Port == 0 { + return errors.New("validation-error: field Port can not be empty or equal to 0") + } + + return nil +} + +func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendServerAdd" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/backend_server_delete.go b/pkg/cloudapi/lb/backend_server_delete.go index 199e549..d572167 100644 --- a/pkg/cloudapi/lb/backend_server_delete.go +++ b/pkg/cloudapi/lb/backend_server_delete.go @@ -1,62 +1,51 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendServerDeleteRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` - ServerName string `url:"serverName"` -} - -func (lbrq BackendServerDeleteRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - if lbrq.ServerName == "" { - return errors.New("validation-error: field ServerName can not be empty") - } - - return nil -} - -func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendServerDelete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendServerDeleteRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` + ServerName string `url:"serverName"` +} + +func (lbrq BackendServerDeleteRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + if lbrq.ServerName == "" { + return errors.New("validation-error: field ServerName can not be empty") + } + + return nil +} + +func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendServerDelete" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/backend_server_update.go b/pkg/cloudapi/lb/backend_server_update.go index 058fe38..c191f84 100644 --- a/pkg/cloudapi/lb/backend_server_update.go +++ b/pkg/cloudapi/lb/backend_server_update.go @@ -1,81 +1,70 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendServerUpdateRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` - ServerName string `url:"serverName"` - Address string `url:"address"` - Port uint `url:"port"` - Check string `url:"check,omitempty"` - Inter uint64 `url:"inter,omitempty"` - DownInter uint64 `url:"downinter,omitempty"` - Rise uint `url:"rise,omitempty"` - Fall uint `url:"fall,omitempty"` - SlowStart uint64 `url:"slowstart,omitempty"` - MaxConn uint `url:"maxconn,omitempty"` - MaxQueue uint `url:"maxqueue,omitempty"` - Weight uint `url:"weight,omitempty"` -} - -func (lbrq BackendServerUpdateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - if lbrq.ServerName == "" { - return errors.New("validation-error: field ServerName can not be empty") - } - - if lbrq.Address == "" { - return errors.New("validation-error: field Address can not be empty") - } - - if lbrq.Port == 0 { - return errors.New("validation-error: field Port can not be empty or equal to 0") - } - - return nil -} - -func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendServerUpdate" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendServerUpdateRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` + ServerName string `url:"serverName"` + Address string `url:"address"` + Port uint `url:"port"` + Check string `url:"check,omitempty"` + Inter uint64 `url:"inter,omitempty"` + DownInter uint64 `url:"downinter,omitempty"` + Rise uint `url:"rise,omitempty"` + Fall uint `url:"fall,omitempty"` + SlowStart uint64 `url:"slowstart,omitempty"` + MaxConn uint `url:"maxconn,omitempty"` + MaxQueue uint `url:"maxqueue,omitempty"` + Weight uint `url:"weight,omitempty"` +} + +func (lbrq BackendServerUpdateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + if lbrq.ServerName == "" { + return errors.New("validation-error: field ServerName can not be empty") + } + + if lbrq.Address == "" { + return errors.New("validation-error: field Address can not be empty") + } + + if lbrq.Port == 0 { + return errors.New("validation-error: field Port can not be empty or equal to 0") + } + + return nil +} + +func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendServerUpdate" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/backend_update.go b/pkg/cloudapi/lb/backend_update.go index 5961724..85b7efb 100644 --- a/pkg/cloudapi/lb/backend_update.go +++ b/pkg/cloudapi/lb/backend_update.go @@ -1,66 +1,55 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type BackendUpdateRequest struct { - LBID uint64 `url:"lbId"` - BackendName string `url:"backendName"` - Algorithm string `url:"algorithm,omitempty"` - Inter uint64 `url:"inter,omitempty"` - DownInter uint64 `url:"downinter,omitempty"` - Rise uint `url:"rise,omitempty"` - Fall uint `url:"fall,omitempty"` - SlowStart uint64 `url:"slowstart,omitempty"` - MaxConn uint `url:"maxconn,omitempty"` - MaxQueue uint `url:"maxqueue,omitempty"` - Weight uint `url:"weight,omitempty"` -} - -func (lbrq BackendUpdateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - return nil -} - -func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/backendUpdate" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type BackendUpdateRequest struct { + LBID uint64 `url:"lbId"` + BackendName string `url:"backendName"` + Algorithm string `url:"algorithm,omitempty"` + Inter uint64 `url:"inter,omitempty"` + DownInter uint64 `url:"downinter,omitempty"` + Rise uint `url:"rise,omitempty"` + Fall uint `url:"fall,omitempty"` + SlowStart uint64 `url:"slowstart,omitempty"` + MaxConn uint `url:"maxconn,omitempty"` + MaxQueue uint `url:"maxqueue,omitempty"` + Weight uint `url:"weight,omitempty"` +} + +func (lbrq BackendUpdateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + return nil +} + +func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/backendUpdate" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/config_reset.go b/pkg/cloudapi/lb/config_reset.go index 395d79f..7e76056 100644 --- a/pkg/cloudapi/lb/config_reset.go +++ b/pkg/cloudapi/lb/config_reset.go @@ -1,52 +1,41 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ConfigResetRequest struct { - LBID uint64 `url:"lbId"` -} - -func (lbrq ConfigResetRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/configReset" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ConfigResetRequest struct { + LBID uint64 `url:"lbId"` +} + +func (lbrq ConfigResetRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/configReset" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/create.go b/pkg/cloudapi/lb/create.go index 97cf5f7..4de6548 100644 --- a/pkg/cloudapi/lb/create.go +++ b/pkg/cloudapi/lb/create.go @@ -1,64 +1,53 @@ -package lb - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateRequest struct { - RGID uint64 `url:"rgId"` - Name string `url:"name"` - ExtnetId uint64 `url:"extnetId"` - VinsId uint64 `url:"vinsId"` - Start bool `url:"start"` - Description string `url:"desc,omitempty"` -} - -func (lbrq CreateRequest) Validate() error { - if lbrq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - - if lbrq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if lbrq.ExtnetId == 0 { - return errors.New("validation-error: field ExtnetId can not be empty or equal to 0") - } - - if lbrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/lb/create" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return strings.ReplaceAll(string(res), "\"", ""), nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type CreateRequest struct { + RGID uint64 `url:"rgId"` + Name string `url:"name"` + ExtNetID uint64 `url:"extnetId"` + VINSID uint64 `url:"vinsId"` + Start bool `url:"start"` + Description string `url:"desc,omitempty"` +} + +func (lbrq CreateRequest) Validate() error { + if lbrq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + + if lbrq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if lbrq.ExtNetID == 0 { + return errors.New("validation-error: field ExtNetID can not be empty or equal to 0") + } + + if lbrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/lb/create" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return strings.ReplaceAll(string(res), "\"", ""), nil +} diff --git a/pkg/cloudapi/lb/delete.go b/pkg/cloudapi/lb/delete.go index 10e8b05..5c85d0b 100644 --- a/pkg/cloudapi/lb/delete.go +++ b/pkg/cloudapi/lb/delete.go @@ -1,53 +1,42 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - LBID uint64 `url:"lbId"` - Permanently bool `url:"permanently"` -} - -func (lbrq DeleteRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/delete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + LBID uint64 `url:"lbId"` + Permanently bool `url:"permanently"` +} + +func (lbrq DeleteRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/delete" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/disable_enable.go b/pkg/cloudapi/lb/disable_enable.go index 73eea00..c293459 100644 --- a/pkg/cloudapi/lb/disable_enable.go +++ b/pkg/cloudapi/lb/disable_enable.go @@ -1,82 +1,62 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisabelEnableRequest struct { - LBID uint64 `url:"lbId"` -} - -func (lbrq DisabelEnableRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/disable" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} - -func (l LB) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/enable" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisabelEnableRequest struct { + LBID uint64 `url:"lbId"` +} + +func (lbrq DisabelEnableRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/disable" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} + +func (l LB) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/enable" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/frontend_bind.go b/pkg/cloudapi/lb/frontend_bind.go index 5229870..bcab4a7 100644 --- a/pkg/cloudapi/lb/frontend_bind.go +++ b/pkg/cloudapi/lb/frontend_bind.go @@ -1,59 +1,48 @@ -package lb - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FrontendBindRequest struct { - LBID uint64 `url:"lbId"` - FrontendName string `url:"frontendName"` - BindingName string `url:"bindingName"` - BindingAddress string `url:"bindingAddress,omitempty"` - BindingPort uint `url:"bindingPort,omitempty"` -} - -func (lbrq FrontendBindRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.FrontendName == "" { - return errors.New("validation-error: field FrontendName can not be empty") - } - - if lbrq.BindingName == "" { - return errors.New("validation-error: field BindingName can not be empty") - } - - return nil -} - -func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/lb/frontendBind" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return strings.ReplaceAll(string(res), "\"", ""), nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type FrontendBindRequest struct { + LBID uint64 `url:"lbId"` + FrontendName string `url:"frontendName"` + BindingName string `url:"bindingName"` + BindingAddress string `url:"bindingAddress,omitempty"` + BindingPort uint `url:"bindingPort,omitempty"` +} + +func (lbrq FrontendBindRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.FrontendName == "" { + return errors.New("validation-error: field FrontendName can not be empty") + } + + if lbrq.BindingName == "" { + return errors.New("validation-error: field BindingName can not be empty") + } + + return nil +} + +func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/lb/frontendBind" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return strings.ReplaceAll(string(res), "\"", ""), nil +} diff --git a/pkg/cloudapi/lb/frontend_bind_delete.go b/pkg/cloudapi/lb/frontend_bind_delete.go index 6e386d6..ec392c5 100644 --- a/pkg/cloudapi/lb/frontend_bind_delete.go +++ b/pkg/cloudapi/lb/frontend_bind_delete.go @@ -1,57 +1,46 @@ -package lb - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FrontendBindDeleteRequest struct { - LBID uint64 `url:"lbId"` - FrontendName string `url:"frontendName"` - BindingName string `url:"bindingName"` -} - -func (lbrq FrontendBindDeleteRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.FrontendName == "" { - return errors.New("validation-error: field FrontendName can not be empty") - } - - if lbrq.BindingName == "" { - return errors.New("validation-error: field BindingName can not be empty") - } - - return nil -} - -func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/lb/frontendBindDelete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return strings.ReplaceAll(string(res), "\"", ""), nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type FrontendBindDeleteRequest struct { + LBID uint64 `url:"lbId"` + FrontendName string `url:"frontendName"` + BindingName string `url:"bindingName"` +} + +func (lbrq FrontendBindDeleteRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.FrontendName == "" { + return errors.New("validation-error: field FrontendName can not be empty") + } + + if lbrq.BindingName == "" { + return errors.New("validation-error: field BindingName can not be empty") + } + + return nil +} + +func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/lb/frontendBindDelete" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return strings.ReplaceAll(string(res), "\"", ""), nil +} diff --git a/pkg/cloudapi/lb/frontend_bind_update.go b/pkg/cloudapi/lb/frontend_bind_update.go index dde8f9a..8afce1e 100644 --- a/pkg/cloudapi/lb/frontend_bind_update.go +++ b/pkg/cloudapi/lb/frontend_bind_update.go @@ -1,59 +1,48 @@ -package lb - -import ( - "context" - "errors" - "strings" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FrontendBindUpdateRequest struct { - LBID uint64 `url:"lbId"` - FrontendName string `url:"frontendName"` - BindingName string `url:"bindingName"` - BindingAddress string `url:"bindingAddress,omitempty"` - BindingPort uint `url:"bindingPort,omitempty"` -} - -func (lbrq FrontendBindUpdateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.FrontendName == "" { - return errors.New("validation-error: field FrontendName can not be empty") - } - - if lbrq.BindingName == "" { - return errors.New("validation-error: field BindingName can not be empty") - } - - return nil -} - -func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/lb/frontendBindingUpdate" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return strings.ReplaceAll(string(res), "\"", ""), nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strings" +) + +type FrontendBindUpdateRequest struct { + LBID uint64 `url:"lbId"` + FrontendName string `url:"frontendName"` + BindingName string `url:"bindingName"` + BindingAddress string `url:"bindingAddress,omitempty"` + BindingPort uint `url:"bindingPort,omitempty"` +} + +func (lbrq FrontendBindUpdateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.FrontendName == "" { + return errors.New("validation-error: field FrontendName can not be empty") + } + + if lbrq.BindingName == "" { + return errors.New("validation-error: field BindingName can not be empty") + } + + return nil +} + +func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/lb/frontendBindingUpdate" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return strings.ReplaceAll(string(res), "\"", ""), nil +} diff --git a/pkg/cloudapi/lb/frontend_create.go b/pkg/cloudapi/lb/frontend_create.go index cba1626..86d97e1 100644 --- a/pkg/cloudapi/lb/frontend_create.go +++ b/pkg/cloudapi/lb/frontend_create.go @@ -1,62 +1,51 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FrontendCreateRequest struct { - LBID uint64 `url:"lbId"` - FrontendName string `url:"frontendName"` - BackendName string `url:"backendName"` -} - -func (lbrq FrontendCreateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.FrontendName == "" { - return errors.New("validation-error: field FrontendName can not be empty") - } - - if lbrq.BackendName == "" { - return errors.New("validation-error: field BackendName can not be empty") - } - - return nil -} - -func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/frontendCreate" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type FrontendCreateRequest struct { + LBID uint64 `url:"lbId"` + FrontendName string `url:"frontendName"` + BackendName string `url:"backendName"` +} + +func (lbrq FrontendCreateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.FrontendName == "" { + return errors.New("validation-error: field FrontendName can not be empty") + } + + if lbrq.BackendName == "" { + return errors.New("validation-error: field BackendName can not be empty") + } + + return nil +} + +func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/frontendCreate" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/frontend_delete.go b/pkg/cloudapi/lb/frontend_delete.go index 1497f7d..c82501e 100644 --- a/pkg/cloudapi/lb/frontend_delete.go +++ b/pkg/cloudapi/lb/frontend_delete.go @@ -1,57 +1,46 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type FrontendDeleteRequest struct { - LBID uint64 `url:"lbId"` - FrontendName string `url:"frontendName"` -} - -func (lbrq FrontendDeleteRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - if lbrq.FrontendName == "" { - return errors.New("validation-error: field FrontendName can not be empty") - } - - return nil -} - -func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/frontendDelete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type FrontendDeleteRequest struct { + LBID uint64 `url:"lbId"` + FrontendName string `url:"frontendName"` +} + +func (lbrq FrontendDeleteRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + if lbrq.FrontendName == "" { + return errors.New("validation-error: field FrontendName can not be empty") + } + + return nil +} + +func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/frontendDelete" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/get.go b/pkg/cloudapi/lb/get.go index 9de1290..5eb9bd3 100644 --- a/pkg/cloudapi/lb/get.go +++ b/pkg/cloudapi/lb/get.go @@ -1,54 +1,43 @@ -package lb - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - LBID uint64 `url:"lbId"` -} - -func (lbrq GetRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*LoadBalancer, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/lb/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - lbRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - lb := &LoadBalancer{} - err = json.Unmarshal(lbRaw, lb) - if err != nil { - return nil, err - } - - return lb, nil - -} +package lb + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + LBID uint64 `url:"lbId"` +} + +func (lbrq GetRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Get(ctx context.Context, req GetRequest) (*LoadBalancer, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/lb/get" + + lbRaw, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + lb := &LoadBalancer{} + err = json.Unmarshal(lbRaw, lb) + if err != nil { + return nil, err + } + + return lb, nil + +} diff --git a/pkg/cloudapi/lb/lb.go b/pkg/cloudapi/lb/lb.go index 51f578c..c8f444b 100644 --- a/pkg/cloudapi/lb/lb.go +++ b/pkg/cloudapi/lb/lb.go @@ -1,15 +1,15 @@ -package lb - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type LB struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *LB { - return &LB{ - client, - } -} +package lb + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type LB struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *LB { + return &LB{ + client, + } +} diff --git a/pkg/cloudapi/lb/list.go b/pkg/cloudapi/lb/list.go index 6aae11d..bc0bd23 100644 --- a/pkg/cloudapi/lb/list.go +++ b/pkg/cloudapi/lb/list.go @@ -1,42 +1,31 @@ -package lb - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDeleted bool `url:"includedeleted"` - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (l LB) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (LBList, error) { - url := "/lb/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - lbListRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - lbList := LBList{} - err = json.Unmarshal(lbListRaw, &lbList) - if err != nil { - return nil, err - } - - return lbList, nil - -} +package lb + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includedeleted"` + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (l LB) List(ctx context.Context, req ListRequest) (LBList, error) { + url := "/cloudapi/lb/list" + + lbListRaw, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + lbList := LBList{} + err = json.Unmarshal(lbListRaw, &lbList) + if err != nil { + return nil, err + } + + return lbList, nil + +} diff --git a/pkg/cloudapi/lb/list_deleted.go b/pkg/cloudapi/lb/list_deleted.go index da4c4ff..88b2871 100644 --- a/pkg/cloudapi/lb/list_deleted.go +++ b/pkg/cloudapi/lb/list_deleted.go @@ -1,41 +1,30 @@ -package lb - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (LBList, error) { - url := "/lb/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - lbListRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - lbList := LBList{} - err = json.Unmarshal(lbListRaw, &lbList) - if err != nil { - return nil, err - } - - return lbList, nil - -} +package lb + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (LBList, error) { + url := "/cloudapi/lb/listDeleted" + + lbListRaw, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + lbList := LBList{} + err = json.Unmarshal(lbListRaw, &lbList) + if err != nil { + return nil, err + } + + return lbList, nil + +} diff --git a/pkg/cloudapi/lb/models.go b/pkg/cloudapi/lb/models.go index 918db52..805d253 100644 --- a/pkg/cloudapi/lb/models.go +++ b/pkg/cloudapi/lb/models.go @@ -1,89 +1,89 @@ -package lb - -type LoadBalancer struct { - HAMode bool `json:"HAmode"` - ACL interface{} `json:"acl"` - Backends []Backend `json:"backends"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Description string `json:"desc"` - DPAPIUser string `json:"dpApiUser"` - ExtnetId uint64 `json:"extnetId"` - Frontends []Frontend `json:"frontends"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - ImageId uint64 `json:"imageId"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - PrimaryNode Node `json:"primaryNode"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - SecondaryNode Node `json:"secondaryNode"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - VinsId uint64 `json:"vinsId"` -} - -type LoadBalancerDetailed struct { - DPAPIPassword string `json:"dpApiPassword"` - LoadBalancer -} - -type Backend struct { - Algorithm string `json:"algorithm"` - GUID string `json:"guid"` - Name string `json:"name"` - ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"` - Servers []Server `json:"servers"` -} - -type LBList []LoadBalancerDetailed - -type ServerSettings struct { - Inter uint64 `json:"inter"` - GUID string `json:"guid"` - DownInter uint64 `json:"downinter"` - Rise uint `json:"rise"` - Fall uint `json:"fall"` - SlowStart uint64 `json:"slowstart"` - MaxConn uint `json:"maxconn"` - MaxQueue uint `json:"maxqueue"` - Weight uint `json:"weight"` -} - -type Server struct { - Address string `json:"address"` - Check string `json:"check"` - GUID string `json:"guid"` - Name string `json:"name"` - Port uint `json:"port"` - ServerSettings ServerSettings `json:"serverSettings"` -} - -type Node struct { - BackendIp string `json:"backendIp"` - ComputeId uint64 `json:"computeId"` - FrontendIp string `json:"frontendIp"` - GUID string `json:"guid"` - MGMTIp string `json:"mgmtIp"` - NetworkId uint64 `json:"networkId"` -} - -type Frontend struct { - Backend string `json:"backend"` - Bindings []Binding `json:"bindings"` - GUID string `json:"guid"` - Name string `json:"name"` -} - -type Binding struct { - Address string `json:"address"` - GUID string `json:"guid"` - Name string `json:"name"` - Port uint `json:"port"` -} +package lb + +type LoadBalancer struct { + HAMode bool `json:"HAmode"` + ACL interface{} `json:"acl"` + Backends []Backend `json:"backends"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Description string `json:"desc"` + DPAPIUser string `json:"dpApiUser"` + ExtNetID uint64 `json:"extnetId"` + Frontends []Frontend `json:"frontends"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + PrimaryNode Node `json:"primaryNode"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + SecondaryNode Node `json:"secondaryNode"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINSID uint64 `json:"vinsId"` +} + +type LoadBalancerDetailed struct { + DPAPIPassword string `json:"dpApiPassword"` + LoadBalancer +} + +type Backend struct { + Algorithm string `json:"algorithm"` + GUID string `json:"guid"` + Name string `json:"name"` + ServerDefaultSettings ServerSettings `json:"serverDefaultSettings"` + Servers []Server `json:"servers"` +} + +type LBList []LoadBalancerDetailed + +type ServerSettings struct { + Inter uint64 `json:"inter"` + GUID string `json:"guid"` + DownInter uint64 `json:"downinter"` + Rise uint64 `json:"rise"` + Fall uint64 `json:"fall"` + SlowStart uint64 `json:"slowstart"` + MaxConn uint64 `json:"maxconn"` + MaxQueue uint64 `json:"maxqueue"` + Weight uint64 `json:"weight"` +} + +type Server struct { + Address string `json:"address"` + Check string `json:"check"` + GUID string `json:"guid"` + Name string `json:"name"` + Port uint64 `json:"port"` + ServerSettings ServerSettings `json:"serverSettings"` +} + +type Node struct { + BackendIP string `json:"backendIp"` + ComputeID uint64 `json:"computeId"` + FrontendIP string `json:"frontendIp"` + GUID string `json:"guid"` + MGMTIP string `json:"mgmtIp"` + NetworkID uint64 `json:"networkId"` +} + +type Frontend struct { + Backend string `json:"backend"` + Bindings []Binding `json:"bindings"` + GUID string `json:"guid"` + Name string `json:"name"` +} + +type Binding struct { + Address string `json:"address"` + GUID string `json:"guid"` + Name string `json:"name"` + Port uint64 `json:"port"` +} diff --git a/pkg/cloudapi/lb/restart.go b/pkg/cloudapi/lb/restart.go index 0ef4be3..ad9d81d 100644 --- a/pkg/cloudapi/lb/restart.go +++ b/pkg/cloudapi/lb/restart.go @@ -1,52 +1,41 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestartRequest struct { - LBID uint64 `url:"lbId"` -} - -func (lbrq RestartRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Restart(ctx context.Context, req RestartRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/restart" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestartRequest struct { + LBID uint64 `url:"lbId"` +} + +func (lbrq RestartRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Restart(ctx context.Context, req RestartRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/restart" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/restore.go b/pkg/cloudapi/lb/restore.go index 26cdcea..36cd2f2 100644 --- a/pkg/cloudapi/lb/restore.go +++ b/pkg/cloudapi/lb/restore.go @@ -1,52 +1,41 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - LBID uint64 `url:"lbId"` -} - -func (lbrq RestoreRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - - return nil -} - -func (l LB) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/restore" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + LBID uint64 `url:"lbId"` +} + +func (lbrq RestoreRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +func (l LB) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/restore" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/lb/update.go b/pkg/cloudapi/lb/update.go index fdc8be7..7a8deca 100644 --- a/pkg/cloudapi/lb/update.go +++ b/pkg/cloudapi/lb/update.go @@ -1,56 +1,45 @@ -package lb - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type UpdateRequest struct { - LBID uint64 `url:"lbId"` - Description string `url:"desc"` -} - -func (lbrq UpdateRequest) Validate() error { - if lbrq.LBID == 0 { - return errors.New("validation-error: field LBID can not be empty or equal to 0") - } - if lbrq.Description == "" { - return errors.New("validation-error: field Description can not be empty") - } - - return nil -} - -func (l LB) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/lb/update" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, err - } - - return result, nil -} +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + LBID uint64 `url:"lbId"` + Description string `url:"desc"` +} + +func (lbrq UpdateRequest) Validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + if lbrq.Description == "" { + return errors.New("validation-error: field Description can not be empty") + } + + return nil +} + +func (l LB) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/update" + + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/locations/get_url.go b/pkg/cloudapi/locations/get_url.go index 39af841..306319f 100644 --- a/pkg/cloudapi/locations/get_url.go +++ b/pkg/cloudapi/locations/get_url.go @@ -1,28 +1,19 @@ -package locations - -import ( - "context" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -func (l Locations) GetUrl(ctx context.Context, options ...opts.DecortOpts) (string, error) { - url := "/locations/getUrl" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := l.client.DecortApiCall(ctx, typed.POST, url, nil) - if err != nil { - return "", err - } - - return string(res), nil -} +package locations + +import ( + "context" + "net/http" +) + +func (l Locations) GetUrl(ctx context.Context) (string, error) { + url := "/locations/getUrl" + prefix := "/cloudapi" + + url = prefix + url + res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, nil) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/locations/list.go b/pkg/cloudapi/locations/list.go index 1b58b7a..15ed0ad 100644 --- a/pkg/cloudapi/locations/list.go +++ b/pkg/cloudapi/locations/list.go @@ -1,41 +1,32 @@ -package locations - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (l Locations) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (LocationsList, error) { - url := "/locations/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - locationsListRaw, err := l.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - locationsList := LocationsList{} - err = json.Unmarshal(locationsListRaw, &locationsList) - if err != nil { - return nil, err - } - - return locationsList, nil - -} +package locations + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (l Locations) List(ctx context.Context, req ListRequest) (LocationsList, error) { + url := "/locations/list" + prefix := "/cloudapi" + + url = prefix + url + locationsListRaw, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + locationsList := LocationsList{} + err = json.Unmarshal(locationsListRaw, &locationsList) + if err != nil { + return nil, err + } + + return locationsList, nil + +} diff --git a/pkg/cloudapi/locations/locations.go b/pkg/cloudapi/locations/locations.go index e96917e..89590fd 100644 --- a/pkg/cloudapi/locations/locations.go +++ b/pkg/cloudapi/locations/locations.go @@ -1,15 +1,15 @@ -package locations - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Locations struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Locations { - return &Locations{ - client, - } -} +package locations + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Locations struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Locations { + return &Locations{ + client, + } +} diff --git a/pkg/cloudapi/locations/models.go b/pkg/cloudapi/locations/models.go index 0c5a11a..80e0c52 100644 --- a/pkg/cloudapi/locations/models.go +++ b/pkg/cloudapi/locations/models.go @@ -1,14 +1,14 @@ -package locations - -type Location struct { - GID int `json:"gid"` - Id int `json:"id"` - Guid int `json:"guid"` - LocationCode string `json:"locationCode"` - Name string `json:"name"` - Flag string `json:"flag"` - Meta []interface{} `json:"_meta"` - CKey string `json:"_ckey"` -} - -type LocationsList []Location +package locations + +type Location struct { + GID uint64 `json:"gid"` + ID uint64 `json:"id"` + GUID uint64 `json:"guid"` + LocationCode string `json:"locationCode"` + Name string `json:"name"` + Flag string `json:"flag"` + Meta []interface{} `json:"_meta"` + CKey string `json:"_ckey"` +} + +type LocationsList []Location diff --git a/pkg/cloudapi/locatons.go b/pkg/cloudapi/locatons.go new file mode 100644 index 0000000..6e70c20 --- /dev/null +++ b/pkg/cloudapi/locatons.go @@ -0,0 +1,7 @@ +package cloudapi + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations" + +func (ca *CloudApi) Locations() *locations.Locations { + return locations.New(ca.client) +} diff --git a/pkg/cloudapi/rg.go b/pkg/cloudapi/rg.go new file mode 100644 index 0000000..3175f82 --- /dev/null +++ b/pkg/cloudapi/rg.go @@ -0,0 +1,7 @@ +package cloudapi + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg" + +func (ca *CloudApi) RG() *rg.RG { + return rg.New(ca.client) +} diff --git a/pkg/cloudapi/rg/access_grant.go b/pkg/cloudapi/rg/access_grant.go index 0812b0b..7bde936 100644 --- a/pkg/cloudapi/rg/access_grant.go +++ b/pkg/cloudapi/rg/access_grant.go @@ -3,11 +3,10 @@ package rg import ( "context" "errors" + "net/http" "strconv" "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type AccessGrantRequest struct { @@ -33,13 +32,13 @@ func (rgrq AccessGrantRequest) Validate() error { return nil } -func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/accessGrant" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/access_revoke.go b/pkg/cloudapi/rg/access_revoke.go index cebf587..1c12409 100644 --- a/pkg/cloudapi/rg/access_revoke.go +++ b/pkg/cloudapi/rg/access_revoke.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type AccessRevokeRequest struct { @@ -27,13 +25,13 @@ func (rgrq AccessRevokeRequest) Validate() error { return nil } -func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/accessRevoke" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/affinity_group_computes.go b/pkg/cloudapi/rg/affinity_group_computes.go index cb64e32..d32307c 100644 --- a/pkg/cloudapi/rg/affinity_group_computes.go +++ b/pkg/cloudapi/rg/affinity_group_computes.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type AffinityGroupComputesRequest struct { @@ -26,13 +24,13 @@ func (rgrq AffinityGroupComputesRequest) Validate() error { return nil } -func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest, options ...opts.DecortOpts) (AffinityGroupComputeList, error) { +func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (AffinityGroupComputeList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/affinityGroupComputes" - agcListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + agcListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/affinity_groups_get.go b/pkg/cloudapi/rg/affinity_groups_get.go index 54ab42b..0990c87 100644 --- a/pkg/cloudapi/rg/affinity_groups_get.go +++ b/pkg/cloudapi/rg/affinity_groups_get.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type AffinityGroupsGetRequest struct { @@ -26,13 +24,13 @@ func (rgrq AffinityGroupsGetRequest) Validate() error { return nil } -func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest, options ...opts.DecortOpts) ([]uint64, error) { +func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/affinityGroupsGet" - agListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/affinity_groups_list.go b/pkg/cloudapi/rg/affinity_groups_list.go index 2fb4ead..8672fd2 100644 --- a/pkg/cloudapi/rg/affinity_groups_list.go +++ b/pkg/cloudapi/rg/affinity_groups_list.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type AffinityGroupsListRequest struct { @@ -21,13 +19,13 @@ func (rgrq AffinityGroupsListRequest) Validate() error { return nil } -func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest, options ...opts.DecortOpts) (map[string][]uint64, error) { +func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/affinityGroupsList" - agListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + agListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/audits.go b/pkg/cloudapi/rg/audits.go index 4830b2e..7adf7cd 100644 --- a/pkg/cloudapi/rg/audits.go +++ b/pkg/cloudapi/rg/audits.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type AuditsRequest struct { @@ -21,13 +19,13 @@ func (rgrq AuditsRequest) Validate() error { return nil } -func (r RG) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) { +func (r RG) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/audits" - auditListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/create.go b/pkg/cloudapi/rg/create.go index d4deeac..c163ffc 100644 --- a/pkg/cloudapi/rg/create.go +++ b/pkg/cloudapi/rg/create.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type CreateRequest struct { @@ -44,13 +42,13 @@ func (rgrq CreateRequest) Validate() error { return nil } -func (r RG) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) { +func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) { if err := req.Validate(); err != nil { return 0, err } url := "/cloudapi/rg/create" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return 0, err } diff --git a/pkg/cloudapi/rg/delete.go b/pkg/cloudapi/rg/delete.go index 4264a5f..b1201a8 100644 --- a/pkg/cloudapi/rg/delete.go +++ b/pkg/cloudapi/rg/delete.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type DeleteRequest struct { @@ -24,13 +22,13 @@ func (rgrq DeleteRequest) Validate() error { return nil } -func (r RG) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/delete" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/disable.go b/pkg/cloudapi/rg/disable.go index f8cb7c1..14c5b69 100644 --- a/pkg/cloudapi/rg/disable.go +++ b/pkg/cloudapi/rg/disable.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type DisableRequest struct { @@ -22,13 +20,13 @@ func (rgrq DisableRequest) Validate() error { return nil } -func (r RG) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/disable" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/enable.go b/pkg/cloudapi/rg/enable.go index cde6914..1176a33 100644 --- a/pkg/cloudapi/rg/enable.go +++ b/pkg/cloudapi/rg/enable.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type EnableRequest struct { @@ -22,13 +20,13 @@ func (rgrq EnableRequest) Validate() error { return nil } -func (r RG) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/enable" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/get.go b/pkg/cloudapi/rg/get.go index f968cc3..f4ff89e 100644 --- a/pkg/cloudapi/rg/get.go +++ b/pkg/cloudapi/rg/get.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type GetRequest struct { @@ -22,13 +20,13 @@ func (rgrq GetRequest) Validate() error { return nil } -func (r RG) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ResourceGroup, error) { +func (r RG) Get(ctx context.Context, req GetRequest) (*ResourceGroup, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/get" - rgRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + rgRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list.go b/pkg/cloudapi/rg/list.go index a4a83ec..79b76e9 100644 --- a/pkg/cloudapi/rg/list.go +++ b/pkg/cloudapi/rg/list.go @@ -3,9 +3,7 @@ package rg import ( "context" "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListRequest struct { @@ -14,9 +12,9 @@ type ListRequest struct { Size uint64 `url:"size,omitempty"` } -func (r RG) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ResourceGroupList, error) { +func (r RG) List(ctx context.Context, req ListRequest) (ResourceGroupList, error) { url := "/cloudapi/rg/list" - rgListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + rgListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list_computes.go b/pkg/cloudapi/rg/list_computes.go index 61169ab..87ee79b 100644 --- a/pkg/cloudapi/rg/list_computes.go +++ b/pkg/cloudapi/rg/list_computes.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListComputesRequest struct { @@ -22,13 +20,13 @@ func (rgrq ListComputesRequest) Validate() error { return nil } -func (r RG) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (ComputeList, error) { +func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ComputeList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/listComputes" - computeListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + computeListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list_deleted.go b/pkg/cloudapi/rg/list_deleted.go index 7899123..3c50f1d 100644 --- a/pkg/cloudapi/rg/list_deleted.go +++ b/pkg/cloudapi/rg/list_deleted.go @@ -3,9 +3,7 @@ package rg import ( "context" "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListDeletedRequest struct { @@ -13,9 +11,9 @@ type ListDeletedRequest struct { Size uint64 `url:"size,omitempty"` } -func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (ResourceGroupList, error) { +func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ResourceGroupList, error) { url := "/cloudapi/rg/listDeleted" - rgListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + rgListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list_lb.go b/pkg/cloudapi/rg/list_lb.go index d1667d9..e7de5f3 100644 --- a/pkg/cloudapi/rg/list_lb.go +++ b/pkg/cloudapi/rg/list_lb.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListLBRequest struct { @@ -21,13 +19,13 @@ func (rgrq ListLBRequest) Validate() error { return nil } -func (r RG) ListLB(ctx context.Context, req ListLBRequest, options ...opts.DecortOpts) (LBList, error) { +func (r RG) ListLB(ctx context.Context, req ListLBRequest) (LBList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/listLb" - lbListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + lbListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list_pfw.go b/pkg/cloudapi/rg/list_pfw.go index b820ffa..0b6b4b0 100644 --- a/pkg/cloudapi/rg/list_pfw.go +++ b/pkg/cloudapi/rg/list_pfw.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListPFWRequest struct { @@ -21,13 +19,13 @@ func (rgrq ListPFWRequest) Validate() error { return nil } -func (r RG) ListPFW(ctx context.Context, req ListPFWRequest, options ...opts.DecortOpts) (PortForwardList, error) { +func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (PortForwardList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/listPFW" - pfwListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + pfwListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/rg/list_vins.go b/pkg/cloudapi/rg/list_vins.go index f629e9d..e8cca3b 100644 --- a/pkg/cloudapi/rg/list_vins.go +++ b/pkg/cloudapi/rg/list_vins.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type ListVINSRequest struct { @@ -22,21 +20,21 @@ func (rgrq ListVINSRequest) Validate() error { return nil } -func (r RG) ListVINS(ctx context.Context, req ListVINSRequest, options ...opts.DecortOpts) (VINSList, error) { +func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (VINSList, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/listVins" - vinsListRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + VINSListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } - vinsList := VINSList{} - if err := json.Unmarshal(vinsListRaw, &vinsList); err != nil { + VINSList := VINSList{} + if err := json.Unmarshal(VINSListRaw, &VINSList); err != nil { return nil, err } - return vinsList, nil + return VINSList, nil } diff --git a/pkg/cloudapi/rg/models.go b/pkg/cloudapi/rg/models.go index 8cc77d0..662b52f 100644 --- a/pkg/cloudapi/rg/models.go +++ b/pkg/cloudapi/rg/models.go @@ -6,17 +6,17 @@ type ResourceGroup struct { ACL []ACL `json:"acl"` CreatedBy string `json:"createdBy"` CreatedTime uint64 `json:"createdTime"` - DefNetID uint64 `json:"def_net_id"` + DefNetID int64 `json:"def_net_id"` DefNetType string `json:"def_net_type"` DeletedBy string `json:"deletedBy"` DeletedTime uint64 `json:"deletedTime"` Desc string `json:"desc"` - Dirty bool `url:"dirty"` + Dirty bool `json:"dirty"` GID uint64 `json:"gid"` GUID uint64 `json:"guid"` ID uint64 `json:"id"` LockStatus string `json:"lockStatus"` - Milestones int `json:"milestones"` + Milestones uint64 `json:"milestones"` Name string `json:"name"` RegisterComputes bool `json:"registerComputes"` ResourceLimits ResourceLimits `json:"resourceLimits"` @@ -111,12 +111,12 @@ type LoadBalancer struct { DeletedTime uint64 `json:"deletedTime"` Description string `json:"desc"` DPAPIUser string `json:"dpApiUser"` - ExtnetId uint64 `json:"extnetId"` + ExtNetID uint64 `json:"extnetId"` Frontends []Frontend `json:"frontends"` GID uint64 `json:"gid"` GUID uint64 `json:"guid"` ID uint64 `json:"id"` - ImageId uint64 `json:"imageId"` + ImageID uint64 `json:"imageId"` Milestones uint64 `json:"milestones"` Name string `json:"name"` PrimaryNode Node `json:"primaryNode"` @@ -127,7 +127,7 @@ type LoadBalancer struct { TechStatus string `json:"techStatus"` UpdatedBy string `json:"updatedBy"` UpdatedTime uint64 `json:"updatedTime"` - VinsId uint64 `json:"vinsId"` + VINSID uint64 `json:"vinsId"` } type LoadBalancerDetailed struct { @@ -149,12 +149,12 @@ type ServerSettings struct { Inter uint64 `json:"inter"` GUID string `json:"guid"` DownInter uint64 `json:"downinter"` - Rise uint `json:"rise"` - Fall uint `json:"fall"` + Rise uint64 `json:"rise"` + Fall uint64 `json:"fall"` SlowStart uint64 `json:"slowstart"` - MaxConn uint `json:"maxconn"` - MaxQueue uint `json:"maxqueue"` - Weight uint `json:"weight"` + MaxConn uint64 `json:"maxconn"` + MaxQueue uint64 `json:"maxqueue"` + Weight uint64 `json:"weight"` } type Server struct { @@ -162,17 +162,17 @@ type Server struct { Check string `json:"check"` GUID string `json:"guid"` Name string `json:"name"` - Port uint `json:"port"` + Port uint64 `json:"port"` ServerSettings ServerSettings `json:"serverSettings"` } type Node struct { - BackendIp string `json:"backendIp"` - ComputeId uint64 `json:"computeId"` - FrontendIp string `json:"frontendIp"` + BackendIP string `json:"backendIp"` + ComputeID uint64 `json:"computeId"` + FrontendIP string `json:"frontendIp"` GUID string `json:"guid"` - MGMTIp string `json:"mgmtIp"` - NetworkId uint64 `json:"networkId"` + MGMTIP string `json:"mgmtIp"` + NetworkID uint64 `json:"networkId"` } type Frontend struct { @@ -186,16 +186,16 @@ type Binding struct { Address string `json:"address"` GUID string `json:"guid"` Name string `json:"name"` - Port uint `json:"port"` + Port uint64 `json:"port"` } type PortForward struct { - PublicPortEnd uint16 `json:"Public Port End"` - PublicPortStart uint16 `json:"Public Port Start"` + PublicPortEnd uint64 `json:"Public Port End"` + PublicPortStart uint64 `json:"Public Port Start"` VMID uint64 `json:"VM ID"` VMIP string `json:"VM IP"` VMName string `json:"VM Name"` - VMPort uint16 `json:"VM Port"` + VMPort uint64 `json:"VM Port"` VINSID uint64 `json:"ViNS ID"` VINSName string `json:"ViNS Name"` } diff --git a/pkg/cloudapi/rg/restore.go b/pkg/cloudapi/rg/restore.go index 8b2d947..da4e98c 100644 --- a/pkg/cloudapi/rg/restore.go +++ b/pkg/cloudapi/rg/restore.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type RestoreRequest struct { @@ -22,13 +20,13 @@ func (rgrq RestoreRequest) Validate() error { return nil } -func (r RG) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/restore" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/set_def_net.go b/pkg/cloudapi/rg/set_def_net.go index 75eaaa4..46df0c0 100644 --- a/pkg/cloudapi/rg/set_def_net.go +++ b/pkg/cloudapi/rg/set_def_net.go @@ -3,11 +3,10 @@ package rg import ( "context" "errors" + "net/http" "strconv" "github.com/rudecs/decort-sdk/internal/validators" - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type SetDefNetRequest struct { @@ -29,13 +28,13 @@ func (rgrq SetDefNetRequest) Validate() error { return nil } -func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest, options ...opts.DecortOpts) (uint64, error) { +func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) { if err := req.Validate(); err != nil { return 0, err } url := "/cloudapi/rg/setDefNet" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return 0, err } diff --git a/pkg/cloudapi/rg/update.go b/pkg/cloudapi/rg/update.go index 16b2dea..b287fc6 100644 --- a/pkg/cloudapi/rg/update.go +++ b/pkg/cloudapi/rg/update.go @@ -3,10 +3,8 @@ package rg import ( "context" "errors" + "net/http" "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" ) type UpdateRequest struct { @@ -30,13 +28,13 @@ func (rgrq UpdateRequest) Validate() error { return nil } -func (r RG) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) { +func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) { if err := req.Validate(); err != nil { return false, err } url := "/cloudapi/rg/update" - res, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return false, err } diff --git a/pkg/cloudapi/rg/usage.go b/pkg/cloudapi/rg/usage.go index 157802a..98e25a3 100644 --- a/pkg/cloudapi/rg/usage.go +++ b/pkg/cloudapi/rg/usage.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" + "net/http" ) type UsageRequest struct { @@ -22,13 +20,13 @@ func (rgrq UsageRequest) Validate() error { return nil } -func (r RG) Usage(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (*ResourceUsage, error) { +func (r RG) Usage(ctx context.Context, req UpdateRequest) (*ResourceUsage, error) { if err := req.Validate(); err != nil { return nil, err } url := "/cloudapi/rg/usage" - usageRaw, err := r.client.DecortApiCall(ctx, typed.POST, url, req) + usageRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } diff --git a/pkg/cloudapi/sizes.go b/pkg/cloudapi/sizes.go new file mode 100644 index 0000000..59fdfac --- /dev/null +++ b/pkg/cloudapi/sizes.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/sizes" +) + +func (ca *CloudApi) Sizes() *sizes.Sizes { + return sizes.New(ca.client) +} diff --git a/pkg/cloudapi/sizes/list.go b/pkg/cloudapi/sizes/list.go index d3dbea1..2ee4811 100644 --- a/pkg/cloudapi/sizes/list.go +++ b/pkg/cloudapi/sizes/list.go @@ -1,31 +1,29 @@ -package sizes - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - CloudspaceID uint64 `url:"cloudspaceId,omitempty"` - Location string `url:"location,omitempty"` - Page uint64 `url:"page,omitempty"` - Size uint64 `url:"size,omitempty"` -} - -func (s Sizes) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (SizesList, error) { - url := "/cloudapi/sizes/list" - sizesListRaw, err := s.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - sizesList := SizesList{} - if err := json.Unmarshal(sizesListRaw, &sizesList); err != nil { - return nil, err - } - - return sizesList, nil -} +package sizes + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + CloudspaceID uint64 `url:"cloudspaceId,omitempty"` + Location string `url:"location,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (s Sizes) List(ctx context.Context, req ListRequest) (SizesList, error) { + url := "/cloudapi/sizes/list" + sizesListRaw, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + sizesList := SizesList{} + if err := json.Unmarshal(sizesListRaw, &sizesList); err != nil { + return nil, err + } + + return sizesList, nil +} diff --git a/pkg/cloudapi/sizes/models.go b/pkg/cloudapi/sizes/models.go index b787111..e50ee12 100644 --- a/pkg/cloudapi/sizes/models.go +++ b/pkg/cloudapi/sizes/models.go @@ -1,12 +1,12 @@ -package sizes - -type Size struct { - Description string `json:"desc"` - Disks []uint64 `json:"disks"` - ID uint64 `json:"id"` - Memory uint64 `json:"memory"` - Name string `json:"name"` - VCPUs uint64 `json:"vcpus"` -} - -type SizesList []Size +package sizes + +type Size struct { + Description string `json:"desc"` + Disks []uint64 `json:"disks"` + ID uint64 `json:"id"` + Memory uint64 `json:"memory"` + Name string `json:"name"` + VCPUs uint64 `json:"vcpus"` +} + +type SizesList []Size diff --git a/pkg/cloudapi/sizes/sizes.go b/pkg/cloudapi/sizes/sizes.go index d468422..ef63993 100644 --- a/pkg/cloudapi/sizes/sizes.go +++ b/pkg/cloudapi/sizes/sizes.go @@ -1,15 +1,15 @@ -package sizes - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Sizes struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Sizes { - return &Sizes{ - client, - } -} +package sizes + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Sizes struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Sizes { + return &Sizes{ + client, + } +} diff --git a/pkg/cloudapi/tasks.go b/pkg/cloudapi/tasks.go new file mode 100644 index 0000000..100ee71 --- /dev/null +++ b/pkg/cloudapi/tasks.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/tasks" +) + +func (ca *CloudApi) Tasks() *tasks.Tasks { + return tasks.New(ca.client) +} diff --git a/pkg/cloudapi/tasks/get.go b/pkg/cloudapi/tasks/get.go index 10ed453..3f9bf83 100644 --- a/pkg/cloudapi/tasks/get.go +++ b/pkg/cloudapi/tasks/get.go @@ -1,54 +1,45 @@ -package tasks - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - AuditId string `url:"auditId"` -} - -func (trq GetRequest) Validate() error { - if trq.AuditId == "" { - return errors.New("validation-error: field AuditId can not be empty") - } - - return nil -} - -func (t Tasks) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AsyncTask, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/tasks/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - taskRaw, err := t.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - task := &AsyncTask{} - err = json.Unmarshal(taskRaw, task) - if err != nil { - return nil, err - } - - return task, nil - -} +package tasks + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + AuditID string `url:"auditId"` +} + +func (trq GetRequest) Validate() error { + if trq.AuditID == "" { + return errors.New("validation-error: field AuditID can not be empty") + } + + return nil +} + +func (t Tasks) Get(ctx context.Context, req GetRequest) (*AsyncTask, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/tasks/get" + prefix := "/cloudapi" + + url = prefix + url + taskRaw, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + task := &AsyncTask{} + err = json.Unmarshal(taskRaw, task) + if err != nil { + return nil, err + } + + return task, nil + +} diff --git a/pkg/cloudapi/tasks/list.go b/pkg/cloudapi/tasks/list.go index 4c89c66..da77644 100644 --- a/pkg/cloudapi/tasks/list.go +++ b/pkg/cloudapi/tasks/list.go @@ -1,41 +1,32 @@ -package tasks - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (t Tasks) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (TasksList, error) { - url := "/tasks/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - taskListRaw, err := t.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - taskList := TasksList{} - err = json.Unmarshal(taskListRaw, &taskList) - if err != nil { - return nil, err - } - - return taskList, nil - -} +package tasks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (t Tasks) List(ctx context.Context, req ListRequest) (TasksList, error) { + url := "/tasks/list" + prefix := "/cloudapi" + + url = prefix + url + taskListRaw, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + taskList := TasksList{} + err = json.Unmarshal(taskListRaw, &taskList) + if err != nil { + return nil, err + } + + return taskList, nil + +} diff --git a/pkg/cloudapi/tasks/models.go b/pkg/cloudapi/tasks/models.go index acc4ee7..157aec6 100644 --- a/pkg/cloudapi/tasks/models.go +++ b/pkg/cloudapi/tasks/models.go @@ -1,51 +1,51 @@ -package tasks - -import ( - "encoding/json" - "fmt" - "strconv" -) - -type TaskResult int - -func (r *TaskResult) UnmarshalJSON(b []byte) error { - if b[0] == '"' { - b := b[1 : len(b)-1] - if len(b) == 0 { - *r = 0 - return nil - } - n, err := strconv.Atoi(string(b)) - if err != nil { - return err - } - *r = TaskResult(n) - } else if b[0] == '[' { - res := []interface{}{} - if err := json.Unmarshal(b, &res); err != nil { - return err - } - if n, ok := res[0].(float64); ok { - *r = TaskResult(n) - } else { - return fmt.Errorf("could not unmarshal %v into int", res[0]) - } - } - - return nil -} - -//AsyncTask represents a long task completion status -type AsyncTask struct { - AuditID string `json:"auditId"` - Completed bool `json:"completed"` - Error string `json:"error"` - Log []string `json:"log"` - Result TaskResult `json:"result"` - Stage string `json:"stage"` - Status string `json:"status"` - UpdateTime uint64 `json:"updateTime"` - UpdatedTime uint64 `json:"updatedTime"` -} - -type TasksList []AsyncTask +package tasks + +import ( + "encoding/json" + "fmt" + "strconv" +) + +type TaskResult int + +func (r *TaskResult) UnmarshalJSON(b []byte) error { + if b[0] == '"' { + b := b[1 : len(b)-1] + if len(b) == 0 { + *r = 0 + return nil + } + n, err := strconv.Atoi(string(b)) + if err != nil { + return err + } + *r = TaskResult(n) + } else if b[0] == '[' { + res := []interface{}{} + if err := json.Unmarshal(b, &res); err != nil { + return err + } + if n, ok := res[0].(float64); ok { + *r = TaskResult(n) + } else { + return fmt.Errorf("could not unmarshal %v into int", res[0]) + } + } + + return nil +} + +//AsyncTask represents a long task completion status +type AsyncTask struct { + AuditID string `json:"auditId"` + Completed bool `json:"completed"` + Error string `json:"error"` + Log []string `json:"log"` + Result TaskResult `json:"result"` + Stage string `json:"stage"` + Status string `json:"status"` + UpdateTime uint64 `json:"updateTime"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type TasksList []AsyncTask diff --git a/pkg/cloudapi/tasks/tasks.go b/pkg/cloudapi/tasks/tasks.go index e901ece..9c0b5ff 100644 --- a/pkg/cloudapi/tasks/tasks.go +++ b/pkg/cloudapi/tasks/tasks.go @@ -1,15 +1,15 @@ -package tasks - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Tasks struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Tasks { - return &Tasks{ - client, - } -} +package tasks + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type Tasks struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Tasks { + return &Tasks{ + client, + } +} diff --git a/pkg/cloudapi/vins.go b/pkg/cloudapi/vins.go new file mode 100644 index 0000000..9b25f5e --- /dev/null +++ b/pkg/cloudapi/vins.go @@ -0,0 +1,9 @@ +package cloudapi + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/vins" +) + +func (ca *CloudApi) VINS() *vins.VINS { + return vins.New(ca.client) +} diff --git a/pkg/cloudapi/vins/audits.go b/pkg/cloudapi/vins/audits.go index 58e2b32..986fdc4 100644 --- a/pkg/cloudapi/vins/audits.go +++ b/pkg/cloudapi/vins/audits.go @@ -1,54 +1,43 @@ -package vins - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type AuditsRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq AuditsRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (VinsAuditsList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/vins/audits" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - auditsRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - audits := VinsAuditsList{} - - err = json.Unmarshal([]byte(auditsRaw), &audits) - if err != nil { - return nil, err - } - - return audits, nil -} +package vins + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AuditsRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq AuditsRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) Audits(ctx context.Context, req AuditsRequest) (VINSAuditsList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/vins/audits" + + auditsRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + audits := VINSAuditsList{} + + err = json.Unmarshal(auditsRaw, &audits) + if err != nil { + return nil, err + } + + return audits, nil +} diff --git a/pkg/cloudapi/vins/create_in_account.go b/pkg/cloudapi/vins/create_in_account.go index 27521a9..bcccb3f 100644 --- a/pkg/cloudapi/vins/create_in_account.go +++ b/pkg/cloudapi/vins/create_in_account.go @@ -1,61 +1,50 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateInAccountRequest struct { - Name string `url:"name"` - AccountId uint64 `url:"accountId"` - GID uint64 `url:"gid,omitempty"` - IPCidr string `url:"ipcidr,omitempty"` - Description string `url:"desc,omitempty"` - PreReservationsNum uint `url:"preReservationsNum,omitempty"` -} - -func (vrq CreateInAccountRequest) Validate() error { - if vrq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if vrq.AccountId == 0 { - return errors.New("validation-error: field AccountId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) CreateInAccount(ctx context.Context, req CreateInAccountRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/vins/createInAccount" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateInAccountRequest struct { + Name string `url:"name"` + AccountID uint64 `url:"accountId"` + GID uint64 `url:"gid,omitempty"` + IPCidr string `url:"ipcidr,omitempty"` + Description string `url:"desc,omitempty"` + PreReservationsNum uint `url:"preReservationsNum,omitempty"` +} + +func (vrq CreateInAccountRequest) Validate() error { + if vrq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if vrq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/vins/createInAccount" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/vins/create_in_rg.go b/pkg/cloudapi/vins/create_in_rg.go index 2fcc743..5aeed61 100644 --- a/pkg/cloudapi/vins/create_in_rg.go +++ b/pkg/cloudapi/vins/create_in_rg.go @@ -1,62 +1,51 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type CreateInRGRequest struct { - Name string `url:"name"` - RGID uint64 `url:"rgId"` - IPCidr string `url:"ipcidr,omitempty"` - ExtNetId uint64 `url:"extNetId,omitempty"` - ExtIP string `url:"extIp,omitempty"` - Description string `url:"desc,omitempty"` - PreReservationsNum uint `url:"preReservationsNum,omitempty"` -} - -func (vrq CreateInRGRequest) Validate() error { - if vrq.Name == "" { - return errors.New("validation-error: field Name can not be empty") - } - - if vrq.RGID == 0 { - return errors.New("validation-error: field RGID can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) CreateInRG(ctx context.Context, req CreateInRGRequest, options ...opts.DecortOpts) (uint64, error) { - err := req.Validate() - if err != nil { - return 0, err - } - - url := "/vins/createInRG" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return 0, err - } - - result, err := strconv.ParseUint(string(res), 10, 64) - if err != nil { - return 0, err - } - - return result, nil -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateInRGRequest struct { + Name string `url:"name"` + RGID uint64 `url:"rgId"` + IPCidr string `url:"ipcidr,omitempty"` + ExtNetID uint64 `url:"extNetId,omitempty"` + ExtIP string `url:"extIp,omitempty"` + Description string `url:"desc,omitempty"` + PreReservationsNum uint `url:"preReservationsNum,omitempty"` +} + +func (vrq CreateInRGRequest) Validate() error { + if vrq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if vrq.RGID == 0 { + return errors.New("validation-error: field RGID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudapi/vins/createInRG" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudapi/vins/delete.go b/pkg/cloudapi/vins/delete.go index 1722301..3a1a55b 100644 --- a/pkg/cloudapi/vins/delete.go +++ b/pkg/cloudapi/vins/delete.go @@ -1,54 +1,43 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DeleteRequest struct { - VinsId uint64 `url:"vinsId"` - Force bool `url:"force"` - Permanently bool `url:"permanently"` -} - -func (vrq DeleteRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/delete" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + VINSID uint64 `url:"vinsId"` + Force bool `url:"force"` + Permanently bool `url:"permanently"` +} + +func (vrq DeleteRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/delete" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/vins/disable_enable.go b/pkg/cloudapi/vins/disable_enable.go index fda9f7a..c0aa12d 100644 --- a/pkg/cloudapi/vins/disable_enable.go +++ b/pkg/cloudapi/vins/disable_enable.go @@ -1,84 +1,64 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type DisableEnableRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq DisableEnableRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) Disable(ctx context.Context, req DisableEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/disable" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} - -func (v Vins) Enable(ctx context.Context, req DisableEnableRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/enable" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisableEnableRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq DisableEnableRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/disable" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} + +func (v VINS) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/enable" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/extnet_connect.go b/pkg/cloudapi/vins/extnet_connect.go index 0540aff..806e365 100644 --- a/pkg/cloudapi/vins/extnet_connect.go +++ b/pkg/cloudapi/vins/extnet_connect.go @@ -1,54 +1,43 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ExtNetConnectRequest struct { - VinsId uint64 `url:"vinsId"` - NetId uint64 `url:"netId"` - IP string `url:"ip"` -} - -func (vrq ExtNetConnectRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/extNetConnect" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ExtNetConnectRequest struct { + VINSID uint64 `url:"vinsId"` + NetID uint64 `url:"netId"` + IP string `url:"ip"` +} + +func (vrq ExtNetConnectRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/extNetConnect" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/vins/extnet_disconnect.go b/pkg/cloudapi/vins/extnet_disconnect.go index 73f3c7d..5441ca2 100644 --- a/pkg/cloudapi/vins/extnet_disconnect.go +++ b/pkg/cloudapi/vins/extnet_disconnect.go @@ -1,52 +1,41 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ExtNetDisconnectRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq ExtNetDisconnectRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/extNetDisconnect" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ExtNetDisconnectRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq ExtNetDisconnectRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/extNetDisconnect" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudapi/vins/extnet_list.go b/pkg/cloudapi/vins/extnet_list.go index 362bd75..2a17bde 100644 --- a/pkg/cloudapi/vins/extnet_list.go +++ b/pkg/cloudapi/vins/extnet_list.go @@ -1,49 +1,38 @@ -package vins - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ExtNetListRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq ExtNetListRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) ExtNetList(ctx context.Context, req ExtNetListRequest, options ...opts.DecortOpts) (ExtnetList, error) { - url := "/vins/extNetList" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - extnetListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - extnetList := ExtnetList{} - err = json.Unmarshal(extnetListRaw, &extnetList) - if err != nil { - return nil, err - } - - return extnetList, nil - -} +package vins + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ExtNetListRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq ExtNetListRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ExtNetList, error) { + url := "/cloudapi/vins/extNetList" + + extnetListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + extnetList := ExtNetList{} + err = json.Unmarshal(extnetListRaw, &extnetList) + if err != nil { + return nil, err + } + + return extnetList, nil + +} diff --git a/pkg/cloudapi/vins/get.go b/pkg/cloudapi/vins/get.go index 89296c9..3a3161c 100644 --- a/pkg/cloudapi/vins/get.go +++ b/pkg/cloudapi/vins/get.go @@ -1,55 +1,44 @@ -package vins - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type GetRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq GetRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*VinsDetailed, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/vins/get" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - vins := &VinsDetailed{} - - err = json.Unmarshal(res, vins) - if err != nil { - return nil, err - } - - return vins, nil - -} +package vins + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq GetRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) Get(ctx context.Context, req GetRequest) (*VINSDetailed, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/vins/get" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + VINS := &VINSDetailed{} + + err = json.Unmarshal(res, VINS) + if err != nil { + return nil, err + } + + return VINS, nil + +} diff --git a/pkg/cloudapi/vins/ip_list.go b/pkg/cloudapi/vins/ip_list.go index 671804a..612d641 100644 --- a/pkg/cloudapi/vins/ip_list.go +++ b/pkg/cloudapi/vins/ip_list.go @@ -1,54 +1,43 @@ -package vins - -import ( - "context" - "encoding/json" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type IPListRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq IPListRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) IPList(ctx context.Context, req IPListRequest, options ...opts.DecortOpts) (IPList, error) { - err := req.Validate() - if err != nil { - return nil, err - } - - url := "/vins/ipList" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - ipListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - ipList := IPList{} - err = json.Unmarshal(ipListRaw, &ipList) - if err != nil { - return nil, err - } - - return ipList, nil - -} +package vins + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type IPListRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq IPListRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) IPList(ctx context.Context, req IPListRequest) (IPList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudapi/vins/ipList" + + ipListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + ipList := IPList{} + err = json.Unmarshal(ipListRaw, &ipList) + if err != nil { + return nil, err + } + + return ipList, nil + +} diff --git a/pkg/cloudapi/vins/ip_release.go b/pkg/cloudapi/vins/ip_release.go index 624fa93..4ed1679 100644 --- a/pkg/cloudapi/vins/ip_release.go +++ b/pkg/cloudapi/vins/ip_release.go @@ -1,55 +1,44 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type IPReleaseRequest struct { - VinsId uint64 `url:"vinsId"` - IPAddr string `url:"ipAddr,omitempty"` - MAC string `url:"mac,omitempty"` -} - -func (vrq IPReleaseRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) IPRelese(ctx context.Context, req IPReleaseRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/ipRelease" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type IPReleaseRequest struct { + VINSID uint64 `url:"vinsId"` + IPAddr string `url:"ipAddr,omitempty"` + MAC string `url:"mac,omitempty"` +} + +func (vrq IPReleaseRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) IPRelese(ctx context.Context, req IPReleaseRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/ipRelease" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/ip_reserve.go b/pkg/cloudapi/vins/ip_reserve.go index 8fec954..6cac006 100644 --- a/pkg/cloudapi/vins/ip_reserve.go +++ b/pkg/cloudapi/vins/ip_reserve.go @@ -1,55 +1,44 @@ -package vins - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type IPReserveRequest struct { - VinsId uint64 `url:"vinsId"` - Type string `url:"type"` - IPAddr string `url:"ipAddr,omitempty"` - MAC string `url:"mac,omitempty"` - ComputeId uint64 `url:"computeId,omitempty"` -} - -func (vrq IPReserveRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - if vrq.Type == "" { - return errors.New("validation-error: field Type can not be empty") - } - - return nil -} - -func (v Vins) IPReserve(ctx context.Context, req IPReserveRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/vins/ipReserve" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil - -} +package vins + +import ( + "context" + "errors" + "net/http" +) + +type IPReserveRequest struct { + VINSID uint64 `url:"vinsId"` + Type string `url:"type"` + IPAddr string `url:"ipAddr,omitempty"` + MAC string `url:"mac,omitempty"` + ComputeID uint64 `url:"computeId,omitempty"` +} + +func (vrq IPReserveRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + if vrq.Type == "" { + return errors.New("validation-error: field Type can not be empty") + } + + return nil +} + +func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/vins/ipReserve" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil + +} diff --git a/pkg/cloudapi/vins/list.go b/pkg/cloudapi/vins/list.go index 82f0d47..21af305 100644 --- a/pkg/cloudapi/vins/list.go +++ b/pkg/cloudapi/vins/list.go @@ -1,42 +1,31 @@ -package vins - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListRequest struct { - IncludeDeleted bool `url:"includeDeleted"` - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (v Vins) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (VinsList, error) { - url := "/vins/list" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - vinsList := VinsList{} - err = json.Unmarshal(vinsListRaw, &vinsList) - if err != nil { - return nil, err - } - - return vinsList, nil - -} +package vins + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + IncludeDeleted bool `url:"includeDeleted"` + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (v VINS) List(ctx context.Context, req ListRequest) (VINSList, error) { + url := "/cloudapi/vins/list" + + VINSListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + VINSList := VINSList{} + err = json.Unmarshal(VINSListRaw, &VINSList) + if err != nil { + return nil, err + } + + return VINSList, nil + +} diff --git a/pkg/cloudapi/vins/list_deleted.go b/pkg/cloudapi/vins/list_deleted.go index e3e52c5..67e9c1b 100644 --- a/pkg/cloudapi/vins/list_deleted.go +++ b/pkg/cloudapi/vins/list_deleted.go @@ -1,41 +1,30 @@ -package vins - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type ListDeletedRequest struct { - Page uint64 `url:"page"` - Size uint64 `url:"size"` -} - -func (v Vins) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (VinsList, error) { - url := "/vins/listDeleted" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - vinsList := VinsList{} - err = json.Unmarshal(vinsListRaw, &vinsList) - if err != nil { - return nil, err - } - - return vinsList, nil - -} +package vins + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page"` + Size uint64 `url:"size"` +} + +func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (VINSList, error) { + url := "/cloudapi/vins/listDeleted" + + VINSListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + VINSList := VINSList{} + err = json.Unmarshal(VINSListRaw, &VINSList) + if err != nil { + return nil, err + } + + return VINSList, nil + +} diff --git a/pkg/cloudapi/vins/models.go b/pkg/cloudapi/vins/models.go index f31dd99..a91a718 100644 --- a/pkg/cloudapi/vins/models.go +++ b/pkg/cloudapi/vins/models.go @@ -1,271 +1,271 @@ -package vins - -type VinsRecord struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ExternalIP string `json:"externalIP"` - ID int `json:"id"` - Name string `json:"name"` - Network string `json:"network"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - VXLanID int `json:"vxlanId"` -} - -type VinsList []VinsRecord - -type VinsAudits struct { - Call string `json:"call"` - ResponseTime float64 `json:"responsetime"` - StatusCode int `json:"statuscode"` - Timestamp float64 `json:"timestamp"` - User string `json:"user"` -} - -type VinsAuditsList []VinsAudits - -type VinsExtnet struct { - DefaultGW string `json:"default_gw"` - ExtNetID uint64 `json:"ext_net_id"` - IP string `json:"ip"` - PrefixLen uint `json:"prefixlen"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` -} - -type ExtnetList []VinsExtnet - -type IP struct { - ClientType string `json:"clientType"` - DomainName string `json:"domainname"` - HostName string `json:"hostname"` - IP string `json:"ip"` - MAC string `json:"mac"` - Type string `json:"type"` - VMId uint64 `json:"vmId"` -} - -type IPList []IP - -type VNFDev struct { - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - Capabilities []string `json:"capabilities"` - Config VNFConfig `json:"config"` - ConfigSaved bool `json:"configSaved"` - CustomPreConfig bool `json:"customPrecfg"` - Description string `json:"desc"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - Interfaces VNFInterfaceList `json:"interfaces"` - LockStatus string `json:"lockStatus"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - Vins []uint64 `json:"vins"` -} - -type VNFConfig struct { - MGMT VNFConfigMGMT `json:"mgmt"` - Resources VNFConfigResources `json:"resources"` -} - -type VNFConfigMGMT struct { - IPAddr string `json:"ipaddr"` - Password string `json:"password"` - SSHKey string `json:"sshkey"` - User string `json:"user"` -} - -type VNFConfigResources struct { - CPU uint64 `json:"cpu"` - RAM uint64 `json:"ram"` - StackId uint64 `json:"stackId"` - UUID string `json:"uuid"` -} - -type VNFInterface struct { - ConnId uint64 `json:"connId"` - ConnType string `json:"connType"` - DefGW string `json:"defGw"` - FlipGroupId uint64 `json:"flipgroupId"` - GUID string `json:"guid"` - IPAddress string `json:"ipAddress"` - ListenSSH bool `json:"listenSsh"` - MAC string `json:"mac"` - Name string `json:"name"` - NetId uint64 `json:"netId"` - NetMask uint64 `json:"netMask"` - NetType string `json:"netType"` - PCISlot uint64 `json:"pciSlot"` - QOS QOS `json:"qos"` - Target string `json:"target"` - Type string `json:"type"` - VNFS []uint64 `json:"vnfs"` -} - -type QOS struct { - ERate uint64 `json:"eRate"` - GUID string `json:"guid"` - InBurst uint64 `json:"inBurst"` - InRate uint64 `json:"inRate"` -} - -type VNFInterfaceList []VNFInterface - -type VINSCompute struct { - ID uint64 `json:"id"` - Name string `json:"name"` -} - -type VINSComputeList []VINSCompute - -type VNFS struct { - DHCP DHCP `json:"DHCP"` - GW GW `json:"GW"` - NAT NAT `json:"NAT"` -} - -type NAT struct { - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - CreatedTime uint64 `json:"createdTime"` - Devices Devices `json:"devices"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - LockStatus string `json:"lockStatus"` - Milestones uint64 `json:"milestones"` - OwnerId uint64 `json:"ownerId"` - OwnerType string `json:"ownerType"` - PureVirtual bool `json:"pureVirtual"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` -} - -type NATConfig struct { - NetMask uint64 `json:"netmask"` - Network string `json:"network"` - Rules []interface{} `json:"rules"` -} - -type GW struct { - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - Config GWConfig `json:"config"` - CreatedTime uint64 `json:"createdTime"` - Devices Devices `json:"devices"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - LockStatus string `json:"lockStatus"` - Milestones uint64 `json:"milestones"` - OwnerId uint64 `json:"ownerId"` - OwnerType string `json:"ownerType"` - PureVirtual bool `json:"pureVirtual"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` -} - -type GWConfig struct { - DefaultGW string `json:"default_gw"` - ExtNetId uint64 `json:"ext_net_id"` - ExtNetIp string `json:"ext_net_ip"` - ExtNetMask uint64 `json:"ext_netmask"` - QOS QOS `json:"qos"` -} - -type Devices struct { - Primary DevicePrimary `json:"primary"` -} - -type DevicePrimary struct { - DevId uint64 `json:"devId"` - IFace01 string `json:"iface01"` - IFace02 string `json:"iface02"` -} - -type DHCP struct { - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - Config DHCPConfig `json:"config"` - CreatedTime uint64 `json:"createdTime"` - Devices Devices `json:"devices"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - LockStatus string `json:"lockStatus"` - Milestones uint64 `json:"milestones"` - OwnerId uint64 `json:"ownerId"` - OwnerType string `json:"ownerType"` - PureVirtual bool `json:"pureVirtual"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` -} - -type DHCPConfig struct { - DefaultGW string `json:"default_gw"` - DNS []string `json:"dns"` - IPEnd string `json:"ip_end"` - IPStart string `json:"ip_start"` - Lease uint64 `json:"lease"` - Netmask uint64 `json:"netmask"` - Network string `json:"network"` - Reservations ReservationList `json:"reservations"` -} - -type VinsDetailed struct { - VNFDev VNFDev `json:"VNFDev"` - CKey string `json:"_ckey"` - AccountId uint64 `json:"accountId"` - AccountName string `json:"accountName"` - Computes VINSComputeList `json:"computes"` - DefaultGW string `json:"defaultGW"` - DefaultQOS QOS `json:"defaultQos"` - Description string `json:"desc"` - GID uint64 `json:"gid"` - GUID uint64 `json:"guid"` - ID uint64 `json:"id"` - LockStatus string `json:"lockStatus"` - ManagerId uint64 `json:"managerId"` - ManagerType string `json:"managerType"` - Milestones uint64 `json:"milestones"` - Name string `json:"name"` - NetMask uint64 `json:"netMask"` - Network string `json:"network"` - PreReservaionsNum uint64 `json:"preReservationsNum"` - Redundant bool `json:"redundant"` - RGID uint64 `json:"rgId"` - RGName string `json:"rgName"` - SecVNFDevId uint64 `json:"secVnfDevId"` - Status string `json:"status"` - UserManaged bool `json:"userManaged"` - VNFS VNFS `json:"vnfs"` - VXLanId uint64 `json:"vxlanId"` -} - -type Reservation struct { - ClientType string `json:"clientType"` - Description string `json:"desc"` - DomainName string `json:"domainname"` - HostName string `json:"hostname"` - IP string `json:"ip"` - MAC string `json:"mac"` - Type string `json:"type"` - VMID int `json:"vmId"` -} - -type ReservationList []Reservation +package vins + +type VINSRecord struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID uint64 `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VXLANID uint64 `json:"vxlanId"` +} + +type VINSList []VINSRecord + +type VINSAudits struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode uint64 `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type VINSAuditsList []VINSAudits + +type VINSExtNet struct { + DefaultGW string `json:"default_gw"` + ExtNetID uint64 `json:"ext_net_id"` + IP string `json:"ip"` + PrefixLen uint64 `json:"prefixlen"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` +} + +type ExtNetList []VINSExtNet + +type IP struct { + ClientType string `json:"clientType"` + DomainName string `json:"domainname"` + HostName string `json:"hostname"` + IP string `json:"ip"` + MAC string `json:"mac"` + Type string `json:"type"` + VMID uint64 `json:"vmId"` +} + +type IPList []IP + +type VNFDev struct { + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + Capabilities []string `json:"capabilities"` + Config VNFConfig `json:"config"` + ConfigSaved bool `json:"configSaved"` + CustomPreConfig bool `json:"customPrecfg"` + Description string `json:"desc"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + Interfaces VNFInterfaceList `json:"interfaces"` + LockStatus string `json:"lockStatus"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + VINS []uint64 `json:"vins"` +} + +type VNFConfig struct { + MGMT VNFConfigMGMT `json:"mgmt"` + Resources VNFConfigResources `json:"resources"` +} + +type VNFConfigMGMT struct { + IPAddr string `json:"ipaddr"` + Password string `json:"password"` + SSHKey string `json:"sshkey"` + User string `json:"user"` +} + +type VNFConfigResources struct { + CPU uint64 `json:"cpu"` + RAM uint64 `json:"ram"` + StackID uint64 `json:"stackId"` + UUID string `json:"uuid"` +} + +type VNFInterface struct { + ConnID uint64 `json:"connId"` + ConnType string `json:"connType"` + DefGW string `json:"defGw"` + FlipGroupID uint64 `json:"flipgroupId"` + GUID string `json:"guid"` + IPAddress string `json:"ipAddress"` + ListenSSH bool `json:"listenSsh"` + MAC string `json:"mac"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetMask uint64 `json:"netMask"` + NetType string `json:"netType"` + PCISlot uint64 `json:"pciSlot"` + QOS QOS `json:"qos"` + Target string `json:"target"` + Type string `json:"type"` + VNFS []uint64 `json:"vnfs"` +} + +type QOS struct { + ERate uint64 `json:"eRate"` + GUID string `json:"guid"` + InBurst uint64 `json:"inBurst"` + InRate uint64 `json:"inRate"` +} + +type VNFInterfaceList []VNFInterface + +type VINSCompute struct { + ID uint64 `json:"id"` + Name string `json:"name"` +} + +type VINSComputeList []VINSCompute + +type VNFS struct { + DHCP DHCP `json:"DHCP"` + GW GW `json:"GW"` + NAT NAT `json:"NAT"` +} + +type NAT struct { + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + CreatedTime uint64 `json:"createdTime"` + Devices Devices `json:"devices"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LockStatus string `json:"lockStatus"` + Milestones uint64 `json:"milestones"` + OwnerID uint64 `json:"ownerId"` + OwnerType string `json:"ownerType"` + PureVirtual bool `json:"pureVirtual"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` +} + +type NATConfig struct { + NetMask uint64 `json:"netmask"` + Network string `json:"network"` + Rules []interface{} `json:"rules"` +} + +type GW struct { + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + Config GWConfig `json:"config"` + CreatedTime uint64 `json:"createdTime"` + Devices Devices `json:"devices"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LockStatus string `json:"lockStatus"` + Milestones uint64 `json:"milestones"` + OwnerID uint64 `json:"ownerId"` + OwnerType string `json:"ownerType"` + PureVirtual bool `json:"pureVirtual"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` +} + +type GWConfig struct { + DefaultGW string `json:"default_gw"` + ExtNetID uint64 `json:"ext_net_id"` + ExtNetIP string `json:"ext_net_ip"` + ExtNetMask uint64 `json:"ext_netmask"` + QOS QOS `json:"qos"` +} + +type Devices struct { + Primary DevicePrimary `json:"primary"` +} + +type DevicePrimary struct { + DevID uint64 `json:"devId"` + IFace01 string `json:"iface01"` + IFace02 string `json:"iface02"` +} + +type DHCP struct { + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + Config DHCPConfig `json:"config"` + CreatedTime uint64 `json:"createdTime"` + Devices Devices `json:"devices"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LockStatus string `json:"lockStatus"` + Milestones uint64 `json:"milestones"` + OwnerID uint64 `json:"ownerId"` + OwnerType string `json:"ownerType"` + PureVirtual bool `json:"pureVirtual"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` +} + +type DHCPConfig struct { + DefaultGW string `json:"default_gw"` + DNS []string `json:"dns"` + IPEnd string `json:"ip_end"` + IPStart string `json:"ip_start"` + Lease uint64 `json:"lease"` + Netmask uint64 `json:"netmask"` + Network string `json:"network"` + Reservations ReservationList `json:"reservations"` +} + +type VINSDetailed struct { + VNFDev VNFDev `json:"VNFDev"` + CKey string `json:"_ckey"` + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + Computes VINSComputeList `json:"computes"` + DefaultGW string `json:"defaultGW"` + DefaultQOS QOS `json:"defaultQos"` + Description string `json:"desc"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + LockStatus string `json:"lockStatus"` + ManagerID uint64 `json:"managerId"` + ManagerType string `json:"managerType"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + NetMask uint64 `json:"netMask"` + Network string `json:"network"` + PreReservaionsNum uint64 `json:"preReservationsNum"` + Redundant bool `json:"redundant"` + RGID uint64 `json:"rgId"` + RGName string `json:"rgName"` + SecVNFDevID uint64 `json:"secVnfDevId"` + Status string `json:"status"` + UserManaged bool `json:"userManaged"` + VNFS VNFS `json:"vnfs"` + VXLanID uint64 `json:"vxlanId"` +} + +type Reservation struct { + ClientType string `json:"clientType"` + Description string `json:"desc"` + DomainName string `json:"domainname"` + HostName string `json:"hostname"` + IP string `json:"ip"` + MAC string `json:"mac"` + Type string `json:"type"` + VMID int `json:"vmId"` +} + +type ReservationList []Reservation diff --git a/pkg/cloudapi/vins/nat_rule_add.go b/pkg/cloudapi/vins/nat_rule_add.go index f731e6a..d0acfae 100644 --- a/pkg/cloudapi/vins/nat_rule_add.go +++ b/pkg/cloudapi/vins/nat_rule_add.go @@ -1,70 +1,59 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type NatRuleAddRequest struct { - VinsId uint64 `url:"vinsId"` - IntIP string `url:"intIp "` - IntPort uint `url:"intPort"` - ExtPortStart uint `url:"extPortStart"` - ExtPortEnd uint `url:"extPortEnd,omitempty"` - Proto string `url:"proto"` -} - -func (vrq NatRuleAddRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - if vrq.IntIP == "" { - return errors.New("validation-error: field IntIP can not be empty") - } - - if vrq.IntPort == 0 { - return errors.New("validation-error: field IntPort can not be empty or equal to 0") - } - - if vrq.ExtPortStart == 0 { - return errors.New("validation-error: field ExtPortStart can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) NatRuleAdd(ctx context.Context, req NatRuleAddRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/natRuleAdd" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type NatRuleAddRequest struct { + VINSID uint64 `url:"vinsId"` + IntIP string `url:"intIp "` + IntPort uint `url:"intPort"` + ExtPortStart uint `url:"extPortStart"` + ExtPortEnd uint `url:"extPortEnd,omitempty"` + Proto string `url:"proto"` +} + +func (vrq NatRuleAddRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + if vrq.IntIP == "" { + return errors.New("validation-error: field IntIP can not be empty") + } + + if vrq.IntPort == 0 { + return errors.New("validation-error: field IntPort can not be empty or equal to 0") + } + + if vrq.ExtPortStart == 0 { + return errors.New("validation-error: field ExtPortStart can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) NatRuleAdd(ctx context.Context, req NatRuleAddRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/natRuleAdd" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/nat_rule_del.go b/pkg/cloudapi/vins/nat_rule_del.go index 56b8bc6..5532d3a 100644 --- a/pkg/cloudapi/vins/nat_rule_del.go +++ b/pkg/cloudapi/vins/nat_rule_del.go @@ -1,58 +1,47 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type NatRuleDelRequest struct { - VinsId uint64 `url:"vinsId"` - RuleId uint64 `url:"ruleId"` -} - -func (vrq NatRuleDelRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - if vrq.RuleId == 0 { - return errors.New("validation-error: field RuleId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) NatRuleDel(ctx context.Context, req NatRuleDelRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/natRuleDel" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type NatRuleDelRequest struct { + VINSID uint64 `url:"vinsId"` + RuleID uint64 `url:"ruleId"` +} + +func (vrq NatRuleDelRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + if vrq.RuleID == 0 { + return errors.New("validation-error: field RuleID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) NatRuleDel(ctx context.Context, req NatRuleDelRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/natRuleDel" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/nat_rule_list.go b/pkg/cloudapi/vins/nat_rule_list.go index 53a6c1f..66bd1a0 100644 --- a/pkg/cloudapi/vins/nat_rule_list.go +++ b/pkg/cloudapi/vins/nat_rule_list.go @@ -1,47 +1,36 @@ -package vins - -import ( - "context" - "errors" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type NatRuleListRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq NatRuleListRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) NatRuleList(ctx context.Context, req NatRuleListRequest, options ...opts.DecortOpts) (string, error) { - err := req.Validate() - if err != nil { - return "", err - } - - url := "/vins/natRuleList" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return "", err - } - - return string(res), nil - -} +package vins + +import ( + "context" + "errors" + "net/http" +) + +type NatRuleListRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq NatRuleListRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) NatRuleList(ctx context.Context, req NatRuleListRequest) (string, error) { + err := req.Validate() + if err != nil { + return "", err + } + + url := "/cloudapi/vins/natRuleList" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil + +} diff --git a/pkg/cloudapi/vins/restore.go b/pkg/cloudapi/vins/restore.go index 99cb8e0..8a2b64c 100644 --- a/pkg/cloudapi/vins/restore.go +++ b/pkg/cloudapi/vins/restore.go @@ -1,53 +1,42 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type RestoreRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq RestoreRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/restore" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq RestoreRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/restore" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/search.go b/pkg/cloudapi/vins/search.go index 2695710..e0b0bfb 100644 --- a/pkg/cloudapi/vins/search.go +++ b/pkg/cloudapi/vins/search.go @@ -1,43 +1,32 @@ -package vins - -import ( - "context" - "encoding/json" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type SearchRequest struct { - AccountId uint64 `url:"accountId,omitempty"` - RGID uint64 `url:"rgId,omitempty"` - Name string `url:"name,omitempty"` - ShowAll bool `url:"show_all,omitempty"` -} - -func (v Vins) Search(ctx context.Context, req SearchRequest, options ...opts.DecortOpts) (VinsList, error) { - url := "/vins/search" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return nil, err - } - - vinsList := VinsList{} - err = json.Unmarshal(vinsListRaw, &vinsList) - if err != nil { - return nil, err - } - - return vinsList, nil - -} +package vins + +import ( + "context" + "encoding/json" + "net/http" +) + +type SearchRequest struct { + AccountID uint64 `url:"accountId,omitempty"` + RGID uint64 `url:"rgId,omitempty"` + Name string `url:"name,omitempty"` + ShowAll bool `url:"show_all,omitempty"` +} + +func (v VINS) Search(ctx context.Context, req SearchRequest) (VINSList, error) { + url := "/cloudapi/vins/search" + + VINSListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + VINSList := VINSList{} + err = json.Unmarshal(VINSListRaw, &VINSList) + if err != nil { + return nil, err + } + + return VINSList, nil + +} diff --git a/pkg/cloudapi/vins/vins.go b/pkg/cloudapi/vins/vins.go index 8a639dc..f7bed8f 100644 --- a/pkg/cloudapi/vins/vins.go +++ b/pkg/cloudapi/vins/vins.go @@ -1,15 +1,15 @@ -package vins - -import ( - "github.com/rudecs/decort-sdk/interfaces" -) - -type Vins struct { - client interfaces.Caller -} - -func New(client interfaces.Caller) *Vins { - return &Vins{ - client, - } -} +package vins + +import ( + "github.com/rudecs/decort-sdk/interfaces" +) + +type VINS struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *VINS { + return &VINS{ + client, + } +} diff --git a/pkg/cloudapi/vins/vnfdev_redeploy.go b/pkg/cloudapi/vins/vnfdev_redeploy.go index 518d027..dd58c4d 100644 --- a/pkg/cloudapi/vins/vnfdev_redeploy.go +++ b/pkg/cloudapi/vins/vnfdev_redeploy.go @@ -1,53 +1,42 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type VnfdevRedeployRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq VnfdevRedeployRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) VnfdevRedeploy(ctx context.Context, req VnfdevRedeployRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/vnfdevRedeploy" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type VNFDevRedeployRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq VNFDevRedeployRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/vnfdevRedeploy" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudapi/vins/vnfdev_restart.go b/pkg/cloudapi/vins/vnfdev_restart.go index 9104ca8..105c2b4 100644 --- a/pkg/cloudapi/vins/vnfdev_restart.go +++ b/pkg/cloudapi/vins/vnfdev_restart.go @@ -1,53 +1,42 @@ -package vins - -import ( - "context" - "errors" - "strconv" - - "github.com/rudecs/decort-sdk/opts" - "github.com/rudecs/decort-sdk/typed" -) - -type VnfdevRestartRequest struct { - VinsId uint64 `url:"vinsId"` -} - -func (vrq VnfdevRestartRequest) Validate() error { - if vrq.VinsId == 0 { - return errors.New("validation-error: field VinsId can not be empty or equal to 0") - } - - return nil -} - -func (v Vins) VnfdevRestart(ctx context.Context, req VnfdevRestartRequest, options ...opts.DecortOpts) (bool, error) { - err := req.Validate() - if err != nil { - return false, err - } - - url := "/vins/vnfdevRestart" - prefix := "/cloudapi" - - option := opts.New(options) - - if option != nil { - if option.IsAdmin { - prefix = "/" + option.AdminValue - } - } - url = prefix + url - res, err := v.client.DecortApiCall(ctx, typed.POST, url, req) - if err != nil { - return false, err - } - - result, err := strconv.ParseBool(string(res)) - if err != nil { - return false, nil - } - - return result, nil - -} +package vins + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type VNFDevRestartRequest struct { + VINSID uint64 `url:"vinsId"` +} + +func (vrq VNFDevRestartRequest) Validate() error { + if vrq.VINSID == 0 { + return errors.New("validation-error: field VINSID can not be empty or equal to 0") + } + + return nil +} + +func (v VINS) VNFDevRestart(ctx context.Context, req VNFDevRestartRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudapi/vins/vnfdevRestart" + + res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/account.go b/pkg/cloudbroker/account.go new file mode 100644 index 0000000..e6124b7 --- /dev/null +++ b/pkg/cloudbroker/account.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudbroker/account" +) + +func (cb *CloudBroker) Account() *account.Account { + return account.New(cb.client) +} diff --git a/pkg/cloudbroker/account/account.go b/pkg/cloudbroker/account/account.go new file mode 100644 index 0000000..d3ca99d --- /dev/null +++ b/pkg/cloudbroker/account/account.go @@ -0,0 +1,13 @@ +package account + +import "github.com/rudecs/decort-sdk/interfaces" + +type Account struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Account { + return &Account{ + client: client, + } +} diff --git a/pkg/cloudbroker/account/add_user.go b/pkg/cloudbroker/account/add_user.go new file mode 100644 index 0000000..c4988e2 --- /dev/null +++ b/pkg/cloudbroker/account/add_user.go @@ -0,0 +1,58 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +type AddUserRequest struct { + AccountID uint64 `url:"accountId"` + UserName string `url:"username"` + AccessType string `url:"accesstype"` +} + +func (arq AddUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + if arq.UserName == "" { + return errors.New("validation-error: field UserName can not be empty") + } + + if arq.AccessType == "" { + return errors.New("validation-error: field AccessType can not be empty") + } + + isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"}) + if !isValid { + return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU") + } + + return nil +} + +func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/addUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/audits.go b/pkg/cloudbroker/account/audits.go new file mode 100644 index 0000000..37d4edf --- /dev/null +++ b/pkg/cloudbroker/account/audits.go @@ -0,0 +1,40 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type AuditsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq AuditsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + return nil +} + +func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/account/audits" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + result := AccountAuditsList{} + err = json.Unmarshal(res, &result) + if err != nil { + return nil, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/create.go b/pkg/cloudbroker/account/create.go new file mode 100644 index 0000000..14c1f2a --- /dev/null +++ b/pkg/cloudbroker/account/create.go @@ -0,0 +1,53 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateRequest struct { + Name string `url:"name"` + Username string `url:"username"` + EmailAddress string `url:"emailaddress,omitempty"` + MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"` + SendAccessEmails bool `url:"sendAccessEmails,omitempty"` + GPUUnits uint `url:"gpu_units,omitempty"` +} + +func (arq CreateRequest) Validate() error { + if arq.Name == "" { + return errors.New("validation-error: field Name can not be empty") + } + + if arq.Username == "" { + return errors.New("validation-error: field Username can not be empty") + } + return nil +} + +func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/account/create" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + id, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return id, nil +} diff --git a/pkg/cloudbroker/account/delete.go b/pkg/cloudbroker/account/delete.go new file mode 100644 index 0000000..dd2cba3 --- /dev/null +++ b/pkg/cloudbroker/account/delete.go @@ -0,0 +1,39 @@ +package account + +import ( + "context" + "errors" + "net/http" +) + +type DeleteRequest struct { + AccountID uint64 `url:"accountId"` + Reason string `url:"reason"` + Permanently bool `url:"permanently,omitempty"` +} + +func (arq DeleteRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + return nil +} + +func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/delete" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/account/delete_accounts.go b/pkg/cloudbroker/account/delete_accounts.go new file mode 100644 index 0000000..c19c940 --- /dev/null +++ b/pkg/cloudbroker/account/delete_accounts.go @@ -0,0 +1,39 @@ +package account + +import ( + "context" + "errors" + "net/http" +) + +type DeleteAccountsRequest struct { + AccountsIDs []uint64 `url:"accountIds"` + Reason string `url:"reason"` + Permanently bool `url:"permanently,omitempty"` +} + +func (arq DeleteAccountsRequest) Validate() error { + if arq.AccountsIDs == nil || len(arq.AccountsIDs) == 0 { + return errors.New("validation-error: field AccountIDs must be set") + } + if arq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + return nil +} + +func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/deleteAccounts" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/account/delete_user.go b/pkg/cloudbroker/account/delete_user.go new file mode 100644 index 0000000..39e8e35 --- /dev/null +++ b/pkg/cloudbroker/account/delete_user.go @@ -0,0 +1,45 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteUserRequest struct { + AccountID uint64 `url:"accountId"` + UserName string `url:"username"` + RecursiveDelete bool `url:"recursivedelete,omitempty"` +} + +func (arq DeleteUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.UserName == "" { + return errors.New("validation-error: field UserName must be set") + } + + return nil +} + +func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/deleteUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + return result, nil +} diff --git a/pkg/cloudbroker/account/disable.go b/pkg/cloudbroker/account/disable.go new file mode 100644 index 0000000..4e06ad0 --- /dev/null +++ b/pkg/cloudbroker/account/disable.go @@ -0,0 +1,44 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisableRequest struct { + AccountID uint64 `url:"accountId"` + Reason string `url:"reason"` +} + +func (arq DisableRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + return nil +} + +func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/disable" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/disable_accounts.go b/pkg/cloudbroker/account/disable_accounts.go new file mode 100644 index 0000000..2c51f15 --- /dev/null +++ b/pkg/cloudbroker/account/disable_accounts.go @@ -0,0 +1,34 @@ +package account + +import ( + "context" + "errors" + "net/http" +) + +type DisableAccountsRequest struct { + AccountIDs []uint64 `url:"accountIds,omitempty"` +} + +func (arq DisableAccountsRequest) Validate() error { + if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 { + return errors.New("validation-error: field AccountIDs must be set") + } + return nil +} + +func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/disableAccounts" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/account/enable.go b/pkg/cloudbroker/account/enable.go new file mode 100644 index 0000000..77b38b7 --- /dev/null +++ b/pkg/cloudbroker/account/enable.go @@ -0,0 +1,44 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EnableRequest struct { + AccountID uint64 `url:"accountId"` + Reason string `url:"reason"` +} + +func (arq EnableRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.Reason == "" { + return errors.New("field Reason must be set") + } + return nil +} + +func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/enable" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/enable_accounts.go b/pkg/cloudbroker/account/enable_accounts.go new file mode 100644 index 0000000..328c248 --- /dev/null +++ b/pkg/cloudbroker/account/enable_accounts.go @@ -0,0 +1,34 @@ +package account + +import ( + "context" + "errors" + "net/http" +) + +type EnableAccountsRequest struct { + AccountIDs []uint64 `url:"accountIds"` +} + +func (arq EnableAccountsRequest) Validate() error { + if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 { + return errors.New("validation-error: field AccountIDs must be set") + } + return nil +} + +func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/enableAccounts" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/pkg/cloudbroker/account/get.go b/pkg/cloudbroker/account/get.go new file mode 100644 index 0000000..c75a1de --- /dev/null +++ b/pkg/cloudbroker/account/get.go @@ -0,0 +1,41 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq GetRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + return nil +} + +func (a Account) Get(ctx context.Context, req GetRequest) (GetResponse, error) { + err := req.Validate() + if err != nil { + return GetResponse{}, err + } + + url := "/cloudbroker/account/get" + + result := GetResponse{} + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return GetResponse{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return GetResponse{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list.go b/pkg/cloudbroker/account/list.go new file mode 100644 index 0000000..61a1225 --- /dev/null +++ b/pkg/cloudbroker/account/list.go @@ -0,0 +1,28 @@ +package account + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (a Account) List(ctx context.Context, req ListRequest) (ListInfoResponse, error) { + url := "/cloudbroker/account/list" + + result := ListInfoResponse{} + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListInfoResponse{}, err + } + err = json.Unmarshal(res, &result) + if err != nil { + return ListInfoResponse{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list_computes.go b/pkg/cloudbroker/account/list_computes.go new file mode 100644 index 0000000..e698498 --- /dev/null +++ b/pkg/cloudbroker/account/list_computes.go @@ -0,0 +1,43 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListComputesRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListComputesRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { + err := req.Validate() + if err != nil { + return ListComputes{}, err + } + + url := "/cloudbroker/account/listComputes" + + result := ListComputes{} + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListComputes{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListComputes{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list_deleted.go b/pkg/cloudbroker/account/list_deleted.go new file mode 100644 index 0000000..6e7b5ee --- /dev/null +++ b/pkg/cloudbroker/account/list_deleted.go @@ -0,0 +1,29 @@ +package account + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListDeletedRequest struct { + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListInfoResponse, error) { + url := "/cloudbroker/account/listDeleted" + + result := ListInfoResponse{} + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListInfoResponse{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListInfoResponse{}, err + } + + return result, err +} diff --git a/pkg/cloudbroker/account/list_disks.go b/pkg/cloudbroker/account/list_disks.go new file mode 100644 index 0000000..f31328f --- /dev/null +++ b/pkg/cloudbroker/account/list_disks.go @@ -0,0 +1,43 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListDisksRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListDisksRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) { + err := req.Validate() + if err != nil { + return ListDisks{}, err + } + + url := "/cloudbroker/account/listDisks" + + result := ListDisks{} + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListDisks{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListDisks{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list_flip_groups.go b/pkg/cloudbroker/account/list_flip_groups.go new file mode 100644 index 0000000..2de4daf --- /dev/null +++ b/pkg/cloudbroker/account/list_flip_groups.go @@ -0,0 +1,43 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListFlipGroupsRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListFlipGroupsRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (ListFlipGroups, error) { + err := req.Validate() + if err != nil { + return ListFlipGroups{}, err + } + + url := "/cloudbroker/account/listFlipGroups" + + result := ListFlipGroups{} + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListFlipGroups{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListFlipGroups{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list_rg.go b/pkg/cloudbroker/account/list_rg.go new file mode 100644 index 0000000..4b6b881 --- /dev/null +++ b/pkg/cloudbroker/account/list_rg.go @@ -0,0 +1,43 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListRGRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListRGRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) { + err := req.Validate() + if err != nil { + return ListRG{}, err + } + + url := "/cloudbroker/account/listRG" + + result := ListRG{} + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListRG{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListRG{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/list_vins.go b/pkg/cloudbroker/account/list_vins.go new file mode 100644 index 0000000..d38e876 --- /dev/null +++ b/pkg/cloudbroker/account/list_vins.go @@ -0,0 +1,43 @@ +package account + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListVINSRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (arq ListVINSRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { + err := req.Validate() + if err != nil { + return ListVINS{}, err + } + + url := "/cloudbroker/account/listVins" + + result := ListVINS{} + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return ListVINS{}, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return ListVINS{}, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/models.go b/pkg/cloudbroker/account/models.go new file mode 100644 index 0000000..32083ff --- /dev/null +++ b/pkg/cloudbroker/account/models.go @@ -0,0 +1,214 @@ +package account + +type AccountAudit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode uint64 `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type AccountAuditsList []AccountAudit + +type Resources struct { + Current Current `json:"Current"` + Reserved Reserved `json:"Reserved"` +} + +type Current struct { + CPU uint64 `json:"cpu"` + DiskSize uint64 `json:"disksize"` + ExtIPs uint64 `json:"extips"` + ExtTraffic uint64 `json:"exttraffic"` + GPU uint64 `json:"gpu"` + RAM uint64 `json:"ram"` +} + +type Reserved struct { + CPU uint64 `json:"cpu"` + DiskSize uint64 `json:"disksize"` + ExtIPs uint64 `json:"extips"` + ExtTraffic uint64 `json:"exttraffic"` + GPU uint64 `json:"gpu"` + RAM uint64 `json:"ram"` +} + +type ACL struct { + Explicit bool `json:"explicit"` + GUID string `json:"guid"` + Right string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UserGroupID string `json:"userGroupId"` +} + +type ResourceLimits struct { + CuC float64 `json:"CU_C"` + CuD float64 `json:"CU_D"` + CuI float64 `json:"CU_I"` + CuM float64 `json:"CU_M"` + CuNP float64 `json:"CU_NP"` + GPUUnits float64 `json:"gpu_units"` +} + +type InfoResponse struct { + DCLocation string `json:"DCLocation"` + CKey string `json:"_ckey"` + ACL []ACL `json:"acl"` + Company string `json:"company"` + CompanyURL string `json:"companyurl"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeactivationTime float64 `json:"deactivationTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + DisplayName string `json:"displayname"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + Name string `json:"name"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + SendAccessEmails bool `json:"sendAccessEmails"` + Status string `json:"status"` + UpdatedTime uint64 `json:"updatedTime"` + Version uint64 `json:"version"` + VINS []uint64 `json:"vins"` +} +type GetResponse struct { + Resources Resources `json:"Resources"` + InfoResponse +} + +type ListInfoResponse []struct { + Meta []interface{} `json:"_meta"` + InfoResponse +} + +type ListComputes []Compute +type Compute struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + CPUs uint64 `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ID uint64 `json:"id"` + Name string `json:"name"` + RAM uint64 `json:"ram"` + Registered bool `json:"registered"` + RgID uint64 `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TotalDisksSize uint64 `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + VINSConnected uint64 `json:"vinsConnected"` +} + +type ListDisks []Disk + +type Disk struct { + ID uint64 `json:"id"` + Name string `json:"name"` + Pool string `json:"pool"` + SepID uint64 `json:"sepId"` + SizeMax uint64 `json:"sizeMax"` + Type string `json:"type"` +} + +type ListFlipGroups []FlipGroup + +type FlipGroup struct { + AccountID uint64 `json:"accountId"` + ClientType string `json:"clientType"` + ConnType string `json:"connType"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefaultGW string `json:"defaultGW"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + Gid uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + IP string `json:"ip"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + NetID uint64 `json:"netId"` + NetType string `json:"netType"` + Netmask uint64 `json:"netmask"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type Computes struct { + Started uint64 `json:"Started"` + Stopped uint64 `json:"Stopped"` +} + +type Consumed struct { + CPU uint64 `json:"cpu"` + DiskSize uint64 `json:"disksize"` + ExtIPs uint64 `json:"extips"` + ExtTraffic uint64 `json:"exttraffic"` + GPU uint64 `json:"gpu"` + RAM uint64 `json:"ram"` +} + +type Limits struct { + CPU int64 `json:"cpu"` + DiskSize int64 `json:"disksize"` + ExtIPs int64 `json:"extips"` + ExtTraffic int64 `json:"exttraffic"` + GPU int64 `json:"gpu"` + RAM int64 `json:"ram"` +} + +type RGResuorces struct { + Consumed Consumed `json:"Consumed"` + Limits Limits `json:"Limits"` + Reserved Reserved `json:"Reserved"` +} + +type RG struct { + Computes Computes `json:"Computes"` + Resources RGResuorces `json:"Resources"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ID uint64 `json:"id"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + VINSes uint64 `json:"vinses"` +} + +type ListRG []RG + +type VINS struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + Computes uint64 `json:"computes"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID uint64 `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + PriVnfDevID uint64 `json:"priVnfDevId"` + RgID uint64 `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type ListVINS []VINS diff --git a/pkg/cloudbroker/account/restore.go b/pkg/cloudbroker/account/restore.go new file mode 100644 index 0000000..a4ffa4f --- /dev/null +++ b/pkg/cloudbroker/account/restore.go @@ -0,0 +1,39 @@ +package account + +import ( + "context" + "errors" + "net/http" +) + +type RestoreRequest struct { + AccountID uint64 `url:"accountId"` + Reason string `url:"reason"` +} + +func (arq RestoreRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + + return nil +} + +func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/restore" + + _, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + return true, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/account/update.go b/pkg/cloudbroker/account/update.go new file mode 100644 index 0000000..e84da49 --- /dev/null +++ b/pkg/cloudbroker/account/update.go @@ -0,0 +1,52 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateRequest struct { + AccountID uint64 `url:"accountId"` + Name string `url:"name"` + MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"` + MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"` + MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"` + MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"` + MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"` + SendAccessEmails bool `url:"sendAccessEmails,omitempty"` + GPUUnits uint64 `url:"gpu_units,omitempty"` +} + +func (arq UpdateRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + + return nil +} + +func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/update" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/account/update_user.go b/pkg/cloudbroker/account/update_user.go new file mode 100644 index 0000000..ac689ce --- /dev/null +++ b/pkg/cloudbroker/account/update_user.go @@ -0,0 +1,49 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateUserRequest struct { + AccountID uint64 `url:"accountId"` + UserID string `url:"userId"` + AccessType string `url:"accesstype"` +} + +func (arq UpdateUserRequest) Validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if arq.UserID == "" { + return errors.New("validation-error: field UserID must be set") + } + if arq.AccessType == "" { + return errors.New("validation-error: field AccessType must be set") + } + + return nil +} + +func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/updateUser" + + res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/cloudbroker.go b/pkg/cloudbroker/cloudbroker.go new file mode 100644 index 0000000..bec0e1f --- /dev/null +++ b/pkg/cloudbroker/cloudbroker.go @@ -0,0 +1,13 @@ +package cloudbroker + +import "github.com/rudecs/decort-sdk/interfaces" + +type CloudBroker struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *CloudBroker { + return &CloudBroker{ + client: client, + } +} diff --git a/pkg/cloudbroker/compute.go b/pkg/cloudbroker/compute.go new file mode 100644 index 0000000..24d2b11 --- /dev/null +++ b/pkg/cloudbroker/compute.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/compute" +) + +func (cb *CloudBroker) Compute() *compute.Compute { + return compute.New(cb.client) +} diff --git a/pkg/cloudbroker/computeci.go b/pkg/cloudbroker/computeci.go new file mode 100644 index 0000000..4ea5f28 --- /dev/null +++ b/pkg/cloudbroker/computeci.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/computeci" +) + +func (cb *CloudBroker) ComputeCI() *computeci.ComputeCI { + return computeci.New(cb.client) +} diff --git a/pkg/cloudbroker/disks.go b/pkg/cloudbroker/disks.go new file mode 100644 index 0000000..8d52c45 --- /dev/null +++ b/pkg/cloudbroker/disks.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudbroker/disks" +) + +func (cb *CloudBroker) Disks() *disks.Disks { + return disks.New(cb.client) +} diff --git a/pkg/cloudbroker/disks/create.go b/pkg/cloudbroker/disks/create.go new file mode 100644 index 0000000..71c9965 --- /dev/null +++ b/pkg/cloudbroker/disks/create.go @@ -0,0 +1,64 @@ +package disks + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type CreateRequest struct { + AccountID uint64 `url:"accountId"` + GID uint64 `url:"gid"` + Name string `url:"name"` + Description string `url:"description,omitempty"` + Size uint64 `url:"size,omitempty"` + Type string `url:"type"` + SSDSize uint64 `url:"ssdSize"` + IOPS uint64 `url:"iops,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + Pool string `url:"pool,omitempty"` +} + +func (drq CreateRequest) Validate() error { + if drq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + if drq.GID == 0 { + return errors.New("validation-error: field GID must be set") + } + + if drq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + + validate := validators.StringInSlice(drq.Type, []string{"B", "D", "T"}) + if !validate { + return errors.New("validation-error: field must be B, D or T") + } + + return nil +} + +func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/disks/create" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/disks/delete.go b/pkg/cloudbroker/disks/delete.go new file mode 100644 index 0000000..de0982d --- /dev/null +++ b/pkg/cloudbroker/disks/delete.go @@ -0,0 +1,44 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + DiskID uint64 `url:"diskId"` + Detach bool `url:"detach,omitempty"` + Permanently bool `url:"permanently,omitempty"` + Reason string `url:"reason,omitempty"` +} + +func (drq DeleteRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + + return nil +} + +func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/delete" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/disks/delete_disks.go b/pkg/cloudbroker/disks/delete_disks.go new file mode 100644 index 0000000..830c8bd --- /dev/null +++ b/pkg/cloudbroker/disks/delete_disks.go @@ -0,0 +1,46 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteDisksRequest struct { + DiskIDS []uint64 `url:"diskIds"` + Reason string `url:"reason"` + Permanently bool `url:"permanently,omitempty"` +} + +func (drq DeleteDisksRequest) Validate() error { + if len(drq.DiskIDS) == 0 { + return errors.New("validation-error: field DiskIDs must be set") + } + if drq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + + return nil +} + +func (d Disks) DeleteDisks(ctx context.Context, req DeleteDisksRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/deleteDisks" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/disks/disks.go b/pkg/cloudbroker/disks/disks.go new file mode 100644 index 0000000..c79853e --- /dev/null +++ b/pkg/cloudbroker/disks/disks.go @@ -0,0 +1,13 @@ +package disks + +import "github.com/rudecs/decort-sdk/interfaces" + +type Disks struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Disks { + return &Disks{ + client: client, + } +} diff --git a/pkg/cloudbroker/disks/get.go b/pkg/cloudbroker/disks/get.go new file mode 100644 index 0000000..0d56856 --- /dev/null +++ b/pkg/cloudbroker/disks/get.go @@ -0,0 +1,43 @@ +package disks + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + DiskID uint64 `url:"diskId"` +} + +func (drq GetRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + + return nil +} + +func (d Disks) Get(ctx context.Context, req GetRequest) (*Disk, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/disks/get" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + disk := Disk{} + + err = json.Unmarshal(res, &disk) + if err != nil { + return nil, err + } + + return &disk, nil +} diff --git a/pkg/cloudbroker/disks/limit_io.go b/pkg/cloudbroker/disks/limit_io.go new file mode 100644 index 0000000..c58744a --- /dev/null +++ b/pkg/cloudbroker/disks/limit_io.go @@ -0,0 +1,55 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type LimitIORequest struct { + DiskID uint64 `url:"diskId"` + IOPS uint64 `url:"iops,omitempty"` + TotalBytesSec uint64 `url:"total_bytes_sec,omitempty"` + ReadBytesSec uint64 `url:"total_bytes_sec,omitempty"` + WriteBytesSec uint64 `url:"write_bytes_sec,omitempty"` + TotalIOPSSec uint64 `url:"total_iops_sec,omitempty"` + ReadIOPSSec uint64 `url:"read_iops_sec,omitempty"` + WriteIOPSSec uint64 `url:"write_iops_sec,omitempty"` + TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty"` + ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty"` + WriteBytesSecMax uint64 `url:"write_bytes_sec_max,omitempty"` + TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"` + ReadIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"` + WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty"` + SizeIOPSSec uint64 `url:"size_iops_sec,omitempty"` +} + +func (drq LimitIORequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + + return nil +} + +func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/limitIO" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/disks/list.go b/pkg/cloudbroker/disks/list.go new file mode 100644 index 0000000..83a4a08 --- /dev/null +++ b/pkg/cloudbroker/disks/list.go @@ -0,0 +1,32 @@ +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + AccountID uint64 `url:"accountId,omitempty"` + Type string `url:"type,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) { + url := "/cloudbroker/disks/list" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + listDisks := ListDisks{} + + err = json.Unmarshal(res, &listDisks) + if err != nil { + return nil, err + } + + return listDisks, nil +} diff --git a/pkg/cloudbroker/disks/list_deleted.go b/pkg/cloudbroker/disks/list_deleted.go new file mode 100644 index 0000000..7e12b4e --- /dev/null +++ b/pkg/cloudbroker/disks/list_deleted.go @@ -0,0 +1,41 @@ +package disks + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListDeletedRequest struct { + AccountID uint64 `url:"accountId"` + Type string `url:"type,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (drq ListDeletedRequest) Validate() error { + if drq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + + return nil +} + +func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) { + url := "/cloudbroker/disks/listDeleted" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + deletedDisks := ListDeletedDisks{} + + err = json.Unmarshal(res, &deletedDisks) + if err != nil { + return nil, err + } + + return deletedDisks, nil +} diff --git a/pkg/cloudbroker/disks/list_types.go b/pkg/cloudbroker/disks/list_types.go new file mode 100644 index 0000000..d9d95a7 --- /dev/null +++ b/pkg/cloudbroker/disks/list_types.go @@ -0,0 +1,30 @@ +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListTypesRequest struct { + Detailed bool `url:"detailed"` +} + +func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) { + url := "/cloudbroker/disks/listTypes" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + typesList := make([]interface{}, 0) + + err = json.Unmarshal(res, &typesList) + if err != nil { + return nil, err + } + + return typesList, nil + +} diff --git a/pkg/cloudbroker/disks/list_unattached.go b/pkg/cloudbroker/disks/list_unattached.go new file mode 100644 index 0000000..7cba2cb --- /dev/null +++ b/pkg/cloudbroker/disks/list_unattached.go @@ -0,0 +1,39 @@ +package disks + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListUnattachedRequest struct { + AccountID uint64 `url:"accountId"` +} + +func (drq ListUnattachedRequest) Validate() error { + if drq.AccountID == 0 { + return errors.New("validation-error: field AccountID can not be empty or equal to 0") + } + + return nil +} + +func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattached, error) { + url := "/cloudbroker/disks/listUnattached" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := ListUnattached{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} diff --git a/pkg/cloudbroker/disks/models.go b/pkg/cloudbroker/disks/models.go new file mode 100644 index 0000000..76978b1 --- /dev/null +++ b/pkg/cloudbroker/disks/models.go @@ -0,0 +1,101 @@ +package disks + +type IOTune struct { + ReadBytesSec uint64 `json:"read_bytes_sec"` + ReadBytesSecMax uint64 `json:"read_bytes_sec_max"` + ReadIOPSSec uint64 `json:"read_iops_sec"` + ReadIOPSSecMax uint64 `json:"read_iops_sec_max"` + SizeIOPSSec uint64 `json:"size_iops_sec"` + TotalBytesSec uint64 `json:"total_bytes_sec"` + TotalBytesSecMax uint64 `json:"total_bytes_sec_max"` + TotalIOPSSec uint64 `json:"total_iops_sec"` + TotalIOPSSecMax uint64 `json:"total_iops_sec_max"` + WriteBytesSec uint64 `json:"write_bytes_sec"` + WriteBytesSecMax uint64 `json:"write_bytes_sec_max"` + WriteIOPSSec uint64 `json:"write_iops_sec"` + WriteIOPSSecMax uint64 `json:"write_iops_sec_max"` +} + +type Info struct { + AccountID uint64 `json:"accountId"` + AccountName string `json:"accountName"` + ACL map[string]interface{} `json:"acl"` + BootPartition uint64 `json:"bootPartition"` + CreatedTime uint64 `json:"createdTime"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + DiskPath string `json:"diskPath"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + ImageID uint64 `json:"imageId"` + Images []uint64 `json:"images"` + IOTune IOTune `json:"iotune"` + Iqn string `json:"iqn"` + Login string `json:"login"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Order uint64 `json:"order"` + Params string `json:"params"` + ParentID uint64 `json:"parentId"` + Passwd string `json:"passwd"` + PCISlot int64 `json:"pciSlot"` + Pool string `json:"pool"` + PurgeAttempts uint64 `json:"purgeAttempts"` + PurgeTime uint64 `json:"purgeTime"` + RealityDeviceNumber uint64 `json:"realityDeviceNumber"` + ReferenceID string `json:"referenceId"` + ResID string `json:"resId"` + ResName string `json:"resName"` + Role string `json:"role"` + SepID uint64 `json:"sepId"` + SizeMax uint64 `json:"sizeMax"` + SizeUsed uint64 `json:"sizeUsed"` + Snapshots []Snapshot `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + VMID uint64 `json:"vmid"` +} + +type Disk struct { + DeviceName string `json:"devicename"` + SepType string `json:"sepType"` + Info +} + +type ListDisks []struct { + ComputeID uint64 `json:"computeId"` + ComputeName string `json:"computeName"` + MachineID uint64 `json:"machineId"` + MachineName string `json:"machineName"` + Disk +} + +type ListDeletedDisks []struct { + ComputeID uint64 `json:"computeId"` + ComputeName string `json:"computeName"` + MachineID uint64 `json:"machineId"` + MachineName string `json:"machineName"` + Disk + UpdatedBy uint64 `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type ListUnattached []struct { + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + Info + UpdatedBy uint64 `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type Snapshot struct { + GUID string `json:"guid"` + Label string `json:"label"` + ResID string `json:"resId"` + SnapSetGUID string `json:"snapSetGuid"` + SnapSetTime uint64 `json:"snapSetTime"` + Timestamp uint64 `json:"timestamp"` +} diff --git a/pkg/cloudbroker/disks/rename.go b/pkg/cloudbroker/disks/rename.go new file mode 100644 index 0000000..2e6f499 --- /dev/null +++ b/pkg/cloudbroker/disks/rename.go @@ -0,0 +1,47 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RenameRequest struct { + DiskID uint64 `url:"diskId"` + Name string `url:"name"` +} + +func (drq RenameRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + + if drq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + + return nil +} + +func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/rename" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/disks/resize.go b/pkg/cloudbroker/disks/resize.go new file mode 100644 index 0000000..141dbbf --- /dev/null +++ b/pkg/cloudbroker/disks/resize.go @@ -0,0 +1,67 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ResizeRequest struct { + DiskID uint64 `url:"diskId"` + Size uint64 `url:"size"` +} + +func (drq ResizeRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + if drq.Size == 0 { + return errors.New("validation-error: field Size must be set") + } + return nil +} + +func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/resize" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} + +func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/resize2" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/disks/restore.go b/pkg/cloudbroker/disks/restore.go new file mode 100644 index 0000000..1fbf982 --- /dev/null +++ b/pkg/cloudbroker/disks/restore.go @@ -0,0 +1,46 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RestoreRequest struct { + DiskID uint64 `url:"diskId"` + Reason string `url:"reason"` +} + +func (drq RestoreRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + if drq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + + return nil +} + +func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/restore" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/disks/search.go b/pkg/cloudbroker/disks/search.go new file mode 100644 index 0000000..8f39aaf --- /dev/null +++ b/pkg/cloudbroker/disks/search.go @@ -0,0 +1,34 @@ +package disks + +import ( + "context" + "encoding/json" + "net/http" +) + +type SearchRequest struct { + AccountID uint64 `url:"accountId,omitempty"` + Name string `url:"name,omitempty"` + ShowAll bool `url:"show_all,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) { + url := "/cloudbroker/disks/search" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + diskList := ListDisks{} + + err = json.Unmarshal(res, &diskList) + if err != nil { + return nil, err + } + + return diskList, nil + +} diff --git a/pkg/cloudbroker/disks/snapshot_delete.go b/pkg/cloudbroker/disks/snapshot_delete.go new file mode 100644 index 0000000..03de522 --- /dev/null +++ b/pkg/cloudbroker/disks/snapshot_delete.go @@ -0,0 +1,46 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotDeleteRequest struct { + DiskID uint64 `url:"diskId"` + Label string `url:"label"` +} + +func (drq SnapshotDeleteRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + if drq.Label == "" { + return errors.New("validation-error: field Label must be set") + } + + return nil +} + +func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/snapshotDelete" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/disks/snapshot_rollback.go b/pkg/cloudbroker/disks/snapshot_rollback.go new file mode 100644 index 0000000..4908b6d --- /dev/null +++ b/pkg/cloudbroker/disks/snapshot_rollback.go @@ -0,0 +1,50 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type SnapshotRollbackRequest struct { + DiskID uint64 `url:"diskId"` + Label string `url:"label"` + TimeStamp uint64 `url:"timestamp"` +} + +func (drq SnapshotRollbackRequest) Validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID must be set") + } + if drq.Label == "" { + return errors.New("validation-error: field Label must be set") + } + if drq.TimeStamp == 0 { + return errors.New("validation-error: field TimeStamp must be set") + } + + return nil +} + +func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/disks/snapshotRollback" + + res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil + +} diff --git a/pkg/cloudbroker/extnet.go b/pkg/cloudbroker/extnet.go new file mode 100644 index 0000000..7eac5ff --- /dev/null +++ b/pkg/cloudbroker/extnet.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/extnet" +) + +func (cb *CloudBroker) ExtNet() *extnet.ExtNet { + return extnet.New(cb.client) +} diff --git a/pkg/cloudbroker/flipgroup.go b/pkg/cloudbroker/flipgroup.go new file mode 100644 index 0000000..a484324 --- /dev/null +++ b/pkg/cloudbroker/flipgroup.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup" +) + +func (cb *CloudBroker) FlipGroup() *flipgroup.FlipGroup { + return flipgroup.New(cb.client) +} diff --git a/pkg/cloudbroker/image.go b/pkg/cloudbroker/image.go new file mode 100644 index 0000000..56cb856 --- /dev/null +++ b/pkg/cloudbroker/image.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudbroker/image" +) + +func (cb *CloudBroker) Image() *image.Image { + return image.New(cb.client) +} diff --git a/pkg/cloudbroker/image/computeci_set.go b/pkg/cloudbroker/image/computeci_set.go new file mode 100644 index 0000000..489150d --- /dev/null +++ b/pkg/cloudbroker/image/computeci_set.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ComputeCISetRequest struct { + ImageID uint64 `url:"imageId"` + ComputeCIID uint64 `url:"computeciId"` +} + +func (irq ComputeCISetRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + if irq.ComputeCIID == 0 { + return errors.New("validation-error: field ComputeCIID must be set") + } + + return nil +} + +func (i Image) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/computeciSet" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/computeci_unset.go b/pkg/cloudbroker/image/computeci_unset.go new file mode 100644 index 0000000..7fb85ef --- /dev/null +++ b/pkg/cloudbroker/image/computeci_unset.go @@ -0,0 +1,41 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ComputeCIUnsetRequest struct { + ImageID uint64 `url:"imageId"` +} + +func (irq ComputeCIUnsetRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/сomputeciUnset" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/create_cdrom_image.go b/pkg/cloudbroker/image/create_cdrom_image.go new file mode 100644 index 0000000..e44efb7 --- /dev/null +++ b/pkg/cloudbroker/image/create_cdrom_image.go @@ -0,0 +1,68 @@ +package image + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type CreateCDROMImageRequest struct { + Name string `url:"name"` + URL string `url:"url"` + GID uint64 `url:"gid"` + AccountID uint64 `url:"accountId,omitempty"` + SepID uint64 `url:"sep_id,omitempty"` + PoolName string `url:"pool_name,omitempty"` + UsernameDL string `url:"usernameDL,omitempty"` + PasswordDl string `url:"passwordDL,omitempty"` + Architecture string `url:"architecture,omitempty"` + Drivers []string `url:"drivers"` +} + +func (irq CreateCDROMImageRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if irq.URL == "" { + return errors.New("validation-error: field URL must be set") + } + if irq.GID == 0 { + return errors.New("validation-error: field GID must be set") + } + + if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 { + return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements") + } + + for _, v := range irq.Drivers { + validate := validators.StringInSlice(v, []string{"KVM_X86"}) + if !validate { + return errors.New("validation-error: field Drivers can be KVM_X86 only") + } + } + + return nil +} + +func (i Image) CreateCDROMImage(ctx context.Context, req CreateCDROMImageRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/image/createCDROMImage" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/create_image.go b/pkg/cloudbroker/image/create_image.go new file mode 100644 index 0000000..f8375ef --- /dev/null +++ b/pkg/cloudbroker/image/create_image.go @@ -0,0 +1,78 @@ +package image + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type CreateRequest struct { + Name string `url:"name"` + URL string `url:"url"` + GID uint64 `url:"gid"` + BootType string `url:"boottype"` + ImageType string `url:"imagetype"` + HotResize bool `url:"hotresize,omitempty"` + Username string `url:"username,omitempty"` + Password string `url:"password,omitempty"` + AccountID uint64 `url:"accountId,omitempty"` + UsernameDL string `url:"usernameDL,omitempty"` + PasswordDL string `url:"passwordDL,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + PoolName string `url:"poolName,omitempty"` + Architecture string `url:"architecture,omitempty"` + Drivers []string `url:"drivers,omitempty"` + Bootable bool `url:"bootable,omitempty"` +} + +func (irq CreateRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if irq.URL == "" { + return errors.New("validation-error: field URL must be set") + } + if irq.GID == 0 { + return errors.New("validation-error: field GID must be set") + } + if irq.BootType == "" { + return errors.New("validation-error: field BootType must be set") + } + if irq.ImageType == "" { + return errors.New("validation-error: field ImageType must be set") + } + + validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"}) + if !validate { + return errors.New("validation-error: field BootType can be bios or uefi") + } + validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"}) + if !validate { + return errors.New("validation-error: field ImageType can be windows, linux or other") + } + + return nil +} + +func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/image/createImage" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/create_virtual.go b/pkg/cloudbroker/image/create_virtual.go new file mode 100644 index 0000000..48cb3ad --- /dev/null +++ b/pkg/cloudbroker/image/create_virtual.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type CreateVirtualRequest struct { + Name string `url:"name"` + TargetID uint64 `url:"targetId"` +} + +func (irq CreateVirtualRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if irq.TargetID == 0 { + return errors.New("validation-error: field TargetID must be set") + } + + return nil +} + +func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/image/createVirtual" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/delete.go b/pkg/cloudbroker/image/delete.go new file mode 100644 index 0000000..5117cc2 --- /dev/null +++ b/pkg/cloudbroker/image/delete.go @@ -0,0 +1,46 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteRequest struct { + ImageID uint64 `url:"imageId"` + Reason string `url:"reason"` + Permanently bool `url:"permanently,omitempty"` +} + +func (irq DeleteRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + if irq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + + return nil +} + +func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/delete" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/delete_cdrom_image.go b/pkg/cloudbroker/image/delete_cdrom_image.go new file mode 100644 index 0000000..e408ac7 --- /dev/null +++ b/pkg/cloudbroker/image/delete_cdrom_image.go @@ -0,0 +1,42 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteCDROMImageRequest struct { + ImageID uint64 `url:"imageId"` + Permanently bool `url:"permanently"` +} + +func (irq DeleteCDROMImageRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) DeleteCDROMImage(ctx context.Context, req DeleteCDROMImageRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/deleteCDROMImage" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/delete_images.go b/pkg/cloudbroker/image/delete_images.go new file mode 100644 index 0000000..c874af1 --- /dev/null +++ b/pkg/cloudbroker/image/delete_images.go @@ -0,0 +1,46 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DeleteImagesRequest struct { + ImageIDs []uint64 `url:"imageIds"` + Reason string `url:"reason"` + Permanently bool `url:"permanently"` +} + +func (irq DeleteImagesRequest) Validate() error { + if len(irq.ImageIDs) == 0 { + return errors.New("validation-error: field ImageIDs must be set") + } + if irq.Reason == "" { + return errors.New("validation-error: field Reason must be set") + } + + return nil +} + +func (i Image) DeleteImages(ctx context.Context, req DeleteImagesRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/deleteImages" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/disable.go b/pkg/cloudbroker/image/disable.go new file mode 100644 index 0000000..3d4d554 --- /dev/null +++ b/pkg/cloudbroker/image/disable.go @@ -0,0 +1,41 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type DisableRequest struct { + ImageID uint64 `url:"imageId"` +} + +func (irq DisableRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) Disable(ctx context.Context, req DisableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/disable" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/edit.go b/pkg/cloudbroker/image/edit.go new file mode 100644 index 0000000..98d6db0 --- /dev/null +++ b/pkg/cloudbroker/image/edit.go @@ -0,0 +1,47 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EditRequest struct { + ImageID uint64 `url:"imageId"` + Name string `url:"name,omitempty"` + Username string `url:"username,omitempty"` + Password string `url:"password,omitempty"` + AccountID uint64 `url:"accountId,omitempty"` + HotResize bool `url:"hotresize,omitempty"` + Bootable bool `url:"bootable,omitempty"` +} + +func (irq EditRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) Edit(ctx context.Context, req EditRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/edit" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/enable.go b/pkg/cloudbroker/image/enable.go new file mode 100644 index 0000000..5f40897 --- /dev/null +++ b/pkg/cloudbroker/image/enable.go @@ -0,0 +1,41 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type EnableRequest struct { + ImageID uint64 `url:"imageId"` +} + +func (irq EnableRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must br set") + } + + return nil +} + +func (i Image) Enable(ctx context.Context, req EnableRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/enable" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/image/get.go b/pkg/cloudbroker/image/get.go new file mode 100644 index 0000000..08eec36 --- /dev/null +++ b/pkg/cloudbroker/image/get.go @@ -0,0 +1,43 @@ +package image + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type GetRequest struct { + ImageID uint64 `url:"imageId"` +} + +func (irq GetRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) Get(ctx context.Context, req GetRequest) (*ImageRecord, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/image/get" + + result := ImageRecord{} + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + err = json.Unmarshal(res, &result) + if err != nil { + return nil, err + } + + return &result, nil +} diff --git a/pkg/cloudbroker/image/image.go b/pkg/cloudbroker/image/image.go new file mode 100644 index 0000000..bb34ee9 --- /dev/null +++ b/pkg/cloudbroker/image/image.go @@ -0,0 +1,13 @@ +package image + +import "github.com/rudecs/decort-sdk/interfaces" + +type Image struct { + client interfaces.Caller +} + +func New(client interfaces.Caller) *Image { + return &Image{ + client: client, + } +} diff --git a/pkg/cloudbroker/image/link.go b/pkg/cloudbroker/image/link.go new file mode 100644 index 0000000..c08c33b --- /dev/null +++ b/pkg/cloudbroker/image/link.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type LinkRequest struct { + ImageID uint64 `url:"imageId"` + TargetID uint64 `url:"targetId"` +} + +func (irq LinkRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + if irq.TargetID == 0 { + return errors.New("validation-error: field TargetID must be set") + } + + return nil +} + +func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/link" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/image/list.go b/pkg/cloudbroker/image/list.go new file mode 100644 index 0000000..ada25c4 --- /dev/null +++ b/pkg/cloudbroker/image/list.go @@ -0,0 +1,32 @@ +package image + +import ( + "context" + "encoding/json" + "net/http" +) + +type ListRequest struct { + SepID uint64 `url:"sepId,omitempty"` + SharedWith uint64 `url:"sharedWith,omitempty"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) { + url := "/cloudbroker/image/list" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + list := ListImages{} + + err = json.Unmarshal(res, &list) + if err != nil { + return nil, err + } + + return list, nil +} diff --git a/pkg/cloudbroker/image/list_stacks.go b/pkg/cloudbroker/image/list_stacks.go new file mode 100644 index 0000000..c872209 --- /dev/null +++ b/pkg/cloudbroker/image/list_stacks.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "encoding/json" + "errors" + "net/http" +) + +type ListStacksRequest struct { + ImageID uint64 `url:"imageId"` + Page uint64 `url:"page,omitempty"` + Size uint64 `url:"size,omitempty"` +} + +func (irq ListStacksRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStacks, error) { + err := req.Validate() + if err != nil { + return nil, err + } + + url := "/cloudbroker/image/listStacks" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + list := ListStacks{} + + err = json.Unmarshal(res, &list) + if err != nil { + return nil, err + } + + return list, nil +} diff --git a/pkg/cloudbroker/image/models.go b/pkg/cloudbroker/image/models.go new file mode 100644 index 0000000..1b78d8f --- /dev/null +++ b/pkg/cloudbroker/image/models.go @@ -0,0 +1,82 @@ +package image + +type ImageRecord struct { + UNCPath string `json:"UNCPath"` + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + AccountID uint64 `json:"accountId"` + ACL []ACL `json:"acl"` + Architecture string `json:"architecture"` + BootType string `json:"bootType"` + Bootable bool `json:"bootable"` + ComputeCIID uint64 `json:"computeciId"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + Drivers []string `json:"drivers"` + Enabled bool `json:"enabled"` + Gid uint64 `json:"gid"` + GUID uint64 `json:"guid"` + History []History `json:"history"` + HotResize bool `json:"hotResize"` + ID uint64 `json:"id"` + LastModified uint64 `json:"lastModified"` + LinkTo uint64 `json:"linkTo"` + Milestones uint64 `json:"milestones"` + Name string `json:"name"` + Password string `json:"password"` + Pool string `json:"pool"` + ProviderName string `json:"provider_name"` + PurgeAttempts uint64 `json:"purgeAttempts"` + ReferenceID string `json:"referenceId"` + ResID string `json:"resId"` + ResName string `json:"resName"` + RescueCD bool `json:"rescuecd"` + SepID uint64 `json:"sepId"` + SharedWith []uint64 `json:"sharedWith"` + Size uint64 `json:"size"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + URL string `json:"url"` + Username string `json:"username"` + Version string `json:"version"` + Virtual bool `json:"virtual"` +} + +type ListImages []ImageRecord + +type ACL struct { + Explicit bool `json:"explicit"` + GUID string `json:"guid"` + Right string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UserGroupID string `json:"userGroupId"` +} +type History struct { + GUID string `json:"guid"` + ID uint64 `json:"id"` + Timestamp uint64 `json:"timestamp"` +} + +type ListStacks []struct { + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + APIURL string `json:"apiUrl"` + APIKey string `json:"apikey"` + AppID string `json:"appId"` + Desc string `json:"desc"` + Drivers []string `json:"drivers"` + Eco interface{} `json:"eco"` + Error uint64 `json:"error"` + GID uint64 `json:"gid"` + GUID uint64 `json:"guid"` + ID uint64 `json:"id"` + Images []uint64 `json:"images"` + Login string `json:"login"` + Name string `json:"name"` + Passwd string `json:"passwd"` + ReferenceID string `json:"referenceId"` + Status string `json:"status"` + Type string `json:"type"` +} diff --git a/pkg/cloudbroker/image/rename.go b/pkg/cloudbroker/image/rename.go new file mode 100644 index 0000000..e1b42e7 --- /dev/null +++ b/pkg/cloudbroker/image/rename.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type RenameRequest struct { + ImageID uint64 `url:"imageId"` + Name string `url:"name"` +} + +func (irq RenameRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + if irq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + + return nil +} + +func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/rename" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/image/share.go b/pkg/cloudbroker/image/share.go new file mode 100644 index 0000000..ff0e54a --- /dev/null +++ b/pkg/cloudbroker/image/share.go @@ -0,0 +1,45 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type ShareRequest struct { + ImageId uint64 `url:"imageId"` + AccountIDs []uint64 `url:"accounts"` +} + +func (irq ShareRequest) Validate() error { + if irq.ImageId == 0 { + return errors.New("validation-error: field ImageID must be set") + } + if len(irq.AccountIDs) == 0 || irq.AccountIDs == nil { + return errors.New("validation-error: field must be set") + } + + return nil +} + +func (i Image) Share(ctx context.Context, req ShareRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/share" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/image/sync_create_image.go b/pkg/cloudbroker/image/sync_create_image.go new file mode 100644 index 0000000..f55fe83 --- /dev/null +++ b/pkg/cloudbroker/image/sync_create_image.go @@ -0,0 +1,89 @@ +package image + +import ( + "context" + "errors" + "github.com/rudecs/decort-sdk/internal/validators" + "net/http" + "strconv" +) + +type SyncCreateRequest struct { + Name string `url:"name"` + URL string `url:"url"` + GID uint64 `url:"gid"` + BootType string `url:"boottype"` + ImageType string `url:"imagetype"` + HotResize bool `url:"hotresize,omitempty"` + Username string `url:"username,omitempty"` + Password string `url:"password,omitempty"` + AccountID uint64 `url:"accountId,omitempty"` + UsernameDL string `url:"usernameDL,omitempty"` + PasswordDL string `url:"passwordDL,omitempty"` + SepID uint64 `url:"sepId,omitempty"` + PoolName string `url:"poolName,omitempty"` + Architecture string `url:"architecture,omitempty"` + Drivers []string `url:"drivers"` + Bootable bool `url:"bootable,omitempty"` +} + +func (irq SyncCreateRequest) Validate() error { + if irq.Name == "" { + return errors.New("validation-error: field Name must be set") + } + if irq.URL == "" { + return errors.New("validation-error: field URL must be set") + } + if irq.GID == 0 { + return errors.New("validation-error: field GID must be set") + } + if irq.BootType == "" { + return errors.New("validation-error: field BootType must be set") + } + if irq.ImageType == "" { + return errors.New("validation-error: field ImageType must be set") + } + + validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"}) + if !validate { + return errors.New("validation-error: field BootType can be bios or uefi") + } + validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"}) + if !validate { + return errors.New("validation-error: field ImageType can be windows, linux or other") + } + + if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 { + return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements") + } + + for _, v := range irq.Drivers { + validate := validators.StringInSlice(v, []string{"KVM_X86"}) + if !validate { + return errors.New("validation-error: field Drivers can be KVM_X86 only") + } + } + + return nil +} + +func (i Image) SyncCreate(ctx context.Context, req SyncCreateRequest) (uint64, error) { + err := req.Validate() + if err != nil { + return 0, err + } + + url := "/cloudbroker/image/syncCreateImage" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return 0, err + } + + result, err := strconv.ParseUint(string(res), 10, 64) + if err != nil { + return 0, err + } + + return result, nil +} \ No newline at end of file diff --git a/pkg/cloudbroker/image/update_nodes.go b/pkg/cloudbroker/image/update_nodes.go new file mode 100644 index 0000000..9095ddb --- /dev/null +++ b/pkg/cloudbroker/image/update_nodes.go @@ -0,0 +1,42 @@ +package image + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +type UpdateNodesRequest struct { + ImageID uint64 `url:"imageId"` + EnabledStacks []uint64 `url:"enabledStacks,omitempty"` +} + +func (irq UpdateNodesRequest) Validate() error { + if irq.ImageID == 0 { + return errors.New("validation-error: field ImageID must be set") + } + + return nil +} + +func (i Image) UpdateNodes(ctx context.Context, req UpdateNodesRequest) (bool, error) { + err := req.Validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/image/updateNodes" + + res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return false, err + } + + result, err := strconv.ParseBool(string(res)) + if err != nil { + return false, err + } + + return result, nil +} diff --git a/pkg/cloudbroker/k8ci.go b/pkg/cloudbroker/k8ci.go new file mode 100644 index 0000000..0d5f260 --- /dev/null +++ b/pkg/cloudbroker/k8ci.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci" +) + +func (cb *CloudBroker) K8CI() *k8ci.K8CI { + return k8ci.New(cb.client) +} diff --git a/pkg/cloudbroker/k8s.go b/pkg/cloudbroker/k8s.go new file mode 100644 index 0000000..e21ecbd --- /dev/null +++ b/pkg/cloudbroker/k8s.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/k8s" +) + +func (cb *CloudBroker) K8S() *k8s.K8S { + return k8s.New(cb.client) +} diff --git a/pkg/cloudbroker/kvmppc.go b/pkg/cloudbroker/kvmppc.go new file mode 100644 index 0000000..78720d8 --- /dev/null +++ b/pkg/cloudbroker/kvmppc.go @@ -0,0 +1,7 @@ +package cloudbroker + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc" + +func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC { + return kvmppc.New(cb.client) +} diff --git a/pkg/cloudbroker/kvmx86.go b/pkg/cloudbroker/kvmx86.go new file mode 100644 index 0000000..0da6b71 --- /dev/null +++ b/pkg/cloudbroker/kvmx86.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86" +) + +func (cb *CloudBroker) KVMX86() *kvmx86.KVMX86 { + return kvmx86.New(cb.client) +} diff --git a/pkg/cloudbroker/lb.go b/pkg/cloudbroker/lb.go new file mode 100644 index 0000000..74bd3a2 --- /dev/null +++ b/pkg/cloudbroker/lb.go @@ -0,0 +1,7 @@ +package cloudbroker + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb" + +func (cb *CloudBroker) LB() *lb.LB { + return lb.New(cb.client) +} diff --git a/pkg/cloudbroker/locatons.go b/pkg/cloudbroker/locatons.go new file mode 100644 index 0000000..426a248 --- /dev/null +++ b/pkg/cloudbroker/locatons.go @@ -0,0 +1,7 @@ +package cloudbroker + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations" + +func (cb *CloudBroker) Locations() *locations.Locations { + return locations.New(cb.client) +} diff --git a/pkg/cloudbroker/rg.go b/pkg/cloudbroker/rg.go new file mode 100644 index 0000000..f6ca4ce --- /dev/null +++ b/pkg/cloudbroker/rg.go @@ -0,0 +1,7 @@ +package cloudbroker + +import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg" + +func (cb *CloudBroker) RG() *rg.RG { + return rg.New(cb.client) +} diff --git a/pkg/cloudbroker/sizes.go b/pkg/cloudbroker/sizes.go new file mode 100644 index 0000000..93ad751 --- /dev/null +++ b/pkg/cloudbroker/sizes.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/sizes" +) + +func (cb *CloudBroker) Sizes() *sizes.Sizes { + return sizes.New(cb.client) +} diff --git a/pkg/cloudbroker/tasks.go b/pkg/cloudbroker/tasks.go new file mode 100644 index 0000000..6b1d392 --- /dev/null +++ b/pkg/cloudbroker/tasks.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/tasks" +) + +func (cb *CloudBroker) Tasks() *tasks.Tasks { + return tasks.New(cb.client) +} diff --git a/pkg/cloudbroker/vins.go b/pkg/cloudbroker/vins.go new file mode 100644 index 0000000..5e2b45e --- /dev/null +++ b/pkg/cloudbroker/vins.go @@ -0,0 +1,9 @@ +package cloudbroker + +import ( + "github.com/rudecs/decort-sdk/pkg/cloudapi/vins" +) + +func (cb *CloudBroker) VINS() *vins.VINS { + return vins.New(cb.client) +} diff --git a/rg.go b/rg.go deleted file mode 100644 index cfc023e..0000000 --- a/rg.go +++ /dev/null @@ -1,7 +0,0 @@ -package decortsdk - -import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg" - -func (dc *Client) RG() *rg.RG { - return rg.New(dc) -} diff --git a/sizes.go b/sizes.go deleted file mode 100644 index 19b4cdf..0000000 --- a/sizes.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/sizes" -) - -func (dc *Client) Sizes() *sizes.Sizes { - return sizes.New(dc) -} diff --git a/tasks.go b/tasks.go deleted file mode 100644 index cedca34..0000000 --- a/tasks.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/tasks" -) - -func (dc *Client) Tasks() *tasks.Tasks { - return tasks.New(dc) -} diff --git a/typed/typed.go b/typed/typed.go deleted file mode 100644 index 06a4a6a..0000000 --- a/typed/typed.go +++ /dev/null @@ -1,6 +0,0 @@ -package typed - -const TypeAdmin = "admin" -const ValueAdmin = "cloudbroker" -const POST = "POST" -const GET = "GET" diff --git a/vins.go b/vins.go deleted file mode 100644 index 6cfdb27..0000000 --- a/vins.go +++ /dev/null @@ -1,9 +0,0 @@ -package decortsdk - -import ( - "github.com/rudecs/decort-sdk/pkg/cloudapi/vins" -) - -func (dc *Client) Vins() *vins.Vins { - return vins.New(dc) -}