mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 01:59:07 +00:00
Backend vCenter: Upload ISO only with linuxkit push
Signed-off-by: Stefan Bourlon <stefan.bourlon@ca.com>
This commit is contained in:
parent
561c204de6
commit
ea5114dc93
@ -10,6 +10,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/vmware/govmomi"
|
||||||
|
"github.com/vmware/govmomi/object"
|
||||||
|
"github.com/vmware/govmomi/vim25/soap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process the push arguments and execute push
|
// Process the push arguments and execute push
|
||||||
@ -67,3 +70,29 @@ func pushVCenter(args []string) {
|
|||||||
// The CreateFolder method isn't necessary as the *newVM.vmname will be created automatically
|
// The CreateFolder method isn't necessary as the *newVM.vmname will be created automatically
|
||||||
uploadFile(c, newVM, dss)
|
uploadFile(c, newVM, dss)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkFile(file string) {
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
|
if os.IsPermission(err) {
|
||||||
|
log.Fatalf("Unable to read file [%s], please check permissions", file)
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
log.Fatalf("File [%s], does not exist", file)
|
||||||
|
} else {
|
||||||
|
log.Fatalf("Unable to stat file [%s]: %v", file, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadFile(c *govmomi.Client, newVM vmConfig, dss *object.Datastore) {
|
||||||
|
_, fileName := path.Split(*newVM.path)
|
||||||
|
log.Infof("Uploading LinuxKit file [%s]", *newVM.path)
|
||||||
|
if *newVM.path == "" {
|
||||||
|
log.Fatalf("No file specified")
|
||||||
|
}
|
||||||
|
dsurl := dss.NewURL(fmt.Sprintf("%s/%s", *newVM.vmFolder, fileName))
|
||||||
|
|
||||||
|
p := soap.DefaultUpload
|
||||||
|
if err := c.Client.UploadFile(*newVM.path, dsurl, &p); err != nil {
|
||||||
|
log.Fatalf("Unable to upload file to vCenter Datastore\n%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/vmware/govmomi"
|
"github.com/vmware/govmomi"
|
||||||
"github.com/vmware/govmomi/find"
|
"github.com/vmware/govmomi/find"
|
||||||
"github.com/vmware/govmomi/object"
|
"github.com/vmware/govmomi/object"
|
||||||
"github.com/vmware/govmomi/vim25/soap"
|
|
||||||
"github.com/vmware/govmomi/vim25/types"
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
@ -89,9 +88,6 @@ func runVcenter(args []string) {
|
|||||||
log.Fatalln("Please pass an \".iso\" file as the path")
|
log.Fatalln("Please pass an \".iso\" file as the path")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test any passed in files before creating a new VM
|
|
||||||
checkFile(*newVM.path)
|
|
||||||
|
|
||||||
// Connect to VMware vCenter and return the default and found values needed for a new VM
|
// Connect to VMware vCenter and return the default and found values needed for a new VM
|
||||||
c, dss, folders, hs, net, rp := vCenterConnect(ctx, newVM)
|
c, dss, folders, hs, net, rp := vCenterConnect(ctx, newVM)
|
||||||
|
|
||||||
@ -127,7 +123,6 @@ func runVcenter(args []string) {
|
|||||||
// Retrieve the new VM
|
// Retrieve the new VM
|
||||||
vm := object.NewVirtualMachine(c.Client, info.Result.(types.ManagedObjectReference))
|
vm := object.NewVirtualMachine(c.Client, info.Result.(types.ManagedObjectReference))
|
||||||
|
|
||||||
uploadFile(c, newVM, dss)
|
|
||||||
addISO(ctx, newVM, vm, dss)
|
addISO(ctx, newVM, vm, dss)
|
||||||
|
|
||||||
if *newVM.persistent != "" {
|
if *newVM.persistent != "" {
|
||||||
@ -237,20 +232,6 @@ func powerOnVM(ctx context.Context, vm *object.VirtualMachine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFile(c *govmomi.Client, newVM vmConfig, dss *object.Datastore) {
|
|
||||||
_, fileName := path.Split(*newVM.path)
|
|
||||||
log.Infof("Uploading LinuxKit file [%s]", *newVM.path)
|
|
||||||
if *newVM.path == "" {
|
|
||||||
log.Fatalf("No file specified")
|
|
||||||
}
|
|
||||||
dsurl := dss.NewURL(fmt.Sprintf("%s/%s", *newVM.vmFolder, fileName))
|
|
||||||
|
|
||||||
p := soap.DefaultUpload
|
|
||||||
if err := c.Client.UploadFile(*newVM.path, dsurl, &p); err != nil {
|
|
||||||
log.Fatalf("Unable to upload file to vCenter Datastore\n%v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addNIC(ctx context.Context, vm *object.VirtualMachine, net object.NetworkReference) {
|
func addNIC(ctx context.Context, vm *object.VirtualMachine, net object.NetworkReference) {
|
||||||
backing, err := net.EthernetCardBackingInfo(ctx)
|
backing, err := net.EthernetCardBackingInfo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -321,15 +302,3 @@ func addISO(ctx context.Context, newVM vmConfig, vm *object.VirtualMachine, dss
|
|||||||
log.Fatalf("Unable to add new CD-ROM device to VM configuration\n%v", err)
|
log.Fatalf("Unable to add new CD-ROM device to VM configuration\n%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkFile(file string) {
|
|
||||||
if _, err := os.Stat(file); err != nil {
|
|
||||||
if os.IsPermission(err) {
|
|
||||||
log.Fatalf("Unable to read file [%s], please check permissions", file)
|
|
||||||
} else if os.IsNotExist(err) {
|
|
||||||
log.Fatalf("File [%s], does not exist", file)
|
|
||||||
} else {
|
|
||||||
log.Fatalf("Unable to stat file [%s]: %v", file, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user