2020-07-10 05:01:10 -04:00
|
|
|
package driver
|
|
|
|
|
2020-08-19 07:20:25 -04:00
|
|
|
import (
|
|
|
|
"github.com/vmware/govmomi/vapi/library"
|
|
|
|
)
|
2020-07-10 05:01:10 -04:00
|
|
|
|
|
|
|
type Library struct {
|
|
|
|
driver *Driver
|
|
|
|
library *library.Library
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Driver) FindContentLibrary(name string) (*Library, error) {
|
|
|
|
lm := library.NewManager(d.restClient)
|
|
|
|
l, err := lm.GetLibraryByName(d.ctx, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Library{
|
|
|
|
library: l,
|
|
|
|
driver: d,
|
|
|
|
}, nil
|
|
|
|
}
|
2020-08-19 07:20:25 -04:00
|
|
|
|
|
|
|
func (d *Driver) FindContentLibraryItem(libraryId string, name string) (*library.Item, error) {
|
|
|
|
lm := library.NewManager(d.restClient)
|
|
|
|
items, err := lm.GetLibraryItems(d.ctx, libraryId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
if item.Name == name {
|
|
|
|
return &item, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|