Use default SR if sr_iso_name
is not specified
This commit is contained in:
parent
b55b096836
commit
d8294d3ccd
@ -223,29 +223,11 @@ func (c CommonConfig) ShouldKeepVM(state multistep.StateBag) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (config CommonConfig) GetSR(c *Connection) (xenapi.SRRef, error) {
|
func (config CommonConfig) GetSR(c *Connection) (xenapi.SRRef, error) {
|
||||||
var srRef xenapi.SRRef
|
|
||||||
if config.SrName == "" {
|
if config.SrName == "" {
|
||||||
hostRef, err := c.GetClient().Session.GetThisHost(c.session, c.session)
|
return getDefaultSR(c)
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
|
var srRef xenapi.SRRef
|
||||||
|
|
||||||
// Use the provided name label to find the SR to use
|
// Use the provided name label to find the SR to use
|
||||||
srs, err := c.GetClient().SR.GetByNameLabel(c.session, config.SrName)
|
srs, err := c.GetClient().SR.GetByNameLabel(c.session, config.SrName)
|
||||||
|
|
||||||
@ -267,7 +249,7 @@ func (config CommonConfig) GetSR(c *Connection) (xenapi.SRRef, error) {
|
|||||||
func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
|
func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
|
||||||
var srRef xenapi.SRRef
|
var srRef xenapi.SRRef
|
||||||
if config.SrISOName == "" {
|
if config.SrISOName == "" {
|
||||||
return srRef, errors.New("sr_iso_name must be specified in the packer configuration")
|
return getDefaultSR(c)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Use the provided name label to find the SR to use
|
// Use the provided name label to find the SR to use
|
||||||
@ -287,3 +269,26 @@ func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
|
|||||||
return srs[0], nil
|
return srs[0], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDefaultSR(c *Connection) (xenapi.SRRef, error) {
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user