Browse Source

Add xenserver-os-template parameter, to use an arbitrary template instead of boot2docker

any_template_pr
Fábio Kaiser Rauber 6 years ago
parent
commit
6260f87198
  1. 34
      xenserver/xenserver.go

34
xenserver/xenserver.go

@ -30,7 +30,6 @@ import (
const (
isoFilename = "boot2docker.iso"
tarFilename = "boot2docker.tar"
osTemplateLabelName = "Other install media"
B2D_USER = "docker"
B2D_PASS = "tcuser"
)
@ -54,6 +53,7 @@ type Driver struct {
WaitTimeout uint
CaCertPath string
PrivateKeyPath string
osTemplateLabelName string
xenAPIClient *XenAPIClient
}
@ -127,6 +127,13 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "XenServer wait VM start timeout(seconds)",
Value: 30 * 60,
},
mcnflag.StringFlag{
EnvVar: "XENSERVER_OS_TEMPLATE",
Name: "xenserver-os-template",
Usage: "XenServer OS Template Label Name",
Value: "Other install media",
},
}
}
@ -186,6 +193,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SwarmDiscovery = flags.String("swarm-discovery")
d.ISO = d.ResolveStorePath(isoFilename)
d.TAR = d.ResolveStorePath(tarFilename)
d.osTemplateLabelName = flags.String("xenserver-os-template")
return nil
}
@ -320,10 +328,16 @@ func (d *Driver) Create() error {
return err
}
// Only upload ISO image if using Other install media, otherwise use existing VM template
var sr *xsclient.SR
var isoVdi,diskVdi *xsclient.VDI
var isoVdiUuid,diskVdiUuid string
if d.osTemplateLabelName == "Other install media" {
log.Infof("Creating ISO VDI...")
// Get the SR
var sr *xsclient.SR
if d.SR == "" {
sr, err = c.GetDefaultSR()
if sr.Ref == "OpaqueRef:NULL" {
@ -346,7 +360,7 @@ func (d *Driver) Create() error {
}
// Create the VDI
isoVdi, err := sr.CreateVdi(isoFilename, isoFileInfo.Size())
isoVdi, err = sr.CreateVdi(isoFilename, isoFileInfo.Size())
if err != nil {
log.Errorf("Unable to create ISO VDI '%s': %v", isoFilename, err)
return err
@ -357,7 +371,7 @@ func (d *Driver) Create() error {
return err
}
isoVdiUuid, err := isoVdi.GetUuid()
isoVdiUuid, err = isoVdi.GetUuid()
if err != nil {
return err
}
@ -369,7 +383,7 @@ func (d *Driver) Create() error {
}
// Create the VDI
diskVdi, err := sr.CreateVdi("bootdocker disk", int64(d.DiskSize)*1024*1024)
diskVdi, err = sr.CreateVdi("bootdocker disk", int64(d.DiskSize)*1024*1024)
if err != nil {
log.Errorf("Unable to create ISO VDI '%s': %v", "bootdocker disk", err)
return err
@ -378,14 +392,16 @@ func (d *Driver) Create() error {
return err
}
diskVdiUuid, err := diskVdi.GetUuid()
diskVdiUuid, err = diskVdi.GetUuid()
if err != nil {
return err
}
}
log.Infof("Creating VM...")
vm0, err := c.GetUniqueVMByNameLabel(osTemplateLabelName)
vm0, err := c.GetUniqueVMByNameLabel(d.osTemplateLabelName)
if err != nil {
return err
}
@ -407,7 +423,7 @@ func (d *Driver) Create() error {
}
otherConfig := map[string]string{
"base_template_name": osTemplateLabelName,
"base_template_name": d.osTemplateLabelName,
"install-methods": "cdrom,nfs,http,ftp",
"linux_template": "true",
"mac_seed": vmMacSeed,
@ -463,6 +479,7 @@ func (d *Driver) Create() error {
return err
}
if d.osTemplateLabelName == "Other install media" {
log.Infof("Add ISO VDI to VM...")
diskVdi, err = c.GetVdiByUuid(isoVdiUuid)
if err != nil {
@ -484,6 +501,7 @@ func (d *Driver) Create() error {
if err != nil {
return err
}
}
log.Infof("Add Network to VM...")
var networks []*xsclient.Network

Loading…
Cancel
Save