Skip to content

Commit

Permalink
Again fixing: Networks must be a pointer to be modified in a loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Jul 15, 2019
1 parent 14e1c66 commit 1f3cd79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
24 changes: 12 additions & 12 deletions cmd/metal-api/internal/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ func (m *Machine) IsFirewall(iMap ImageMap) bool {

// A MachineAllocation stores the data which are only present for allocated machines.
type MachineAllocation struct {
Created time.Time `rethinkdb:"created"`
Name string `rethinkdb:"name"`
Description string `rethinkdb:"description"`
Tenant string `rethinkdb:"tenant"`
Project string `rethinkdb:"project"`
ImageID string `rethinkdb:"imageid"`
MachineNetworks []MachineNetwork `rethinkdb:"networks"`
Hostname string `rethinkdb:"hostname"`
SSHPubKeys []string `rethinkdb:"sshPubKeys"`
UserData string `rethinkdb:"userdata"`
ConsolePassword string `rethinkdb:"console_password"`
Succeeded bool `rethinkdb:"succeeded"`
Created time.Time `rethinkdb:"created"`
Name string `rethinkdb:"name"`
Description string `rethinkdb:"description"`
Tenant string `rethinkdb:"tenant"`
Project string `rethinkdb:"project"`
ImageID string `rethinkdb:"imageid"`
MachineNetworks []*MachineNetwork `rethinkdb:"networks"`
Hostname string `rethinkdb:"hostname"`
SSHPubKeys []string `rethinkdb:"sshPubKeys"`
UserData string `rethinkdb:"userdata"`
ConsolePassword string `rethinkdb:"console_password"`
Succeeded bool `rethinkdb:"succeeded"`
}

// MachineNetwork stores the Network details of the machine
Expand Down
9 changes: 5 additions & 4 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,19 @@ func findAvailableMachine(ds *datastore.RethinkStore, partitionID, sizeID string
return machine, nil
}

func makeMachineNetworks(ds *datastore.RethinkStore, ipamer ipam.IPAMer, allocationSpec *machineAllocationSpec) ([]metal.MachineNetwork, error) {
func makeMachineNetworks(ds *datastore.RethinkStore, ipamer ipam.IPAMer, allocationSpec *machineAllocationSpec) ([]*metal.MachineNetwork, error) {
networks, err := gatherNetworks(ds, ipamer, allocationSpec)
if err != nil {
return nil, err
}

machineNetworks := []metal.MachineNetwork{}
machineNetworks := []*metal.MachineNetwork{}
for _, n := range networks {
machineNetwork, err := makeMachineNetwork(ds, ipamer, allocationSpec, n)
if err != nil {
return nil, err
}
machineNetworks = append(machineNetworks, *machineNetwork)
machineNetworks = append(machineNetworks, machineNetwork)
}

// TODO: It's duplicated information, but the ASN of the tenant network must be present on all other networks...
Expand All @@ -773,6 +773,7 @@ func makeMachineNetworks(ds *datastore.RethinkStore, ipamer ipam.IPAMer, allocat
break
}
}
fmt.Printf("Halo: %v", asn)
for _, n := range machineNetworks {
n.ASN = asn
}
Expand Down Expand Up @@ -1162,7 +1163,7 @@ func (r machineResource) freeMachine(request *restful.Request, response *restful
response.WriteHeaderAndEntity(http.StatusOK, makeMachineResponse(m, r.ds, utils.Logger(request).Sugar()))
}

func (r machineResource) releaseMachineNetworks(machine *metal.Machine, machineNetworks []metal.MachineNetwork) error {
func (r machineResource) releaseMachineNetworks(machine *metal.Machine, machineNetworks []*metal.MachineNetwork) error {
for _, machineNetwork := range machineNetworks {
for _, ipString := range machineNetwork.IPs {
ip, err := r.ds.FindIP(ipString)
Expand Down
2 changes: 1 addition & 1 deletion test/rest/machines.rest
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ X-Date: 1985-04-12T23:20:50.52Z
"tenant": "dkb",
"sizeid": "v1-small-x86",
"ssh_pub_keys": [],
"ips": ["185.24.0.5"],
"ips": [],
"networks": [
{"networkid": "internet-vagrant-lab"}
]
Expand Down
2 changes: 2 additions & 0 deletions test/rest/networks.rest
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### get all ips
# @name getAll
GET {{baseurl}}
Authorization: Metal-Admin 8d7b8a807d368b716ce7d712266b680edb77ff70d050be30e0bbf2e50e189b2b
X-Date: 1985-04-12T23:20:50.52Z

### create tenant network
# @name createTenantNetwork
Expand Down

0 comments on commit 1f3cd79

Please sign in to comment.