Skip to content

Commit c68dd35

Browse files
committed
2 parents a06ed57 + f1ab3ae commit c68dd35

8 files changed

Lines changed: 281 additions & 2 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3769,7 +3769,9 @@ private VmStatsEntry getVmStat(Connect conn, String vmName)
37693769

37703770
NodeInfo node = conn.nodeInfo();
37713771
utilization = utilization / node.cpus;
3772-
stats.setCPUUtilization(utilization * 100);
3772+
if(utilization > 0){
3773+
stats.setCPUUtilization(utilization * 100);
3774+
}
37733775
}
37743776

37753777
/* get network stats */
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
package com.cloud.agent.api;
18+
19+
public class FindLogicalSwitchPortAnswer extends Answer {
20+
private String _logicalSwitchPortUuid;
21+
22+
public FindLogicalSwitchPortAnswer(Command command, boolean success,
23+
String details, String localSwitchPortUuid) {
24+
super(command, success, details);
25+
this._logicalSwitchPortUuid = localSwitchPortUuid;
26+
}
27+
28+
public String getLogicalSwitchPortUuid() {
29+
return _logicalSwitchPortUuid;
30+
}
31+
32+
public FindLogicalSwitchPortAnswer(Command command, Exception e) {
33+
super(command, e);
34+
}
35+
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
package com.cloud.agent.api;
18+
19+
public class FindLogicalSwitchPortCommand extends Command {
20+
private String _logicalSwitchUuid;
21+
private String _logicalSwitchPortUuid;
22+
23+
public FindLogicalSwitchPortCommand(String logicalSwitchUuid, String logicalSwitchPortUuid) {
24+
this._logicalSwitchUuid = logicalSwitchUuid;
25+
this._logicalSwitchPortUuid = logicalSwitchPortUuid;
26+
}
27+
28+
29+
public String getLogicalSwitchUuid() {
30+
return _logicalSwitchUuid;
31+
}
32+
33+
34+
public String getLogicalSwitchPortUuid() {
35+
return _logicalSwitchPortUuid;
36+
}
37+
38+
39+
@Override
40+
public boolean executeInSequence() {
41+
return false;
42+
}
43+
44+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
package com.cloud.agent.api;
18+
19+
public class UpdateLogicalSwitchPortAnswer extends Answer {
20+
private String _logicalSwitchPortUuid;
21+
22+
public UpdateLogicalSwitchPortAnswer(Command command, boolean success,
23+
String details, String localSwitchPortUuid) {
24+
super(command, success, details);
25+
this._logicalSwitchPortUuid = localSwitchPortUuid;
26+
}
27+
28+
public String getLogicalSwitchPortUuid() {
29+
return _logicalSwitchPortUuid;
30+
}
31+
32+
public UpdateLogicalSwitchPortAnswer(Command command, Exception e) {
33+
super(command, e);
34+
}
35+
36+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
package com.cloud.agent.api;
18+
19+
public class UpdateLogicalSwitchPortCommand extends Command {
20+
private String _logicalSwitchUuid;
21+
private String _logicalSwitchPortUuid;
22+
private String _attachmentUuid;
23+
private String _ownerName;
24+
private String _nicName;
25+
26+
public UpdateLogicalSwitchPortCommand(String logicalSwitchPortUuid, String logicalSwitchUuid, String attachmentUuid, String ownerName, String nicName) {
27+
this._logicalSwitchUuid = logicalSwitchUuid;
28+
this._logicalSwitchPortUuid = logicalSwitchPortUuid;
29+
this._attachmentUuid = attachmentUuid;
30+
this._ownerName = ownerName;
31+
this._nicName = nicName;
32+
}
33+
34+
35+
public String getLogicalSwitchUuid() {
36+
return _logicalSwitchUuid;
37+
}
38+
39+
40+
public String getLogicalSwitchPortUuid() {
41+
return _logicalSwitchPortUuid;
42+
}
43+
44+
45+
public String getAttachmentUuid() {
46+
return _attachmentUuid;
47+
}
48+
49+
50+
public String getOwnerName() {
51+
return _ownerName;
52+
}
53+
54+
55+
public String getNicName() {
56+
return _nicName;
57+
}
58+
59+
60+
@Override
61+
public boolean executeInSequence() {
62+
return false;
63+
}
64+
65+
}

plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@
5151
import com.cloud.agent.api.CreateLogicalSwitchPortCommand;
5252
import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer;
5353
import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
54+
import com.cloud.agent.api.FindLogicalSwitchPortAnswer;
55+
import com.cloud.agent.api.FindLogicalSwitchPortCommand;
5456
import com.cloud.agent.api.StartupCommand;
5557
import com.cloud.agent.api.StartupNiciraNvpCommand;
58+
import com.cloud.agent.api.UpdateLogicalSwitchPortAnswer;
59+
import com.cloud.agent.api.UpdateLogicalSwitchPortCommand;
5660
import com.cloud.api.commands.AddNiciraNvpDeviceCmd;
5761
import com.cloud.api.commands.DeleteNiciraNvpDeviceCmd;
5862
import com.cloud.api.commands.ListNiciraNvpDeviceNetworksCmd;
@@ -198,6 +202,26 @@ public boolean prepare(Network network, NicProfile nic,
198202
}
199203
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
200204
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
205+
206+
NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
207+
if (existingNicMap != null) {
208+
FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchUuid(),
209+
existingNicMap.getLogicalSwitchPortUuid());
210+
FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr.easySend(niciraNvpHost.getId(), findCmd);
211+
212+
if (answer.getResult()) {
213+
s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
214+
UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(),
215+
network.getBroadcastUri().getSchemeSpecificPart(), nicVO.getUuid(),
216+
context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
217+
_agentMgr.easySend(niciraNvpHost.getId(), cmd);
218+
return true;
219+
}
220+
else {
221+
s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid());
222+
_niciraNvpNicMappingDao.remove(existingNicMap.getId());
223+
}
224+
}
201225

202226
CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(network.getBroadcastUri().getSchemeSpecificPart(), nicVO.getUuid(),
203227
context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
@@ -244,7 +268,7 @@ public boolean release(Network network, NicProfile nic,
244268
s_logger.error("No mapping for nic " + nic.getName());
245269
return false;
246270
}
247-
271+
248272
DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
249273
DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
250274

plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ public ControlClusterStatus getControlClusterStatus() throws NiciraNvpApiExcepti
195195
return ccs;
196196
}
197197

198+
public NiciraNvpList<LogicalSwitchPort> findLogicalSwitchPortsByUuid(String logicalSwitchUuid, String logicalSwitchPortUuid) throws NiciraNvpApiException {
199+
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport";
200+
Map<String,String> params = new HashMap<String,String>();
201+
params.put("uuid", logicalSwitchPortUuid);
202+
params.put("fields", "uuid");
203+
204+
NiciraNvpList<LogicalSwitchPort> lspl = executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalSwitchPort>>(){}.getType(), uri, params);
205+
206+
if (lspl == null ) {
207+
throw new NiciraNvpApiException("Unexpected response from API");
208+
}
209+
210+
return lspl;
211+
}
212+
213+
198214
private <T> void executeUpdateObject(T newObject, String uri, Map<String,String> parameters) throws NiciraNvpApiException {
199215
String url;
200216
try {

plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@
3535
import com.cloud.agent.api.DeleteLogicalSwitchCommand;
3636
import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer;
3737
import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
38+
import com.cloud.agent.api.FindLogicalSwitchPortAnswer;
39+
import com.cloud.agent.api.FindLogicalSwitchPortCommand;
3840
import com.cloud.agent.api.MaintainAnswer;
3941
import com.cloud.agent.api.MaintainCommand;
4042
import com.cloud.agent.api.PingCommand;
4143
import com.cloud.agent.api.ReadyAnswer;
4244
import com.cloud.agent.api.ReadyCommand;
4345
import com.cloud.agent.api.StartupCommand;
4446
import com.cloud.agent.api.StartupNiciraNvpCommand;
47+
import com.cloud.agent.api.UpdateLogicalSwitchPortAnswer;
48+
import com.cloud.agent.api.UpdateLogicalSwitchPortCommand;
4549
import com.cloud.host.Host;
4650
import com.cloud.host.Host.Type;
4751
import com.cloud.network.nicira.ControlClusterStatus;
4852
import com.cloud.network.nicira.LogicalSwitch;
4953
import com.cloud.network.nicira.LogicalSwitchPort;
5054
import com.cloud.network.nicira.NiciraNvpApi;
5155
import com.cloud.network.nicira.NiciraNvpApiException;
56+
import com.cloud.network.nicira.NiciraNvpList;
5257
import com.cloud.network.nicira.NiciraNvpTag;
5358
import com.cloud.network.nicira.TransportZoneBinding;
5459
import com.cloud.network.nicira.VifAttachment;
@@ -186,6 +191,12 @@ else if (cmd instanceof CreateLogicalSwitchPortCommand) {
186191
else if (cmd instanceof DeleteLogicalSwitchPortCommand) {
187192
return executeRequest((DeleteLogicalSwitchPortCommand) cmd, numRetries);
188193
}
194+
else if (cmd instanceof UpdateLogicalSwitchPortCommand) {
195+
return executeRequest((UpdateLogicalSwitchPortCommand) cmd, numRetries);
196+
}
197+
else if (cmd instanceof FindLogicalSwitchPortCommand) {
198+
return executeRequest((FindLogicalSwitchPortCommand) cmd, numRetries);
199+
}
189200
s_logger.debug("Received unsupported command " + cmd.toString());
190201
return Answer.createUnsupportedCommandAnswer(cmd);
191202
}
@@ -284,6 +295,51 @@ private Answer executeRequest(DeleteLogicalSwitchPortCommand cmd, int numRetries
284295
}
285296
}
286297

298+
private Answer executeRequest(UpdateLogicalSwitchPortCommand cmd, int numRetries) {
299+
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
300+
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
301+
String attachmentUuid = cmd.getAttachmentUuid();
302+
303+
try {
304+
// Tags set to scope cs_account and account name
305+
List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
306+
tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName()));
307+
308+
_niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, new VifAttachment(attachmentUuid));
309+
return new UpdateLogicalSwitchPortAnswer(cmd, true, "Attachment for " + logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
310+
} catch (NiciraNvpApiException e) {
311+
if (numRetries > 0) {
312+
return retry(cmd, --numRetries);
313+
}
314+
else {
315+
return new UpdateLogicalSwitchPortAnswer(cmd, e);
316+
}
317+
}
318+
319+
}
320+
321+
private Answer executeRequest(FindLogicalSwitchPortCommand cmd, int numRetries) {
322+
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
323+
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
324+
325+
try {
326+
NiciraNvpList<LogicalSwitchPort> ports = _niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
327+
if (ports.getResult_count() == 0) {
328+
return new FindLogicalSwitchPortAnswer(cmd, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null);
329+
}
330+
else {
331+
return new FindLogicalSwitchPortAnswer(cmd, true, "Logical switchport " + logicalSwitchPortUuid + " found", logicalSwitchPortUuid);
332+
}
333+
} catch (NiciraNvpApiException e) {
334+
if (numRetries > 0) {
335+
return retry(cmd, --numRetries);
336+
}
337+
else {
338+
return new FindLogicalSwitchPortAnswer(cmd, e);
339+
}
340+
}
341+
}
342+
287343
private Answer executeRequest(ReadyCommand cmd) {
288344
return new ReadyAnswer(cmd);
289345
}

0 commit comments

Comments
 (0)