forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalNetworkDeviceManagerImpl.java
More file actions
executable file
·274 lines (251 loc) · 12.5 KB
/
ExternalNetworkDeviceManagerImpl.java
File metadata and controls
executable file
·274 lines (251 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.api.ApiConstants;
import com.cloud.api.IdentityService;
import com.cloud.api.PlugService;
import com.cloud.api.commands.AddNetworkDeviceCmd;
import com.cloud.api.commands.DeleteNetworkDeviceCmd;
import com.cloud.api.commands.ListNetworkDeviceCmd;
import com.cloud.baremetal.ExternalDhcpManager;
import com.cloud.baremetal.PxeServerManager;
import com.cloud.baremetal.PxeServerProfile;
import com.cloud.baremetal.PxeServerManager.PxeServerType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Host.Type;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.network.dao.ExternalFirewallDeviceDao;
import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.InlineLoadBalancerNicMapDao;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkExternalFirewallDao;
import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.ServerResource;
import com.cloud.server.ManagementServer;
import com.cloud.server.api.response.NetworkDeviceResponse;
import com.cloud.server.api.response.NwDeviceDhcpResponse;
import com.cloud.server.api.response.PxePingResponse;
import com.cloud.user.AccountManager;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
@Local(value = {ExternalNetworkDeviceManager.class})
public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceManager {
@Inject ExternalDhcpManager _dhcpMgr;
@Inject PxeServerManager _pxeMgr;
@Inject AgentManager _agentMgr;
@Inject NetworkManager _networkMgr;
@Inject HostDao _hostDao;
@Inject DataCenterDao _dcDao;
@Inject AccountDao _accountDao;
@Inject DomainRouterDao _routerDao;
@Inject IPAddressDao _ipAddressDao;
@Inject VlanDao _vlanDao;
@Inject UserStatisticsDao _userStatsDao;
@Inject NetworkDao _networkDao;
@Inject PortForwardingRulesDao _portForwardingRulesDao;
@Inject LoadBalancerDao _loadBalancerDao;
@Inject ConfigurationDao _configDao;
@Inject NetworkOfferingDao _networkOfferingDao;
@Inject NicDao _nicDao;
@Inject VpnUserDao _vpnUsersDao;
@Inject InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao;
@Inject AccountManager _accountMgr;
@Inject PhysicalNetworkDao _physicalNetworkDao;
@Inject PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@Inject ExternalLoadBalancerDeviceDao _externalLoadBalancerDeviceDao;
@Inject ExternalFirewallDeviceDao _externalFirewallDeviceDao;
@Inject NetworkExternalLoadBalancerDao _networkExternalLBDao;
@Inject NetworkExternalFirewallDao _networkExternalFirewallDao;
ScheduledExecutorService _executor;
int _externalNetworkStatsInterval;
private final static IdentityService _identityService = (IdentityService)ComponentLocator.getLocator(ManagementServer.Name).getManager(IdentityService.class);
private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalNetworkDeviceManagerImpl.class);
protected String _name;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public Host addNetworkDevice(AddNetworkDeviceCmd cmd) {
Map paramList = cmd.getParamList();
if (paramList == null) {
throw new CloudRuntimeException("Parameter list is null");
}
Collection paramsCollection = paramList.values();
HashMap params = (HashMap) (paramsCollection.toArray())[0];
if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.ExternalDhcp.getName())) {
//Long zoneId = _identityService.getIdentityId("data_center", (String) params.get(ApiConstants.ZONE_ID));
//Long podId = _identityService.getIdentityId("host_pod_ref", (String)params.get(ApiConstants.POD_ID));
Long zoneId = Long.valueOf((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.valueOf((String)params.get(ApiConstants.POD_ID));
String type = (String) params.get(ApiConstants.DHCP_SERVER_TYPE);
String url = (String) params.get(ApiConstants.URL);
String username = (String) params.get(ApiConstants.USERNAME);
String password = (String) params.get(ApiConstants.PASSWORD);
return _dhcpMgr.addDhcpServer(zoneId, podId, type, url, username, password);
} else if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.PxeServer.getName())) {
Long zoneId = Long.parseLong((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.parseLong((String)params.get(ApiConstants.POD_ID));
//Long zoneId = _identityService.getIdentityId("data_center", (String) params.get(ApiConstants.ZONE_ID));
//Long podId = _identityService.getIdentityId("host_pod_ref", (String)params.get(ApiConstants.POD_ID));
String type = (String) params.get(ApiConstants.PXE_SERVER_TYPE);
String url = (String) params.get(ApiConstants.URL);
String username = (String) params.get(ApiConstants.USERNAME);
String password = (String) params.get(ApiConstants.PASSWORD);
String pingStorageServerIp = (String) params.get(ApiConstants.PING_STORAGE_SERVER_IP);
String pingDir = (String) params.get(ApiConstants.PING_DIR);
String tftpDir = (String) params.get(ApiConstants.TFTP_DIR);
String pingCifsUsername = (String) params.get(ApiConstants.PING_CIFS_USERNAME);
String pingCifsPassword = (String) params.get(ApiConstants.PING_CIFS_PASSWORD);
PxeServerProfile profile = new PxeServerProfile(zoneId, podId, url, username, password, type, pingStorageServerIp, pingDir, tftpDir,
pingCifsUsername, pingCifsPassword);
return _pxeMgr.addPxeServer(profile);
} else {
throw new CloudRuntimeException("Unsupported network device type:" + cmd.getDeviceType());
}
}
@Override
public NetworkDeviceResponse getApiResponse(Host device) {
NetworkDeviceResponse response;
HostVO host = (HostVO)device;
_hostDao.loadDetails(host);
if (host.getType() == Host.Type.ExternalDhcp) {
NwDeviceDhcpResponse r = new NwDeviceDhcpResponse();
r.setZoneId(host.getDataCenterId());
r.setPodId(host.getPodId());
r.setUrl(host.getPrivateIpAddress());
r.setType(host.getDetail("type"));
response = r;
} else if (host.getType() == Host.Type.PxeServer) {
String pxeType = host.getDetail("type");
if (pxeType.equalsIgnoreCase(PxeServerType.PING.getName())) {
PxePingResponse r = new PxePingResponse();
r.setZoneId(host.getDataCenterId());
r.setPodId(host.getPodId());
r.setUrl(host.getPrivateIpAddress());
r.setType(pxeType);
r.setStorageServerIp(host.getDetail("storageServer"));
r.setPingDir(host.getDetail("pingDir"));
r.setTftpDir(host.getDetail("tftpDir"));
response = r;
} else {
throw new CloudRuntimeException("Unsupported PXE server type:" + pxeType);
}
} else {
throw new CloudRuntimeException("Unsupported network device type:" + host.getType());
}
response.setId(device.getId());
return response;
}
private List<Host> listNetworkDevice(Long zoneId, Long physicalNetworkId, Long podId, Host.Type type) {
// List<Host> res = new ArrayList<Host>();
// if (podId != null) {
// List<HostVO> devs = _hostDao.listBy(type, null, podId, zoneId);
// if (devs.size() == 1) {
// res.add(devs.get(0));
// } else {
// s_logger.debug("List " + type + ": " + devs.size() + " found");
// }
// } else {
// List<HostVO> devs = _hostDao.listBy(type, zoneId);
// res.addAll(devs);
// }
// return res;
return null;
}
@Override
public List<Host> listNetworkDevice(ListNetworkDeviceCmd cmd) {
Map paramList = cmd.getParamList();
if (paramList == null) {
throw new CloudRuntimeException("Parameter list is null");
}
List<Host> res;
Collection paramsCollection = paramList.values();
HashMap params = (HashMap) (paramsCollection.toArray())[0];
if (NetworkDevice.ExternalDhcp.getName().equalsIgnoreCase(cmd.getDeviceType())) {
Long zoneId = Long.parseLong((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.parseLong((String)params.get(ApiConstants.POD_ID));
res = listNetworkDevice(zoneId, null, podId, Host.Type.ExternalDhcp);
} else if (NetworkDevice.PxeServer.getName().equalsIgnoreCase(cmd.getDeviceType())) {
Long zoneId = Long.parseLong((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.parseLong((String)params.get(ApiConstants.POD_ID));
res = listNetworkDevice(zoneId, null, podId, Host.Type.PxeServer);
} else if (cmd.getDeviceType() == null){
Long zoneId = Long.parseLong((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.parseLong((String)params.get(ApiConstants.POD_ID));
Long physicalNetworkId = (params.get(ApiConstants.PHYSICAL_NETWORK_ID)==null)?Long.parseLong((String)params.get(ApiConstants.PHYSICAL_NETWORK_ID)):null;
List<Host> res1 = listNetworkDevice(zoneId, physicalNetworkId, podId, Host.Type.PxeServer);
List<Host> res2 = listNetworkDevice(zoneId, physicalNetworkId, podId, Host.Type.ExternalDhcp);
List<Host> res3 = listNetworkDevice(zoneId, physicalNetworkId, podId, Host.Type.ExternalLoadBalancer);
List<Host> res4 = listNetworkDevice(zoneId, physicalNetworkId, podId, Host.Type.ExternalFirewall);
List<Host> deviceAll = new ArrayList<Host>();
deviceAll.addAll(res1);
deviceAll.addAll(res2);
deviceAll.addAll(res3);
deviceAll.addAll(res4);
res = deviceAll;
} else {
throw new CloudRuntimeException("Unknown network device type:" + cmd.getDeviceType());
}
return res;
}
@Override
public boolean deleteNetworkDevice(DeleteNetworkDeviceCmd cmd) {
HostVO device = _hostDao.findById(cmd.getId());
return true;
}
}