Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/src/main/java/com/cloud/agent/api/to/NicTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.cloud.agent.api.to;

import com.cloud.offering.NetworkOffering;
import com.cloud.vm.Nic;

import java.util.List;
import java.util.Map;
Expand All @@ -33,6 +34,7 @@ public class NicTO extends NetworkTO {
boolean dpdkEnabled;
Integer mtu;
Long networkId;
Nic.LinkState linkState;

String networkSegmentName;

Expand Down Expand Up @@ -154,4 +156,12 @@ public String getNetworkSegmentName() {
public void setNetworkSegmentName(String networkSegmentName) {
this.networkSegmentName = networkSegmentName;
}

public Nic.LinkState getLinkState() {
return linkState;
}

public void setLinkState(Nic.LinkState linkState) {
this.linkState = linkState;
}
}
6 changes: 6 additions & 0 deletions api/src/main/java/com/cloud/vm/Nic.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ enum Event {
ReservationRequested, ReleaseRequested, CancelRequested, OperationCompleted, OperationFailed,
}

enum LinkState {
Enabled, Disabled
}

public enum State implements FiniteState<State, Event> {
Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing(
"Resource is being released"), Deallocating("Resource is being deallocated");
Expand Down Expand Up @@ -162,4 +166,6 @@ public enum ReservationStrategy {
String getIPv6Address();

Integer getMtu();

LinkState getLinkState();
}
10 changes: 10 additions & 0 deletions api/src/main/java/com/cloud/vm/NicProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class NicProfile implements InternalIdentity, Serializable {
boolean defaultNic;
Integer networkRate;
boolean isSecurityGroupEnabled;
Nic.LinkState linkState;

Integer orderIndex;

Expand Down Expand Up @@ -87,6 +88,7 @@ public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri,
broadcastType = network.getBroadcastDomainType();
trafficType = network.getTrafficType();
format = nic.getAddressFormat();
linkState = nic.getLinkState();

iPv4Address = nic.getIPv4Address();
iPv4Netmask = nic.getIPv4Netmask();
Expand Down Expand Up @@ -414,6 +416,14 @@ public void setIpv4AllocationRaceCheck(boolean ipv4AllocationRaceCheck) {
this.ipv4AllocationRaceCheck = ipv4AllocationRaceCheck;
}

public Nic.LinkState getLinkState() {
return linkState;
}

public void setLinkState(Nic.LinkState linkState) {
this.linkState = linkState;
}

//
// OTHER METHODS
//
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
import org.apache.cloudstack.api.command.user.vm.UpdateVmNicCmd;
import org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd;
import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
Expand Down Expand Up @@ -152,6 +153,8 @@ void startVirtualMachineForHA(VirtualMachine vm, Map<VirtualMachineProfile.Param
*/
UserVm updateNicIpForVirtualMachine(UpdateVmNicIpCmd cmd);

UserVm updateVirtualMachineNic(UpdateVmNicCmd cmd);

UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ public interface ResponseGenerator {

UserVm findUserVmById(Long vmId);

UserVm findUserVmByNicId(Long nicId);

Volume findVolumeById(Long volumeId);

Account findAccountByNameDomain(String accountName, Long domainId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 org.apache.cloudstack.api.command.user.vm;

import com.cloud.exception.InvalidParameterValueException;
import com.cloud.vm.Nic;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.NicResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang3.StringUtils;

import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;

import java.util.ArrayList;
import java.util.EnumSet;

@APICommand(name = "updateVmNic", description = "Updates the specified VM NIC", responseObject = NicResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
authorized = { RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User })
public class UpdateVmNicCmd extends BaseAsyncCmd {

@Parameter(name = ApiConstants.NIC_ID, type = CommandType.UUID, entityType = NicResponse.class, required = true, description = "NIC ID")
private Long nicId;

@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "Whether the NIC link state is enabled or disabled")
private String linkState;

public Long getNicId() {
return nicId;
}

public Nic.LinkState getLinkState() {
if (linkState == null) {
return null;
}

try {
return Nic.LinkState.valueOf(StringUtils.capitalize(StringUtils.lowerCase(linkState)));
} catch (IllegalArgumentException ex) {
throw new InvalidParameterValueException(String.format("Unable to resolve link state [%s] to a supported value (Enabled or Disabled).", linkState));
}
}

@Override
public String getEventType() {
return EventTypes.EVENT_NIC_UPDATE;
}

@Override
public String getEventDescription() {
return String.format("Updating NIC %s.", getResourceUuid(ApiConstants.NIC_ID));
}

@Override
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmByNicId(nicId);
if (vm == null) {
return Account.ACCOUNT_ID_SYSTEM;
}
return vm.getAccountId();
}

@Override
public void execute() {
CallContext.current().setEventDetails(String.format("NIC ID: %s", getResourceUuid(ApiConstants.NIC_ID)));
UserVm result = _userVmService.updateVirtualMachineNic(this);
ArrayList<ApiConstants.VMDetails> dc = new ArrayList<ApiConstants.VMDetails>();
dc.add(ApiConstants.VMDetails.valueOf("nics"));
EnumSet<ApiConstants.VMDetails> details = EnumSet.copyOf(dc);
if (result != null){
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseObject.ResponseView.Restricted, "virtualmachine", details, result).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update NIC from VM.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;

import com.cloud.vm.Nic.LinkState;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
Expand Down Expand Up @@ -146,6 +147,10 @@ public class NicResponse extends BaseResponse {
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
private String publicIp;

@SerializedName(ApiConstants.STATE)
@Param(description = "NIC's link state")
private LinkState linkState;

public void setVmId(String vmId) {
this.vmId = vmId;
}
Expand Down Expand Up @@ -416,4 +421,12 @@ public void setPublicIpId(String publicIpId) {
public void setPublicIp(String publicIp) {
this.publicIp = publicIp;
}

public LinkState getLinkState() {
return linkState;
}

public void setLinkState(LinkState linkState) {
this.linkState = linkState;
}
}
27 changes: 27 additions & 0 deletions core/src/main/java/com/cloud/agent/api/UpdateVmNicAnswer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.agent.api;

public class UpdateVmNicAnswer extends Answer {
public UpdateVmNicAnswer() {
}

public UpdateVmNicAnswer(UpdateVmNicCommand cmd, boolean success, String result) {
super(cmd, success, result);
}
}
53 changes: 53 additions & 0 deletions core/src/main/java/com/cloud/agent/api/UpdateVmNicCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.agent.api;

import com.cloud.vm.Nic;

public class UpdateVmNicCommand extends Command {

String nicMacAddress;
String instanceName;
Nic.LinkState linkState;

@Override
public boolean executeInSequence() {
return true;
}

protected UpdateVmNicCommand() {
}

public UpdateVmNicCommand(String nicMacAdderss, String instanceName, Nic.LinkState linkState) {
this.nicMacAddress = nicMacAdderss;
this.instanceName = instanceName;
this.linkState = linkState;
}

public String getNicMacAddress() {
return nicMacAddress;
}

public String getVmName() {
return instanceName;
}

public Nic.LinkState getLinkState() {
return linkState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile request

Boolean updateDefaultNicForVM(VirtualMachine vm, Nic nic, Nic defaultNic);

boolean updateVmNic(VirtualMachine vm, Nic nic, Nic.LinkState linkState) throws ResourceUnavailableException;

/**
* @param vm
* @param network
Expand Down
Loading
Loading