github.com/vmware/govmomi@v0.43.0/govc/importx/ova.go (about) 1 /* 2 Copyright (c) 2014-2024 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package importx 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/object" 25 "github.com/vmware/govmomi/ovf/importer" 26 "github.com/vmware/govmomi/vim25/types" 27 ) 28 29 type ova struct { 30 *ovfx 31 } 32 33 func init() { 34 cli.Register("import.ova", &ova{&ovfx{}}) 35 } 36 37 func (cmd *ova) Usage() string { 38 return "PATH_TO_OVA" 39 } 40 41 func (cmd *ova) Run(ctx context.Context, f *flag.FlagSet) error { 42 fpath, err := cmd.Prepare(f) 43 if err != nil { 44 return err 45 } 46 47 archive := &importer.TapeArchive{Path: fpath} 48 archive.Client = cmd.Importer.Client 49 50 cmd.Importer.Archive = archive 51 52 moref, err := cmd.Import(fpath) 53 if err != nil { 54 return err 55 } 56 57 vm := object.NewVirtualMachine(cmd.Importer.Client, *moref) 58 return cmd.Deploy(vm, cmd.OutputFlag) 59 } 60 61 func (cmd *ova) Import(fpath string) (*types.ManagedObjectReference, error) { 62 ovf := "*.ovf" 63 return cmd.Importer.Import(context.TODO(), ovf, cmd.Options) 64 }