Skip to content

Commit 4961641

Browse files
committed
Add support for applying image configuration to uncustomised server deployment configuration.
1 parent 5f93b25 commit 4961641

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

compute/customer_images.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func (image *CustomerImage) GetOS() OperatingSystem {
9191
return image.Guest.OperatingSystem
9292
}
9393

94+
// RequiresCustomization determines whether the image requires guest OS customisation during deployment.
95+
func (image *CustomerImage) RequiresCustomization() bool {
96+
return image.Guest.OSCustomization
97+
}
98+
9499
// ApplyTo applies the CustomerImage to the specified ServerDeploymentConfiguration.
95100
func (image *CustomerImage) ApplyTo(config *ServerDeploymentConfiguration) {
96101
config.ImageID = image.ID
@@ -102,6 +107,20 @@ func (image *CustomerImage) ApplyTo(config *ServerDeploymentConfiguration) {
102107
}
103108
}
104109

110+
// ApplyToUncustomized applies the CustomerImage to the specified UncustomizedServerDeploymentConfiguration.
111+
func (image *CustomerImage) ApplyToUncustomized(config *UncustomizedServerDeploymentConfiguration) {
112+
config.ImageID = image.ID
113+
config.CPU = image.CPU
114+
config.MemoryGB = image.MemoryGB
115+
if len(image.SCSIControllers) == 0 {
116+
return
117+
}
118+
config.Disks = make(VirtualMachineDisks, len(image.SCSIControllers[0].Disks))
119+
for index, disk := range image.SCSIControllers[0].Disks {
120+
config.Disks[index] = disk
121+
}
122+
}
123+
105124
var _ Image = &CustomerImage{}
106125

107126
// Request body when exporting a customer image to an OVF package.

compute/images.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ type Image interface {
3939
// GetOS retrieves information about the image's operating system.
4040
GetOS() OperatingSystem
4141

42+
// RequiresCustomization determines whether the image requires guest OS customisation during deployment.
43+
RequiresCustomization() bool
44+
4245
// ApplyTo applies the Image to the specified ServerDeploymentConfiguration.
4346
ApplyTo(config *ServerDeploymentConfiguration)
47+
48+
// ApplyToUncustomized applies the Image to the specified UncustomizedServerDeploymentConfiguration.
49+
ApplyToUncustomized(config *UncustomizedServerDeploymentConfiguration)
4450
}

compute/os_images.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func (image *OSImage) GetOS() OperatingSystem {
7474
return image.Guest.OperatingSystem
7575
}
7676

77+
// RequiresCustomization determines whether the image requires guest OS customisation during deployment.
78+
func (image *OSImage) RequiresCustomization() bool {
79+
return image.Guest.OSCustomization
80+
}
81+
7782
// ApplyTo applies the OSImage to the specified ServerDeploymentConfiguration.
7883
func (image *OSImage) ApplyTo(config *ServerDeploymentConfiguration) {
7984
config.ImageID = image.ID
@@ -83,7 +88,20 @@ func (image *OSImage) ApplyTo(config *ServerDeploymentConfiguration) {
8388
for index, scsiController := range image.SCSIControllers {
8489
config.SCSIControllers[index] = scsiController
8590
}
91+
}
8692

93+
// ApplyToUncustomized applies the OSImage to the specified UncustomizedServerDeploymentConfiguration.
94+
func (image *OSImage) ApplyToUncustomized(config *UncustomizedServerDeploymentConfiguration) {
95+
config.ImageID = image.ID
96+
config.CPU = image.CPU
97+
config.MemoryGB = image.MemoryGB
98+
if len(image.SCSIControllers) == 0 {
99+
return
100+
}
101+
config.Disks = make(VirtualMachineDisks, len(image.SCSIControllers[0].Disks))
102+
for index, disk := range image.SCSIControllers[0].Disks {
103+
config.Disks[index] = disk
104+
}
87105
}
88106

89107
var _ Image = &OSImage{}

0 commit comments

Comments
 (0)