github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/api/cloudcontroller/ccv3/isolation_segment.go (about) 1 package ccv3 2 3 import ( 4 "bytes" 5 "encoding/json" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 10 ) 11 12 // IsolationSegment represents a Cloud Controller Isolation Segment. 13 type IsolationSegment struct { 14 //GUID is the unique ID of the isolation segment. 15 GUID string `json:"guid,omitempty"` 16 //Name is the name of the isolation segment. 17 Name string `json:"name"` 18 } 19 20 // CreateIsolationSegment will create an Isolation Segment on the Cloud 21 // Controller. Note: This will not validate that the placement tag exists in 22 // the diego cluster. 23 func (client *Client) CreateIsolationSegment(isolationSegment IsolationSegment) (IsolationSegment, Warnings, error) { 24 body, err := json.Marshal(isolationSegment) 25 if err != nil { 26 return IsolationSegment{}, nil, err 27 } 28 29 request, err := client.newHTTPRequest(requestOptions{ 30 RequestName: internal.PostIsolationSegmentsRequest, 31 Body: bytes.NewReader(body), 32 }) 33 if err != nil { 34 return IsolationSegment{}, nil, err 35 } 36 37 var responseIsolationSegment IsolationSegment 38 response := cloudcontroller.Response{ 39 DecodeJSONResponseInto: &responseIsolationSegment, 40 } 41 42 err = client.connection.Make(request, &response) 43 return responseIsolationSegment, response.Warnings, err 44 } 45 46 // DeleteIsolationSegment removes an isolation segment from the cloud 47 // controller. Note: This will only remove it from the cloud controller 48 // database. It will not remove it from diego. 49 func (client *Client) DeleteIsolationSegment(guid string) (Warnings, error) { 50 request, err := client.newHTTPRequest(requestOptions{ 51 RequestName: internal.DeleteIsolationSegmentRequest, 52 URIParams: map[string]string{"isolation_segment_guid": guid}, 53 }) 54 if err != nil { 55 return nil, err 56 } 57 58 var response cloudcontroller.Response 59 err = client.connection.Make(request, &response) 60 return response.Warnings, err 61 } 62 63 // GetIsolationSegment returns back the requested isolation segment that 64 // matches the GUID. 65 func (client *Client) GetIsolationSegment(guid string) (IsolationSegment, Warnings, error) { 66 request, err := client.newHTTPRequest(requestOptions{ 67 RequestName: internal.GetIsolationSegmentRequest, 68 URIParams: map[string]string{"isolation_segment_guid": guid}, 69 }) 70 if err != nil { 71 return IsolationSegment{}, nil, err 72 } 73 var isolationSegment IsolationSegment 74 response := cloudcontroller.Response{ 75 DecodeJSONResponseInto: &isolationSegment, 76 } 77 78 err = client.connection.Make(request, &response) 79 if err != nil { 80 return IsolationSegment{}, response.Warnings, err 81 } 82 83 return isolationSegment, response.Warnings, nil 84 } 85 86 // GetIsolationSegments lists isolation segments with optional filters. 87 func (client *Client) GetIsolationSegments(query ...Query) ([]IsolationSegment, Warnings, error) { 88 request, err := client.newHTTPRequest(requestOptions{ 89 RequestName: internal.GetIsolationSegmentsRequest, 90 Query: query, 91 }) 92 if err != nil { 93 return nil, nil, err 94 } 95 96 var fullIsolationSegmentsList []IsolationSegment 97 warnings, err := client.paginate(request, IsolationSegment{}, func(item interface{}) error { 98 if isolationSegment, ok := item.(IsolationSegment); ok { 99 fullIsolationSegmentsList = append(fullIsolationSegmentsList, isolationSegment) 100 } else { 101 return ccerror.UnknownObjectInListError{ 102 Expected: IsolationSegment{}, 103 Unexpected: item, 104 } 105 } 106 return nil 107 }) 108 109 return fullIsolationSegmentsList, warnings, err 110 }