-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change network configuration to read it from the hypervisor
- Loading branch information
Showing
8 changed files
with
183 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package base | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
// extract test data using: https://www.ipaddressguide.com/cidr | ||
func TestNewSubnet(t *testing.T) { | ||
type args struct { | ||
anIp string | ||
netmask string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Subnet | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "test subnet 192.168", | ||
args: args{anIp: "192.168.100.4", netmask: "255.255.255.0"}, | ||
want: &Subnet{start: 3232261120, current: 3232261120, Len: 255}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test subnet 172.31 with /20 cidr", | ||
args: args{anIp: "172.31.17.69", netmask: "255.255.240.0"}, | ||
want: &Subnet{start: 2887716864, current: 2887716864, Len: 4095}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewSubnet(tt.args.anIp, tt.args.netmask) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewSubnet() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewSubnet() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func findBridgeInfo(keys ...string) ([]string, error) { | ||
|
||
r, err := vboxManage("list", "bridgedifs").Call() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
list := strings.Split(r, "\n\n")[0] | ||
lines := strings.Split(list, "\n") | ||
|
||
elements := make(map[string]string) | ||
|
||
for _, line := range lines { | ||
s := strings.SplitN(line, ":", 2) | ||
|
||
key := strings.TrimSpace(s[0]) | ||
value := strings.TrimSpace(s[1]) | ||
elements[key] = value | ||
} | ||
|
||
var ret = make([]string, len(keys)) | ||
for i, key := range keys { | ||
ret[i] = elements[key] | ||
} | ||
|
||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters