Skip to content
Merged
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
15 changes: 15 additions & 0 deletions api/src/com/cloud/configuration/ConfigurationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.List;

import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.network.DeleteManagementNetworkIpRangeCmd;
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
Expand Down Expand Up @@ -160,6 +162,19 @@ public interface ConfigurationService {
*/
Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState);

/**
* Creates a mutual exclusive IP range in the pod with same gateway, netmask.
* @param cmd - The command specifying pod ID, start IP, end IP, gateway, netmask.
* @return The new range if successful, null otherwise.
*/
Pod createPodIpRange(CreateManagementNetworkIpRangeCmd cmd);

/**
* Deletes a mutually exclusive IP range in the pod.
* @param cmd - The command specifying pod ID, start IP, end IP.
*/
void deletePodIpRange(DeleteManagementNetworkIpRangeCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException;

/**
* Edits a pod in the database. Will not allow you to edit pods that are being used anywhere in the system.
*
Expand Down
11 changes: 5 additions & 6 deletions api/src/com/cloud/dc/StorageNetworkIpRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
import org.apache.cloudstack.api.InternalIdentity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitin-maharana I saw the related mail so went ahead and looked at it. You don't need my review but I am never merging blindly (unless as RM;)

Is there a reason you changed this file? I don't see any significance in the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DaanHoogland, Firstly thanks for reviewing it.

I agree this change has no significance to the feature. But exactly I don't remember why I changed the order because I implemented it long back. I guess, one reason must be to maintain all UUIDs on one side, gateway & netmask another side, startIp and endIp together in the middle.


public interface StorageNetworkIpRange extends InfrastructureEntity, InternalIdentity, Identity {

Integer getVlan();

String getPodUuid();
String getGateway();

String getNetmask();

String getStartIp();

String getEndIp();

String getNetworkUuid();

String getZoneUuid();

String getNetmask();
String getPodUuid();

String getGateway();
String getNetworkUuid();
}
6 changes: 6 additions & 0 deletions api/src/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ public class EventTypes {
public static final String EVENT_VLAN_IP_RANGE_DEDICATE = "VLAN.IP.RANGE.DEDICATE";
public static final String EVENT_VLAN_IP_RANGE_RELEASE = "VLAN.IP.RANGE.RELEASE";

public static final String EVENT_MANAGEMENT_IP_RANGE_CREATE = "MANAGEMENT.IP.RANGE.CREATE";
public static final String EVENT_MANAGEMENT_IP_RANGE_DELETE = "MANAGEMENT.IP.RANGE.DELETE";

public static final String EVENT_STORAGE_IP_RANGE_CREATE = "STORAGE.IP.RANGE.CREATE";
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";
public static final String EVENT_STORAGE_IP_RANGE_UPDATE = "STORAGE.IP.RANGE.UPDATE";
Expand Down Expand Up @@ -761,6 +764,9 @@ public class EventTypes {
entityEventDetails.put(EVENT_VLAN_IP_RANGE_DEDICATE, Vlan.class);
entityEventDetails.put(EVENT_VLAN_IP_RANGE_RELEASE, Vlan.class);

entityEventDetails.put(EVENT_MANAGEMENT_IP_RANGE_CREATE, Pod.class);
entityEventDetails.put(EVENT_MANAGEMENT_IP_RANGE_DELETE, Pod.class);

entityEventDetails.put(EVENT_STORAGE_IP_RANGE_CREATE, StorageNetworkIpRange.class);
entityEventDetails.put(EVENT_STORAGE_IP_RANGE_DELETE, StorageNetworkIpRange.class);
entityEventDetails.put(EVENT_STORAGE_IP_RANGE_UPDATE, StorageNetworkIpRange.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// 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.admin.network;

import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.ApiArgValidator;
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.ServerApiException;
import org.apache.cloudstack.api.response.PodResponse;

import com.cloud.dc.Pod;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;

@APICommand(name = CreateManagementNetworkIpRangeCmd.APINAME,
description = "Creates a Management network IP range.",
responseObject = PodResponse.class,
since = "4.11.0.0",
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
authorized = {RoleType.Admin})
public class CreateManagementNetworkIpRangeCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(CreateManagementNetworkIpRangeCmd.class);

public static final String APINAME = "createManagementNetworkIpRange";

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.POD_ID,
type = CommandType.UUID,
entityType = PodResponse.class,
required = true,
description = "UUID of POD, where the IP range belongs to.",
validations = {ApiArgValidator.PositiveNumber})
private Long podId;

@Parameter(name = ApiConstants.GATEWAY,
type = CommandType.STRING,
required = true,
description = "The gateway for the management network.",
validations = {ApiArgValidator.NotNullOrEmpty})
private String gateway;

@Parameter(name = ApiConstants.NETMASK,
type = CommandType.STRING,
required = true,
description = "The netmask for the management network.",
validations = {ApiArgValidator.NotNullOrEmpty})
private String netmask;

@Parameter(name = ApiConstants.START_IP,
type = CommandType.STRING,
required = true,
description = "The starting IP address.",
validations = {ApiArgValidator.NotNullOrEmpty})
private String startIp;

@Parameter(name = ApiConstants.END_IP,
type = CommandType.STRING,
description = "The ending IP address.")
private String endIp;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public Long getPodId() {
return podId;
}

public String getGateWay() {
return gateway;
}

public String getNetmask() {
return netmask;
}

public String getStartIp() {
return startIp;
}

public String getEndIp() {
return endIp;
}

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

@Override
public String getEventDescription() {
return "Creating management ip range from " + getStartIp() + " to " + getEndIp() + " and gateway=" + getGateWay() + ", netmask=" + getNetmask() + " of pod=" + getPodId();
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException {
Pod result = _configService.createPodIpRange(this);
if (result != null) {
PodResponse response = _responseGenerator.createPodResponse(result, false);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Pod IP Range.");
}
}

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// 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.admin.network;

import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.ApiArgValidator;
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.response.PodResponse;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;

import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;

@APICommand(name = DeleteManagementNetworkIpRangeCmd.APINAME,
description = "Deletes a management network IP range. This action is only allowed when no IPs in this range are allocated.",
responseObject = SuccessResponse.class,
since = "4.11.0.0",
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
authorized = {RoleType.Admin})
public class DeleteManagementNetworkIpRangeCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteManagementNetworkIpRangeCmd.class);

public static final String APINAME = "deleteManagementNetworkIpRange";

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.POD_ID,
type = CommandType.UUID,
entityType = PodResponse.class,
required = true,
description = "UUID of POD, where the IP range belongs to.",
validations = ApiArgValidator.PositiveNumber)
private Long podId;

@Parameter(name = ApiConstants.START_IP,
type = CommandType.STRING,
required = true,
description = "The starting IP address.",
validations = ApiArgValidator.NotNullOrEmpty)
private String startIp;

@Parameter(name = ApiConstants.END_IP,
type = CommandType.STRING,
required = true,
description = "The ending IP address.",
validations = ApiArgValidator.NotNullOrEmpty)
private String endIp;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public Long getPodId() {
return podId;
}

public String getStartIp() {
return startIp;
}

public String getEndIp() {
return endIp;
}

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

@Override
public String getEventDescription() {
return "Deleting management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId();
}

@Override
public void execute() {
try {
_configService.deletePodIpRange(this);
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (Exception e) {
s_logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

}
12 changes: 6 additions & 6 deletions api/src/org/apache/cloudstack/api/response/PodResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public class PodResponse extends BaseResponse {

@SerializedName("startip")
@Param(description = "the starting IP for the Pod")
private String startIp;
private List<String> startIp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this breaks API response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are adding multiple ranges in a pod, so there will be a list of startIps and endIps. It is not breaking because if you look at the createPodResponse method of ApiResonseHelper, where the startIp and endIp variable are converted to list. And the Start IP and End IP field are removed from pod detail page. Hope this clarifies.


@SerializedName("endip")
@Param(description = "the ending IP for the Pod")
private String endIp;
private List<String> endIp;

@SerializedName("allocationstate")
@Param(description = "the allocation state of the Pod")
Expand Down Expand Up @@ -117,19 +117,19 @@ public void setNetmask(String netmask) {
this.netmask = netmask;
}

public String getStartIp() {
public List<String> getStartIp() {
return startIp;
}

public void setStartIp(String startIp) {
public void setStartIp(List<String> startIp) {
this.startIp = startIp;
}

public String getEndIp() {
public List<String> getEndIp() {
return endIp;
}

public void setEndIp(String endIp) {
public void setEndIp(List<String> endIp) {
this.endIp = endIp;
}

Expand Down
Loading