driver fix; start/stop compute
This commit is contained in:
@@ -27,6 +27,7 @@ package decort
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
// "net/url"
|
// "net/url"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -174,6 +175,7 @@ func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []interface{} {
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []map[string]interface{} {
|
func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []map[string]interface{} {
|
||||||
// return value will be used to d.Set("network") item of dataSourceCompute schema
|
// return value will be used to d.Set("network") item of dataSourceCompute schema
|
||||||
@@ -200,7 +202,6 @@ func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []map[string]int
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// NOTE: this function is retained for historical purposes and actually not used as of rc-1.10
|
// NOTE: this function is retained for historical purposes and actually not used as of rc-1.10
|
||||||
func parseComputeInterfaces(ifaces []InterfaceRecord) []map[string]interface{} {
|
func parseComputeInterfaces(ifaces []InterfaceRecord) []map[string]interface{} {
|
||||||
// return value was designed to d.Set("interfaces",) item of dataSourceCompute schema
|
// return value was designed to d.Set("interfaces",) item of dataSourceCompute schema
|
||||||
@@ -274,6 +275,12 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
|||||||
// d.Set("status", model.Status)
|
// d.Set("status", model.Status)
|
||||||
// d.Set("tech_status", model.TechStatus)
|
// d.Set("tech_status", model.TechStatus)
|
||||||
|
|
||||||
|
if model.TechStatus == "STARTED" {
|
||||||
|
d.Set("started", true)
|
||||||
|
} else {
|
||||||
|
d.Set("started", false)
|
||||||
|
}
|
||||||
|
|
||||||
if len(model.Disks) > 0 {
|
if len(model.Disks) > 0 {
|
||||||
log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
||||||
if err = d.Set("extra_disks", parseComputeDisksToExtraDisks(model.Disks)); err != nil {
|
if err = d.Set("extra_disks", parseComputeDisksToExtraDisks(model.Disks)); err != nil {
|
||||||
@@ -465,6 +472,13 @@ func dataSourceCompute() *schema.Resource {
|
|||||||
Description: "Placeholder for cloud_init parameters.",
|
Description: "Placeholder for cloud_init parameters.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"started": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
Description: "Is compute started.",
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
"status": {
|
"status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ type KvmVmCreateParam struct { // this is unified structure for both x86 and PPC
|
|||||||
|
|
||||||
// structures related to cloudapi/compute/start API
|
// structures related to cloudapi/compute/start API
|
||||||
const ComputeStartAPI = "/restmachine/cloudapi/compute/start"
|
const ComputeStartAPI = "/restmachine/cloudapi/compute/start"
|
||||||
|
const ComputeStopAPI = "/restmachine/cloudapi/compute/stop"
|
||||||
|
|
||||||
// structures related to cloudapi/compute/delete API
|
// structures related to cloudapi/compute/delete API
|
||||||
const ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
|
const ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
|
||||||
@@ -473,6 +474,7 @@ type ComputeNetMgmtRecord struct { // used to "cache" network specs when prepari
|
|||||||
IPAddress string
|
IPAddress string
|
||||||
MAC string
|
MAC string
|
||||||
}
|
}
|
||||||
|
|
||||||
const ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
|
const ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
|
||||||
|
|
||||||
const ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
|
const ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
|
||||||
@@ -512,7 +514,6 @@ const DisksRenameAPI = "/restmachine/cloudapi/disks/rename"
|
|||||||
//
|
//
|
||||||
const DisksDeleteAPI = "/restmachine/cloudapi/disks/delete"
|
const DisksDeleteAPI = "/restmachine/cloudapi/disks/delete"
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// ViNS structures
|
// ViNS structures
|
||||||
//
|
//
|
||||||
@@ -531,6 +532,7 @@ type VinsSearchRecord struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const VinsSearchAPI = "/restmachine/cloudapi/vins/search"
|
const VinsSearchAPI = "/restmachine/cloudapi/vins/search"
|
||||||
|
|
||||||
type VinsSearchResp []VinsSearchRecord
|
type VinsSearchResp []VinsSearchRecord
|
||||||
|
|
||||||
type VnfRecord struct {
|
type VnfRecord struct {
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
computeCreateAPI := KvmX86CreateAPI
|
computeCreateAPI := KvmX86CreateAPI
|
||||||
arch := d.Get("arch").(string)
|
driver := d.Get("driver").(string)
|
||||||
if arch == "KVM_PPC" {
|
if driver == "KVM_PPC" {
|
||||||
computeCreateAPI = KvmPPCCreateAPI
|
computeCreateAPI = KvmPPCCreateAPI
|
||||||
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM PowerPC")
|
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM PowerPC")
|
||||||
} else { // note that we do not validate arch value for explicit "KVM_X86" here
|
} else { // note that we do not validate arch value for explicit "KVM_X86" here
|
||||||
@@ -163,6 +163,7 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error {
|
|||||||
|
|
||||||
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
|
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
|
||||||
// now we need to start it before we report the sequence complete
|
// now we need to start it before we report the sequence complete
|
||||||
|
if d.Get("started").(bool) {
|
||||||
reqValues := &url.Values{}
|
reqValues := &url.Values{}
|
||||||
reqValues.Add("computeId", fmt.Sprintf("%d", compId))
|
reqValues.Add("computeId", fmt.Sprintf("%d", compId))
|
||||||
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId)
|
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId)
|
||||||
@@ -170,6 +171,7 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", compId, d.Get("name").(string))
|
log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", compId, d.Get("name").(string))
|
||||||
|
|
||||||
@@ -214,6 +216,7 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
|
|||||||
2. Resize (grow) boot disk
|
2. Resize (grow) boot disk
|
||||||
3. Update extra disks
|
3. Update extra disks
|
||||||
4. Update networks
|
4. Update networks
|
||||||
|
5. Start/stop
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 1. Resize CPU/RAM
|
// 1. Resize CPU/RAM
|
||||||
@@ -284,6 +287,21 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
|
|||||||
d.SetPartial("network")
|
d.SetPartial("network")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("started") {
|
||||||
|
params := &url.Values{}
|
||||||
|
params.Add("computeId", d.Id())
|
||||||
|
if d.Get("started").(bool) {
|
||||||
|
if _, err := controller.decortAPICall("POST", ComputeStartAPI, params); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err := controller.decortAPICall("POST", ComputeStopAPI, params); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.SetPartial("started")
|
||||||
|
}
|
||||||
|
|
||||||
d.Partial(false)
|
d.Partial(false)
|
||||||
|
|
||||||
// we may reuse dataSourceComputeRead here as we maintain similarity
|
// we may reuse dataSourceComputeRead here as we maintain similarity
|
||||||
@@ -398,7 +416,7 @@ func resourceCompute() *schema.Resource {
|
|||||||
Description: "ID of the resource group where this compute should be deployed.",
|
Description: "ID of the resource group where this compute should be deployed.",
|
||||||
},
|
},
|
||||||
|
|
||||||
"arch": {
|
"driver": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
@@ -473,7 +491,6 @@ func resourceCompute() *schema.Resource {
|
|||||||
Description: "Optional text description of this compute instance.",
|
Description: "Optional text description of this compute instance.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
"cloud_init": {
|
"cloud_init": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@@ -516,6 +533,13 @@ func resourceCompute() *schema.Resource {
|
|||||||
Description: "Guest OS users provisioned on this compute instance.",
|
Description: "Guest OS users provisioned on this compute instance.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"started": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
Description: "Is compute started.",
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
"disks": {
|
"disks": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
|
|||||||
Reference in New Issue
Block a user