-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(vsphere-iso) remove deprecated network and disk fields (#9149)
* remove deprecated network and disk fields
- Loading branch information
jhawk28
authored
May 19, 2020
1 parent
541ec89
commit 820f353
Showing
7 changed files
with
266 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package fix | ||
|
||
import ( | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
// FixerVSphereNetworkDisk changes vsphere-iso network and networkCard fields into a network adapter and | ||
// changes the disk_size, disk_thin_provisioned, and disk_eagerly_scrub into a storage adapter | ||
type FixerVSphereNetworkDisk struct{} | ||
|
||
func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]interface{}, error) { | ||
// The type we'll decode into; we only care about builders | ||
type template struct { | ||
Builders []map[string]interface{} | ||
} | ||
|
||
// Decode the input into our structure, if we can | ||
var tpl template | ||
if err := mapstructure.Decode(input, &tpl); err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, builder := range tpl.Builders { | ||
builderTypeRaw, ok := builder["type"] | ||
if !ok { | ||
continue | ||
} | ||
|
||
builderType, ok := builderTypeRaw.(string) | ||
if !ok { | ||
continue | ||
} | ||
|
||
if builderType != "vsphere-iso" { | ||
continue | ||
} | ||
|
||
var networkAdapters []interface{} | ||
nic := make(map[string]interface{}) | ||
hasNetwork := false | ||
|
||
networkRaw, ok := builder["network"] | ||
if ok { | ||
nic["network"] = networkRaw | ||
delete(builder, "network") | ||
hasNetwork = true | ||
} | ||
|
||
networkCardRaw, ok := builder["networkCard"] | ||
if ok { | ||
nic["networkCard"] = networkCardRaw | ||
delete(builder, "networkCard") | ||
hasNetwork = true | ||
} | ||
|
||
if hasNetwork { | ||
networkAdapters = append(networkAdapters, nic) | ||
adaptersRaw, ok := builder["network_adapters"] | ||
if ok { | ||
existingAdapters := adaptersRaw.([]interface{}) | ||
networkAdapters = append(networkAdapters, existingAdapters...) | ||
} | ||
|
||
builder["network_adapters"] = networkAdapters | ||
} | ||
|
||
var storage []interface{} | ||
disk := make(map[string]interface{}) | ||
hasStorage := false | ||
|
||
diskSizeRaw, ok := builder["disk_size"] | ||
if ok { | ||
disk["disk_size"] = diskSizeRaw | ||
delete(builder, "disk_size") | ||
hasStorage = true | ||
} | ||
|
||
discThinProvisionedRaw, ok := builder["disk_thin_provisioned"] | ||
if ok { | ||
disk["disk_thin_provisioned"] = discThinProvisionedRaw | ||
hasStorage = true | ||
delete(builder, "disk_thin_provisioned") | ||
} | ||
|
||
diskEagerlyScrubRaw, ok := builder["disk_eagerly_scrub"] | ||
if ok { | ||
disk["disk_eagerly_scrub"] = diskEagerlyScrubRaw | ||
hasStorage = true | ||
delete(builder, "disk_eagerly_scrub") | ||
} | ||
|
||
if hasStorage { | ||
storage = append(storage, disk) | ||
storageRaw, ok := builder["storage"] | ||
if ok { | ||
existingStorage := storageRaw.([]interface{}) | ||
storage = append(storage, existingStorage...) | ||
} | ||
|
||
builder["storage"] = storage | ||
} | ||
} | ||
|
||
input["builders"] = tpl.Builders | ||
return input, nil | ||
} | ||
|
||
func (FixerVSphereNetworkDisk) Synopsis() string { | ||
return `Removes deprecated network and disk fields from "vsphere-iso" builder` | ||
} |
Oops, something went wrong.