Merge pull request #64 from ddelnano/revert-63-ddelnano/sohonetlabs/iso-sr

Revert "Allow ISO Storage repository to fallback to default SR if unspecified"
This commit is contained in:
Dom Del Nano 2023-04-14 06:44:58 -07:00 committed by GitHub
commit bb64b86619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -223,11 +223,29 @@ func (c CommonConfig) ShouldKeepVM(state multistep.StateBag) bool {
}
func (config CommonConfig) GetSR(c *Connection) (xenapi.SRRef, error) {
var srRef xenapi.SRRef
if config.SrName == "" {
return getDefaultSR(c)
} else {
var srRef xenapi.SRRef
hostRef, err := c.GetClient().Session.GetThisHost(c.session, c.session)
if err != nil {
return srRef, err
}
pools, err := c.GetClient().Pool.GetAllRecords(c.session)
if err != nil {
return srRef, err
}
for _, pool := range pools {
if pool.Master == hostRef {
return pool.DefaultSR, nil
}
}
return srRef, errors.New(fmt.Sprintf("failed to find default SR on host '%s'", hostRef))
} else {
// Use the provided name label to find the SR to use
srs, err := c.GetClient().SR.GetByNameLabel(c.session, config.SrName)
@ -249,7 +267,7 @@ func (config CommonConfig) GetSR(c *Connection) (xenapi.SRRef, error) {
func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
var srRef xenapi.SRRef
if config.SrISOName == "" {
return getDefaultSR(c)
return srRef, errors.New("sr_iso_name must be specified in the packer configuration")
} else {
// Use the provided name label to find the SR to use
@ -269,34 +287,3 @@ func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
return srs[0], nil
}
}
func getDefaultSR(c *Connection) (xenapi.SRRef, error) {
var srRef xenapi.SRRef
client := c.GetClient()
hostRef, err := client.Session.GetThisHost(c.session, c.session)
if err != nil {
return srRef, err
}
// The current version of the go-xen-api-client does not fully support XenAPI version 8.2
// In particular, some values for the pool `allowed_operations` are not recognised, resulting
// in a parse error when retrieving pool records. As a workaround, we only fetch pool refs.
pool_refs, err := client.Pool.GetAll(c.session)
if err != nil {
return srRef, err
}
for _, pool_ref := range pool_refs {
pool_master, err := client.Pool.GetMaster(c.session, pool_ref)
if err != nil {
return srRef, err
}
if pool_master == hostRef {
return client.Pool.GetDefaultSR(c.session, pool_ref)
}
}
return srRef, errors.New(fmt.Sprintf("failed to find default SR on host '%s'", hostRef))
}