Skip to content

Commit 10544e2

Browse files
author
Frank.Zhang
committed
CLOUDSTACK-6278
Baremetal Advanced Networking support
1 parent 1973324 commit 10544e2

12 files changed

Lines changed: 577 additions & 98 deletions

File tree

plugins/hypervisors/baremetal/resources/META-INF/cloudstack/core/spring-baremetal-core-context.xml

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<bean id="BaremetalManager" class="com.cloud.baremetal.manager.BaremetalManagerImpl" />
3131
<bean id="BaremetalVlanManager" class="com.cloud.baremetal.manager.BaremetalVlanManagerImpl" />
32+
<bean id="Force10BaremetalSwitchBackend" class="com.cloud.baremetal.networkservice.Force10BaremetalSwitchBackend" />
3233

3334
<bean id="BaremetalKickStartPxeService"
3435
class="com.cloud.baremetal.networkservice.BaremetalKickStartServiceImpl" />

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalRct.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void setType(String type) {
6565
public static class HostEntry {
6666
private String uuid;
6767
private String mac;
68-
private int port;
68+
private String port;
6969

7070
public String getUuid() {
7171
return uuid;
@@ -83,11 +83,11 @@ public void setMac(String mac) {
8383
this.mac = mac;
8484
}
8585

86-
public int getPort() {
86+
public String getPort() {
8787
return port;
8888
}
8989

90-
public void setPort(int port) {
90+
public void setPort(String port) {
9191
this.port = port;
9292
}
9393
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package com.cloud.baremetal.manager;
1919

2020
import com.cloud.baremetal.networkservice.BaremetalRctResponse;
21+
import com.cloud.deploy.DeployDestination;
22+
import com.cloud.network.Network;
2123
import com.cloud.utils.component.Manager;
2224
import com.cloud.utils.component.PluggableService;
25+
import com.cloud.vm.VirtualMachineProfile;
2326
import org.apache.cloudstack.api.AddBaremetalRctCmd;
2427

2528
/**
@@ -29,4 +32,8 @@ public interface BaremetalVlanManager extends Manager, PluggableService {
2932
public static final String BAREMETAL_SYSTEM_ACCOUNT_NAME = "baremetal-system-account";
3033

3134
BaremetalRctResponse addRct(AddBaremetalRctCmd cmd);
35+
36+
void prepareVlan(Network nw, DeployDestination destHost);
37+
38+
void releaseVlan(Network nw, VirtualMachineProfile vm);
3239
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java

Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
import com.cloud.baremetal.database.BaremetalRctDao;
2121
import com.cloud.baremetal.database.BaremetalRctVO;
2222
import com.cloud.baremetal.networkservice.BaremetalRctResponse;
23+
import com.cloud.baremetal.networkservice.BaremetalSwitchBackend;
24+
import com.cloud.baremetal.networkservice.BaremetalVlanStruct;
25+
import com.cloud.deploy.DeployDestination;
26+
import com.cloud.host.HostVO;
27+
import com.cloud.host.dao.HostDao;
28+
import com.cloud.network.Network;
29+
import com.cloud.network.Networks;
2330
import com.cloud.user.Account;
2431
import com.cloud.user.AccountManager;
2532
import com.cloud.user.AccountVO;
@@ -29,6 +36,8 @@
2936
import com.cloud.utils.component.ManagerBase;
3037
import com.cloud.utils.db.QueryBuilder;
3138
import com.cloud.utils.db.SearchCriteria;
39+
import com.cloud.utils.exception.CloudRuntimeException;
40+
import com.cloud.vm.VirtualMachineProfile;
3241
import com.google.gson.Gson;
3342
import org.apache.cloudstack.api.AddBaremetalRctCmd;
3443
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
@@ -38,7 +47,9 @@
3847
import java.net.MalformedURLException;
3948
import java.net.URL;
4049
import java.util.ArrayList;
50+
import java.util.HashMap;
4151
import java.util.List;
52+
import java.util.Map;
4253
import java.util.UUID;
4354

4455
/**
@@ -50,12 +61,21 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl
5061
@Inject
5162
private BaremetalRctDao rctDao;
5263
@Inject
64+
private HostDao hostDao;
65+
@Inject
5366
private AccountDao acntDao;
5467
@Inject
5568
private UserDao userDao;
5669
@Inject
5770
private AccountManager acntMgr;
5871

72+
private Map<String, BaremetalSwitchBackend> backends = new HashMap<>();
73+
74+
private class RackPair {
75+
BaremetalRct.Rack rack;
76+
BaremetalRct.HostEntry host;
77+
}
78+
5979
@Override
6080
public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) {
6181
try {
@@ -87,11 +107,95 @@ public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) {
87107
}
88108
}
89109

110+
@Override
111+
public void prepareVlan(Network nw, DeployDestination destHost) {
112+
List<BaremetalRctVO> vos = rctDao.listAll();
113+
if (vos.isEmpty()) {
114+
throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
115+
}
116+
117+
BaremetalRctVO vo = vos.get(0);
118+
BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
119+
120+
RackPair rp = findRack(rct, destHost.getHost().getPrivateMacAddress());
121+
if (rp == null) {
122+
throw new CloudRuntimeException(String.format("cannot find any rack contains host[mac:%s], please double check your rack configuration file, update it and call addBaremetalRct again", destHost.getHost().getPrivateMacAddress()));
123+
}
124+
125+
int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
126+
BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
127+
BaremetalVlanStruct struct = new BaremetalVlanStruct();
128+
struct.setHostMac(rp.host.getMac());
129+
struct.setPort(rp.host.getPort());
130+
struct.setSwitchIp(rp.rack.getL2Switch().getIp());
131+
struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
132+
struct.setSwitchType(rp.rack.getL2Switch().getType());
133+
struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
134+
struct.setVlan(vlan);
135+
backend.prepareVlan(struct);
136+
}
137+
138+
@Override
139+
public void releaseVlan(Network nw, VirtualMachineProfile vm) {
140+
List<BaremetalRctVO> vos = rctDao.listAll();
141+
if (vos.isEmpty()) {
142+
throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
143+
}
144+
145+
BaremetalRctVO vo = vos.get(0);
146+
BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
147+
HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
148+
RackPair rp = findRack(rct, host.getPrivateMacAddress());
149+
assert rp != null : String.format("where is my rack???");
150+
151+
int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
152+
BaremetalVlanStruct struct = new BaremetalVlanStruct();
153+
struct.setHostMac(rp.host.getMac());
154+
struct.setPort(rp.host.getPort());
155+
struct.setSwitchIp(rp.rack.getL2Switch().getIp());
156+
struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
157+
struct.setSwitchType(rp.rack.getL2Switch().getType());
158+
struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
159+
struct.setVlan(vlan);
160+
BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
161+
backend.removePortFromVlan(struct);
162+
}
163+
164+
private BaremetalSwitchBackend getSwitchBackend(String type) {
165+
BaremetalSwitchBackend backend = backends.get(type);
166+
if (backend == null) {
167+
throw new CloudRuntimeException(String.format("cannot find switch backend[type:%s]", type));
168+
}
169+
return backend;
170+
}
171+
172+
private RackPair findRack(BaremetalRct rct, String mac) {
173+
for (BaremetalRct.Rack rack : rct.getRacks()) {
174+
for (BaremetalRct.HostEntry host : rack.getHosts()) {
175+
if (mac.equals(host.getMac())) {
176+
RackPair p = new RackPair();
177+
p.host = host;
178+
p.rack = rack;
179+
return p;
180+
}
181+
}
182+
}
183+
return null;
184+
}
185+
90186
@Override
91187
public String getName() {
92188
return "Baremetal Vlan Manager";
93189
}
94190

191+
192+
@Override
193+
public List<Class<?>> getCommands() {
194+
List<Class<?>> cmds = new ArrayList<Class<?>>();
195+
cmds.add(AddBaremetalRctCmd.class);
196+
return cmds;
197+
}
198+
95199
@Override
96200
public boolean start() {
97201
QueryBuilder<AccountVO> acntq = QueryBuilder.create(AccountVO.class);
@@ -126,12 +230,4 @@ public boolean start() {
126230
userDao.update(user.getId(), user);
127231
return true;
128232
}
129-
130-
131-
@Override
132-
public List<Class<?>> getCommands() {
133-
List<Class<?>> cmds = new ArrayList<Class<?>>();
134-
cmds.add(AddBaremetalRctCmd.class);
135-
return cmds;
136-
}
137233
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
package com.cloud.baremetal.networkservice;
2020

2121
import com.cloud.baremetal.database.BaremetalPxeVO;
22+
import com.cloud.baremetal.manager.BaremetalVlanManager;
2223
import com.cloud.dc.DataCenter;
24+
import com.cloud.dc.DataCenterVO;
2325
import com.cloud.dc.Pod;
26+
import com.cloud.dc.dao.DataCenterDao;
2427
import com.cloud.deploy.DeployDestination;
2528
import com.cloud.exception.ConcurrentOperationException;
2629
import com.cloud.exception.InsufficientCapacityException;
@@ -67,6 +70,10 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement {
6770
VMInstanceDao _vmDao;
6871
@Inject
6972
NicDao _nicDao;
73+
@Inject
74+
BaremetalVlanManager vlanMgr;
75+
@Inject
76+
DataCenterDao zoneDao;
7077

7178
static {
7279
Capability cap = new Capability(BaremetalPxeManager.BAREMETAL_PXE_CAPABILITY);
@@ -133,15 +140,31 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
133140
}
134141
}
135142

136-
return false;
143+
if (dest.getDataCenter().getNetworkType() == DataCenter.NetworkType.Advanced){
144+
prepareVlan(network, dest);
145+
}
146+
147+
return true;
148+
}
149+
150+
private void prepareVlan(Network network, DeployDestination dest) {
151+
vlanMgr.prepareVlan(network, dest);
137152
}
138153

139154
@Override
140155
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
141156
ResourceUnavailableException {
157+
DataCenterVO dc = zoneDao.findById(vm.getVirtualMachine().getDataCenterId());
158+
if (dc.getNetworkType() == DataCenter.NetworkType.Advanced) {
159+
releaseVlan(network, vm);
160+
}
142161
return true;
143162
}
144163

164+
private void releaseVlan(Network network, VirtualMachineProfile vm) {
165+
vlanMgr.releaseVlan(network, vm);
166+
}
167+
145168
@Override
146169
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
147170
return true;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
//
18+
// Automatically generated by addcopyright.py at 01/29/2013
19+
// Apache License, Version 2.0 (the "License"); you may not use this
20+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
//
22+
// Automatically generated by addcopyright.py at 04/03/2012
23+
package com.cloud.baremetal.networkservice;
24+
25+
/**
26+
* Created by frank on 9/2/14.
27+
*/
28+
public interface BaremetalSwitchBackend {
29+
String getSwitchBackendType();
30+
31+
void prepareVlan(BaremetalVlanStruct struct);
32+
33+
void removePortFromVlan(BaremetalVlanStruct struct);
34+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
//
18+
// Automatically generated by addcopyright.py at 01/29/2013
19+
// Apache License, Version 2.0 (the "License"); you may not use this
20+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
//
22+
// Automatically generated by addcopyright.py at 04/03/2012
23+
package com.cloud.baremetal.networkservice;
24+
25+
/**
26+
* Created by frank on 9/2/14.
27+
*/
28+
public class BaremetalVlanStruct {
29+
private String switchType;
30+
private String switchIp;
31+
private String switchUsername;
32+
private String switchPassword;
33+
private String hostMac;
34+
private String port;
35+
private int vlan;
36+
37+
public String getSwitchType() {
38+
return switchType;
39+
}
40+
41+
public void setSwitchType(String switchType) {
42+
this.switchType = switchType;
43+
}
44+
45+
public String getSwitchIp() {
46+
return switchIp;
47+
}
48+
49+
public void setSwitchIp(String switchIp) {
50+
this.switchIp = switchIp;
51+
}
52+
53+
public String getSwitchUsername() {
54+
return switchUsername;
55+
}
56+
57+
public void setSwitchUsername(String switchUsername) {
58+
this.switchUsername = switchUsername;
59+
}
60+
61+
public String getSwitchPassword() {
62+
return switchPassword;
63+
}
64+
65+
public void setSwitchPassword(String switchPassword) {
66+
this.switchPassword = switchPassword;
67+
}
68+
69+
public String getHostMac() {
70+
return hostMac;
71+
}
72+
73+
public void setHostMac(String hostMac) {
74+
this.hostMac = hostMac;
75+
}
76+
77+
public String getPort() {
78+
return port;
79+
}
80+
81+
public void setPort(String port) {
82+
this.port = port;
83+
}
84+
85+
public int getVlan() {
86+
return vlan;
87+
}
88+
89+
public void setVlan(int vlan) {
90+
this.vlan = vlan;
91+
}
92+
}

0 commit comments

Comments
 (0)