Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Added support for nics.*.allow_restricted_traffic, .allow_ip_spoofing…
Browse files Browse the repository at this point in the history
…, .allow_mac_spoofing.
  • Loading branch information
john-terrell committed May 26, 2020
1 parent cec07be commit 9429ee4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
38 changes: 29 additions & 9 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ func stringsAreEqual(a interface{}, b interface{}) bool {
type NetworkInterface struct {
/*
AllowDHCPSpoofing bool `json:"allow_dhcp_spoofing,omitempty"`
AllowIPSpoofing bool `json:"allow_ip_spoofing,omitempty"`
AllowMACSpoofing bool `json:"allow_mac_spoofing,omitempty"`
AllowRestrictedTrafic bool `json:"allow_restricted_traffic,omitempty"`
*/
AllowIPSpoofing bool `json:"allow_ip_spoofing"`
AllowMACSpoofing bool `json:"allow_mac_spoofing"`
AllowRestrictedTraffic bool `json:"allow_restricted_traffic"`
/*
BlockedOutgoingPorts []uint16 `json:"blocked_outgoing_ports,omitempty"`
*/
Gateways []string `json:"gateways,omitempty"`
Expand All @@ -222,6 +224,21 @@ func getNetworkInterfaces(d interface{}) ([]NetworkInterface, error) {
for _, nid := range networkInterfaceDefinitions {
networkInterfaceDefinition := nid.(map[string]interface{})

allowRestrictedTraffic := false
if value, ok := networkInterfaceDefinition["allow_restricted_traffic"].(bool); ok {
allowRestrictedTraffic = value
}

allowIPSpoofing := false
if value, ok := networkInterfaceDefinition["allow_ip_spoofing"].(bool); ok {
allowIPSpoofing = value
}

allowMACSpoofing := false
if value, ok := networkInterfaceDefinition["allow_mac_spoofing"].(bool); ok {
allowMACSpoofing = value
}

var gateways []string
for _, gateway := range networkInterfaceDefinition["gateways"].([]interface{}) {
gateways = append(gateways, gateway.(string))
Expand All @@ -247,12 +264,15 @@ func getNetworkInterfaces(d interface{}) ([]NetworkInterface, error) {
}

networkInterface := NetworkInterface{
Interface: interfaceName,
IPAddresses: ips,
Tag: nicTag,
Gateways: gateways,
VirtualLANID: vlanID,
Model: model,
AllowRestrictedTraffic: allowRestrictedTraffic,
AllowIPSpoofing: allowIPSpoofing,
AllowMACSpoofing: allowMACSpoofing,
Interface: interfaceName,
IPAddresses: ips,
Tag: nicTag,
Gateways: gateways,
VirtualLANID: vlanID,
Model: model,
}

networkInterfaces = append(networkInterfaces, networkInterface)
Expand Down
26 changes: 26 additions & 0 deletions resource_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ func resourceMachine() *schema.Resource {
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allow_restricted_traffic": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"allow_ip_spoofing": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"allow_mac_spoofing": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"gateways": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -518,6 +533,17 @@ func resourceMachineUpdate(d *schema.ResourceData, m interface{}) error {
updatesRequired = true
}

if d.HasChange("nics") && !d.IsNewResource() {
_, newSchemaValue := d.GetChange("nics")

var nics []NetworkInterface
for _, nic := range newSchemaValue.([]interface{}) {
nics = append(nics, nic.(NetworkInterface))
}
machineUpdate.NetworkInterfaces = nics
updatesRequired = true
}

if updatesRequired {
client := m.(*SmartOSClient)

Expand Down

0 comments on commit 9429ee4

Please sign in to comment.