本文整理汇总了Golang中github.com/vmware/govmomi/object.NewFileManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileManager函数的具体用法?Golang NewFileManager怎么用?Golang NewFileManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFileManager函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deleteFile
func deleteFile(client *govmomi.Client, f *file) error {
dc, err := getDatacenter(client, f.datacenter)
if err != nil {
return err
}
finder := find.NewFinder(client.Client, true)
finder = finder.SetDatacenter(dc)
ds, err := getDatastore(finder, f.datastore)
if err != nil {
return fmt.Errorf("error %s", err)
}
fm := object.NewFileManager(client.Client)
task, err := fm.DeleteDatastoreFile(context.TODO(), ds.Path(f.destinationFile), dc)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
return err
}
return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:27,代码来源:resource_vsphere_file.go
示例2: NewDatastore
// NewDatastore returns a Datastore.
// ctx is a context,
// s is an authenticated session
// ds is the vsphere datastore
// rootdir is the top level directory to root all data. If root does not exist,
// it will be created. If it already exists, NOOP. This cannot be empty.
func NewDatastore(ctx context.Context, s *session.Session, ds *object.Datastore, rootdir string) (*Datastore, error) {
d := &Datastore{
ds: ds,
s: s,
fm: object.NewFileManager(s.Vim25()),
}
if strings.HasPrefix(rootdir, "/") {
rootdir = strings.TrimPrefix(rootdir, "/")
}
// Get the root directory element split from the rest of the path (if there is one)
root := strings.SplitN(rootdir, "/", 2)
// Create the first element. This handles vsan vmfs top level dirs.
if err := d.mkRootDir(ctx, root[0]); err != nil {
log.Infof("error creating root directory %s: %s", rootdir, err)
return nil, err
}
// Create the rest conventionally
if len(root) > 1 {
r, err := d.Mkdir(ctx, true, root[1])
if err != nil {
return nil, err
}
d.RootURL = r
}
log.Infof("Datastore path is %s", d.RootURL)
return d, nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:39,代码来源:datastore.go
示例3: deleteDatastoreFiles
func (d *Dispatcher) deleteDatastoreFiles(ds *object.Datastore, path string, force bool) (bool, error) {
defer trace.End(trace.Begin(fmt.Sprintf("path %q, force %t", path, force)))
// refuse to delete everything on the datstore, ignore force
if path == "" {
dsn, _ := ds.ObjectName(d.ctx)
msg := fmt.Sprintf("refusing to remove datastore files for path \"\" on datastore %q", dsn)
return false, errors.New(msg)
}
var empty bool
dsPath := ds.Path(path)
res, err := d.lsFolder(ds, dsPath)
if err != nil {
if !types.IsFileNotFound(err) {
err = errors.Errorf("Failed to browse folder %q: %s", dsPath, err)
return empty, err
}
log.Debugf("Folder %q is not found", dsPath)
empty = true
return empty, nil
}
if len(res.File) > 0 && !force {
log.Debugf("Folder %q is not empty, leave it there", dsPath)
return empty, nil
}
m := object.NewFileManager(ds.Client())
if err = d.deleteFilesIteratively(m, ds, dsPath); err != nil {
return empty, err
}
return true, nil
}
开发者ID:vmware,项目名称:vic,代码行数:34,代码来源:store_files.go
示例4: resourceVSphereFileUpdate
func resourceVSphereFileUpdate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] updating file: %#v", d)
if d.HasChange("destination_file") {
oldDestinationFile, newDestinationFile := d.GetChange("destination_file")
f := file{}
if v, ok := d.GetOk("datacenter"); ok {
f.datacenter = v.(string)
}
if v, ok := d.GetOk("datastore"); ok {
f.datastore = v.(string)
} else {
return fmt.Errorf("datastore argument is required")
}
if v, ok := d.GetOk("source_file"); ok {
f.sourceFile = v.(string)
} else {
return fmt.Errorf("source_file argument is required")
}
if v, ok := d.GetOk("destination_file"); ok {
f.destinationFile = v.(string)
} else {
return fmt.Errorf("destination_file argument is required")
}
client := meta.(*govmomi.Client)
dc, err := getDatacenter(client, f.datacenter)
if err != nil {
return err
}
finder := find.NewFinder(client.Client, true)
finder = finder.SetDatacenter(dc)
ds, err := getDatastore(finder, f.datastore)
if err != nil {
return fmt.Errorf("error %s", err)
}
fm := object.NewFileManager(client.Client)
task, err := fm.MoveDatastoreFile(context.TODO(), ds.Path(oldDestinationFile.(string)), dc, ds.Path(newDestinationFile.(string)), dc, true)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
return err
}
}
return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:58,代码来源:resource_vsphere_file.go
示例5: Run
func (cmd *mkdir) Run(ctx context.Context, f *flag.FlagSet) error {
args := f.Args()
if len(args) == 0 {
return errors.New("missing operand")
}
c, err := cmd.Client()
if err != nil {
return err
}
if cmd.isNamespace {
var uuid string
var ds *object.Datastore
if ds, err = cmd.Datastore(); err != nil {
return err
}
path := args[0]
nm := object.NewDatastoreNamespaceManager(c)
if uuid, err = nm.CreateDirectory(ctx, ds, path, ""); err != nil {
return err
}
fmt.Println(uuid)
} else {
var dc *object.Datacenter
var path string
dc, err = cmd.Datacenter()
if err != nil {
return err
}
path, err = cmd.DatastorePath(args[0])
if err != nil {
return err
}
m := object.NewFileManager(c)
err = m.MakeDirectory(ctx, path, dc, cmd.createParents)
// ignore EEXIST if -p flag is given
if err != nil && cmd.createParents {
if soap.IsSoapFault(err) {
soapFault := soap.ToSoapFault(err)
if _, ok := soapFault.VimFault().(types.FileAlreadyExists); ok {
return nil
}
}
}
}
return err
}
开发者ID:vmware,项目名称:vic,代码行数:57,代码来源:mkdir.go
示例6: rm
func rm(t *testing.T, client *session.Session, name string) {
t.Logf("deleting %s", name)
fm := object.NewFileManager(client.Vim25())
task, err := fm.DeleteDatastoreFile(context.TODO(), name, client.Datacenter)
if !assert.NoError(t, err) {
return
}
_, _ = task.WaitForResult(context.TODO(), nil)
}
开发者ID:vmware,项目名称:vic,代码行数:9,代码来源:image_test.go
示例7: testDeleteDatastoreFiles
func testDeleteDatastoreFiles(v *validate.Validator, t *testing.T) {
d := &Dispatcher{
session: v.Session,
ctx: v.Context,
isVC: v.Session.IsVC(),
force: false,
}
ds := v.Session.Datastore
m := object.NewFileManager(ds.Client())
err := m.MakeDirectory(v.Context, ds.Path("Test/folder/data"), v.Session.Datacenter, true)
if err != nil {
t.Errorf("Failed to create datastore dir: %s", err)
return
}
err = m.MakeDirectory(v.Context, ds.Path("Test/folder/metadata"), v.Session.Datacenter, true)
if err != nil {
t.Errorf("Failed to create datastore dir: %s", err)
return
}
err = m.MakeDirectory(v.Context, ds.Path("Test/folder/file"), v.Session.Datacenter, true)
if err != nil {
t.Errorf("Failed to create datastore dir: %s", err)
return
}
isVSAN := d.isVSAN(ds)
t.Logf("datastore is vsan: %t", isVSAN)
if err = createDatastoreFiles(d, ds, t); err != nil {
t.Errorf("Failed to upload file: %s", err)
return
}
if err = d.deleteFilesIteratively(m, ds, ds.Path("Test")); err != nil {
t.Errorf("Failed to delete recursively: %s", err)
}
err = m.MakeDirectory(v.Context, ds.Path("Test/folder/data"), v.Session.Datacenter, true)
if err != nil {
t.Errorf("Failed to create datastore dir: %s", err)
return
}
if err = createDatastoreFiles(d, ds, t); err != nil {
t.Errorf("Failed to upload file: %s", err)
return
}
if _, err = d.deleteDatastoreFiles(ds, "Test", true); err != nil {
t.Errorf("Failed to delete recursively: %s", err)
}
}
开发者ID:vmware,项目名称:vic,代码行数:53,代码来源:delete_test.go
示例8: Run
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
args := f.Args()
if len(args) == 0 {
return errors.New("missing operand")
}
c, err := cmd.Client()
if err != nil {
return err
}
var dc *object.Datacenter
dc, err = cmd.Datacenter()
if err != nil {
return err
}
if cmd.isNamespace {
path := args[0]
nm := object.NewDatastoreNamespaceManager(c)
err = nm.DeleteDirectory(ctx, dc, path)
} else {
var path string
var task *object.Task
// TODO(PN): Accept multiple args
path, err = cmd.DatastorePath(args[0])
if err != nil {
return err
}
m := object.NewFileManager(c)
task, err = m.DeleteDatastoreFile(ctx, path, dc)
if err != nil {
return err
}
err = task.Wait(ctx)
}
if err != nil {
if types.IsFileNotFound(err) && cmd.force {
// Ignore error
return nil
}
}
return err
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:50,代码来源:rm.go
示例9: vmCleanup
func vmCleanup(dc *object.Datacenter, ds *object.Datastore, vmName string) error {
client := testAccProvider.Meta().(*govmomi.Client)
fileManager := object.NewFileManager(client.Client)
task, err := fileManager.DeleteDatastoreFile(context.TODO(), ds.Path(vmName), dc)
if err != nil {
log.Printf("[ERROR] checkForDisk - Couldn't delete vm folder '%v': %v", vmName, err)
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
log.Printf("[ERROR] checForDisk - Failed while deleting vm folder '%v': %v", vmName, err)
return err
}
return nil
}
开发者ID:paultyng,项目名称:terraform,代码行数:16,代码来源:resource_vsphere_virtual_machine_test.go
示例10: makeDirectoryInDatastore
// Creates a folder using the specified name.
// If the intermediate level folders do not exist,
// and the parameter createParents is true,
// all the non-existent folders are created.
func makeDirectoryInDatastore(c *govmomi.Client, dc *object.Datacenter, path string, createParents bool) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
fileManager := object.NewFileManager(c.Client)
err := fileManager.MakeDirectory(ctx, path, dc, createParents)
if err != nil {
if soap.IsSoapFault(err) {
soapFault := soap.ToSoapFault(err)
if _, ok := soapFault.VimFault().(types.FileAlreadyExists); ok {
return ErrFileAlreadyExist
}
}
}
return err
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:22,代码来源:vsphere.go
示例11: PrepareDestination
// PrepareDestination makes sure that the destination VMDK does not yet exist.
// If the force flag is passed, it removes the existing VMDK. This functions
// exists to give a meaningful error if the remote VMDK already exists.
//
// CopyVirtualDisk can return a "<src> file does not exist" error while in fact
// the source file *does* exist and the *destination* file also exist.
//
func (cmd *vmdk) PrepareDestination(i importable) error {
ctx := context.TODO()
vmdkPath := i.RemoteDstVMDK()
res, err := cmd.Datastore.Stat(ctx, vmdkPath)
if err != nil {
switch err.(type) {
case object.DatastoreNoSuchDirectoryError:
// The base path doesn't exist. Create it.
dsPath := cmd.Datastore.Path(path.Dir(vmdkPath))
m := object.NewFileManager(cmd.Client)
return m.MakeDirectory(ctx, dsPath, cmd.Datacenter, true)
case object.DatastoreNoSuchFileError:
// Destination path doesn't exist; all good to continue with import.
return nil
}
return err
}
// Check that the returned entry has the right type.
switch res.(type) {
case *types.VmDiskFileInfo:
default:
expected := "VmDiskFileInfo"
actual := reflect.TypeOf(res)
panic(fmt.Sprintf("Expected: %s, actual: %s", expected, actual))
}
if !cmd.force {
dsPath := cmd.Datastore.Path(vmdkPath)
err = fmt.Errorf("File %s already exists", dsPath)
return err
}
// Delete existing disk.
err = cmd.DeleteDisk(vmdkPath)
if err != nil {
return err
}
return nil
}
开发者ID:vmware,项目名称:vic,代码行数:49,代码来源:vmdk.go
示例12: checkForDisk
func checkForDisk(datacenter string, datastore string, vmName string, path string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*govmomi.Client)
finder := find.NewFinder(client.Client, true)
dc, err := getDatacenter(client, datacenter)
if err != nil {
return err
}
finder.SetDatacenter(dc)
ds, err := finder.Datastore(context.TODO(), datastore)
if err != nil {
log.Printf("[ERROR] checkForDisk - Couldn't find Datastore '%v': %v", datastore, err)
return err
}
diskPath := vmName + "/" + path
_, err = ds.Stat(context.TODO(), diskPath)
if err != nil {
log.Printf("[ERROR] checkForDisk - Couldn't stat file '%v': %v", diskPath, err)
return err
}
// Cleanup
fileManager := object.NewFileManager(client.Client)
task, err := fileManager.DeleteDatastoreFile(context.TODO(), ds.Path(vmName), dc)
if err != nil {
log.Printf("[ERROR] checkForDisk - Couldn't delete vm folder '%v': %v", vmName, err)
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
log.Printf("[ERROR] checForDisk - Failed while deleting vm folder '%v': %v", vmName, err)
return err
}
return nil
}
}
开发者ID:Originate,项目名称:terraform,代码行数:42,代码来源:resource_vsphere_virtual_machine_test.go
示例13: deleteUpgradeImages
func (d *Dispatcher) deleteUpgradeImages(ds *object.Datastore, settings *data.InstallerData) {
defer trace.End(trace.Begin(""))
log.Infof("Deleting upgrade images")
// do clean up aggressively, even the previous operation failed with context deadline excceeded.
d.ctx = context.Background()
m := object.NewFileManager(ds.Client())
file := ds.Path(path.Join(d.vmPathName, settings.ApplianceISO))
if err := d.deleteVMFSFiles(m, ds, file); err != nil {
log.Warnf("Image file %q is not removed for %s. Use the vSphere UI to delete content", file, err)
}
file = ds.Path(path.Join(d.vmPathName, settings.BootstrapISO))
if err := d.deleteVMFSFiles(m, ds, file); err != nil {
log.Warnf("Image file %q is not removed for %s. Use the vSphere UI to delete content", file, err)
}
}
开发者ID:vmware,项目名称:vic,代码行数:20,代码来源:upgrade.go
示例14: Run
func (cmd *rm) Run(f *flag.FlagSet) error {
args := f.Args()
if len(args) == 0 {
return errors.New("missing operand")
}
c, err := cmd.Client()
if err != nil {
return err
}
dc, err := cmd.Datacenter()
if err != nil {
return err
}
// TODO(PN): Accept multiple args
path, err := cmd.DatastorePath(args[0])
if err != nil {
return err
}
m := object.NewFileManager(c)
task, err := m.DeleteDatastoreFile(context.TODO(), path, dc)
if err != nil {
return err
}
err = task.Wait(context.TODO())
if err != nil {
if types.IsFileNotFound(err) && cmd.force {
// Ignore error
return nil
}
}
return err
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:38,代码来源:rm.go
示例15: GetDatastores
// GetDatastores returns a map of datastores given a map of names and urls
func GetDatastores(ctx context.Context, s *session.Session, dsURLs map[string]*url.URL) (map[string]*Helper, error) {
stores := make(map[string]*Helper)
fm := object.NewFileManager(s.Vim25())
for name, dsURL := range dsURLs {
vsDs, err := s.Finder.DatastoreOrDefault(ctx, s.DatastorePath)
if err != nil {
return nil, err
}
d := &Helper{
ds: vsDs,
s: s,
fm: fm,
RootURL: dsURL.Path,
}
stores[name] = d
}
return stores, nil
}
开发者ID:vmware,项目名称:vic,代码行数:24,代码来源:datastore.go
示例16: Run
func (cmd *mkdir) Run(f *flag.FlagSet) error {
args := f.Args()
if len(args) == 0 {
return errors.New("missing operand")
}
c, err := cmd.Client()
if err != nil {
return err
}
dc, err := cmd.Datacenter()
if err != nil {
return err
}
// TODO(PN): Accept multiple args
path, err := cmd.DatastorePath(args[0])
if err != nil {
return err
}
m := object.NewFileManager(c)
err = m.MakeDirectory(context.TODO(), path, dc, cmd.createParents)
// ignore EEXIST if -p flag is given
if err != nil && cmd.createParents {
if soap.IsSoapFault(err) {
soapFault := soap.ToSoapFault(err)
if _, ok := soapFault.VimFault().(types.FileAlreadyExists); ok {
return nil
}
}
}
return err
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:37,代码来源:mkdir.go
示例17: NewHelper
// NewDatastore returns a Datastore.
// ctx is a context,
// s is an authenticated session
// ds is the vsphere datastore
// rootdir is the top level directory to root all data. If root does not exist,
// it will be created. If it already exists, NOOP. This cannot be empty.
func NewHelper(ctx context.Context, s *session.Session, ds *object.Datastore, rootdir string) (*Helper, error) {
d := &Helper{
ds: ds,
s: s,
fm: object.NewFileManager(s.Vim25()),
}
if path.IsAbs(rootdir) {
rootdir = rootdir[1:]
}
if err := d.mkRootDir(ctx, rootdir); err != nil {
log.Infof("error creating root directory %s: %s", rootdir, err)
return nil, err
}
if d.RootURL == "" {
return nil, fmt.Errorf("failed to create root directory")
}
log.Infof("Datastore path is %s", d.RootURL)
return d, nil
}
开发者ID:vmware,项目名称:vic,代码行数:30,代码来源:datastore.go
示例18: Run
func (cmd *mv) Run(f *flag.FlagSet) error {
args := f.Args()
if len(args) != 2 {
return errors.New("SRC and DST arguments are required")
}
c, err := cmd.Client()
if err != nil {
return err
}
dc, err := cmd.Datacenter()
if err != nil {
return err
}
// TODO: support cross-datacenter move
src, err := cmd.DatastorePath(args[0])
if err != nil {
return err
}
dst, err := cmd.DatastorePath(args[1])
if err != nil {
return err
}
m := object.NewFileManager(c)
task, err := m.MoveDatastoreFile(context.TODO(), src, dc, dst, dc, cmd.force)
if err != nil {
return err
}
return task.Wait(context.TODO())
}
开发者ID:kristinn,项目名称:govmomi,代码行数:36,代码来源:mv.go
示例19: Remove
func (d *Driver) Remove() error {
machineState, err := d.GetState()
if err != nil {
return err
}
if machineState == state.Running {
if err = d.Kill(); err != nil {
return fmt.Errorf("can't stop VM: %s", err)
}
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := d.vsphereLogin(ctx)
if err != nil {
return err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
dc, err := f.DatacenterOrDefault(ctx, d.Datacenter)
if err != nil {
return err
}
f.SetDatacenter(dc)
dss, err := f.DatastoreOrDefault(ctx, d.Datastore)
if err != nil {
return err
}
// Remove B2D Iso from VM folder
m := object.NewFileManager(c.Client)
task, err := m.DeleteDatastoreFile(ctx, dss.Path(fmt.Sprintf("%s/%s", d.MachineName, isoFilename)), dc)
if err != nil {
return err
}
err = task.Wait(ctx)
if err != nil {
if types.IsFileNotFound(err) {
// Ignore error
return nil
}
}
vm, err := d.fetchVM(c, ctx, d.MachineName)
if err != nil {
return err
}
task, err = vm.Destroy(ctx)
if err != nil {
return err
}
_, err = task.WaitForResult(ctx, nil)
if err != nil {
return err
}
return nil
}
开发者ID:HewlettPackard,项目名称:oneview-golang,代码行数:65,代码来源:vsphere.go
示例20: Remove
func (c *Container) Remove(ctx context.Context, sess *session.Session) error {
defer trace.End(trace.Begin("Container.Remove"))
c.Lock()
defer c.Unlock()
if c.vm == nil {
return NotFoundError{}
}
// check state first
if c.State == StateRunning {
return RemovePowerError{fmt.Errorf("Container is powered on")}
}
// get existing state and set to removing
// if there's a failure we'll revert to existing
existingState := c.State
c.State = StateRemoving
// get the folder the VM is in
url, err := c.vm.DSPath(ctx)
if err != nil {
// handle the out-of-band removal case
if soap.IsSoapFault(err) {
fault := soap.ToSoapFault(err).VimFault()
if _, ok := fault.(types.ManagedObjectNotFound); ok {
containers.Remove(c.ExecConfig.ID)
return NotFoundError{}
}
}
log.Errorf("Failed to get datastore path for %s: %s", c.ExecConfig.ID, err)
c.State = existingState
return err
}
// FIXME: was expecting to find a utility function to convert to/from datastore/url given
// how widely it's used but couldn't - will ask around.
dsPath := fmt.Sprintf("[%s] %s", url.Host, url.Path)
//removes the vm from vsphere, but detaches the disks first
_, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return c.vm.DeleteExceptDisks(ctx)
})
if err != nil {
c.State = existingState
return err
}
// remove from datastore
fm := object.NewFileManager(c.vm.Client.Client)
if _, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return fm.DeleteDatastoreFile(ctx, dsPath, sess.Datacenter)
}); err != nil {
c.State = existingState
log.Debugf("Failed to delete %s, %s", dsPath, err)
}
//remove container from cache
containers.Remove(c.ExecConfig.ID)
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:63,代码来源:container.go
注:本文中的github.com/vmware/govmomi/object.NewFileManager函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论