Skip to content

Commit 5d22e56

Browse files
authored
Merge branch 'main' into getUserByApiKey-not-checking-for-null-pointers
2 parents a5ae44b + 5d61ba3 commit 5d22e56

File tree

49 files changed

+734
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+734
-27
lines changed

.codespellrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
[codespell]
19+
ignore-words = .github/linters/codespell.txt
20+
skip = systemvm/agent/noVNC/*,ui/package.json,ui/package-lock.json,ui/public/js/less.min.js,ui/public/locales/*.json,server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java,test/integration/smoke/test_ssl_offloading.py

.pre-commit-config.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,15 @@ repos:
162162
- id: forbid-submodules
163163
- id: mixed-line-ending
164164
- id: trailing-whitespace
165-
files: ^(LICENSE|NOTICE)$|\.(bat|cfg|cs|css|gitignore|header|in|install|java|md|properties|py|rb|rc|sh|sql|te|template|txt|ucls|vue|xml|xsl|yaml|yml)$|^cloud-cli/bindir/cloud-tool$|^debian/changelog$
165+
files: ^(LICENSE|NOTICE)$|README$|\.(bat|cfg|config|cs|css|erb|gitignore|header|in|install|java|md|properties|py|rb|rc|sh|sql|svg|te|template|txt|ucls|vue|xml|xsl|yaml|yml)$|^cloud-cli/bindir/cloud-tool$|^debian/changelog$
166166
args: [--markdown-linebreak-ext=md]
167167
exclude: ^services/console-proxy/rdpconsole/src/test/doc/freerdp-debug-log\.txt$
168168
- repo: https://github.com/codespell-project/codespell
169-
rev: v2.4.1
169+
rev: v2.4.2
170170
hooks:
171171
- id: codespell
172172
name: run codespell
173173
description: Check spelling with codespell
174-
args: [--ignore-words=.github/linters/codespell.txt]
175-
exclude: ^systemvm/agent/noVNC/|^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$|^server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java$|^test/integration/smoke/test_ssl_offloading.py$
176174
- repo: https://github.com/pycqa/flake8
177175
rev: 7.0.0
178176
hooks:
@@ -186,7 +184,7 @@ repos:
186184
description: check Markdown files with markdownlint
187185
args: [--config=.github/linters/.markdown-lint.yml]
188186
types: [markdown]
189-
files: \.(md|mdown|markdown)$
187+
files: \.md$
190188
- repo: https://github.com/adrienverge/yamllint
191189
rev: v1.37.1
192190
hooks:

api/src/main/java/com/cloud/agent/api/to/NicTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class NicTO extends NetworkTO {
3333
boolean dpdkEnabled;
3434
Integer mtu;
3535
Long networkId;
36+
boolean enabled;
3637

3738
String networkSegmentName;
3839

@@ -154,4 +155,12 @@ public String getNetworkSegmentName() {
154155
public void setNetworkSegmentName(String networkSegmentName) {
155156
this.networkSegmentName = networkSegmentName;
156157
}
158+
159+
public boolean isEnabled() {
160+
return enabled;
161+
}
162+
163+
public void setEnabled(boolean enabled) {
164+
this.enabled = enabled;
165+
}
157166
}

api/src/main/java/com/cloud/vm/Nic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,6 @@ public enum ReservationStrategy {
162162
String getIPv6Address();
163163

164164
Integer getMtu();
165+
166+
boolean isEnabled();
165167
}

api/src/main/java/com/cloud/vm/NicProfile.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class NicProfile implements InternalIdentity, Serializable {
5252
boolean defaultNic;
5353
Integer networkRate;
5454
boolean isSecurityGroupEnabled;
55+
boolean enabled;
5556

5657
Integer orderIndex;
5758

@@ -87,6 +88,7 @@ public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri,
8788
broadcastType = network.getBroadcastDomainType();
8889
trafficType = network.getTrafficType();
8990
format = nic.getAddressFormat();
91+
enabled = nic.isEnabled();
9092

9193
iPv4Address = nic.getIPv4Address();
9294
iPv4Netmask = nic.getIPv4Netmask();
@@ -414,6 +416,14 @@ public void setIpv4AllocationRaceCheck(boolean ipv4AllocationRaceCheck) {
414416
this.ipv4AllocationRaceCheck = ipv4AllocationRaceCheck;
415417
}
416418

419+
public boolean isEnabled() {
420+
return enabled;
421+
}
422+
423+
public void setEnabled(boolean enabled) {
424+
this.enabled = enabled;
425+
}
426+
417427
//
418428
// OTHER METHODS
419429
//

api/src/main/java/com/cloud/vm/UserVmService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
4141
import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
4242
import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
43+
import org.apache.cloudstack.api.command.user.vm.UpdateVmNicCmd;
4344
import org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd;
4445
import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
4546
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
@@ -152,6 +153,8 @@ void startVirtualMachineForHA(VirtualMachine vm, Map<VirtualMachineProfile.Param
152153
*/
153154
UserVm updateNicIpForVirtualMachine(UpdateVmNicIpCmd cmd);
154155

156+
UserVm updateVirtualMachineNic(UpdateVmNicCmd cmd);
157+
155158
UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;
156159

157160
/**

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ public interface ResponseGenerator {
343343

344344
UserVm findUserVmById(Long vmId);
345345

346+
UserVm findUserVmByNicId(Long nicId);
347+
346348
Volume findVolumeById(Long volumeId);
347349

348350
Account findAccountByNameDomain(String accountName, Long domainId);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 org.apache.cloudstack.api.command.user.vm;
18+
19+
import org.apache.cloudstack.acl.RoleType;
20+
import org.apache.cloudstack.api.ACL;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.ApiErrorCode;
24+
import org.apache.cloudstack.api.BaseAsyncCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.ResponseObject;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.NicResponse;
29+
import org.apache.cloudstack.api.response.UserVmResponse;
30+
import org.apache.cloudstack.context.CallContext;
31+
32+
import com.cloud.event.EventTypes;
33+
import com.cloud.user.Account;
34+
import com.cloud.uservm.UserVm;
35+
36+
import java.util.ArrayList;
37+
import java.util.EnumSet;
38+
39+
@APICommand(name = "updateVmNic", description = "Updates the specified VM NIC", responseObject = NicResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
40+
authorized = { RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User })
41+
public class UpdateVmNicCmd extends BaseAsyncCmd {
42+
43+
@ACL
44+
@Parameter(name = ApiConstants.NIC_ID, type = CommandType.UUID, entityType = NicResponse.class, required = true, description = "NIC ID")
45+
private Long nicId;
46+
47+
@Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, description = "If true, sets the NIC state to UP; otherwise, sets the NIC state to DOWN")
48+
private Boolean enabled;
49+
50+
public Long getNicId() {
51+
return nicId;
52+
}
53+
54+
public Boolean isEnabled() {
55+
return enabled;
56+
}
57+
58+
@Override
59+
public String getEventType() {
60+
return EventTypes.EVENT_NIC_UPDATE;
61+
}
62+
63+
@Override
64+
public String getEventDescription() {
65+
return String.format("Updating NIC %s.", getResourceUuid(ApiConstants.NIC_ID));
66+
}
67+
68+
@Override
69+
public long getEntityOwnerId() {
70+
UserVm vm = _responseGenerator.findUserVmByNicId(nicId);
71+
if (vm == null) {
72+
return Account.ACCOUNT_ID_SYSTEM;
73+
}
74+
return vm.getAccountId();
75+
}
76+
77+
@Override
78+
public void execute() {
79+
CallContext.current().setEventDetails(String.format("NIC ID: %s", getResourceUuid(ApiConstants.NIC_ID)));
80+
81+
UserVm result = _userVmService.updateVirtualMachineNic(this);
82+
83+
ArrayList<ApiConstants.VMDetails> dc = new ArrayList<>();
84+
dc.add(ApiConstants.VMDetails.valueOf("nics"));
85+
EnumSet<ApiConstants.VMDetails> details = EnumSet.copyOf(dc);
86+
87+
if (result != null){
88+
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseObject.ResponseView.Restricted, "virtualmachine", details, result).get(0);
89+
response.setResponseName(getCommandName());
90+
this.setResponseObject(response);
91+
} else {
92+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update NIC from VM.");
93+
}
94+
}
95+
}

api/src/main/java/org/apache/cloudstack/api/response/NicResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public class NicResponse extends BaseResponse {
146146
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
147147
private String publicIp;
148148

149+
@SerializedName(ApiConstants.ENABLED)
150+
@Param(description = "whether the NIC is enabled or not")
151+
private Boolean isEnabled;
152+
149153
public void setVmId(String vmId) {
150154
this.vmId = vmId;
151155
}
@@ -416,4 +420,12 @@ public void setPublicIpId(String publicIpId) {
416420
public void setPublicIp(String publicIp) {
417421
this.publicIp = publicIp;
418422
}
423+
424+
public Boolean getEnabled() {
425+
return isEnabled;
426+
}
427+
428+
public void setEnabled(Boolean enabled) {
429+
isEnabled = enabled;
430+
}
419431
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
package com.cloud.agent.api;
19+
20+
public class UpdateVmNicAnswer extends Answer {
21+
public UpdateVmNicAnswer() {
22+
}
23+
24+
public UpdateVmNicAnswer(UpdateVmNicCommand cmd, boolean success, String result) {
25+
super(cmd, success, result);
26+
}
27+
}

0 commit comments

Comments
 (0)