4.7.3
This commit is contained in:
@@ -316,6 +316,7 @@ func flattenNetwork(networks []interface{}, interfaces compute.ListInterfaces) [
|
||||
"net_type": network.NetType,
|
||||
"ip_address": network.IPAddress,
|
||||
"mac": network.MAC,
|
||||
"mtu": network.MTU,
|
||||
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
|
||||
}
|
||||
res = append(res, temp)
|
||||
|
||||
@@ -158,6 +158,15 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "weight the network if you need to sort network list, the smallest attach first. zero or null weight attach last",
|
||||
},
|
||||
|
||||
"mtu": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Default: 1500,
|
||||
ValidateFunc: validation.IntBetween(1, 9216),
|
||||
Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -162,6 +162,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
NetID: uint64(netInterfaceVal["net_id"].(int)),
|
||||
}
|
||||
|
||||
if reqInterface.NetType == "DPDK" {
|
||||
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
|
||||
}
|
||||
|
||||
ipaddr, ipSet := netInterfaceVal["ip_address"]
|
||||
if ipSet {
|
||||
reqInterface.IPAddr = ipaddr.(string)
|
||||
@@ -2439,6 +2443,15 @@ func ResourceCompute() *schema.Resource {
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
||||
if diff.HasChanges() || diff.HasChanges("network", "affinity_rules", "anti_affinity_rules",
|
||||
"disks", "extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices") {
|
||||
diff.SetNewComputed("updated_time")
|
||||
diff.SetNewComputed("updated_by")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
|
||||
@@ -224,7 +224,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
|
||||
needStart := false
|
||||
|
||||
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 {
|
||||
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || hasDPDKnetwork(attachMap) {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if err := utilityComputeStop(ctx, computeId, m); err != nil {
|
||||
apiErrCount++
|
||||
@@ -259,6 +259,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
req.IPAddr = netData["ip_address"].(string)
|
||||
}
|
||||
|
||||
if req.NetType == "DPDK" {
|
||||
req.MTU = uint64(netData["mtu"].(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().NetAttach(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
|
||||
@@ -285,6 +289,15 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasDPDKnetwork(networkAttachMap []map[string]interface{}) bool {
|
||||
for _, elem := range networkAttachMap {
|
||||
if elem["net_type"].(string) == "DPDK" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
@@ -374,12 +387,12 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
found := false
|
||||
for _, newNetwork := range newList {
|
||||
newMap := newNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] {
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && newMap["ip_address"] != oldMap["ip_address"] {
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && (newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
|
||||
changeIpMap = append(changeIpMap, newMap)
|
||||
found = true
|
||||
break
|
||||
} else if newMap["ip_address"] == oldMap["ip_address"] {
|
||||
} else if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -396,8 +409,10 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
found := false
|
||||
for _, oldNetwork := range oldList {
|
||||
oldMap := oldNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] {
|
||||
if newMap["ip_address"] == oldMap["ip_address"] || ((newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && newMap["ip_address"] != oldMap["ip_address"]) {
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" ||
|
||||
((newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") &&
|
||||
newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -695,7 +695,6 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
|
||||
log.Debugf("parseComputeInterfacesToNetworks: called for %d ifaces", length)
|
||||
|
||||
result := []interface{}{}
|
||||
|
||||
for _, value := range ifaces {
|
||||
elem := make(map[string]interface{})
|
||||
// Keys in this map should correspond to the Schema definition for "network"
|
||||
@@ -703,6 +702,7 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
|
||||
elem["net_type"] = value.NetType
|
||||
elem["ip_address"] = value.IPAddress
|
||||
elem["mac"] = value.MAC
|
||||
elem["mtu"] = value.MTU
|
||||
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
|
||||
|
||||
result = append(result, elem)
|
||||
|
||||
@@ -75,10 +75,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
createReqX86.StackID = uint64(stackID.(int))
|
||||
}
|
||||
|
||||
if start, ok := d.GetOk("started"); ok {
|
||||
createReqX86.Start = start.(bool)
|
||||
}
|
||||
|
||||
if ipaType, ok := d.GetOk("ipa_type"); ok {
|
||||
createReqX86.IPAType = ipaType.(string)
|
||||
}
|
||||
@@ -116,6 +112,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
NetID: uint64(netInterfaceVal["net_id"].(int)),
|
||||
}
|
||||
|
||||
if reqInterface.NetType == "DPDK" {
|
||||
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
|
||||
}
|
||||
|
||||
ipaddr, ipSet := netInterfaceVal["ip_address"]
|
||||
if ipSet {
|
||||
reqInterface.IPAddr = ipaddr.(string)
|
||||
@@ -208,6 +208,11 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
simpleCompRec, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
|
||||
cleanup := false
|
||||
defer func() {
|
||||
if cleanup {
|
||||
@@ -255,6 +260,41 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if libvirtSettings, ok := d.GetOk("libvirt_settings"); ok {
|
||||
if libvirtSettings.(*schema.Set).Len() > 0 {
|
||||
lvs := libvirtSettings.(*schema.Set).List()
|
||||
for _, elem := range lvs {
|
||||
netLibvirtMap := elem.(map[string]interface{})
|
||||
|
||||
netType := netLibvirtMap["net_type"].(string)
|
||||
netId := uint64(netLibvirtMap["net_id"].(int))
|
||||
var mac string
|
||||
for _, iface := range simpleCompRec.Interfaces {
|
||||
if iface.NetID == netId && iface.NetType == netType {
|
||||
mac = iface.MAC
|
||||
break
|
||||
}
|
||||
}
|
||||
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
|
||||
req := compute.SetNetConfigRequest{
|
||||
ComputeID: computeId,
|
||||
MAC: mac,
|
||||
TXMode: netLibvirtMap["txmode"].(string),
|
||||
IOEventFD: netLibvirtMap["ioeventfd"].(string),
|
||||
EventIDx: netLibvirtMap["event_idx"].(string),
|
||||
Queues: uint64(netLibvirtMap["queues"].(int)),
|
||||
RXQueueSize: uint64(netLibvirtMap["rx_queue_size"].(int)),
|
||||
TXQueueSize: uint64(netLibvirtMap["tx_queue_size"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().SetNetConfig(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if start, ok := d.GetOk("started"); ok && start.(bool) {
|
||||
req := compute.StartRequest{ComputeID: computeId}
|
||||
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
|
||||
@@ -485,31 +525,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ars, ok := d.GetOk("libvirt_settings"); ok {
|
||||
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on ComputeID: %d", computeId)
|
||||
settings := ars.(*schema.Set).List()
|
||||
if len(settings) > 0 {
|
||||
for _, v := range settings {
|
||||
settingsConv := v.(map[string]interface{})
|
||||
req := compute.SetNetConfigRequest{
|
||||
ComputeID: computeId,
|
||||
MAC: settingsConv["mac"].(string),
|
||||
TXMode: settingsConv["txmode"].(string),
|
||||
IOEventFD: settingsConv["ioeventfd"].(string),
|
||||
EventIDx: settingsConv["event_idx"].(string),
|
||||
Queues: uint64(settingsConv["queues"].(int)),
|
||||
RXQueueSize: uint64(settingsConv["rx_queue_size"].(int)),
|
||||
TXQueueSize: uint64(settingsConv["tx_queue_size"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().SetNetConfig(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", computeId, d.Get("name").(string))
|
||||
@@ -664,7 +679,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("network") {
|
||||
if d.HasChanges("network", "libvirt_settings") {
|
||||
err = utilityComputeNetworksConfigure(ctx, d, m) // pass do_delta = true to apply changes, if any
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -773,12 +788,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("libvirt_settings") {
|
||||
if err := utilityComputeUpdateLibvirtSettings(ctx, d, m); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return append(resourceComputeRead(ctx, d, m), warnings.Get()...)
|
||||
}
|
||||
|
||||
@@ -829,6 +838,15 @@ func ResourceCompute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
||||
if diff.HasChanges() || diff.HasChanges("libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
|
||||
"disks", "extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices") {
|
||||
diff.SetNewComputed("updated_time")
|
||||
diff.SetNewComputed("updated_by")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
CreateContext: resourceComputeCreate,
|
||||
ReadContext: resourceComputeRead,
|
||||
UpdateContext: resourceComputeUpdate,
|
||||
|
||||
@@ -3012,13 +3012,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS", "VFNIC", "DPDK"}, false), // observe case while validating
|
||||
Description: "Type of the network for this connection, either EXTNET or VINS.",
|
||||
},
|
||||
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the network for this connection.",
|
||||
},
|
||||
|
||||
"ip_address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@@ -3026,24 +3024,82 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
|
||||
Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.",
|
||||
},
|
||||
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "MAC address associated with this connection. MAC address is assigned automatically.",
|
||||
},
|
||||
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "weight the network if you need to sort network list, the smallest attach first. zero or null weight attach last",
|
||||
},
|
||||
"mtu": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Default: 1500,
|
||||
ValidateFunc: validation.IntBetween(1, 9216),
|
||||
Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216",
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
|
||||
},
|
||||
|
||||
"libvirt_settings": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"net_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
ValidateFunc: validation.StringInSlice([]string{"VINS", "VFNIC", "DPDK"}, false), // observe case while validating
|
||||
Description: "Type of the network",
|
||||
},
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the network",
|
||||
},
|
||||
"txmode": {
|
||||
Type: schema.TypeString,
|
||||
Default: "",
|
||||
Optional: true,
|
||||
},
|
||||
"ioeventfd": {
|
||||
Type: schema.TypeString,
|
||||
Default: "",
|
||||
Optional: true,
|
||||
},
|
||||
"event_idx": {
|
||||
Type: schema.TypeString,
|
||||
Default: "",
|
||||
Optional: true,
|
||||
},
|
||||
"queues": {
|
||||
Type: schema.TypeInt,
|
||||
Default: 0,
|
||||
Optional: true,
|
||||
},
|
||||
"rx_queue_size": {
|
||||
Type: schema.TypeInt,
|
||||
Default: 0,
|
||||
Optional: true,
|
||||
},
|
||||
"tx_queue_size": {
|
||||
Type: schema.TypeInt,
|
||||
Default: 0,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Configure libvirt virtio interface parameters. You can only delete values locally. Data on the platform cannot be deleted.",
|
||||
},
|
||||
|
||||
"affinity_label": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@@ -3412,43 +3468,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
Description: "ID of the connected pci devices",
|
||||
},
|
||||
"libvirt_settings": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"txmode": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"ioeventfd": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"event_idx": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"queues": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"rx_queue_size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"tx_queue_size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Configure libvirt virtio interface parameters. You can only delete values locally. Data on the platform cannot be deleted.",
|
||||
},
|
||||
// Computed properties
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
|
||||
@@ -629,7 +629,11 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
|
||||
needStart := false
|
||||
|
||||
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 {
|
||||
oldLibvirtSet, newLibvirtSet := d.GetChange("libvirt_settings")
|
||||
addedLibvirtSettings := (newLibvirtSet.(*schema.Set).Difference(oldLibvirtSet.(*schema.Set))).List()
|
||||
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), attachMap)
|
||||
|
||||
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(attachMap) {
|
||||
if err := utilityComputeStop(ctx, d, m); err != nil {
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
@@ -659,6 +663,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
NetID: uint64(netData["net_id"].(int)),
|
||||
}
|
||||
|
||||
if req.NetType == "DPDK" {
|
||||
req.MTU = uint64(netData["mtu"].(int))
|
||||
}
|
||||
|
||||
if netData["ip_address"].(string) != "" {
|
||||
req.IPAddr = netData["ip_address"].(string)
|
||||
}
|
||||
@@ -672,6 +680,51 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
}
|
||||
}
|
||||
|
||||
if len(libvirtSettingsMap) > 0 {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to read information about compute with ID %s: %s",
|
||||
d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
|
||||
if computeRec != nil {
|
||||
log.Debugf("utilityComputeNetworksConfigure: libvirt virtio set has %d items for Compute ID %s", len(attachMap), d.Id())
|
||||
for _, libvirtSetting := range libvirtSettingsMap {
|
||||
netType := libvirtSetting["net_type"].(string)
|
||||
netId := uint64(libvirtSetting["net_id"].(int))
|
||||
var mac string
|
||||
for _, iface := range computeRec.Interfaces {
|
||||
if iface.NetID == netId && iface.NetType == netType {
|
||||
mac = iface.MAC
|
||||
break
|
||||
}
|
||||
}
|
||||
log.Debugf("utilityComputeNetworksConfigure: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
|
||||
req := compute.SetNetConfigRequest{
|
||||
ComputeID: computeId,
|
||||
MAC: mac,
|
||||
TXMode: libvirtSetting["txmode"].(string),
|
||||
IOEventFD: libvirtSetting["ioeventfd"].(string),
|
||||
EventIDx: libvirtSetting["event_idx"].(string),
|
||||
Queues: uint64(libvirtSetting["queues"].(int)),
|
||||
RXQueueSize: uint64(libvirtSetting["rx_queue_size"].(int)),
|
||||
TXQueueSize: uint64(libvirtSetting["tx_queue_size"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().SetNetConfig(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to set net config to net ID %d of type %s to Compute ID %s: %s",
|
||||
netId, netType, d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if needStart {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil {
|
||||
@@ -698,12 +751,12 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
found := false
|
||||
for _, newNetwork := range newList {
|
||||
newMap := newNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] {
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && newMap["ip_address"] != oldMap["ip_address"] {
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && (newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
|
||||
changeIpMap = append(changeIpMap, newMap)
|
||||
found = true
|
||||
break
|
||||
} else if newMap["ip_address"] == oldMap["ip_address"] {
|
||||
} else if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -720,8 +773,10 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
found := false
|
||||
for _, oldNetwork := range oldList {
|
||||
oldMap := oldNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] {
|
||||
if newMap["ip_address"] == oldMap["ip_address"] || ((newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && newMap["ip_address"] != oldMap["ip_address"]) {
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if newMap["ip_address"] == oldMap["ip_address"] || newMap["ip_address"].(string) == "" ||
|
||||
((newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") &&
|
||||
newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -736,6 +791,49 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
return
|
||||
}
|
||||
|
||||
func hasDPDKnetwork(networkAttachMap []map[string]interface{}) bool {
|
||||
for _, elem := range networkAttachMap {
|
||||
if elem["net_type"].(string) == "DPDK" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// addAttachedNetwork adds libvirt_settings of attached networks to the libvirt_settings settings list
|
||||
func addAttachedNetwork(addedLibvirtSettings []interface{}, newLibvirtSettings []interface{}, networkAttachMap []map[string]interface{}) (addedLibvirtSettingsMap []map[string]interface{}) {
|
||||
addedLibvirtSettingsMap = make([]map[string]interface{}, 0)
|
||||
|
||||
for _, attach := range networkAttachMap {
|
||||
found := false
|
||||
for _, elem := range addedLibvirtSettings {
|
||||
addedLVSMap := elem.(map[string]interface{})
|
||||
if attach["net_id"] == addedLVSMap["net_id"] && attach["net_type"] == addedLVSMap["net_type"] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
for _, elem := range newLibvirtSettings {
|
||||
newVirtSettingMap := elem.(map[string]interface{})
|
||||
if attach["net_id"] == newVirtSettingMap["net_id"] && attach["net_type"] == newVirtSettingMap["net_type"] {
|
||||
addedLibvirtSettingsMap = append(addedLibvirtSettingsMap, newVirtSettingMap)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, elem := range addedLibvirtSettings {
|
||||
addedLVSMap := elem.(map[string]interface{})
|
||||
addedLibvirtSettingsMap = append(addedLibvirtSettingsMap, addedLVSMap)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
@@ -1015,36 +1113,6 @@ func utilityComputeUpdatePciDevices(ctx context.Context, d *schema.ResourceData,
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeUpdateLibvirtSettings(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
oldSet, newSet := d.GetChange("libvirt_settings")
|
||||
|
||||
added := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
|
||||
if len(added) > 0 {
|
||||
for _, v := range added {
|
||||
settingsConv := v.(map[string]interface{})
|
||||
req := compute.SetNetConfigRequest{
|
||||
ComputeID: computeId,
|
||||
MAC: settingsConv["mac"].(string),
|
||||
TXMode: settingsConv["txmode"].(string),
|
||||
IOEventFD: settingsConv["ioeventfd"].(string),
|
||||
EventIDx: settingsConv["event_idx"].(string),
|
||||
Queues: uint64(settingsConv["queues"].(int)),
|
||||
RXQueueSize: uint64(settingsConv["rx_queue_size"].(int)),
|
||||
TXQueueSize: uint64(settingsConv["tx_queue_size"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().SetNetConfig(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeUpdateTags(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
@@ -1510,7 +1578,7 @@ func utilityComputeStop(ctx context.Context, d *schema.ResourceData, m interface
|
||||
req.Depresent = depresent
|
||||
}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", req.ComputeID)
|
||||
log.Debugf("utilityComputeStop: stopping compute %d", req.ComputeID)
|
||||
_, err := c.CloudBroker().Compute().Stop(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1522,7 +1590,7 @@ func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (
|
||||
c := m.(*controller.ControllerCfg)
|
||||
startReq := compute.StartRequest{ComputeID: computeID}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
|
||||
log.Debugf("utilityComputeStart: starting compute %d", computeID)
|
||||
_, err := c.CloudBroker().Compute().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
|
||||
Reference in New Issue
Block a user