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..3330e250a 100644 --- a/opennebula/shared_schemas.go +++ b/opennebula/shared_schemas.go @@ -206,8 +206,10 @@ func nicFields() map[string]*schema.Schema { Description: "Only if model is virtio", }, "network_id": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Optional: true, + ConflictsWith: []string{"network_mode_auto"}, + Default: -1, }, "network": { Type: schema.TypeString, @@ -224,6 +226,19 @@ func nicFields() map[string]*schema.Schema { Type: schema.TypeInt, }, }, + "network_mode_auto": { + Type: schema.TypeBool, + Optional: true, + ConflictsWith: []string{"network_id"}, + }, + "sched_requirements": { + Type: schema.TypeString, + Optional: true, + }, + "sched_rank": { + Type: schema.TypeString, + Optional: true, + }, } } @@ -558,6 +573,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)) + } }