Skip to content

Commit

Permalink
feat: Add library item storage APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyar85 committed May 17, 2024
1 parent 077b0b0 commit 3796269
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 18 deletions.
2 changes: 1 addition & 1 deletion govc/library/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {

cmd.library.Name = f.Arg(0)
cmd.library.Type = "LOCAL"
cmd.library.Storage = []library.StorageBackings{
cmd.library.Storage = []library.StorageBacking{
{
DatastoreID: ds.Reference().Value,
Type: "DATASTORE",
Expand Down
3 changes: 2 additions & 1 deletion vapi/internal/internal.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2018-2023 VMware, Inc. All Rights Reserved.
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@ const (
LibraryItemFileData = "/com/vmware/cis/data"
LibraryItemPath = "/com/vmware/content/library/item"
LibraryItemFilePath = "/com/vmware/content/library/item/file"
LibraryItemStoragePath = "/com/vmware/content/library/item/storage"
LibraryItemUpdateSession = "/com/vmware/content/library/item/update-session"
LibraryItemUpdateSessionFile = "/com/vmware/content/library/item/updatesession/file"
LibraryItemDownloadSession = "/com/vmware/content/library/item/download-session"
Expand Down
2 changes: 1 addition & 1 deletion vapi/library/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ExampleManager_CreateLibrary() {
id, err := m.CreateLibrary(ctx, library.Library{
Name: "example",
Type: "LOCAL",
Storage: []library.StorageBackings{{
Storage: []library.StorageBacking{{
DatastoreID: ds.Reference().Value,
Type: "DATASTORE",
}},
Expand Down
31 changes: 16 additions & 15 deletions vapi/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@ import (
"github.com/vmware/govmomi/vapi/rest"
)

// StorageBackings for Content Libraries
type StorageBackings struct {
// StorageBacking defines a storage location where content in a library will be stored.
type StorageBacking struct {
DatastoreID string `json:"datastore_id,omitempty"`
Type string `json:"type,omitempty"`
StorageURI string `json:"storage_uri,omitempty"`
}

// Library provides methods to create, read, update, delete, and enumerate libraries.
type Library struct {
CreationTime *time.Time `json:"creation_time,omitempty"`
Description *string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
LastModifiedTime *time.Time `json:"last_modified_time,omitempty"`
LastSyncTime *time.Time `json:"last_sync_time,omitempty"`
Name string `json:"name,omitempty"`
Storage []StorageBackings `json:"storage_backings,omitempty"`
Type string `json:"type,omitempty"`
Version string `json:"version,omitempty"`
Subscription *Subscription `json:"subscription_info,omitempty"`
Publication *Publication `json:"publish_info,omitempty"`
SecurityPolicyID string `json:"security_policy_id,omitempty"`
UnsetSecurityPolicyID bool `json:"unset_security_policy_id,omitempty"`
CreationTime *time.Time `json:"creation_time,omitempty"`
Description *string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
LastModifiedTime *time.Time `json:"last_modified_time,omitempty"`
LastSyncTime *time.Time `json:"last_sync_time,omitempty"`
Name string `json:"name,omitempty"`
Storage []StorageBacking `json:"storage_backings,omitempty"`
Type string `json:"type,omitempty"`
Version string `json:"version,omitempty"`
Subscription *Subscription `json:"subscription_info,omitempty"`
Publication *Publication `json:"publish_info,omitempty"`
SecurityPolicyID string `json:"security_policy_id,omitempty"`
UnsetSecurityPolicyID bool `json:"unset_security_policy_id,omitempty"`
}

// Subscription info
Expand Down
53 changes: 53 additions & 0 deletions vapi/library/library_item_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright (c) 2024 VMware, Inc. All Rights Reserved.

Check failure on line 2 in vapi/library/library_item_storage.go

View workflow job for this annotation

GitHub Actions / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: vapi/library/library_item_storage.go:2: found mismatched boilerplate lines: {[]string}[0]: -: "Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved." +: "Copyright (c) 2024 VMware, Inc. All Rights Reserved." {[]string}[6]: -: "http://www.apache.org/licenses/LICENSE-2.0" +: " http://www.apache.org/licenses/LICENSE-2.0"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package library

import (
"context"
"net/http"

"github.com/vmware/govmomi/vapi/internal"
)

// Storage is an expanded form of library.File that includes details about the
// storage backing for a file in a library item
type Storage struct {
Checksum Checksum `json:"checksum_info,omitempty"`
StorageBacking StorageBacking `json:"storage_backing"`
StorageURIs []string `json:"storage_uris"`
Name string `json:"name"`
Size int64 `json:"size"`
Cached bool `json:"cached"`
Version string `json:"version"`
}

// ListLibraryItemStorage returns a list of all the storage for a library item.
func (c *Manager) ListLibraryItemStorage(ctx context.Context, id string) ([]Storage, error) {
url := c.Resource(internal.LibraryItemStoragePath).WithParam("library_item_id", id)
var res []Storage
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
}

// GetLibraryItemStorage returns the storage for a specific file in a library item.
func (c *Manager) GetLibraryItemStorage(ctx context.Context, id, fileName string) (*Storage, error) {
url := c.Resource(internal.LibraryItemStoragePath).WithID(id).WithAction("get")
spec := struct {
Name string `json:"name"`
}{fileName}
var res Storage
return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}

0 comments on commit 3796269

Please sign in to comment.