diff --git a/client/cluster_edge.go b/client/cluster_edge.go deleted file mode 100644 index e869bdc7..00000000 --- a/client/cluster_edge.go +++ /dev/null @@ -1,79 +0,0 @@ -package client - -import ( - clientv1 "github.com/spectrocloud/palette-api-go/client/v1" - "github.com/spectrocloud/palette-api-go/models" - "github.com/spectrocloud/palette-sdk-go/client/apiutil" -) - -// TODO: edgev1 deprecation - -// CreateClusterEdge creates a new edge cluster. -func (h *V1Client) CreateClusterEdge(cluster *models.V1SpectroEdgeClusterEntity) (string, error) { - params := clientv1.NewV1SpectroClustersEdgeCreateParamsWithContext(h.ctx). - WithBody(cluster) - resp, err := h.Client.V1SpectroClustersEdgeCreate(params) - if err != nil { - return "", err - } - return *resp.Payload.UID, nil -} - -// CreateMachinePoolEdge creates a new edge machine pool. -func (h *V1Client) CreateMachinePoolEdge(cloudConfigUID string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { - params := clientv1.NewV1CloudConfigsEdgeMachinePoolCreateParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithBody(machinePool) - _, err := h.Client.V1CloudConfigsEdgeMachinePoolCreate(params) - return err -} - -// UpdateMachinePoolEdge updates an existing edge machine pool. -func (h *V1Client) UpdateMachinePoolEdge(cloudConfigUID string, machinePool *models.V1EdgeMachinePoolConfigEntity) error { - params := clientv1.NewV1CloudConfigsEdgeMachinePoolUpdateParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - _, err := h.Client.V1CloudConfigsEdgeMachinePoolUpdate(params) - return err -} - -// DeleteMachinePoolEdge deletes an existing edge machine pool. -func (h *V1Client) DeleteMachinePoolEdge(cloudConfigUID, machinePoolName string) error { - params := clientv1.NewV1CloudConfigsEdgeMachinePoolDeleteParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithMachinePoolName(machinePoolName) - _, err := h.Client.V1CloudConfigsEdgeMachinePoolDelete(params) - return err -} - -// GetCloudConfigEdge retrieves an existing edge cluster's cloud config. -func (h *V1Client) GetCloudConfigEdge(configUID string) (*models.V1EdgeCloudConfig, error) { - params := clientv1.NewV1CloudConfigsEdgeGetParamsWithContext(h.ctx). - WithConfigUID(configUID) - resp, err := h.Client.V1CloudConfigsEdgeGet(params) - if apiutil.Is404(err) { - return nil, nil - } else if err != nil { - return nil, err - } - return resp.Payload, nil -} - -// GetNodeStatusMapEdge retrieves the status of all nodes in an edge machine pool. -func (h *V1Client) GetNodeStatusMapEdge(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientv1.NewV1CloudConfigsEdgePoolMachinesListParamsWithContext(h.ctx). - WithConfigUID(configUID). - WithMachinePoolName(machinePoolName) - mpList, err := h.Client.V1CloudConfigsEdgePoolMachinesList(params) - if err != nil { - return nil, err - } - nMap := map[string]models.V1CloudMachineStatus{} - if len(mpList.Payload.Items) > 0 { - for _, node := range mpList.Payload.Items { - nMap[node.Metadata.UID] = *node.Status - } - } - return nMap, nil -} diff --git a/client/cluster_libvirt.go b/client/cluster_libvirt.go deleted file mode 100644 index 7f669a04..00000000 --- a/client/cluster_libvirt.go +++ /dev/null @@ -1,79 +0,0 @@ -package client - -import ( - clientv1 "github.com/spectrocloud/palette-api-go/client/v1" - "github.com/spectrocloud/palette-api-go/models" - "github.com/spectrocloud/palette-sdk-go/client/apiutil" -) - -// TODO: edgev1 deprecation - -// CreateClusterLibvirt creates a new libvirt edge cluster. -func (h *V1Client) CreateClusterLibvirt(cluster *models.V1SpectroLibvirtClusterEntity) (string, error) { - params := clientv1.NewV1SpectroClustersLibvirtCreateParamsWithContext(h.ctx). - WithBody(cluster) - resp, err := h.Client.V1SpectroClustersLibvirtCreate(params) - if err != nil { - return "", err - } - return *resp.Payload.UID, nil -} - -// CreateMachinePoolLibvirt creates a new libvirt edge machine pool. -func (h *V1Client) CreateMachinePoolLibvirt(cloudConfigUID string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - params := clientv1.NewV1CloudConfigsLibvirtMachinePoolCreateParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithBody(machinePool) - _, err := h.Client.V1CloudConfigsLibvirtMachinePoolCreate(params) - return err -} - -// UpdateMachinePoolLibvirt updates an existing libvirt edge machine pool. -func (h *V1Client) UpdateMachinePoolLibvirt(cloudConfigUID string, machinePool *models.V1LibvirtMachinePoolConfigEntity) error { - params := clientv1.NewV1CloudConfigsLibvirtMachinePoolUpdateParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithMachinePoolName(*machinePool.PoolConfig.Name). - WithBody(machinePool) - _, err := h.Client.V1CloudConfigsLibvirtMachinePoolUpdate(params) - return err -} - -// DeleteMachinePoolLibvirt deletes an existing libvirt edge machine pool. -func (h *V1Client) DeleteMachinePoolLibvirt(cloudConfigUID, machinePoolName string) error { - params := clientv1.NewV1CloudConfigsLibvirtMachinePoolDeleteParamsWithContext(h.ctx). - WithConfigUID(cloudConfigUID). - WithMachinePoolName(machinePoolName) - _, err := h.Client.V1CloudConfigsLibvirtMachinePoolDelete(params) - return err -} - -// GetCloudConfigLibvirt retrieves an existing libvirt edge cluster's cloud config. -func (h *V1Client) GetCloudConfigLibvirt(configUID string) (*models.V1LibvirtCloudConfig, error) { - params := clientv1.NewV1CloudConfigsLibvirtGetParamsWithContext(h.ctx). - WithConfigUID(configUID) - resp, err := h.Client.V1CloudConfigsLibvirtGet(params) - if apiutil.Is404(err) { - return nil, nil - } else if err != nil { - return nil, err - } - return resp.Payload, nil -} - -// GetNodeStatusMapLibvirt retrieves the status of all nodes in a libvirt machine pool. -func (h *V1Client) GetNodeStatusMapLibvirt(configUID, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) { - params := clientv1.NewV1CloudConfigsLibvirtPoolMachinesListParamsWithContext(h.ctx). - WithConfigUID(configUID). - WithMachinePoolName(machinePoolName) - mpList, err := h.Client.V1CloudConfigsLibvirtPoolMachinesList(params) - if err != nil { - return nil, err - } - nMap := map[string]models.V1CloudMachineStatus{} - if len(mpList.Payload.Items) > 0 { - for _, node := range mpList.Payload.Items { - nMap[node.Metadata.UID] = *node.Status - } - } - return nMap, nil -} diff --git a/client/macro.go b/client/macro.go index 26206154..b188f2b1 100644 --- a/client/macro.go +++ b/client/macro.go @@ -1,6 +1,7 @@ package client import ( + "errors" clientv1 "github.com/spectrocloud/palette-api-go/client/v1" "github.com/spectrocloud/palette-api-go/models" "github.com/spectrocloud/palette-sdk-go/client/apiutil" @@ -15,10 +16,14 @@ func (h *V1Client) CreateMacro(uid string, macros *models.V1Macros) error { _, err := h.Client.V1ProjectsUIDMacrosCreate(params) return err } - tenantUID, err := h.GetTenantUID() + userInfo, err := h.GetUsersInfo() if err != nil { return err } + if userInfo == nil { + return errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosCreateParams(). WithTenantUID(tenantUID). @@ -57,10 +62,14 @@ func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) { } macros = resp.Payload.Macros } else { - tenantUID, err := h.GetTenantUID() - if err != nil || tenantUID == "" { + userInfo, err := h.GetUsersInfo() + if err != nil { return nil, err } + if userInfo == nil { + return nil, errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosListParams(). WithTenantUID(tenantUID) @@ -83,10 +92,14 @@ func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error { _, err := h.Client.V1ProjectsUIDMacrosUpdateByMacroName(params) return err } - tenantUID, err := h.GetTenantUID() - if err != nil || tenantUID == "" { + userInfo, err := h.GetUsersInfo() + if err != nil { return err } + if userInfo == nil { + return errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosUpdateByMacroNameParams(). WithTenantUID(tenantUID). @@ -106,10 +119,14 @@ func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error { return err } } else { - tenantUID, err := h.GetTenantUID() + userInfo, err := h.GetUsersInfo() if err != nil { return err } + if userInfo == nil { + return errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). WithTenantUID(tenantUID). diff --git a/client/macros.go b/client/macros.go index e786e9a0..488d7df3 100644 --- a/client/macros.go +++ b/client/macros.go @@ -1,6 +1,7 @@ package client import ( + "errors" "fmt" clientv1 "github.com/spectrocloud/palette-api-go/client/v1" @@ -18,10 +19,14 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er return "", err } } else { - tenantUID, err := h.GetTenantUID() + userInfo, err := h.GetUsersInfo() if err != nil { return "", err } + if userInfo == nil { + return "", errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosCreateParams(). WithTenantUID(tenantUID). @@ -91,10 +96,14 @@ func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) { } return macrosListOk.Payload.Macros, nil } - tenantUID, err := h.GetTenantUID() - if err != nil || tenantUID == "" { + userInfo, err := h.GetUsersInfo() + if err != nil { return nil, err } + if userInfo == nil { + return nil, errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosListParams(). WithTenantUID(tenantUID) @@ -114,10 +123,14 @@ func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error { _, err := h.Client.V1ProjectsUIDMacrosUpdate(params) return err } - tenantUID, err := h.GetTenantUID() - if err != nil || tenantUID == "" { + userInfo, err := h.GetUsersInfo() + if err != nil { return err } + if userInfo == nil { + return errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosUpdateParams(). WithTenantUID(tenantUID). @@ -135,10 +148,14 @@ func (h *V1Client) DeleteMacros(uid string, body *models.V1Macros) error { _, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params) return err } - tenantUID, err := h.GetTenantUID() + userInfo, err := h.GetUsersInfo() if err != nil { return err } + if userInfo == nil { + return errors.New("empty userinfo received from GetUsersInfo()") + } + tenantUID := userInfo.TenantUID // As discussed with hubble team, we should not set context for tenant macros. params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams(). WithTenantUID(tenantUID). @@ -154,10 +171,14 @@ func (h *V1Client) GetMacrosID(uid string) (string, error) { if uid != "" { hashID = fmt.Sprintf("%s-%s-%s", "project", "macros", uid) } else { - tenantID, err := h.GetTenantUID() + userInfo, err := h.GetUsersInfo() if err != nil { return "", err } + if userInfo == nil { + return "", errors.New("empty userinfo received from GetUsersInfo()") + } + tenantID := userInfo.TenantUID hashID = fmt.Sprintf("%s-%s-%s", "tenant", "macros", tenantID) } return hashID, nil diff --git a/client/node_actions.go b/client/node_actions.go index 6b29d33e..40516e36 100644 --- a/client/node_actions.go +++ b/client/node_actions.go @@ -88,21 +88,6 @@ func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUID, machineName, no return resp.Payload.Status.MaintenanceStatus, nil } -// GetNodeMaintenanceStatusEdge retrieves maintenance status for an edge node. -// TODO: edgev1 deprecation -func (h *V1Client) GetNodeMaintenanceStatusEdge(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientv1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx). - WithConfigUID(configUID). - WithMachinePoolName(machineName). - WithMachineUID(nodeID) - - resp, err := h.Client.V1CloudConfigsEdgePoolMachinesUIDGet(params) - if err != nil { - return nil, err - } - return resp.Payload.Status.MaintenanceStatus, nil -} - // GetNodeMaintenanceStatusEdgeVsphere retrieves maintenance status for a vSphere edge node. // TODO: edgev1 deprecation func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { @@ -174,21 +159,6 @@ func (h *V1Client) GetNodeMaintenanceStatusGke(configUID, machineName, nodeID st return resp.Payload.Status.MaintenanceStatus, nil } -// GetNodeMaintenanceStatusLibvirt retrieves maintenance status for a libvirt node. -// TODO: edgev1 deprecation -func (h *V1Client) GetNodeMaintenanceStatusLibvirt(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { - params := clientv1.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.ctx). - WithConfigUID(configUID). - WithMachinePoolName(machineName). - WithMachineUID(nodeID) - - resp, err := h.Client.V1CloudConfigsLibvirtPoolMachinesUIDGet(params) - if err != nil { - return nil, err - } - return resp.Payload.Status.MaintenanceStatus, nil -} - // GetNodeMaintenanceStatusOpenStack retrieves maintenance status for an OpenStack node. func (h *V1Client) GetNodeMaintenanceStatusOpenStack(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) { params := clientv1.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.ctx).