From 4fe1a715cc8bc6c45d8ccce5cc0174d49e06b23e Mon Sep 17 00:00:00 2001 From: Pierre Lafievre Date: Wed, 11 Oct 2023 15:54:50 +0200 Subject: [PATCH] WIP: F #477: add nic attributes --- .../resource_opennebula_virtual_machine.go | 37 ++++++++++++++++++- opennebula/shared_schemas.go | 24 +++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/opennebula/resource_opennebula_virtual_machine.go b/opennebula/resource_opennebula_virtual_machine.go index 2c21f4fdc..f2f178f32 100644 --- a/opennebula/resource_opennebula_virtual_machine.go +++ b/opennebula/resource_opennebula_virtual_machine.go @@ -104,6 +104,18 @@ func nicComputedVMFields() map[string]*schema.Schema { Type: schema.TypeInt, }, }, + //"computed_network_mode_auto": { + // Type: schema.TypeBool, + // Computed: true, + //}, + //"computed_sched_requirements": { + // Type: schema.TypeString, + // Computed: true, + //}, + //"computed_sched_rank": { + // Type: schema.TypeString, + // Computed: true, + //}, } } @@ -123,6 +135,10 @@ func templateNICVMSchema() *schema.Schema { Type: schema.TypeString, Computed: true, }, + //"network_mode_auto": { + // Type: schema.TypeBool, + // Computed: true, + //}, }), }, } @@ -902,6 +918,21 @@ func flattenVMNICComputed(NICConfig map[string]interface{}, NIC shared.NIC) map[ NICMap["security_groups"] = NICMap["computed_security_groups"] } + networkMode, err := NIC.Get(shared.NetworkMode) + if err == nil && networkMode == "auto" { + NICMap["network_mode_auto"] = true + } + + schedReqs, err := NIC.Get(shared.SchedRequirements) + if err == nil { + NICMap["sched_requirements"] = schedReqs + } + + schedRank, err := NIC.Get(shared.SchedRank) + if err == nil { + NICMap["sched_rank"] = schedRank + } + return NICMap } @@ -1863,7 +1894,11 @@ func updateNIC(ctx context.Context, d *schema.ResourceData, meta interface{}) er "security_groups", "model", "virtio_queues", - "physical_device") + "physical_device", + "network_mode_auto", + "sched_requirements", + "sched_rank", + ) // in case of NICs updated in the middle of the NIC list // they would be reattached at the end of the list (we don't have in place XML-RPC update method). diff --git a/opennebula/shared_schemas.go b/opennebula/shared_schemas.go index df279d516..2d330ff6e 100644 --- a/opennebula/shared_schemas.go +++ b/opennebula/shared_schemas.go @@ -207,7 +207,8 @@ func nicFields() map[string]*schema.Schema { }, "network_id": { Type: schema.TypeInt, - Required: true, + Optional: true, + Default: -1, }, "network": { Type: schema.TypeString, @@ -224,6 +225,18 @@ func nicFields() map[string]*schema.Schema { Type: schema.TypeInt, }, }, + "network_mode_auto": { + Type: schema.TypeBool, + Optional: true, + }, + "sched_requirements": { + Type: schema.TypeString, + Optional: true, + }, + "sched_rank": { + Type: schema.TypeString, + Optional: true, + }, } } @@ -558,6 +571,15 @@ func makeNICVector(nicConfig map[string]interface{}) *shared.NIC { case "security_groups": nicSecGroups := ArrayToString(v.([]interface{}), ",") nic.Add(shared.SecurityGroups, nicSecGroups) + case "network_mode_auto": + if v.(bool) { + nic.Add(shared.NetworkMode, "auto") + } + case "sched_requirements": + nic.Add(shared.SchedRequirements, v.(string)) + case "sched_rank": + nic.Add(shared.SchedRank, v.(string)) + } }