diff options
author | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-10 20:21:38 +0100 |
---|---|---|
committer | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-16 11:26:28 +0100 |
commit | 4271bcd7af38442f2836f42607f02561b0af4fc7 (patch) | |
tree | 31e7c1508b9dcb15f8be0f8f9d51224c046ed93d | |
parent | 5c914a032d864314c5b81373c940d354120bffdb (diff) | |
download | terraform-provider-libvirt-4271bcd7af38442f2836f42607f02561b0af4fc7.tar terraform-provider-libvirt-4271bcd7af38442f2836f42607f02561b0af4fc7.tar.gz |
golinting on various files
-rw-r--r-- | libvirt/cloudinit_def.go | 3 | ||||
-rw-r--r-- | libvirt/disk_def.go | 1 | ||||
-rw-r--r-- | libvirt/libvirt_interfaces.go | 1 | ||||
-rw-r--r-- | libvirt/network_def.go | 4 | ||||
-rw-r--r-- | libvirt/provider.go | 1 | ||||
-rw-r--r-- | libvirt/qemu_agent.go | 3 | ||||
-rw-r--r-- | libvirt/resource_cloud_init.go | 354 | ||||
-rw-r--r-- | libvirt/resource_libvirt_coreos_ignition_test.go | 4 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 22 | ||||
-rw-r--r-- | libvirt/resource_libvirt_volume.go | 30 | ||||
-rw-r--r-- | libvirt/resource_libvirt_volume_test.go | 4 | ||||
-rw-r--r-- | libvirt/stream.go | 2 | ||||
-rw-r--r-- | libvirt/utils.go | 1 | ||||
-rw-r--r-- | libvirt/utils_net.go | 2 |
14 files changed, 110 insertions, 322 deletions
diff --git a/libvirt/cloudinit_def.go b/libvirt/cloudinit_def.go index ef43ba2c..59ccbb63 100644 --- a/libvirt/cloudinit_def.go +++ b/libvirt/cloudinit_def.go @@ -21,10 +21,11 @@ import ( // USERDATA is the name of file expected by cloud-init const USERDATA string = "user-data" + // METADATA is the name of file expected by cloud-init const METADATA string = "meta-data" -// CloudInitUserData struct +// CloudInitUserData struct type CloudInitUserData struct { SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"` } diff --git a/libvirt/disk_def.go b/libvirt/disk_def.go index fd3f9aa8..3283f03b 100644 --- a/libvirt/disk_def.go +++ b/libvirt/disk_def.go @@ -8,7 +8,6 @@ import ( const oui = "05abcd" - func newDefDisk() libvirtxml.DomainDisk { return libvirtxml.DomainDisk{ Type: "file", diff --git a/libvirt/libvirt_interfaces.go b/libvirt/libvirt_interfaces.go index 4c2b4fcd..af21fb14 100644 --- a/libvirt/libvirt_interfaces.go +++ b/libvirt/libvirt_interfaces.go @@ -8,6 +8,7 @@ type LibVirtDomain interface { QemuAgentCommand(command string, timeout libvirt.DomainQemuAgentCommandTimeout, flags uint32) (string, error) } +// LibVirtNetwork interface type LibVirtNetwork interface { GetXMLDesc(flags libvirt.NetworkXMLFlags) (string, error) } diff --git a/libvirt/network_def.go b/libvirt/network_def.go index e62bdfc2..9c774373 100644 --- a/libvirt/network_def.go +++ b/libvirt/network_def.go @@ -28,12 +28,12 @@ func newDefNetworkFromXML(s string) (libvirtxml.Network, error) { } func newDefNetworkfromLibvirt(network LibVirtNetwork) (libvirtxml.Network, error) { - networkXmlDesc, err := network.GetXMLDesc(0) + networkXMLDesc, err := network.GetXMLDesc(0) if err != nil { return libvirtxml.Network{}, fmt.Errorf("Error retrieving libvirt domain XML description: %s", err) } networkDef := libvirtxml.Network{} - err = xml.Unmarshal([]byte(networkXmlDesc), &networkDef) + err = xml.Unmarshal([]byte(networkXMLDesc), &networkDef) if err != nil { return libvirtxml.Network{}, fmt.Errorf("Error reading libvirt network XML description: %s", err) } diff --git a/libvirt/provider.go b/libvirt/provider.go index 010ad8b4..c5f9b09f 100644 --- a/libvirt/provider.go +++ b/libvirt/provider.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) +// Provider libvirt func Provider() terraform.ResourceProvider { return &schema.Provider{ Schema: map[string]*schema.Schema{ diff --git a/libvirt/qemu_agent.go b/libvirt/qemu_agent.go index d89866a3..71fc6db1 100644 --- a/libvirt/qemu_agent.go +++ b/libvirt/qemu_agent.go @@ -7,16 +7,19 @@ import ( libvirt "github.com/libvirt/libvirt-go" ) + // QemuAgentInterfacesResponse type type QemuAgentInterfacesResponse struct { Interfaces []QemuAgentInterface `json:"return"` } + // QemuAgentInterface type type QemuAgentInterface struct { Name string `json:"name"` Hwaddr string `json:"hardware-address"` IPAddresses []QemuAgentInterfaceIPAddress `json:"ip-addresses"` } + // QemuAgentInterfaceIPAddress type type QemuAgentInterfaceIPAddress struct { Type string `json:"ip-address-type"` diff --git a/libvirt/resource_cloud_init.go b/libvirt/resource_cloud_init.go index 86c72ac7..da3e9832 100644 --- a/libvirt/resource_cloud_init.go +++ b/libvirt/resource_cloud_init.go @@ -1,341 +1,119 @@ package libvirt import ( - "encoding/xml" "fmt" "log" - "net/http" - "strconv" "github.com/hashicorp/terraform/helper/schema" - libvirt "github.com/libvirt/libvirt-go" ) -func volumeCommonSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "name": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "pool": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Default: "default", - ForceNew: true, - }, - "source": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "size": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - "format": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "base_volume_id": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "base_volume_pool": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "base_volume_name": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - } -} - -func resourceLibvirtVolume() *schema.Resource { +func resourceCloudInit() *schema.Resource { return &schema.Resource{ - Create: resourceLibvirtVolumeCreate, - Read: resourceLibvirtVolumeRead, - Delete: resourceLibvirtVolumeDelete, - Schema: volumeCommonSchema(), - } -} - -func remoteImageSize(url string) (int, error) { - response, err := http.Head(url) - if err != nil { - return 0, err - } - length, err := strconv.Atoi(response.Header.Get("Content-Length")) - if err != nil { - return 0, err + Create: resourceCloudInitCreate, + Read: resourceCloudInitRead, + Delete: resourceCloudInitDelete, + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "pool": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "default", + ForceNew: true, + }, + "local_hostname": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "user_data": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ssh_authorized_key": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + }, } - return length, nil } -func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error { +func resourceCloudInitCreate(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] creating cloudinit") virConn := meta.(*Client).libvirt if virConn == nil { return fmt.Errorf("the libvirt connection was nil") } - poolName := "default" - if _, ok := d.GetOk("pool"); ok { - poolName = d.Get("pool").(string) - } - - PoolSync.AcquireLock(poolName) - defer PoolSync.ReleaseLock(poolName) - - pool, err := virConn.LookupStoragePoolByName(poolName) - if err != nil { - return fmt.Errorf("can't find storage pool '%s'", poolName) - } - defer pool.Free() - - // Refresh the pool of the volume so that libvirt knows it is - // not longer in use. - WaitForSuccess("Error refreshing pool for volume", func() error { - return pool.Refresh(0) - }) - - volumeDef := newDefVolume() + cloudInit := newCloudInitDef() + cloudInit.Metadata.LocalHostname = d.Get("local_hostname").(string) + cloudInit.UserDataRaw = d.Get("user_data").(string) - if name, ok := d.GetOk("name"); ok { - volumeDef.Name = name.(string) + if _, ok := d.GetOk("ssh_authorized_key"); ok { + sshKey := d.Get("ssh_authorized_key").(string) + cloudInit.UserData.SSHAuthorizedKeys = append( + cloudInit.UserData.SSHAuthorizedKeys, + sshKey) } - volumeFormat := "qcow2" - if _, ok := d.GetOk("format"); ok { - volumeFormat = d.Get("format").(string) - } - volumeDef.Target.Format.Type = volumeFormat - - var ( - img image - volume *libvirt.StorageVol = nil - ) - - // an source image was given, this mean we can't choose size - if source, ok := d.GetOk("source"); ok { - // source and size conflict - if _, ok := d.GetOk("size"); ok { - return fmt.Errorf("'size' can't be specified when also 'source' is given (the size will be set to the size of the source image") - } - if _, ok := d.GetOk("base_volume_id"); ok { - return fmt.Errorf("'base_volume_id' can't be specified when also 'source' is given") - } - - if _, ok := d.GetOk("base_volume_name"); ok { - return fmt.Errorf("'base_volume_name' can't be specified when also 'source' is given") - } + cloudInit.Name = d.Get("name").(string) + cloudInit.PoolName = d.Get("pool").(string) - // Check if we already have this image in the pool - if len(volumeDef.Name) > 0 { - if v, err := pool.LookupStorageVolByName(volumeDef.Name); err != nil { - log.Printf("Could not find image %s in pool %s", volumeDef.Name, poolName) - } else { - volume = v - volumeDef, err = newDefVolumeFromLibvirt(volume) - if err != nil { - return fmt.Errorf("could not get a volume definition from XML for %s: %s", volumeDef.Name, err) - } - } - } - - if img, err = newImage(source.(string)); err != nil { - return err - } - - // update the image in the description, even if the file has not changed - if size, err := img.Size(); err != nil { - return err - } else { - log.Printf("Image %s image is: %d bytes", img, size) - volumeDef.Capacity.Unit = "B" - volumeDef.Capacity.Value = size - } - } else { - _, noSize := d.GetOk("size") - _, noBaseVol := d.GetOk("base_volume_id") - - if noSize && noBaseVol { - return fmt.Errorf("'size' needs to be specified if no 'source' or 'base_volume_id' is given") - } - volumeDef.Capacity.Value = uint64(d.Get("size").(int)) - } + log.Printf("[INFO] cloudInit: %+v", cloudInit) - if baseVolumeId, ok := d.GetOk("base_volume_id"); ok { - if _, ok := d.GetOk("size"); ok { - return fmt.Errorf("'size' can't be specified when also 'base_volume_id' is given (the size will be set to the size of the backing image") - } - - if _, ok := d.GetOk("base_volume_name"); ok { - return fmt.Errorf("'base_volume_name' can't be specified when also 'base_volume_id' is given") - } - - volume = nil - baseVolume, err := virConn.LookupStorageVolByKey(baseVolumeId.(string)) - if err != nil { - return fmt.Errorf("Can't retrieve volume %s", baseVolumeId.(string)) - } - backingStoreDef, err := newDefBackingStoreFromLibvirt(baseVolume) - if err != nil { - return fmt.Errorf("Could not retrieve backing store %s", baseVolumeId.(string)) - } - volumeDef.BackingStore = &backingStoreDef - } - - if baseVolumeName, ok := d.GetOk("base_volume_name"); ok { - if _, ok := d.GetOk("size"); ok { - return fmt.Errorf("'size' can't be specified when also 'base_volume_name' is given (the size will be set to the size of the backing image") - } - - volume = nil - baseVolumePool := pool - if _, ok := d.GetOk("base_volume_pool"); ok { - baseVolumePoolName := d.Get("base_volume_pool").(string) - baseVolumePool, err = virConn.LookupStoragePoolByName(baseVolumePoolName) - if err != nil { - return fmt.Errorf("can't find storage pool '%s'", baseVolumePoolName) - } - defer baseVolumePool.Free() - } - baseVolume, err := baseVolumePool.LookupStorageVolByName(baseVolumeName.(string)) - if err != nil { - return fmt.Errorf("Can't retrieve volume %s", baseVolumeName.(string)) - } - backingStoreDef, err := newDefBackingStoreFromLibvirt(baseVolume) - if err != nil { - return fmt.Errorf("Could not retrieve backing store %s", baseVolumeName.(string)) - } - volumeDef.BackingStore = &backingStoreDef - } - - if volume == nil { - volumeDefXml, err := xml.Marshal(volumeDef) - if err != nil { - return fmt.Errorf("Error serializing libvirt volume: %s", err) - } - - // create the volume - v, err := pool.StorageVolCreateXML(string(volumeDefXml), 0) - if err != nil { - return fmt.Errorf("Error creating libvirt volume: %s", err) - } - volume = v - defer volume.Free() - } - - // we use the key as the id - key, err := volume.GetKey() + key, err := cloudInit.CreateAndUpload(virConn) if err != nil { - return fmt.Errorf("Error retrieving volume key: %s", err) + return err } d.SetId(key) // make sure we record the id even if the rest of this gets interrupted - d.Partial(true) + d.Partial(true) // make sure we record the id even if the rest of this gets interrupted d.Set("id", key) d.SetPartial("id") + // TODO: at this point we have collected more things than the ID, so let's save as many things as we can d.Partial(false) - log.Printf("[INFO] Volume ID: %s", d.Id()) - - // upload source if present - if _, ok := d.GetOk("source"); ok { - err = img.Import(newCopier(virConn, volume, volumeDef.Capacity.Value), volumeDef) - if err != nil { - return fmt.Errorf("Error while uploading source %s: %s", img.String(), err) - } - } - - return resourceLibvirtVolumeRead(d, meta) + return resourceCloudInitRead(d, meta) } -func resourceLibvirtVolumeRead(d *schema.ResourceData, meta interface{}) error { +func resourceCloudInitRead(d *schema.ResourceData, meta interface{}) error { virConn := meta.(*Client).libvirt if virConn == nil { return fmt.Errorf("the libvirt connection was nil") } - volume, err := virConn.LookupStorageVolByKey(d.Id()) - if err != nil { - virErr := err.(libvirt.Error) - if virErr.Code != libvirt.ERR_NO_STORAGE_VOL { - return fmt.Errorf("Can't retrieve volume %s", d.Id()) - } - - log.Printf("[INFO] Volume %s not found, attempting to start its pool") - - volId := d.Id() - volPoolName := d.Get("pool").(string) - volPool, err := virConn.LookupStoragePoolByName(volPoolName) - if err != nil { - return fmt.Errorf("Error retrieving pool %s for volume %s: %s", volPoolName, volId, err) - } - defer volPool.Free() - - active, err := volPool.IsActive() - if err != nil { - return fmt.Errorf("error retrieving status of pool %s for volume %s: %s", volPoolName, volId, err) - } - if active { - return fmt.Errorf("can't retrieve volume %s", d.Id()) - } - - err = volPool.Create(0) - if err != nil { - return fmt.Errorf("error starting pool %s: %s", volPoolName, err) - } - - // attempt a new lookup - volume, err = virConn.LookupStorageVolByKey(d.Id()) - if err != nil { - return fmt.Errorf("second attempt: Can't retrieve volume %s", d.Id()) - } - } - defer volume.Free() - - volName, err := volume.GetName() - if err != nil { - return fmt.Errorf("error retrieving volume name: %s", err) - } - - volPool, err := volume.LookupPoolByVolume() + ci, err := newCloudInitDefFromRemoteISO(virConn, d.Id()) if err != nil { - return fmt.Errorf("error retrieving pool for volume: %s", err) + return fmt.Errorf("error while retrieving remote ISO: %s", err) } - defer volPool.Free() + d.Set("pool", ci.PoolName) + d.Set("name", ci.Name) + d.Set("local_hostname", ci.Metadata.LocalHostname) + d.Set("user_data", ci.UserDataRaw) - volPoolName, err := volPool.GetName() - if err != nil { - return fmt.Errorf("error retrieving pool name: %s", err) - } - - d.Set("pool", volPoolName) - d.Set("name", volName) - - info, err := volume.GetInfo() - if err != nil { - return fmt.Errorf("error retrieving volume name: %s", err) + if len(ci.UserData.SSHAuthorizedKeys) == 1 { + d.Set("ssh_authorized_key", ci.UserData.SSHAuthorizedKeys[0]) } - d.Set("size", info.Capacity) return nil } -func resourceLibvirtVolumeDelete(d *schema.ResourceData, meta interface{}) error { +func resourceCloudInitDelete(d *schema.ResourceData, meta interface{}) error { virConn := meta.(*Client).libvirt if virConn == nil { return fmt.Errorf("the libvirt connection was nil") } - return RemoveVolume(virConn, d.Id()) + key, err := getCloudInitVolumeKeyFromTerraformID(d.Id()) + if err != nil { + return err + } + + return RemoveVolume(virConn, key) } diff --git a/libvirt/resource_libvirt_coreos_ignition_test.go b/libvirt/resource_libvirt_coreos_ignition_test.go index 44e2561d..027cbd3a 100644 --- a/libvirt/resource_libvirt_coreos_ignition_test.go +++ b/libvirt/resource_libvirt_coreos_ignition_test.go @@ -72,12 +72,12 @@ func testAccCheckIgnitionVolumeExists(n string, volume *libvirt.StorageVol) reso } fmt.Printf("The ID is %s", rs.Primary.ID) - realId, err := retrievedVol.GetKey() + realID, err := retrievedVol.GetKey() if err != nil { return err } - if realId != ignKey { + if realID != ignKey { return fmt.Errorf("Resource ID and volume key does not match") } diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 3ca8d43f..70c06b93 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -19,11 +19,13 @@ import ( "github.com/libvirt/libvirt-go-xml" ) +// DomainMeta struct type DomainMeta struct { domain *libvirt.Domain ifaces chan libvirtxml.DomainInterface } +// PoolSync exported pool sync var PoolSync = NewLibVirtPoolSync() func init() { @@ -364,7 +366,7 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error disksCount := d.Get("disk.#").(int) var disks []libvirtxml.DomainDisk - var scsiDisk bool = false + var scsiDisk = false for i := 0; i < disksCount; i++ { disk := libvirtxml.DomainDisk{ Type: "file", @@ -682,16 +684,16 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error // if we were waiting for an IP address for this MAC, go ahead. if pending, ok := partialNetIfaces[mac]; ok { // we should have the address now - if addressesI, ok := d.GetOk(prefix + ".addresses"); !ok { + addressesI, ok := d.GetOk(prefix + ".addresses") + if !ok { return fmt.Errorf("Did not obtain the IP address for MAC=%s", mac) - } else { - for _, addressI := range addressesI.([]interface{}) { - address := addressI.(string) - log.Printf("[INFO] Finally adding IP/MAC/host=%s/%s/%s", address, mac, pending.hostname) - addHost(pending.network, address, mac, pending.hostname) - if err != nil { - return fmt.Errorf("Could not add IP/MAC/host=%s/%s/%s: %s", address, mac, pending.hostname, err) - } + } + for _, addressI := range addressesI.([]interface{}) { + address := addressI.(string) + log.Printf("[INFO] Finally adding IP/MAC/host=%s/%s/%s", address, mac, pending.hostname) + addHost(pending.network, address, mac, pending.hostname) + if err != nil { + return fmt.Errorf("Could not add IP/MAC/host=%s/%s/%s: %s", address, mac, pending.hostname, err) } } } diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go index 8a16bf0b..cdf1ddb0 100644 --- a/libvirt/resource_libvirt_volume.go +++ b/libvirt/resource_libvirt_volume.go @@ -119,7 +119,7 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error var ( img image - volume *libvirt.StorageVol = nil + volume *libvirt.StorageVol ) // an source image was given, this mean we can't choose size @@ -154,13 +154,13 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error } // update the image in the description, even if the file has not changed - if size, err := img.Size(); err != nil { + size, err := img.Size() + if err != nil { return err - } else { - log.Printf("Image %s image is: %d bytes", img, size) - volumeDef.Capacity.Unit = "B" - volumeDef.Capacity.Value = size } + log.Printf("Image %s image is: %d bytes", img, size) + volumeDef.Capacity.Unit = "B" + volumeDef.Capacity.Value = size } else { _, noSize := d.GetOk("size") _, noBaseVol := d.GetOk("base_volume_id") @@ -171,7 +171,7 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error volumeDef.Capacity.Value = uint64(d.Get("size").(int)) } - if baseVolumeId, ok := d.GetOk("base_volume_id"); ok { + if baseVolumeID, ok := d.GetOk("base_volume_id"); ok { if _, ok := d.GetOk("size"); ok { return fmt.Errorf("'size' can't be specified when also 'base_volume_id' is given (the size will be set to the size of the backing image") } @@ -181,13 +181,13 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error } volume = nil - baseVolume, err := virConn.LookupStorageVolByKey(baseVolumeId.(string)) + baseVolume, err := virConn.LookupStorageVolByKey(baseVolumeID.(string)) if err != nil { - return fmt.Errorf("Can't retrieve volume %s", baseVolumeId.(string)) + return fmt.Errorf("Can't retrieve volume %s", baseVolumeID.(string)) } backingStoreDef, err := newDefBackingStoreFromLibvirt(baseVolume) if err != nil { - return fmt.Errorf("Could not retrieve backing store %s", baseVolumeId.(string)) + return fmt.Errorf("Could not retrieve backing store %s", baseVolumeID.(string)) } volumeDef.BackingStore = &backingStoreDef } @@ -219,13 +219,13 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error } if volume == nil { - volumeDefXml, err := xml.Marshal(volumeDef) + volumeDefXML, err := xml.Marshal(volumeDef) if err != nil { return fmt.Errorf("Error serializing libvirt volume: %s", err) } // create the volume - v, err := pool.StorageVolCreateXML(string(volumeDefXml), 0) + v, err := pool.StorageVolCreateXML(string(volumeDefXML), 0) if err != nil { return fmt.Errorf("Error creating libvirt volume: %s", err) } @@ -274,17 +274,17 @@ func resourceLibvirtVolumeRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] Volume %s not found, attempting to start its pool") - volId := d.Id() + volID := d.Id() volPoolName := d.Get("pool").(string) volPool, err := virConn.LookupStoragePoolByName(volPoolName) if err != nil { - return fmt.Errorf("Error retrieving pool %s for volume %s: %s", volPoolName, volId, err) + return fmt.Errorf("Error retrieving pool %s for volume %s: %s", volPoolName, volID, err) } defer volPool.Free() active, err := volPool.IsActive() if err != nil { - return fmt.Errorf("error retrieving status of pool %s for volume %s: %s", volPoolName, volId, err) + return fmt.Errorf("error retrieving status of pool %s for volume %s: %s", volPoolName, volID, err) } if active { return fmt.Errorf("can't retrieve volume %s", d.Id()) diff --git a/libvirt/resource_libvirt_volume_test.go b/libvirt/resource_libvirt_volume_test.go index 107149df..9f047a67 100644 --- a/libvirt/resource_libvirt_volume_test.go +++ b/libvirt/resource_libvirt_volume_test.go @@ -47,12 +47,12 @@ func testAccCheckLibvirtVolumeExists(n string, volume *libvirt.StorageVol) resou } fmt.Printf("The ID is %s", rs.Primary.ID) - realId, err := retrievedVol.GetKey() + realID, err := retrievedVol.GetKey() if err != nil { return err } - if realId != rs.Primary.ID { + if realID != rs.Primary.ID { return fmt.Errorf("Resource ID and volume key does not match") } diff --git a/libvirt/stream.go b/libvirt/stream.go index e8d9b3e8..1c5a24e9 100644 --- a/libvirt/stream.go +++ b/libvirt/stream.go @@ -7,7 +7,7 @@ type StreamIO struct { Stream libvirt.Stream } -// NewStreamIO return libvirt StreamIO +// NewStreamIO return libvirt StreamIO func NewStreamIO(s libvirt.Stream) *StreamIO { return &StreamIO{Stream: s} } diff --git a/libvirt/utils.go b/libvirt/utils.go index 0660abeb..bb2f0b3c 100644 --- a/libvirt/utils.go +++ b/libvirt/utils.go @@ -12,6 +12,7 @@ import ( ) var diskLetters = []rune("abcdefghijklmnopqrstuvwxyz") + // DiskLetterForIndex return diskLetters for index func DiskLetterForIndex(i int) string { diff --git a/libvirt/utils_net.go b/libvirt/utils_net.go index e39ce55d..a769d806 100644 --- a/libvirt/utils_net.go +++ b/libvirt/utils_net.go @@ -14,6 +14,7 @@ import ( const ( maxIfaceNum = 100 ) + // RandomMACAddress mac random func RandomMACAddress() (string, error) { buf := make([]byte, 6) @@ -35,6 +36,7 @@ func RandomMACAddress() (string, error) { return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]), nil } + // RandomPort return randomport func RandomPort() int { const minPort = 1024 |