Skip to content

Commit be316c3

Browse files
authored
feat(baremetal): add support for projects (#535)
1 parent c88def7 commit be316c3

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

api/baremetal/v1/baremetal_sdk.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ type Server struct {
542542
ID string `json:"id"`
543543
// OrganizationID: organization ID the server is attached to
544544
OrganizationID string `json:"organization_id"`
545+
// ProjectID: project ID the server is attached to
546+
ProjectID string `json:"project_id"`
545547
// Name: name of the server
546548
Name string `json:"name"`
547549
// Description: description of the server
@@ -620,11 +622,13 @@ type ListServersRequest struct {
620622
Name *string `json:"-"`
621623
// OrganizationID: filter servers by organization ID
622624
OrganizationID *string `json:"-"`
625+
// ProjectID: filter servers by project ID
626+
ProjectID *string `json:"-"`
623627
}
624628

625-
// ListServers: list baremetal servers
629+
// ListServers: list baremetal servers for organization
626630
//
627-
// List baremetal servers.
631+
// List baremetal servers for organization.
628632
func (s *API) ListServers(req *ListServersRequest, opts ...scw.RequestOption) (*ListServersResponse, error) {
629633
var err error
630634

@@ -646,6 +650,7 @@ func (s *API) ListServers(req *ListServersRequest, opts ...scw.RequestOption) (*
646650
parameter.AddToQuery(query, "status", req.Status)
647651
parameter.AddToQuery(query, "name", req.Name)
648652
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
653+
parameter.AddToQuery(query, "project_id", req.ProjectID)
649654

650655
if fmt.Sprint(req.Zone) == "" {
651656
return nil, errors.New("field Zone cannot be empty in request")
@@ -731,7 +736,11 @@ type CreateServerRequest struct {
731736
// OfferID: offer ID of the new server
732737
OfferID string `json:"offer_id"`
733738
// OrganizationID: organization ID with which the server will be created
734-
OrganizationID string `json:"organization_id"`
739+
// Precisely one of OrganizationID, ProjectID must be set.
740+
OrganizationID *string `json:"organization_id,omitempty"`
741+
// ProjectID: project ID with which the server will be created
742+
// Precisely one of OrganizationID, ProjectID must be set.
743+
ProjectID *string `json:"project_id,omitempty"`
735744
// Name: name of the server (≠hostname)
736745
Name string `json:"name"`
737746
// Description: description associated to the server, max 255 characters
@@ -748,9 +757,14 @@ type CreateServerRequest struct {
748757
func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption) (*Server, error) {
749758
var err error
750759

751-
if req.OrganizationID == "" {
752-
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
753-
req.OrganizationID = defaultOrganizationID
760+
defaultProjectID, exist := s.client.GetDefaultProjectID()
761+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
762+
req.ProjectID = &defaultProjectID
763+
}
764+
765+
defaultOrganizationID, exist := s.client.GetDefaultOrganizationID()
766+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
767+
req.OrganizationID = &defaultOrganizationID
754768
}
755769

756770
if req.Zone == "" {

0 commit comments

Comments
 (0)