Skip to content

Commit e48f1ff

Browse files
committed
Add CnsSyncVolume API bindings
Signed-off-by: Nikhil Barge <[email protected]>
1 parent 75e9720 commit e48f1ff

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

cns/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,16 @@ func (c *Client) SyncDatastore(ctx context.Context, dsURL string, fullSync bool)
307307
}
308308
return object.NewTask(c.vim25Client, res.Returnval), nil
309309
}
310+
311+
// SyncVolume calls the CnsSyncVolume API
312+
func (c *Client) SyncVolume(ctx context.Context, syncSpecs []cnstypes.CnsSyncVolumeSpec) (*object.Task, error) {
313+
req := cnstypes.CnsSyncVolume{
314+
This: CnsVolumeManagerInstance,
315+
SyncSpecs: syncSpecs,
316+
}
317+
res, err := methods.CnsSyncVolume(ctx, c, &req)
318+
if err != nil {
319+
return nil, err
320+
}
321+
return object.NewTask(c.vim25Client, res.Returnval), nil
322+
}

cns/client_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,37 @@ func TestClient(t *testing.T) {
16411641
t.Fatalf("%+v", syncDatastoreTaskInfo.Error)
16421642
}
16431643
t.Logf("syncDatastore on %v with full sync successful\n", dsUrl)
1644+
1645+
// Test CnsSyncVolume API
1646+
/*
1647+
t.Logf("Calling syncVolume for volumeId: %v ...\n", volumeId)
1648+
var cnsSyncVolumeSpecs []cnstypes.CnsSyncVolumeSpec
1649+
dataStore := ds.Reference()
1650+
cnsSyncVolumeSpec := cnstypes.CnsSyncVolumeSpec{
1651+
VolumeId: cnstypes.CnsVolumeId{
1652+
Id: volumeId,
1653+
},
1654+
Datastore: &dataStore,
1655+
SyncMode: []string{string(cnstypes.CnsSyncVolumeModeSPACE_USAGE)},
1656+
}
1657+
cnsSyncVolumeSpecs = append(cnsSyncVolumeSpecs, cnsSyncVolumeSpec)
1658+
syncVolumeTask, err := cnsClient.SyncVolume(ctx, cnsSyncVolumeSpecs)
1659+
if err != nil {
1660+
t.Errorf("Failed to sync volume %v. Error: %+v \n", volumeId, err)
1661+
t.Fatal(err)
1662+
}
1663+
syncVolumeTaskInfo, err := GetTaskInfo(ctx, syncVolumeTask)
1664+
if err != nil {
1665+
t.Errorf("Failed to get sync volume taskInfo. Error: %+v \n", err)
1666+
t.Fatal(err)
1667+
}
1668+
if syncVolumeTaskInfo.State != vim25types.TaskInfoStateSuccess {
1669+
t.Errorf("Failed to sync volume. Error: %+v \n", syncVolumeTaskInfo.Error)
1670+
t.Fatalf("%+v", syncVolumeTaskInfo.Error)
1671+
}
1672+
t.Logf("syncVolume for volumeId: %v successful...\n", volumeId)
1673+
*/
1674+
16441675
}
16451676

16461677
// isvSphereVersion70U3orAbove checks if specified version is 7.0 Update 3 or higher

cns/methods/methods.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,23 @@ func CnsSyncDatastore(ctx context.Context, r soap.RoundTripper, req *types.CnsSy
355355

356356
return resBody.Res, nil
357357
}
358+
359+
type CnsSyncVolumeBody struct {
360+
Req *types.CnsSyncVolume `xml:"urn:vsan CnsSyncVolume,omitempty"`
361+
Res *types.CnsSyncVolumeResponse `xml:"urn:vsan CnsSyncVolumeResponse,omitempty"`
362+
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
363+
}
364+
365+
func (b *CnsSyncVolumeBody) Fault() *soap.Fault { return b.Fault_ }
366+
367+
func CnsSyncVolume(ctx context.Context, r soap.RoundTripper, req *types.CnsSyncVolume) (*types.CnsSyncVolumeResponse, error) {
368+
var reqBody, resBody CnsSyncVolumeBody
369+
370+
reqBody.Req = req
371+
372+
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
373+
return nil, err
374+
}
375+
376+
return resBody.Res, nil
377+
}

cns/types/enum.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ const (
8585
func init() {
8686
types.Add("CnsKubernetesEntityType", reflect.TypeOf((*CnsKubernetesEntityType)(nil)).Elem())
8787
}
88+
89+
type CnsSyncVolumeMode string
90+
91+
const (
92+
CnsSyncVolumeModeSPACE_USAGE = CnsSyncVolumeMode("SPACE_USAGE")
93+
)
94+
95+
func init() {
96+
types.Add("vsan:CnsSyncVolumeMode", reflect.TypeOf((*CnsSyncVolumeMode)(nil)).Elem())
97+
}

cns/types/types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,3 +950,34 @@ func init() {
950950
type CnsSyncDatastoreResponse struct {
951951
Returnval types.ManagedObjectReference `xml:"returnval" json:"returnval"`
952952
}
953+
954+
type CnsSyncVolume CnsSyncVolumeRequestType
955+
956+
func init() {
957+
types.Add("vsan:CnsSyncVolume", reflect.TypeOf((*CnsSyncVolume)(nil)).Elem())
958+
}
959+
960+
type CnsSyncVolumeRequestType struct {
961+
This types.ManagedObjectReference `xml:"_this"`
962+
SyncSpecs []CnsSyncVolumeSpec `xml:"syncSpecs,omitempty"`
963+
}
964+
965+
func init() {
966+
types.Add("vsan:CnsSyncVolumeRequestType", reflect.TypeOf((*CnsSyncVolumeRequestType)(nil)).Elem())
967+
}
968+
969+
type CnsSyncVolumeResponse struct {
970+
Returnval types.ManagedObjectReference `xml:"returnval"`
971+
}
972+
973+
type CnsSyncVolumeSpec struct {
974+
types.DynamicData
975+
976+
VolumeId CnsVolumeId `xml:"volumeId"`
977+
Datastore *types.ManagedObjectReference `xml:"datastore,omitempty"`
978+
SyncMode []string `xml:"syncMode,omitempty"`
979+
}
980+
981+
func init() {
982+
types.Add("vsan:CnsSyncVolumeSpec", reflect.TypeOf((*CnsSyncVolumeSpec)(nil)).Elem())
983+
}

0 commit comments

Comments
 (0)