Implement ViNS resource update method
This commit is contained in:
@@ -78,7 +78,7 @@ func flattenVins(d *schema.ResourceData, vins_facts string) error {
|
|||||||
|
|
||||||
if noExtNetConnection {
|
if noExtNetConnection {
|
||||||
d.Set("ext_ip_addr", "")
|
d.Set("ext_ip_addr", "")
|
||||||
d.Set("ext_net_id", -1)
|
d.Set("ext_net_id", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("flattenVins: EXTRA CHECK - schema rg_id=%d, ext_net_id=%d", d.Get("rg_id").(int), d.Get("ext_net_id").(int))
|
log.Debugf("flattenVins: EXTRA CHECK - schema rg_id=%d, ext_net_id=%d", d.Get("rg_id").(int), d.Get("ext_net_id").(int))
|
||||||
@@ -112,7 +112,7 @@ func dataSourceVins() *schema.Resource {
|
|||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Required: true,
|
||||||
Description: "Name of the ViNS. Names are case sensitive and unique within the context of an account or resource group.",
|
Description: "Name of the ViNS. Names are case sensitive and unique within the context of an account or resource group.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -565,8 +565,8 @@ const VinsGetAPI = "/restmachine/cloudapi/vins/get"
|
|||||||
const VinsCreateInAccountAPI = "/restmachine/cloudapi/vins/createInAccount"
|
const VinsCreateInAccountAPI = "/restmachine/cloudapi/vins/createInAccount"
|
||||||
const VinsCreateInRgAPI = "/restmachine/cloudapi/vins/createInRG"
|
const VinsCreateInRgAPI = "/restmachine/cloudapi/vins/createInRG"
|
||||||
|
|
||||||
const VinsExtNetConnect = "/restmachine/cloudapi/vins/extNetConnect"
|
const VinsExtNetConnectAPI = "/restmachine/cloudapi/vins/extNetConnect"
|
||||||
const VinsExtNetDisconnect = "/restmachine/cloudapi/vins/extNetDisconnect"
|
const VinsExtNetDisconnectAPI = "/restmachine/cloudapi/vins/extNetDisconnect"
|
||||||
|
|
||||||
const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
|
const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
|
||||||
|
|
||||||
|
|||||||
@@ -78,11 +78,15 @@ func resourceVinsCreate(d *schema.ResourceData, m interface{}) error {
|
|||||||
if argVal.(int) > 0 {
|
if argVal.(int) > 0 {
|
||||||
// connect to specific external network
|
// connect to specific external network
|
||||||
urlValues.Add("extNetId", fmt.Sprintf("%d", argVal.(int)))
|
urlValues.Add("extNetId", fmt.Sprintf("%d", argVal.(int)))
|
||||||
|
/*
|
||||||
|
Commented out, as we've made "ext_net_ip" parameter non-configurable via Terraform!
|
||||||
|
|
||||||
// in case of specific ext net connection user may also want a particular IP address
|
// in case of specific ext net connection user may also want a particular IP address
|
||||||
argVal, argSet = d.GetOk("ext_net_ip")
|
argVal, argSet = d.GetOk("ext_net_ip")
|
||||||
if argSet && argVal.(string) != "" {
|
if argSet && argVal.(string) != "" {
|
||||||
urlValues.Add("extIp", argVal.(string))
|
urlValues.Add("extIp", argVal.(string))
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} else {
|
} else {
|
||||||
// ext_net_id is set to a negative value - connect to default external network
|
// ext_net_id is set to a negative value - connect to default external network
|
||||||
// no particular IP address selection in this case
|
// no particular IP address selection in this case
|
||||||
@@ -132,37 +136,46 @@ func resourceVinsRead(d *schema.ResourceData, m interface{}) error {
|
|||||||
|
|
||||||
func resourceVinsUpdate(d *schema.ResourceData, m interface{}) error {
|
func resourceVinsUpdate(d *schema.ResourceData, m interface{}) error {
|
||||||
|
|
||||||
return fmt.Errorf("resourceVinsUpdate: method not implemnted yet - ViNS ID %s", d.Id())
|
log.Debugf("resourceVinsUpdate: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d",
|
||||||
|
d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||||
/*
|
|
||||||
log.Debugf("resourceVinsUpdate: called for ViNS ID / name %s / %s, Account ID %d",
|
|
||||||
d.Id(), d.Get("name").(string), d.Get("account_id").(int))
|
|
||||||
|
|
||||||
d.Partial(true)
|
|
||||||
|
|
||||||
controller := m.(*ControllerCfg)
|
controller := m.(*ControllerCfg)
|
||||||
|
|
||||||
|
d.Partial(true)
|
||||||
|
|
||||||
oldName, newName := d.GetChange("name")
|
// 1. Handle external network connection change
|
||||||
if oldName.(string) != newName.(string) {
|
oldExtNetId, newExtNedId := d.GetChange("ext_net_id")
|
||||||
log.Debugf("resourceVinsUpdate: renaming ViNS ID %d - %s -> %s",
|
if oldExtNetId.(int) != newExtNedId.(int) {
|
||||||
d.Get("disk_id").(int), oldName.(string), newName.(string))
|
log.Debugf("resourceVinsUpdate: changing ViNS ID %s - ext_net_id %d -> %d", d.Id(), oldExtNetId.(int), newExtNedId.(int))
|
||||||
renameParams := &url.Values{}
|
|
||||||
renameParams.Add("vinsId", d.Id())
|
extnetParams := &url.Values{}
|
||||||
renameParams.Add("name", newName.(string))
|
extnetParams.Add("vinsId", d.Id())
|
||||||
_, err := controller.decortAPICall("POST", VinsRenameAPI, renameParams)
|
|
||||||
if err != nil {
|
if oldExtNetId.(int) > 0 {
|
||||||
return err
|
// there was preexisting external net connection - disconnect ViNS
|
||||||
|
_, err := controller.decortAPICall("POST", VinsExtNetDisconnectAPI, extnetParams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
d.SetPartial("name")
|
|
||||||
|
if newExtNedId.(int) > 0 {
|
||||||
|
// new external network connection requested - connect ViNS
|
||||||
|
extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int)))
|
||||||
|
_, err := controller.decortAPICall("POST", VinsExtNetConnectAPI, extnetParams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetPartial("ext_net_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Partial(false)
|
d.Partial(false)
|
||||||
*/
|
|
||||||
|
|
||||||
// we may reuse dataSourceVinsRead here as we maintain similarity
|
// we may reuse dataSourceVinsRead here as we maintain similarity
|
||||||
// between Compute resource and Compute data source schemas
|
// between Compute resource and Compute data source schemas
|
||||||
// return dataSourceVinsRead(d, m)
|
return dataSourceVinsRead(d, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVinsDelete(d *schema.ResourceData, m interface{}) error {
|
func resourceVinsDelete(d *schema.ResourceData, m interface{}) error {
|
||||||
@@ -225,15 +238,31 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
|||||||
"rg_id": {
|
"rg_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Default: 0,
|
||||||
Description: "ID of the resource group, where this ViNS belongs to. Non-zero for ViNS created at resource group level, 0 otherwise.",
|
Description: "ID of the resource group, where this ViNS belongs to. Non-zero for ViNS created at resource group level, 0 otherwise.",
|
||||||
},
|
},
|
||||||
|
|
||||||
"account_id": {
|
"account_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
Description: "ID of the account, which this ViNS belongs to. For ViNS created at account level, resource group ID is 0.",
|
Description: "ID of the account, which this ViNS belongs to. For ViNS created at account level, resource group ID is 0.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"ext_net_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "ID of the external network this ViNS is connected to. Pass 0 if no external connection required.",
|
||||||
|
},
|
||||||
|
|
||||||
|
"ipcidr": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
DiffSuppressFunc: ipcidrDiffSupperss,
|
||||||
|
Description: "Network address to use by this ViNS. This parameter is only valid when creating new ViNS.",
|
||||||
|
},
|
||||||
|
|
||||||
"description": {
|
"description": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@@ -241,25 +270,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
|||||||
Description: "Optional user-defined text description of this ViNS.",
|
Description: "Optional user-defined text description of this ViNS.",
|
||||||
},
|
},
|
||||||
|
|
||||||
"ext_net_id": {
|
|
||||||
Type: schema.TypeInt,
|
|
||||||
Optional: true,
|
|
||||||
Description: "ID of the external network this ViNS is connected to (set to 0 if no external connection required, -1 to connect to default external network).",
|
|
||||||
},
|
|
||||||
|
|
||||||
"ext_ip_addr": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
Description: "IP address of the external connection (valid for ViNS connected to external network, ignored otherwise).",
|
|
||||||
},
|
|
||||||
|
|
||||||
"ipcidr": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
DiffSuppressFunc: ipcidrDiffSupperss,
|
|
||||||
Description: "Network address to use by this ViNS.",
|
|
||||||
},
|
|
||||||
|
|
||||||
// the rest of attributes are computed
|
// the rest of attributes are computed
|
||||||
"account_name": {
|
"account_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@@ -267,6 +277,11 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
|||||||
Description: "Name of the account, which this ViNS belongs to.",
|
Description: "Name of the account, which this ViNS belongs to.",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"ext_ip_addr": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "IP address of the external connection (valid for ViNS connected to external network, ignored otherwise).",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return rets
|
return rets
|
||||||
|
|||||||
Reference in New Issue
Block a user