driver fix; start/stop compute

rc-1.25
kjubybot 3 years ago
parent 8058b1c08f
commit 5db588e5dc

@ -27,6 +27,7 @@ package decort
import (
"encoding/json"
"fmt"
// "net/url"
log "github.com/sirupsen/logrus"
@ -43,7 +44,7 @@ func parseComputeDisksToExtraDisks(disks []DiskRecord) []interface{} {
length := len(disks)
log.Debugf("parseComputeDisksToExtraDisks: called for %d disks", length)
if length == 0 || ( length == 1 && disks[0].Type == "B" ) {
if length == 0 || (length == 1 && disks[0].Type == "B") {
// the disk list is empty (which is kind of strange - diskless compute?), or
// there is only one disk in the list and it is a boot disk;
// as we skip boot disks, the result will be of 0 length anyway
@ -174,6 +175,7 @@ func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []interface{} {
return result
}
/*
func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []map[string]interface{} {
// 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
func parseComputeInterfaces(ifaces []InterfaceRecord) []map[string]interface{} {
// 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("tech_status", model.TechStatus)
if model.TechStatus == "STARTED" {
d.Set("started", true)
} else {
d.Set("started", false)
}
if len(model.Disks) > 0 {
log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
if err = d.Set("extra_disks", parseComputeDisksToExtraDisks(model.Disks)); err != nil {
@ -406,7 +413,7 @@ func dataSourceCompute() *schema.Resource {
Type: schema.TypeSet,
Computed: true,
MaxItems: MaxExtraDisksPerCompute,
Elem: &schema.Schema {
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "IDs of the extra disk(s) attached to this compute.",
@ -465,6 +472,13 @@ func dataSourceCompute() *schema.Resource {
Description: "Placeholder for cloud_init parameters.",
},
"started": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Is compute started.",
},
/*
"status": {
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
const ComputeStartAPI = "/restmachine/cloudapi/compute/start"
const ComputeStopAPI = "/restmachine/cloudapi/compute/stop"
// structures related to cloudapi/compute/delete API
const ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
@ -473,6 +474,7 @@ type ComputeNetMgmtRecord struct { // used to "cache" network specs when prepari
IPAddress string
MAC string
}
const ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
const ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
@ -512,7 +514,6 @@ const DisksRenameAPI = "/restmachine/cloudapi/disks/rename"
//
const DisksDeleteAPI = "/restmachine/cloudapi/disks/delete"
//
// ViNS structures
//
@ -531,6 +532,7 @@ type VinsSearchRecord struct {
}
const VinsSearchAPI = "/restmachine/cloudapi/vins/search"
type VinsSearchResp []VinsSearchRecord
type VnfRecord struct {

@ -85,8 +85,8 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error {
*/
computeCreateAPI := KvmX86CreateAPI
arch := d.Get("arch").(string)
if arch == "KVM_PPC" {
driver := d.Get("driver").(string)
if driver == "KVM_PPC" {
computeCreateAPI = KvmPPCCreateAPI
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM PowerPC")
} 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),
// now we need to start it before we report the sequence complete
if d.Get("started").(bool) {
reqValues := &url.Values{}
reqValues.Add("computeId", fmt.Sprintf("%d", 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 {
return err
}
}
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
3. Update extra disks
4. Update networks
5. Start/stop
*/
// 1. Resize CPU/RAM
@ -284,6 +287,21 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error {
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)
// 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.",
},
"arch": {
"driver": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
@ -473,7 +491,6 @@ func resourceCompute() *schema.Resource {
Description: "Optional text description of this compute instance.",
},
"cloud_init": {
Type: schema.TypeString,
Optional: true,
@ -516,6 +533,13 @@ func resourceCompute() *schema.Resource {
Description: "Guest OS users provisioned on this compute instance.",
},
"started": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Is compute started.",
},
/*
"disks": {
Type: schema.TypeList,

Loading…
Cancel
Save