parent
f6a317cb41
commit
5c090071a9
@ -624,6 +624,17 @@ func ConnectNetwork(c *Connection, networkRef xenapi.NetworkRef, vmRef xenapi.VM
|
||||
return &vif, nil
|
||||
}
|
||||
|
||||
func AddVMTags(c *Connection, vmRef xenapi.VMRef, tags []string) error {
|
||||
for _, tag := range tags {
|
||||
log.Printf("Adding tag %s to VM %s\n", tag, vmRef)
|
||||
err := c.GetClient().VM.AddTags(c.session, vmRef, tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
func (self *VM) SetIsATemplate(is_a_template bool) (err error) {
|
||||
|
@ -24,6 +24,7 @@ type CommonConfig struct {
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
NetworkNames []string `mapstructure:"network_names"`
|
||||
ExportNetworkNames []string `mapstructure:"export_network_names"`
|
||||
VMTags []string `mapstructure:"vm_tags"`
|
||||
|
||||
HostPortMin uint `mapstructure:"host_port_min"`
|
||||
HostPortMax uint `mapstructure:"host_port_max"`
|
||||
|
@ -20,6 +20,7 @@ type Config struct {
|
||||
DiskSize uint `mapstructure:"disk_size"`
|
||||
CloneTemplate string `mapstructure:"clone_template"`
|
||||
VMOtherConfig map[string]string `mapstructure:"vm_other_config"`
|
||||
VMTags []string `mapstructure:"vm_tags"`
|
||||
|
||||
ISOChecksum string `mapstructure:"iso_checksum"`
|
||||
ISOUrls []string `mapstructure:"iso_urls"`
|
||||
|
@ -216,6 +216,12 @@ func (self *StepCreateInstance) Run(ctx context.Context, state multistep.StateBa
|
||||
}
|
||||
}
|
||||
|
||||
err = AddVMTags(c, instance, config.VMTags)
|
||||
if err != nil {
|
||||
ui.Error(fmt.Sprintf("Failed to add tags: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
instanceId, err := c.GetClient().VM.GetUUID(c.GetSessionRef(), instance)
|
||||
if err != nil {
|
||||
ui.Error(fmt.Sprintf("Unable to get VM UUID: %s", err.Error()))
|
||||
|
@ -86,6 +86,12 @@ func (self *stepImportInstance) Run(ctx context.Context, state multistep.StateBa
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
err = xscommon.AddVMTags(c, instance, config.VMTags)
|
||||
if err != nil {
|
||||
ui.Error(fmt.Sprintf("Failed to add tags: %s", err.Error()))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
ui.Say(fmt.Sprintf("Imported instance '%s'", instanceId))
|
||||
|
||||
return multistep.ActionContinue
|
||||
|
Loading…
Reference in New Issue
Block a user