Skip to content

Commit

Permalink
WIP: F #477: add nic attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh committed Oct 19, 2023
1 parent 9ded40f commit e24c7f2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
37 changes: 36 additions & 1 deletion opennebula/resource_opennebula_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
//},
}

}
Expand All @@ -123,6 +135,10 @@ func templateNICVMSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
//"network_mode_auto": {
// Type: schema.TypeBool,
// Computed: true,
//},
}),
},
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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).
Expand Down
28 changes: 26 additions & 2 deletions opennebula/shared_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
}
}

Expand Down Expand Up @@ -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))

}
}

Expand Down

0 comments on commit e24c7f2

Please sign in to comment.