diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 4577f8ec778..f132b53fb07 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -86,6 +86,7 @@ public class ApiConstants { public static final String IS_PUBLIC = "ispublic"; public static final String IS_READY = "isready"; public static final String IS_RECURSIVE = "isrecursive"; + public static final String IS_SHARED = "isshared"; public static final String ISO_FILTER = "isofilter"; public static final String JOB_ID = "jobid"; public static final String JOB_STATUS = "jobstatus"; @@ -165,4 +166,11 @@ public class ApiConstants { public static final String NETWORK_TYPE = "networktype"; public static final String PAGE = "page"; public static final String PAGE_SIZE = "pagesize"; + public static final String TRAFFIC_TYPE = "traffictype"; + public static final String MAX_CONNECTIONS = "maxconnections"; + public static final String NETWORK_OFFERING_ID = "networkofferingid"; + public static final String NETWORK_IDS = "networkids"; + public static final String SPECIFY_VLAN = "specifyvlan"; + public static final String IS_DEFAULT = "isdefault"; } + diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 7edfa10910c..75dad3250e8 100644 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -40,6 +40,8 @@ import com.cloud.api.response.IpForwardingRuleResponse; import com.cloud.api.response.ListResponse; import com.cloud.api.response.LoadBalancerResponse; import com.cloud.api.response.NetworkGroupResponse; +import com.cloud.api.response.NetworkOfferingResponse; +import com.cloud.api.response.NetworkResponse; import com.cloud.api.response.PodResponse; import com.cloud.api.response.PreallocatedLunResponse; import com.cloud.api.response.RemoteAccessVpnResponse; @@ -69,6 +71,7 @@ import com.cloud.event.Event; import com.cloud.host.Host; import com.cloud.network.IpAddress; import com.cloud.network.LoadBalancer; +import com.cloud.network.Network; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VpnUser; import com.cloud.network.router.VirtualRouter; @@ -77,6 +80,7 @@ import com.cloud.network.security.IngressRule; import com.cloud.network.security.NetworkGroup; import com.cloud.network.security.NetworkGroupRules; import com.cloud.offering.DiskOffering; +import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; import com.cloud.storage.Snapshot; @@ -201,5 +205,9 @@ public interface ResponseGenerator { TemplatePermissionsResponse createTemplatePermissionsResponse(List accountNames, Long id, boolean isAdmin); AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd); + + NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering); + + NetworkResponse createNetworkResponse(Network network); } diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java new file mode 100644 index 00000000000..161605aea57 --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -0,0 +1,155 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.NetworkResponse; +import com.cloud.network.Network; + +@Implementation(description="Creates a network", responseObject=NetworkResponse.class) +public class CreateNetworkCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName()); + + private static final String s_name = "createnetworkresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network") + private String name; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network") + private String displayText; + + @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id") + private Long networkOfferingId; + + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the Vlan ip range") + private Long zoneId; + + @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="the Pod ID for the Vlan ip range") + private Long podId; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the VLAN IP range") + private String gateway; + + @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, description="the cidr of the VLAN IP range") + private String cidr; + + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the VLAN IP range") + private String netmask; + + @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the VLAN IP range") + private String startIp; + + @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the VLAN IP range") + private String endIp; + + @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the VLAN. Default is an \"untagged\" VLAN.") + private String vlan; + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the VLAN. If VLAN is Zone wide, this parameter should be ommited") + private String accountName; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN") + private Long domainId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getNetworkOfferingId() { + return networkOfferingId; + } + + public Long getZoneId() { + return zoneId; + } + + public Long getPodId() { + return podId; + } + + public String getGateway() { + return gateway; + } + + public String getCidr() { + return cidr; + } + + public String getVlan() { + return vlan; + } + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public String getNetmask() { + return netmask; + } + + public String getStartIp() { + return startIp; + } + + public String getEndIp() { + return endIp; + } + + public String getNetworkName() { + return name; + } + + public String getDisplayText() { + return displayText; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getName() { + return s_name; + } + + @Override + public void execute(){ + Network result = _networkService.createNetwork(this); + if (result != null) { + NetworkResponse response = _responseGenerator.createNetworkResponse(result); + response.setResponseName(getName()); + this.setResponseObject(response); + }else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network"); + } + } +} diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java new file mode 100644 index 00000000000..64f9d59276b --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.NetworkOfferingResponse; +import com.cloud.offering.NetworkOffering; + +@Implementation(description="Creates a network offering.", responseObject=NetworkOfferingResponse.class) +public class CreateNetworkOfferingCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(CreateNetworkOfferingCmd.class.getName()); + private static final String _name = "createnetworkofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network offering") + private String networkOfferingName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network offering") + private String displayText; + + @Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, required=true, description="type of the network. Supported types Virtualized, DirectSingle, DirectDual") + private String type; + + @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.") + private String traffictype; + + @Parameter(name=ApiConstants.MAX_CONNECTIONS, type=CommandType.INTEGER, description="maximum number of concurrent connections supported by the network offering") + private Integer maxConnections; + + @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the network offering.") + private String tags; + + @Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true is network offering supports vlans") + private Boolean specifyVlan; + + @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans") + private Boolean isShared; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getNetworkOfferingName() { + return networkOfferingName; + } + + public String getDisplayText() { + return displayText; + } + + public String getTags() { + return tags; + } + + public String getType() { + return type; + } + + public String getTraffictype() { + return traffictype; + } + + public Integer getMaxconnections() { + return maxConnections; + } + + public Boolean getSpecifyVlan() { + return specifyVlan; + } + + public Boolean getIsShared() { + return isShared; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getName() { + return _name; + } + + @Override + public void execute(){ + NetworkOffering result = _configService.createNetworkOffering(this); + if (result != null) { + NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result); + response.setResponseName(getName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network offering"); + } + } +} diff --git a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java index 420c2b215e3..04dfa5fb806 100644 --- a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java +++ b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java @@ -49,8 +49,8 @@ public class CreateVlanIpRangeCmd extends BaseCmd { @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the VLAN IP range") private String endIp; - @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="true if VLAN is of Virtual type, false if Direct") - private Boolean forVirtualNetwork; +// @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="true if VLAN is of Virtual type, false if Direct") +// private Boolean forVirtualNetwork; @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the VLAN IP range") private String gateway; @@ -86,9 +86,9 @@ public class CreateVlanIpRangeCmd extends BaseCmd { return endIp; } - public Boolean isForVirtualNetwork() { - return forVirtualNetwork; - } +// public Boolean isForVirtualNetwork() { +// return forVirtualNetwork; +// } public String getGateway() { return gateway; diff --git a/api/src/com/cloud/api/commands/DeleteNetworkCmd.java b/api/src/com/cloud/api/commands/DeleteNetworkCmd.java new file mode 100644 index 00000000000..1291fbe71c2 --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteNetworkCmd.java @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; + +@Implementation(description="Deletes a network", responseObject=SuccessResponse.class) +public class DeleteNetworkCmd extends BaseCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName()); + private static final String s_name = "deletenetworkresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getName() { + return s_name; + } + + @Override + public void execute(){ + boolean result = _networkService.deleteNetwork(this); + if (result) { + SuccessResponse response = new SuccessResponse(getName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network"); + } + } +} diff --git a/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java new file mode 100644 index 00000000000..9719f14badc --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; + +@Implementation(description="Deletes a network offering.", responseObject=SuccessResponse.class) +public class DeleteNetworkOfferingCmd extends BaseCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName()); + private static final String s_name = "deletenetworkofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network offering") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getName() { + return s_name; + } + + @Override + public void execute(){ + boolean result = _configService.deleteNetworkOffering(this); + if (result) { + SuccessResponse response = new SuccessResponse(getName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete service offering"); + } + } +} diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 489708c674d..c1b4221c664 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -84,6 +84,9 @@ public class DeployVMCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="availability zone for the virtual machine") private Long zoneId; + + @Parameter(name=ApiConstants.NETWORK_IDS, type=CommandType.LIST, collectionType=CommandType.LONG) + private List networkIds; // unexposed parameter needed for serializing/deserializing the command @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, expose=false) @@ -149,11 +152,19 @@ public class DeployVMCmd extends BaseAsyncCmd { public void setPassword(String password) { this.password = password; } + + public List getNetworkIds() { + return networkIds; + } + + public void setNetworkList(List networkIds) { + this.networkIds = networkIds; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// - + @Override public String getName() { return s_name; @@ -216,12 +227,16 @@ public class DeployVMCmd extends BaseAsyncCmd { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm"); } } catch (ResourceAllocationException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (InsufficientStorageCapacityException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (StorageUnavailableException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (Exception ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java new file mode 100644 index 00000000000..563fd6ec1ee --- /dev/null +++ b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java @@ -0,0 +1,125 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseListCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.NetworkOfferingResponse; +import com.cloud.offering.NetworkOffering; + + +@Implementation(description="Lists all available network offerings.", responseObject=NetworkOfferingResponse.class) +public class ListNetworkOfferingsCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(ListNetworkOfferingsCmd.class.getName()); + private static final String _name = "listnetworkofferingsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list network offerings by id") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list network offerings by name") + private String networkOfferingName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="list network offerings by display text") + private String displayText; + + @Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="list by type of the network") + private String type; + + @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="list by traffic type") + private String trafficType; + + @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if need to list only default network offerings. Default value is false") + private Boolean isDefault; + + @Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="the tags for the network offering.") + private Boolean specifyVlan; + + @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans") + private Boolean isShared; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getNetworkOfferingName() { + return networkOfferingName; + } + + public String getDisplayText() { + return displayText; + } + + public String getType() { + return type; + } + + public String getTrafficType() { + return trafficType; + } + + public Long getId() { + return id; + } + + public Boolean getIsDefault() { + return isDefault; + } + + public Boolean getSpecifyVlan() { + return specifyVlan; + } + + public Boolean getIsShared() { + return isShared; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getName() { + return _name; + } + + @Override + public void execute(){ + List offerings = _configService.searchForNetworkOfferings(this); + ListResponse response = new ListResponse(); + List offeringResponses = new ArrayList(); + for (NetworkOffering offering : offerings) { + NetworkOfferingResponse offeringResponse = _responseGenerator.createNetworkOfferingResponse(offering); + offeringResponses.add(offeringResponse); + } + + response.setResponses(offeringResponses); + response.setResponseName(getName()); + this.setResponseObject(response); + } +} diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java new file mode 100644 index 00000000000..4cb95e9516f --- /dev/null +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseListCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.NetworkResponse; +import com.cloud.network.Network; + + +@Implementation(description="Lists all available networks.", responseObject=NetworkResponse.class) +public class ListNetworksCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName()); + private static final String _name = "listnetworksresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list networks by id") + private Long id; + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the VLAN. If VLAN is Zone wide, this parameter should be ommited") + private String accountName; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN") + private Long domainId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getName() { + return _name; + } + + @Override + public void execute(){ + List networks = _networkService.searchForNetworks(this); + ListResponse response = new ListResponse(); + List networkResponses = new ArrayList(); + for (Network network : networks) { + NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network); + networkResponses.add(networkResponse); + } + + response.setResponses(networkResponses); + response.setResponseName(getName()); + this.setResponseObject(response); + } +} diff --git a/api/src/com/cloud/api/commands/StartVMCmd.java b/api/src/com/cloud/api/commands/StartVMCmd.java index cc77fe1fd6b..e1ea9c54649 100644 --- a/api/src/com/cloud/api/commands/StartVMCmd.java +++ b/api/src/com/cloud/api/commands/StartVMCmd.java @@ -110,10 +110,13 @@ public class StartVMCmd extends BaseAsyncCmd { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm"); } }catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); }catch (StorageUnavailableException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); }catch (ExecutionException ex) { + s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/com/cloud/api/response/DomainRouterResponse.java b/api/src/com/cloud/api/response/DomainRouterResponse.java index 54af0bed0ea..122033da668 100644 --- a/api/src/com/cloud/api/response/DomainRouterResponse.java +++ b/api/src/com/cloud/api/response/DomainRouterResponse.java @@ -18,6 +18,7 @@ package com.cloud.api.response; import java.util.Date; +import java.util.List; import com.cloud.api.ApiConstants; import com.cloud.serializer.Param; @@ -107,6 +108,9 @@ public class DomainRouterResponse extends BaseResponse { return getId(); } + @SerializedName("nics") @Param(description="the list of nics associated with domain router") + private List nics; + public Long getId() { return id; } @@ -314,4 +318,12 @@ public class DomainRouterResponse extends BaseResponse { public void setDomainName(String domainName) { this.domainName = domainName; } + + public List getNics() { + return nics; + } + + public void setNics(List nics) { + this.nics = nics; + } } diff --git a/api/src/com/cloud/api/response/NetworkOfferingResponse.java b/api/src/com/cloud/api/response/NetworkOfferingResponse.java new file mode 100644 index 00000000000..ded3bc6775f --- /dev/null +++ b/api/src/com/cloud/api/response/NetworkOfferingResponse.java @@ -0,0 +1,137 @@ +package com.cloud.api.response; + +import java.util.Date; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class NetworkOfferingResponse extends BaseResponse{ + @SerializedName("id") @Param(description="the id of the network offering") + private Long id; + + @SerializedName("name") @Param(description="the name of the network offering") + private String name; + + @SerializedName("displaytext") @Param(description="an alternate display text of the network offering.") + private String displayText; + + @SerializedName("tags") @Param(description="the tags for the network offering") + private String tags; + + @SerializedName("created") @Param(description="the date this network offering was created") + private Date created; + + @SerializedName("maxconnections") @Param(description="the max number of concurrent connection the network offering supports") + private Integer maxConnections; + + @SerializedName("type") @Param(description="type of the network. Supported types are Virtualized, DirectSingle, DirectDual") + private String type; + + @SerializedName("traffictype") @Param(description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.") + private String trafficType; + + @SerializedName("isdefault") @Param(description="true if network offering is default, false otherwise") + private Boolean isDefault; + + @SerializedName("isshared") @Param(description="true if network offering is shared, false otherwise") + private Boolean isShared; + + @SerializedName("specifyvlan") @Param(description="true if network offering supports vlans, false otherwise") + private Boolean specifyVlan; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Integer getMaxconnections() { + return maxConnections; + } + + public void setMaxconnections(Integer maxConnections) { + this.maxConnections = maxConnections; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getTrafficType() { + return trafficType; + } + + public void setTrafficType(String trafficType) { + this.trafficType = trafficType; + } + + public Boolean getIsDefault() { + return isDefault; + } + + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + public Integer getMaxConnections() { + return maxConnections; + } + + public void setMaxConnections(Integer maxConnections) { + this.maxConnections = maxConnections; + } + + public Boolean getSpecifyVlan() { + return specifyVlan; + } + + public void setSpecifyVlan(Boolean specifyVlan) { + this.specifyVlan = specifyVlan; + } + + public Boolean getIsShared() { + return isShared; + } + + public void setIsShared(Boolean isShared) { + this.isShared = isShared; + } +} diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java new file mode 100644 index 00000000000..8da95663ac0 --- /dev/null +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -0,0 +1,231 @@ +package com.cloud.api.response; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class NetworkResponse extends BaseResponse{ + + @SerializedName("id") @Param(description="the id of the network") + private Long id; + + @SerializedName("name") @Param(description="the name of the network") + private String name; + + @SerializedName("displaytext") @Param(description="the displaytext of the network") + private String displaytext; + + //TODO - add description + @SerializedName("broadcastdomaintype") + private String broadcastDomainType; + + //TODO - add description + @SerializedName("traffictype") + private String trafficType; + + //TODO - add description + @SerializedName("gateway") + private String gateway; + + //TODO - add description + @SerializedName("cidr") + private String cidr; + + //TODO - add description + @SerializedName("zoneid") + private Long zoneId; + + //TODO - add description + @SerializedName("networkofferingid") + private Long networkOfferingId; + + //TODO - add description + @SerializedName("networkofferingname") + private String networkOfferingName; + + //TODO - add description + @SerializedName("networkofferingdisplaytext") + private String networkOfferingDisplayText; + + //TODO - add description + @SerializedName("state") + private String state; + + //TODO - add description + @SerializedName("related") + private Long related; + + //TODO - add description + @SerializedName("broadcasturi") + private String broadcastUri; + + //TODO - add description + @SerializedName("dns1") + private String dns1; + + //TODO - add description + @SerializedName("dns2") + private String dns2; + + //TODO - add description + @SerializedName("type") + private String type; + + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account associated with the network") + private String accountName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id associated with the network") + private Long domainId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBroadcastDomainType() { + return broadcastDomainType; + } + + public void setBroadcastDomainType(String broadcastDomainType) { + this.broadcastDomainType = broadcastDomainType; + } + + public String getTrafficType() { + return trafficType; + } + + public void setTrafficType(String trafficType) { + this.trafficType = trafficType; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + public String getCidr() { + return cidr; + } + + public void setCidr(String cidr) { + this.cidr = cidr; + } + + public Long getZoneId() { + return zoneId; + } + + public void setZoneId(Long zoneId) { + this.zoneId = zoneId; + } + + public Long getNetworkOfferingId() { + return networkOfferingId; + } + + public void setNetworkOfferingId(Long networkOfferingId) { + this.networkOfferingId = networkOfferingId; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public Long getRelated() { + return related; + } + + public void setRelated(Long related) { + this.related = related; + } + + public String getBroadcastUri() { + return broadcastUri; + } + + public void setBroadcastUri(String broadcastUri) { + this.broadcastUri = broadcastUri; + } + + public String getDns1() { + return dns1; + } + + public void setDns1(String dns1) { + this.dns1 = dns1; + } + + public String getDns2() { + return dns2; + } + + public void setDns2(String dns2) { + this.dns2 = dns2; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + public String getNetworkOfferingName() { + return networkOfferingName; + } + + public void setNetworkOfferingName(String networkOfferingName) { + this.networkOfferingName = networkOfferingName; + } + + public String getNetworkOfferingDisplayText() { + return networkOfferingDisplayText; + } + + public void setNetworkOfferingDisplayText(String networkOfferingDisplayText) { + this.networkOfferingDisplayText = networkOfferingDisplayText; + } + + public String getDisplaytext() { + return displaytext; + } + + public void setDisplaytext(String displaytext) { + this.displaytext = displaytext; + } +} diff --git a/api/src/com/cloud/api/response/NicResponse.java b/api/src/com/cloud/api/response/NicResponse.java new file mode 100644 index 00000000000..97eb5a822f9 --- /dev/null +++ b/api/src/com/cloud/api/response/NicResponse.java @@ -0,0 +1,101 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class NicResponse extends BaseResponse { + + @SerializedName("id") @Param(description="the ID of the nic") + private Long id; + + @SerializedName("networkid") @Param(description="the ID of the corresponding network") + private Long networkid; + + @SerializedName("netmask") @Param(description="the netmask of the nic") + private String netmask; + + @SerializedName("gateway") @Param(description="the gateway of the nic") + private String gateway; + + @SerializedName("ipaddress") @Param(description="the ip address of the nic") + private String ipaddress; + + @SerializedName("isolationuri") @Param(description="the isolation uri of the nic") + private String isolationUri; + + @SerializedName("broadcasturi") @Param(description="the broadcast uri of the nic") + private String broadcastUri; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getNetworkid() { + return networkid; + } + + public void setNetworkid(Long networkid) { + this.networkid = networkid; + } + + public String getNetmask() { + return netmask; + } + + public void setNetmask(String netmask) { + this.netmask = netmask; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + public String getIpaddress() { + return ipaddress; + } + + public void setIpaddress(String ipaddress) { + this.ipaddress = ipaddress; + } + + public String getIsolationUri() { + return isolationUri; + } + + public void setIsolationUri(String isolationUri) { + this.isolationUri = isolationUri; + } + + public String getBroadcastUri() { + return broadcastUri; + } + + public void setBroadcastUri(String broadcastUri) { + this.broadcastUri = broadcastUri; + } +} diff --git a/api/src/com/cloud/api/response/SystemVmResponse.java b/api/src/com/cloud/api/response/SystemVmResponse.java index a24fd0b5bab..3b34066f4fe 100644 --- a/api/src/com/cloud/api/response/SystemVmResponse.java +++ b/api/src/com/cloud/api/response/SystemVmResponse.java @@ -18,6 +18,7 @@ package com.cloud.api.response; import java.util.Date; +import java.util.List; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -99,6 +100,9 @@ public class SystemVmResponse extends BaseResponse { return getId(); } + @SerializedName("nics") @Param(description="the list of nics associated with system vm") + private List nics; + public Long getId() { return id; } @@ -290,4 +294,12 @@ public class SystemVmResponse extends BaseResponse { public void setActiveViewerSessions(Integer activeViewerSessions) { this.activeViewerSessions = activeViewerSessions; } + + public List getNics() { + return nics; + } + + public void setNics(List nics) { + this.nics = nics; + } } diff --git a/api/src/com/cloud/api/response/UserVmResponse.java b/api/src/com/cloud/api/response/UserVmResponse.java index e06ec3c1a1a..2dbc3272f27 100644 --- a/api/src/com/cloud/api/response/UserVmResponse.java +++ b/api/src/com/cloud/api/response/UserVmResponse.java @@ -18,6 +18,7 @@ package com.cloud.api.response; import java.util.Date; +import java.util.List; import com.cloud.api.ApiConstants; import com.cloud.serializer.Param; @@ -144,6 +145,9 @@ public class UserVmResponse extends BaseResponse { public Long getObjectId() { return getId(); } + + @SerializedName("nics") @Param(description="the list of nics associated with vm") + private List nics; public Long getId() { return id; @@ -456,4 +460,12 @@ public class UserVmResponse extends BaseResponse { public void setForVirtualNetwork(Boolean forVirtualNetwork) { this.forVirtualNetwork = forVirtualNetwork; } + + public List getNics() { + return nics; + } + + public void setNics(List nics) { + this.nics = nics; + } } diff --git a/api/src/com/cloud/api/response/VlanIpRangeResponse.java b/api/src/com/cloud/api/response/VlanIpRangeResponse.java index 6fe2d236119..7fbb9bf3f99 100644 --- a/api/src/com/cloud/api/response/VlanIpRangeResponse.java +++ b/api/src/com/cloud/api/response/VlanIpRangeResponse.java @@ -62,6 +62,9 @@ public class VlanIpRangeResponse extends BaseResponse { @SerializedName("endip") @Param(description="the end ip of the VLAN IP range") private String endIp; + + @SerializedName("networkid") @Param(description="the network id of vlan range") + private Long networkId; public Long getId() { return id; @@ -174,4 +177,12 @@ public class VlanIpRangeResponse extends BaseResponse { public void setEndIp(String endIp) { this.endIp = endIp; } + + public Long getNetworkId() { + return networkId; + } + + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } } diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index 310cb2f2fd1..f651cdce577 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -1,16 +1,21 @@ package com.cloud.configuration; +import java.util.List; + import com.cloud.api.commands.CreateCfgCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; +import com.cloud.api.commands.CreateNetworkOfferingCmd; import com.cloud.api.commands.CreatePodCmd; import com.cloud.api.commands.CreateServiceOfferingCmd; import com.cloud.api.commands.CreateVlanIpRangeCmd; import com.cloud.api.commands.CreateZoneCmd; import com.cloud.api.commands.DeleteDiskOfferingCmd; +import com.cloud.api.commands.DeleteNetworkOfferingCmd; import com.cloud.api.commands.DeletePodCmd; import com.cloud.api.commands.DeleteServiceOfferingCmd; import com.cloud.api.commands.DeleteVlanIpRangeCmd; import com.cloud.api.commands.DeleteZoneCmd; +import com.cloud.api.commands.ListNetworkOfferingsCmd; import com.cloud.api.commands.UpdateCfgCmd; import com.cloud.api.commands.UpdateDiskOfferingCmd; import com.cloud.api.commands.UpdatePodCmd; @@ -23,6 +28,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.offering.DiskOffering; +import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; public interface ConfigurationService { @@ -166,7 +172,14 @@ public interface ConfigurationService { * @throws * @return The new Vlan object */ - Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException; + Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd); + + NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd); + + List searchForNetworkOfferings(ListNetworkOfferingsCmd cmd); + + boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd); + } diff --git a/api/src/com/cloud/dc/Vlan.java b/api/src/com/cloud/dc/Vlan.java index 5182310b250..588092f1dfa 100644 --- a/api/src/com/cloud/dc/Vlan.java +++ b/api/src/com/cloud/dc/Vlan.java @@ -43,5 +43,7 @@ public interface Vlan { public void setVlanType(VlanType ipRange); public VlanType getVlanType(); + + public Long getNetworkId(); } \ No newline at end of file diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 8adf074e265..fd5b5ab16b0 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -132,6 +132,11 @@ public class EventTypes { public static final String EVENT_DISK_OFFERING_CREATE = "DISK.OFFERING.CREATE"; public static final String EVENT_DISK_OFFERING_EDIT = "DISK.OFFERING.EDIT"; public static final String EVENT_DISK_OFFERING_DELETE = "DISK.OFFERING.DELETE"; + + //Network offerings + public static final String EVENT_NETWORK_OFFERING_CREATE = "NETWORK.OFFERING.CREATE"; + public static final String EVENT_NETWORK_OFFERING_EDIT = "NETWORK.OFFERING.EDIT"; + public static final String EVENT_NETWORK_OFFERING_DELETE = "NETWORK.OFFERING.DELETE"; // Pods public static final String EVENT_POD_CREATE = "POD.CREATE"; diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 2a250609247..d00f4d616d3 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -80,6 +80,8 @@ public interface Network extends ControlledEntity { * @return id of the network profile. Null means the network profile is not from the database. */ long getId(); + + String getName(); Mode getMode(); @@ -106,4 +108,6 @@ public interface Network extends ControlledEntity { String getDns2(); GuestIpType getGuestType(); + + String getDisplayText(); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 0bc9dc0d5f6..04ad345671f 100644 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -23,11 +23,14 @@ import com.cloud.api.commands.AddVpnUserCmd; import com.cloud.api.commands.AssignToLoadBalancerRuleCmd; import com.cloud.api.commands.AssociateIPAddrCmd; import com.cloud.api.commands.CreateLoadBalancerRuleCmd; +import com.cloud.api.commands.CreateNetworkCmd; import com.cloud.api.commands.CreatePortForwardingRuleCmd; import com.cloud.api.commands.CreateRemoteAccessVpnCmd; import com.cloud.api.commands.DeleteLoadBalancerRuleCmd; +import com.cloud.api.commands.DeleteNetworkCmd; import com.cloud.api.commands.DeleteRemoteAccessVpnCmd; import com.cloud.api.commands.DisassociateIPAddrCmd; +import com.cloud.api.commands.ListNetworksCmd; import com.cloud.api.commands.ListPortForwardingRulesCmd; import com.cloud.api.commands.RemoveFromLoadBalancerRuleCmd; import com.cloud.api.commands.RemoveVpnUserCmd; @@ -122,5 +125,9 @@ public interface NetworkService { boolean deleteIpForwardingRule(Long id); boolean deletePortForwardingRule(Long id, boolean sysContext); + + Network createNetwork(CreateNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException; + List searchForNetworks(ListNetworksCmd cmd) throws InvalidParameterValueException, PermissionDeniedException; + boolean deleteNetwork(DeleteNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException; } diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 0b4f9e84b91..10ce22ad873 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -70,4 +70,10 @@ public interface NetworkOffering { TrafficType getTrafficType(); boolean getSpecifyVlan(); + + String getTags(); + + boolean isShared(); + + boolean isDefault(); } diff --git a/api/src/com/cloud/vm/Nic.java b/api/src/com/cloud/vm/Nic.java index 321a72a06ca..0576b553e6a 100644 --- a/api/src/com/cloud/vm/Nic.java +++ b/api/src/com/cloud/vm/Nic.java @@ -17,6 +17,8 @@ */ package com.cloud.vm; +import java.net.URI; + import com.cloud.network.Networks.Mode; import com.cloud.resource.Resource; @@ -48,4 +50,9 @@ public interface Nic extends Resource { int getDeviceId(); Mode getMode(); + + URI getIsolationUri(); + + URI getBroadcastUri(); + } diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 84b1f9af1cb..709d78b795b 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -230,3 +230,13 @@ listRemoteAccessVpns=com.cloud.api.commands.ListRemoteAccessVpnsCmd;15 addVpnUser=com.cloud.api.commands.AddVpnUserCmd;15 removeVpnUser=com.cloud.api.commands.RemoveVpnUserCmd;15 listVpnUsers=com.cloud.api.commands.ListVpnUsersCmd;15 + +#### network offering commands +createNetworkOffering=com.cloud.api.commands.CreateNetworkOfferingCmd;1 +deleteNetworkOffering=com.cloud.api.commands.DeleteNetworkOfferingCmd;1 +listNetworkOfferings=com.cloud.api.commands.ListNetworkOfferingsCmd;15 + +#### network commands +createNetwork=com.cloud.api.commands.CreateNetworkCmd;1 +deleteNetwork=com.cloud.api.commands.DeleteNetworkCmd;1 +listNetworks=com.cloud.api.commands.ListNetworksCmd;15 \ No newline at end of file diff --git a/core/src/com/cloud/agent/api/StartCommand.java b/core/src/com/cloud/agent/api/StartCommand.java index eb5c80e9765..ac99dfd88cf 100755 --- a/core/src/com/cloud/agent/api/StartCommand.java +++ b/core/src/com/cloud/agent/api/StartCommand.java @@ -18,7 +18,6 @@ package com.cloud.agent.api; import java.util.List; -import java.util.Map; import com.cloud.network.router.VirtualRouter; import com.cloud.offering.ServiceOffering; @@ -69,8 +68,6 @@ public class StartCommand extends AbstractStartCommand { guestMacAddress = vm.getGuestMacAddress(); vncPassword = vm.getVncPassword(); hostName = vm.getHostName(); -// networkRateMbps = offering.getRateMbps(); -// networkRateMulticastMbps = offering.getMulticastRateMbps(); networkRateMbps = networkRate; networkRateMulticastMbps = multicastRate; if (bits == 32) { diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index b2a2be27dd9..02a3f4a2a11 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -37,6 +37,8 @@ import com.cloud.network.security.NetworkGroup; import com.cloud.network.security.NetworkGroupManager; import com.cloud.network.security.dao.NetworkGroupDao; import com.cloud.offering.ServiceOffering; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.server.Criteria; import com.cloud.server.ManagementServer; import com.cloud.server.StatsCollector; @@ -125,6 +127,7 @@ public class ApiDBUtils { private static VlanDao _vlanDao; private static VolumeDao _volumeDao; private static DataCenterDao _zoneDao; + private static NetworkOfferingDao _networkOfferingDao; static { _ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); @@ -165,6 +168,7 @@ public class ApiDBUtils { _volumeDao = locator.getDao(VolumeDao.class); _zoneDao = locator.getDao(DataCenterDao.class); _networkGroupDao = locator.getDao(NetworkGroupDao.class); + _networkOfferingDao = locator.getDao(NetworkOfferingDao.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -487,4 +491,8 @@ public class ApiDBUtils { _asyncMgr.syncAsyncJobExecution((AsyncJobVO)job, syncObjType, syncObjId); } + public static NetworkOfferingVO findNetworkOfferingById(long networkOfferingId) { + return _networkOfferingDao.findByIdIncludingRemoved(networkOfferingId); + } + } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index c55d5642691..faf15d31f3f 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -68,22 +68,22 @@ public class ApiDispatcher { cmd.callCreate(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); }else if (t instanceof PermissionDeniedException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); }else if (t instanceof AccountLimitException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); }else if (t instanceof InsufficientCapacityException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); }else if (t instanceof ResourceAllocationException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); }else if (t instanceof ResourceUnavailableException) { - s_logger.warn(t); + s_logger.warn("Exception: ", t); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); }else if (t instanceof ServerApiException) { s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); @@ -91,7 +91,6 @@ public class ApiDispatcher { }else if (t instanceof AsyncCommandQueued) { throw (AsyncCommandQueued)t; }else { - s_logger.warn(t); s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); @@ -107,22 +106,22 @@ public class ApiDispatcher { cmd.execute(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); }else if (t instanceof PermissionDeniedException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); }else if (t instanceof AccountLimitException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); }else if (t instanceof InsufficientCapacityException) { - s_logger.info(t); + s_logger.info("Exception: ", t); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); }else if (t instanceof ResourceAllocationException) { - s_logger.warn(t); + s_logger.warn("Exception: ", t); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); }else if (t instanceof ResourceUnavailableException) { - s_logger.warn(t); + s_logger.warn("Exception: ", t); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); }else if (t instanceof ServerApiException) { s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); @@ -130,7 +129,6 @@ public class ApiDispatcher { } else if (t instanceof AsyncCommandQueued) { throw (AsyncCommandQueued)t; }else { - s_logger.warn(t); s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index f26f014dcf3..1b97fb5e6c9 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -52,6 +52,9 @@ import com.cloud.api.response.IpForwardingRuleResponse; import com.cloud.api.response.ListResponse; import com.cloud.api.response.LoadBalancerResponse; import com.cloud.api.response.NetworkGroupResponse; +import com.cloud.api.response.NetworkOfferingResponse; +import com.cloud.api.response.NetworkResponse; +import com.cloud.api.response.NicResponse; import com.cloud.api.response.PodResponse; import com.cloud.api.response.PreallocatedLunResponse; import com.cloud.api.response.RemoteAccessVpnResponse; @@ -96,7 +99,6 @@ import com.cloud.host.HostVO; import com.cloud.network.IpAddress; import com.cloud.network.LoadBalancer; import com.cloud.network.Network; -import com.cloud.network.Networks.TrafficType; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VpnUser; import com.cloud.network.router.VirtualRouter; @@ -105,6 +107,7 @@ import com.cloud.network.security.IngressRule; import com.cloud.network.security.NetworkGroup; import com.cloud.network.security.NetworkGroupRules; import com.cloud.offering.DiskOffering; +import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; @@ -756,6 +759,7 @@ public class ApiResponseHelper implements ResponseGenerator { vlanResponse.setGateway(vlan.getVlanGateway()); vlanResponse.setNetmask(vlan.getVlanNetmask()); vlanResponse.setDescription(vlan.getIpRange()); + vlanResponse.setNetworkId(vlan.getNetworkId()); vlanResponse.setObjectName("vlan"); return vlanResponse; @@ -1199,14 +1203,27 @@ public class ApiResponseHelper implements ResponseGenerator { userVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId())); List nics = ApiDBUtils.getNics(userVm); + List nicResponses = new ArrayList(); for (Nic singleNic : nics) { - Long configId = singleNic.getNetworkId(); - Network networkConf = ApiDBUtils.getNetwork(configId); - if (networkConf.getTrafficType() == TrafficType.Guest) { - userVmResponse.setIpAddress(singleNic.getIp4Address()); - } + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(singleNic.getId()); + nicResponse.setIpaddress(singleNic.getIp4Address()); + nicResponse.setGateway(singleNic.getGateway()); + nicResponse.setNetmask(singleNic.getNetmask()); + nicResponse.setNetworkid(singleNic.getNetworkId()); + if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) { + if (singleNic.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(singleNic.getBroadcastUri().toString()); + } + if (singleNic.getIsolationUri() != null) { + nicResponse.setIsolationUri(singleNic.getIsolationUri().toString()); + } + } + nicResponse.setObjectName("nic"); + + nicResponses.add(nicResponse); } - + userVmResponse.setNics(nicResponses); userVmResponse.setObjectName("virtualmachine"); return userVmResponse; } @@ -1236,35 +1253,31 @@ public class ApiResponseHelper implements ResponseGenerator { } List nics = ApiDBUtils.getNics(router); + List nicResponses = new ArrayList(); for (Nic singleNic : nics) { - Long configId = singleNic.getNetworkId(); - Network networkConf = ApiDBUtils.getNetwork(configId); - - if (networkConf.getTrafficType() == TrafficType.Guest) { - routerResponse.setGuestIpAddress(singleNic.getIp4Address()); - routerResponse.setGuestMacAddress(singleNic.getMacAddress()); - routerResponse.setGuestNetmask(singleNic.getNetmask()); + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(singleNic.getId()); + nicResponse.setIpaddress(singleNic.getIp4Address()); + nicResponse.setGateway(singleNic.getGateway()); + nicResponse.setNetmask(singleNic.getNetmask()); + nicResponse.setNetworkid(singleNic.getNetworkId()); + if (singleNic.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(singleNic.getBroadcastUri().toString()); } - - if (networkConf.getTrafficType() == TrafficType.Control) { - routerResponse.setPrivateIp(singleNic.getIp4Address()); - routerResponse.setPrivateMacAddress(singleNic.getMacAddress()); - routerResponse.setPrivateNetmask(singleNic.getNetmask()); - } - - if (networkConf.getTrafficType() == TrafficType.Public) { - routerResponse.setPublicIp(singleNic.getIp4Address()); - routerResponse.setPublicMacAddress(singleNic.getMacAddress()); - routerResponse.setPublicNetmask(singleNic.getNetmask()); - routerResponse.setGateway(singleNic.getGateway()); - } - - DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterId()); - if (zone != null) { - routerResponse.setZoneName(zone.getName()); - routerResponse.setDns1(zone.getDns1()); - routerResponse.setDns2(zone.getDns2()); + if (singleNic.getIsolationUri() != null) { + nicResponse.setIsolationUri(singleNic.getIsolationUri().toString()); } + + nicResponse.setObjectName("nic"); + nicResponses.add(nicResponse); + } + routerResponse.setNics(nicResponses); + + DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterId()); + if (zone != null) { + routerResponse.setZoneName(zone.getName()); + routerResponse.setDns1(zone.getDns1()); + routerResponse.setDns2(zone.getDns2()); } routerResponse.setObjectName("domainrouter"); @@ -1321,25 +1334,26 @@ public class ApiResponseHelper implements ResponseGenerator { } List nics = ApiDBUtils.getNics(systemVM); + List nicResponses = new ArrayList(); for (Nic singleNic : nics) { - Long configId = singleNic.getNetworkId(); - Network networkConf = ApiDBUtils.getNetwork(configId); - - if (networkConf.getTrafficType() == TrafficType.Management) { - vmResponse.setPrivateIp(singleNic.getIp4Address()); - vmResponse.setPrivateMacAddress(singleNic.getMacAddress()); - vmResponse.setPrivateNetmask(singleNic.getNetmask()); + NicResponse nicResponse = new NicResponse(); + nicResponse.setId(singleNic.getId()); + nicResponse.setIpaddress(singleNic.getIp4Address()); + nicResponse.setGateway(singleNic.getGateway()); + nicResponse.setNetmask(singleNic.getNetmask()); + nicResponse.setNetworkid(singleNic.getNetworkId()); + if (singleNic.getBroadcastUri() != null) { + nicResponse.setBroadcastUri(singleNic.getBroadcastUri().toString()); } - - if (networkConf.getTrafficType() == TrafficType.Public) { - vmResponse.setPublicIp(singleNic.getIp4Address()); - vmResponse.setPublicMacAddress(singleNic.getMacAddress()); - vmResponse.setPublicNetmask(singleNic.getNetmask()); - vmResponse.setGateway(singleNic.getGateway()); + if (singleNic.getIsolationUri() != null) { + nicResponse.setIsolationUri(singleNic.getIsolationUri().toString()); } + + nicResponse.setObjectName("nic"); + nicResponses.add(nicResponse); } + vmResponse.setNics(nicResponses); } - vmResponse.setObjectName("systemvm"); return vmResponse; } @@ -2159,7 +2173,7 @@ public class ApiResponseHelper implements ResponseGenerator { capacityResponse.setZoneId(summedCapacity.getDataCenterId()); capacityResponse.setZoneName(ApiDBUtils.findZoneById(summedCapacity.getDataCenterId()).getName()); if (summedCapacity.getTotalCapacity() != 0) { - float computed = ((float)summedCapacity.getUsedCapacity() / (float)summedCapacity.getTotalCapacity() * 100f); + //float computed = ((float)summedCapacity.getUsedCapacity() / (float)summedCapacity.getTotalCapacity() * 100f); capacityResponse.setPercentUsed(format.format((float)summedCapacity.getUsedCapacity() / (float)summedCapacity.getTotalCapacity() * 100f)); } else { capacityResponse.setPercentUsed(format.format(0L)); @@ -2264,4 +2278,68 @@ public class ApiResponseHelper implements ResponseGenerator { } return response; } + + @Override + public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) { + NetworkOfferingResponse response = new NetworkOfferingResponse(); + response.setId(offering.getId()); + response.setName(offering.getName()); + response.setDisplayText(offering.getDisplayText()); + response.setTags(offering.getTags()); + response.setTrafficType(offering.getTrafficType().toString()); + if (offering.getGuestIpType() != null) { + response.setType(offering.getGuestIpType().toString()); + } + response.setMaxconnections(offering.getConcurrentConnections()); + response.setIsDefault(offering.isDefault()); + response.setSpecifyVlan(offering.getSpecifyVlan()); + response.setIsShared(offering.isShared()); + response.setObjectName("networkoffering"); + return response; + } + + @Override + public NetworkResponse createNetworkResponse(Network network) { + NetworkResponse response = new NetworkResponse(); + response.setId(network.getId()); + response.setName(network.getName()); + response.setDisplaytext(network.getDisplayText()); + if (network.getBroadcastDomainType() != null) { + response.setBroadcastDomainType(network.getBroadcastDomainType().toString()); + } + if (network.getBroadcastUri() != null) { + response.setBroadcastUri(network.getBroadcastUri().toString()); + } + + if (response.getTrafficType() != null) { + response.setTrafficType(network.getTrafficType().toString()); + } + + if (response.getType() != null) { + response.setType(network.getGuestType().toString()); + } + response.setGateway(network.getGateway()); + response.setCidr(network.getCidr()); + response.setZoneId(network.getDataCenterId()); + + //populate network offering information + NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId()); + if (networkOffering != null) { + response.setNetworkOfferingId(networkOffering.getId()); + response.setNetworkOfferingName(networkOffering.getName()); + response.setNetworkOfferingDisplayText(networkOffering.getDisplayText()); + } + response.setState(network.getState().toString()); + response.setRelated(network.getRelated()); + response.setDns1(network.getDns1()); + response.setDns2(network.getDns2()); + + Account account = ApiDBUtils.findAccountById(network.getAccountId()); + if (account != null) { + response.setAccountName(account.getAccountName()); + response.setDomainId(account.getDomainId()); + } + response.setObjectName("network"); + return response; + } } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 0b14e777626..7c635d030a1 100644 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -198,7 +198,8 @@ public enum Config { SSOKey("Hidden", ManagementServer.class, String.class, "security.singlesignon.key", null, "A Single Sign-On key used for logging into the cloud", null), SSOAuthTolerance("Advanced", ManagementServer.class, Long.class, "security.singlesignon.tolerance.millis", "300000", "The allowable clock difference in milliseconds between when an SSO login request is made and when it is received.", null), NetworkType("Hidden", ManagementServer.class, String.class, "network.type", "vlan", "The type of network that this deployment will use.", "vlan,direct"), - HashKey("Hidden", ManagementServer.class, String.class, "security.hash.key", null, "for generic key-ed hash", null); + HashKey("Hidden", ManagementServer.class, String.class, "security.hash.key", null, "for generic key-ed hash", null), + UseNewNetwork("Hidden", NetworkManager.class, Boolean.class, "use.new.networking", "false", null, null); private final String _category; private final Class _componentClass; diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index f05e478226a..7af2974a5fc 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -19,15 +19,22 @@ package com.cloud.configuration; import java.util.List; +import com.cloud.api.commands.CreateVlanIpRangeCmd; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.DataCenterNetworkType; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Vlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.offering.DiskOffering; import com.cloud.offering.ServiceOffering; +import com.cloud.network.Networks.TrafficType; +import com.cloud.offering.NetworkOffering.GuestIpType; +import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.user.Account; @@ -63,8 +70,6 @@ public interface ConfigurationManager extends Manager { */ ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, Long domainId); - - /** * Creates a new disk offering * @param domainId @@ -161,4 +166,22 @@ public interface ConfigurationManager extends Manager { void checkDiskOfferingAccess(Account caller, DiskOffering dof) throws PermissionDeniedException; + + + /** + * Creates a new network offering + * @param id + * @param name + * @param displayText + * @param type + * @param trafficType + * @param tags + * @param maxConnections + * @param specifyVlan; + * @return network offering object + */ + NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared); + + Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; + } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 20f418602df..22547a2b5a5 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -34,15 +34,18 @@ import com.cloud.api.BaseCmd; import com.cloud.api.ServerApiException; import com.cloud.api.commands.CreateCfgCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; +import com.cloud.api.commands.CreateNetworkOfferingCmd; import com.cloud.api.commands.CreatePodCmd; import com.cloud.api.commands.CreateServiceOfferingCmd; import com.cloud.api.commands.CreateVlanIpRangeCmd; import com.cloud.api.commands.CreateZoneCmd; import com.cloud.api.commands.DeleteDiskOfferingCmd; +import com.cloud.api.commands.DeleteNetworkOfferingCmd; import com.cloud.api.commands.DeletePodCmd; import com.cloud.api.commands.DeleteServiceOfferingCmd; import com.cloud.api.commands.DeleteVlanIpRangeCmd; import com.cloud.api.commands.DeleteZoneCmd; +import com.cloud.api.commands.ListNetworkOfferingsCmd; import com.cloud.api.commands.UpdateCfgCmd; import com.cloud.api.commands.UpdateDiskOfferingCmd; import com.cloud.api.commands.UpdatePodCmd; @@ -81,11 +84,14 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkManager; +import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; @@ -103,6 +109,8 @@ import com.cloud.utils.component.Adapters; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; @@ -131,6 +139,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Inject DomainDao _domainDao; @Inject ServiceOfferingDao _serviceOfferingDao; @Inject DiskOfferingDao _diskOfferingDao; + @Inject NetworkOfferingDao _networkOfferingDao; @Inject VlanDao _vlanDao; @Inject IPAddressDao _publicIpAddressDao; @Inject DataCenterIpAddressDao _privateIpAddressDao; @@ -1053,7 +1062,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String internalDns2 = cmd.getInternalDns2(); String vnetRange = cmd.getVlan(); String guestCidr = cmd.getGuestCidrAddress(); - String domain = cmd.getDomain();//we are not passing domain right now, always null Long domainId = cmd.getDomainId(); String type = cmd.getNetworkType(); Boolean isBasic = false; @@ -1412,9 +1420,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return genChangeRangeSuccessString(problemIPs, add); } } - + @Override - public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException { + public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException { Long zoneId = cmd.getZoneId(); Long podId = cmd.getPodId(); String startIP = cmd.getStartIp(); @@ -1422,12 +1430,25 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String vlanGateway = cmd.getGateway(); String vlanNetmask = cmd.getNetmask(); Long userId = UserContext.current().getUserId(); - - if (userId == null) { - userId = Long.valueOf(User.UID_SYSTEM); + String vlanId = cmd.getVlan(); + // If an account name and domain ID are specified, look up the account + String accountName = cmd.getAccountName(); + Long domainId = cmd.getDomainId(); + Account account = null; + if ((accountName != null) && (domainId != null)) { + account = _accountDao.findActiveAccount(accountName, domainId); + if (account == null) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid account."); + } } + return createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, vlanGateway, vlanNetmask, true, vlanId, account, null); + } + + + @Override + public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException{ - // Check that the pod ID is valid + // Check that the pod ID is valid if (podId != null && ((_podDao.findById(podId)) == null)) { throw new InvalidParameterValueException("Please specify a valid pod."); } @@ -1436,15 +1457,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (podId != null && _podDao.findById(podId).getDataCenterId() != zoneId) { throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId); } - - // If forVirtualNetworks isn't specified, default it to true - Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); - if (forVirtualNetwork == null) { - forVirtualNetwork = Boolean.TRUE; - } - // If the VLAN id is null, default it to untagged - String vlanId = cmd.getVlan(); if (vlanId == null) { vlanId = Vlan.UNTAGGED; } @@ -1466,17 +1479,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Can't add virtual network to the zone id=" + zone.getId() + " as zone doesn't have guest vlan configured"); } - // If an account name and domain ID are specified, look up the account - String accountName = cmd.getAccountName(); - Long domainId = cmd.getDomainId(); - Account account = null; - if ((accountName != null) && (domainId != null)) { - account = _accountDao.findActiveAccount(accountName, domainId); - if (account == null) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid account."); - } - } - VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; @@ -1643,7 +1645,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (endIP != null) { ipRange += "-" + endIP; } - VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange); + VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId); vlan = _vlanDao.persist(vlan); // Persist the IP range @@ -1685,7 +1687,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura // if this is an account VLAN, now associate the IP Addresses to the account associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId()); } - return vlan; } @@ -2378,4 +2379,155 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura assert false : "How can all of the security checkers pass on checking this caller?"; throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to zone:" + zone.getId()); } + + + + @Override + public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) throws InvalidParameterValueException { + Long userId = UserContext.current().getUserId(); + String name = cmd.getNetworkOfferingName(); + String displayText = cmd.getDisplayText(); + String tags = cmd.getTags(); + String typeString = cmd.getType(); + String trafficTypeString = cmd.getTraffictype(); + Boolean specifyVlan = cmd.getSpecifyVlan(); + Boolean isShared = cmd.getIsShared(); + TrafficType trafficType = null; + GuestIpType type = null; + + //Verify traffic type + for (TrafficType tType : TrafficType.values()) { + if (tType.name().equalsIgnoreCase(trafficTypeString)) { + trafficType = tType; + } + } + if (trafficType == null) { + throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage"); + } + + //Verify type + for (GuestIpType gType : GuestIpType.values()) { + if (gType.name().equalsIgnoreCase(typeString)) { + type = gType; + } + } + if (type == null) { + throw new InvalidParameterValueException("Invalid value for type. Supported types: Virtualized, DirectSingle, DirectDual"); + } + + if (specifyVlan == null) { + specifyVlan = false; + } + + if (isShared == null) { + isShared = false; + } + + Integer maxConnections = cmd.getMaxconnections(); + return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan, isShared); + } + + @Override + public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared) { + String networkRateStr = _configDao.getValue("network.throttling.rate"); + String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); + int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); + int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); + tags = cleanupTags(tags); + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, type, false, specifyVlan, networkRate, multicastRate, maxConnections, isShared, false); + + if ((offering = _networkOfferingDao.persist(offering)) != null) { + saveConfigurationEvent(userId, null, EventTypes.EVENT_NETWORK_OFFERING_CREATE, "Successfully created new network offering with name: " + name + ".", "noId=" + offering.getId(), "name=" + name, + "displayText=" + displayText, "tags=" + tags); + return offering; + } else { + return null; + } + } + + @Override + public List searchForNetworkOfferings(ListNetworkOfferingsCmd cmd) { + Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _networkOfferingDao.createSearchCriteria(); + + Object id = cmd.getId(); + Object name = cmd.getNetworkOfferingName(); + Object displayText = cmd.getDisplayText(); + Object type = cmd.getType(); + Object trafficType = cmd.getTrafficType(); + Object isDefault = cmd.getIsDefault(); + Object specifyVlan = cmd.getSpecifyVlan(); + Object isShared = cmd.getIsShared(); + + Object keyword = cmd.getKeyword(); + + if (keyword != null) { + SearchCriteria ssc = _networkOfferingDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + if (displayText != null) { + sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); + } + if (type != null) { + sc.addAnd("guestIpType", SearchCriteria.Op.EQ, type); + } + + if (trafficType != null) { + sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType); + } + + if (isDefault != null) { + sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); + } + + if (specifyVlan != null) { + sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan); + } + + if (isShared != null) { + sc.addAnd("isShared", SearchCriteria.Op.EQ, isShared); + } + + //Don't return system network offerings to the user + sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false); + + return _networkOfferingDao.search(sc, searchFilter); + } + + @Override + public boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd) throws InvalidParameterValueException{ + Long offeringId = cmd.getId(); + Long userId = UserContext.current().getUserId(); + + //Verify network offering id + NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId); + if (offering == null) { + throw new InvalidParameterValueException("unable to find network offering " + offeringId); + } else if (offering.getRemoved() != null || offering.isSystemOnly()) { + throw new InvalidParameterValueException("unable to find network offering " + offeringId); + } + + //Don't allow to delete default network offerings + if (offering.isDefault() == true) { + throw new InvalidParameterValueException("Default network offering can't be deleted"); + } + + if (_networkOfferingDao.remove(offeringId)) { + saveConfigurationEvent(userId, null, EventTypes.EVENT_NETWORK_OFFERING_DELETE, "Successfully deleted network offering with name: " + offering.getName(), "noId=" + offeringId, "name=" + offering.getName(), + "displayText=" + offering.getDisplayText()); + return true; + } else { + return false; + } + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index a36fba7a863..6e299080619 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1071,9 +1071,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null)); } ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); try { diff --git a/server/src/com/cloud/dc/VlanVO.java b/server/src/com/cloud/dc/VlanVO.java index 1cb991b5f92..29e94e50fad 100644 --- a/server/src/com/cloud/dc/VlanVO.java +++ b/server/src/com/cloud/dc/VlanVO.java @@ -51,17 +51,21 @@ public class VlanVO implements Vlan { @Column(name="description") String ipRange; + @Column(name="network_id") + Long networkId; + @Column(name="vlan_type") @Enumerated(EnumType.STRING) VlanType vlanType; - public VlanVO(VlanType vlanType, String vlanTag, String vlanGateway, String vlanNetmask, long dataCenterId, String ipRange) { + public VlanVO(VlanType vlanType, String vlanTag, String vlanGateway, String vlanNetmask, long dataCenterId, String ipRange, Long networkId) { this.vlanType = vlanType; this.vlanId = vlanTag; this.vlanGateway = vlanGateway; this.vlanNetmask = vlanNetmask; this.dataCenterId = dataCenterId; this.ipRange = ipRange; + this.networkId = networkId; } public VlanVO() { @@ -107,4 +111,8 @@ public class VlanVO implements Vlan { public VlanType getVlanType() { return vlanType; } + + public Long getNetworkId() { + return networkId; + } } diff --git a/server/src/com/cloud/dc/dao/VlanDao.java b/server/src/com/cloud/dc/dao/VlanDao.java index cef49bc268f..047cfc263c7 100644 --- a/server/src/com/cloud/dc/dao/VlanDao.java +++ b/server/src/com/cloud/dc/dao/VlanDao.java @@ -51,4 +51,6 @@ public interface VlanDao extends GenericDao { List listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId); List searchForZoneWideVlans(long dcId, String vlanType,String vlanId); + + List listVlansByNetworkId(long networkId); } diff --git a/server/src/com/cloud/dc/dao/VlanDaoImpl.java b/server/src/com/cloud/dc/dao/VlanDaoImpl.java index f98a4dc644b..d3ff641396a 100644 --- a/server/src/com/cloud/dc/dao/VlanDaoImpl.java +++ b/server/src/com/cloud/dc/dao/VlanDaoImpl.java @@ -55,6 +55,7 @@ public class VlanDaoImpl extends GenericDaoBase implements VlanDao protected SearchBuilder ZoneTypeAllPodsSearch; protected SearchBuilder ZoneTypePodSearch; protected SearchBuilder ZoneVlanSearch; + protected SearchBuilder NetworkVlanSearch; protected PodVlanMapDaoImpl _podVlanMapDao = new PodVlanMapDaoImpl(); protected AccountVlanMapDao _accountVlanMapDao = new AccountVlanMapDaoImpl(); @@ -90,6 +91,9 @@ public class VlanDaoImpl extends GenericDaoBase implements VlanDao ZoneTypeSearch.and("vlanType", ZoneTypeSearch.entity().getVlanType(), SearchCriteria.Op.EQ); ZoneTypeSearch.done(); + NetworkVlanSearch = createSearchBuilder(); + NetworkVlanSearch.and("networkOfferingId", NetworkVlanSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + NetworkVlanSearch.done(); } @Override @@ -299,7 +303,13 @@ public class VlanDaoImpl extends GenericDaoBase implements VlanDao } catch (SQLException e) { throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); } - } + @Override + public List listVlansByNetworkId(long networkOfferingId) { + SearchCriteria sc = NetworkVlanSearch.create(); + sc.setParameters("networkOfferingId", networkOfferingId); + return listBy(sc); + } + } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 34771685b92..06ec7fd910a 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -220,8 +220,8 @@ public interface NetworkManager extends NetworkService { */ List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat); - List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan); - List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan); + List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText); + List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText); List getSystemAccountNetworkOfferings(String... offeringNames); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e43409e8f4b..a805d08baaa 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -50,11 +50,14 @@ import com.cloud.api.commands.AddVpnUserCmd; import com.cloud.api.commands.AssignToLoadBalancerRuleCmd; import com.cloud.api.commands.AssociateIPAddrCmd; import com.cloud.api.commands.CreateLoadBalancerRuleCmd; +import com.cloud.api.commands.CreateNetworkCmd; import com.cloud.api.commands.CreatePortForwardingRuleCmd; import com.cloud.api.commands.CreateRemoteAccessVpnCmd; import com.cloud.api.commands.DeleteLoadBalancerRuleCmd; +import com.cloud.api.commands.DeleteNetworkCmd; import com.cloud.api.commands.DeleteRemoteAccessVpnCmd; import com.cloud.api.commands.DisassociateIPAddrCmd; +import com.cloud.api.commands.ListNetworksCmd; import com.cloud.api.commands.ListPortForwardingRulesCmd; import com.cloud.api.commands.RemoveFromLoadBalancerRuleCmd; import com.cloud.api.commands.RemoveVpnUserCmd; @@ -69,12 +72,14 @@ import com.cloud.configuration.dao.ResourceLimitDao; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; +import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.domain.dao.DomainDao; @@ -97,6 +102,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.TrafficType; import com.cloud.network.configuration.NetworkGuru; import com.cloud.network.dao.FirewallRulesDao; @@ -143,6 +149,7 @@ import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; @@ -206,7 +213,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; @Inject NetworkDao _networkConfigDao = null; - @Inject NicDao _nicDao; + @Inject NicDao _nicDao = null; @Inject GuestOSDao _guestOSDao = null; @Inject RemoteAccessVpnDao _remoteAccessVpnDao = null; @Inject VpnUserDao _vpnUsersDao = null; @@ -1720,9 +1727,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemVmStorageNetwork, storageNetworkOffering); - NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null); + NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null, false, true); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering); - NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null); + NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null, false, true); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); AccountsUsingNetworkConfigurationSearch = _accountDao.createSearchBuilder(); @@ -1802,12 +1809,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan) { - return setupNetworkConfiguration(owner, offering, null, plan); + public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText) { + return setupNetworkConfiguration(owner, offering, null, plan, name, displayText); } @Override - public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan) { + public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText) { List configs = _networkConfigDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { if (s_logger.isDebugEnabled()) { @@ -1840,7 +1847,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag related = id; } - NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related); + NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText); configs.add(_networkConfigDao.persist(vo)); } @@ -1881,12 +1888,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkVO config = network.first(); NetworkGuru concierge = _networkGurus.get(config.getGuruName()); NicProfile requested = network.second(); + if (requested != null && requested.getMode() == null) { + requested.setMode(config.getMode()); + } NicProfile profile = concierge.allocate(config, requested, vm); if (profile == null) { continue; } NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId()); - vo.setMode(network.first().getMode()); while (deviceIds[deviceId] && deviceId < deviceIds.length) { deviceId++; @@ -1931,12 +1940,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else if (deviceId != null ) { vo.setDeviceId(deviceId++); } + + vo.setReservationStrategy(profile.getReservationStrategy()); vo.setDefaultNic(profile.isDefaultNic()); if (profile.getIp4Address() != null) { vo.setIp4Address(profile.getIp4Address()); vo.setState(NicVO.State.Reserved); + vo.setAddressFormat(AddressFormat.Ip4); } if (profile.getMacAddress() != null) { @@ -2079,6 +2091,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } element.prepare(config, profile, vmProfile, dest, context); } + } else { + profile = new NicProfile(nic, config, nic.getBroadcastUri(), nic.getIsolationUri()); } vmProfile.addNic(profile); @@ -2670,7 +2684,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public List setupNetworkConfiguration(Account owner, ServiceOfferingVO offering, DeploymentPlan plan) { NetworkOfferingVO networkOffering = _networkOfferingDao.findByServiceOffering(offering); - return setupNetworkConfiguration(owner, networkOffering, plan); + return setupNetworkConfiguration(owner, networkOffering, plan, null, null); } private String [] getGuestIpRange() { @@ -3289,4 +3303,234 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return true; } } + + @Override @DB + public Network createNetwork(CreateNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{ + Account ctxAccount = UserContext.current().getAccount(); + Long userId = UserContext.current().getUserId(); + Long networkOfferingId = cmd.getNetworkOfferingId(); + Long zoneId = cmd.getZoneId(); + Long podId = cmd.getPodId(); + String gateway = cmd.getGateway(); + String cidr = cmd.getCidr(); + String startIP = cmd.getStartIp(); + String endIP = cmd.getEndIp(); + String vlanNetmask = cmd.getNetmask(); + String accountName = cmd.getAccountName(); + Long domainId = cmd.getDomainId(); + String vlanId = cmd.getVlan(); + String name = cmd.getNetworkName(); + String displayText = cmd.getDisplayText(); + Account owner = null; + + //Check if network offering exists + NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); + if (networkOffering == null || networkOffering.isSystemOnly()) { + throw new InvalidParameterValueException("Unable to find network offeirng by id " + networkOfferingId); + } + + //Check if zone exists + if (zoneId == null || ((_dcDao.findById(zoneId)) == null)) { + throw new InvalidParameterValueException("Please specify a valid zone."); + } + + //Check permissions + if (isAdmin(ctxAccount.getType())) { + if (domainId != null) { + if ((ctxAccount != null) && !_domainDao.isChildDomain(ctxAccount.getDomainId(), domainId)) { + throw new PermissionDeniedException("Failed to create a newtwork, invalid domain id (" + domainId + ") given."); + } + if (accountName != null) { + owner = _accountDao.findActiveAccount(accountName, domainId); + if (owner == null) { + throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + } + } + } else { + owner = ctxAccount; + } + } else { + owner = ctxAccount; + } + + if (owner.getId() == Account.ACCOUNT_ID_SYSTEM && !networkOffering.isShared()) { + throw new InvalidParameterValueException("Non-system account is required when create a network from Dedicated network offering with id=" + networkOfferingId); + } + + //VlanId can be specified only when network offering supports it + if (vlanId != null && !networkOffering.getSpecifyVlan()) { + throw new InvalidParameterValueException("Can't specify vlan because network offering doesn't support it"); + } + + //If gateway, startIp, endIp are speicified, cidr should be present as well + if (gateway != null && startIP != null && endIP != null && cidr == null) { + throw new InvalidParameterValueException("Cidr is missing"); + } + + Transaction txn = Transaction.currentTxn(); + txn.start(); + try { + //Create network + DataCenterDeployment plan = new DataCenterDeployment(zoneId, null, null, null); + NetworkVO userNetwork = new NetworkVO(); + + //cidr should be set only when the user is admin + if (ctxAccount.getType() == Account.ACCOUNT_TYPE_ADMIN && cidr != null && gateway != null) { + userNetwork.setCidr(cidr); + userNetwork.setGateway(gateway); + if (vlanId != null) { + userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId)); + } + } + + List networks = setupNetworkConfiguration(owner, networkOffering, userNetwork, plan, name, displayText); + Long networkId = null; + + if (networks == null || networks.isEmpty()) { + txn.rollback(); + throw new CloudRuntimeException("Fail to create a network"); + } else { + networkId = networks.get(0).getId(); + } + + //If network offering is shared, don't pass owner account and networkOfferingId for vlan + if (networkOffering.isShared()) { + owner = null; + } + + if (ctxAccount.getType() == Account.ACCOUNT_TYPE_ADMIN && networkOffering.getGuestIpType() != GuestIpType.Virtualized && startIP != null && endIP != null && gateway != null) { + //Create vlan ip range + Vlan vlan = _configMgr.createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, gateway, vlanNetmask, false, vlanId, owner, networkId); + if (vlan == null) { + txn.rollback(); + throw new CloudRuntimeException("Fail to create a vlan"); + } + } + txn.commit(); + return networks.get(0); + } catch (Exception ex) { + s_logger.warn("Unexpected exception while creating network ", ex); + txn.rollback(); + }finally { + txn.close(); + } + return null; + } + + @Override + public List searchForNetworks(ListNetworksCmd cmd) { + Object id = cmd.getId(); + Object keyword = cmd.getKeyword(); + Account account = UserContext.current().getAccount(); + Long domainId = cmd.getDomainId(); + String accountName = cmd.getAccountName(); + Long accountId = null; + if (isAdmin(account.getType())) { + if (domainId != null) { + if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) { + throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list networks"); + } + + if (accountName != null) { + account = _accountDao.findActiveAccount(accountName, domainId); + if (account == null) { + throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + } + accountId = account.getId(); + } + } + } else { + accountId = account.getId(); + } + + + Filter searchFilter = new Filter(NetworkVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _networkConfigDao.createSearchCriteria(); + + if (keyword != null) { + SearchCriteria ssc = _networkConfigDao.createSearchCriteria(); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (accountId != null) { + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + } + return _networkConfigDao.search(sc, searchFilter); + } + + @Override @DB + public boolean deleteNetwork(DeleteNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{ + Long networkId = cmd.getId(); + Long userId = UserContext.current().getUserId(); + Account account = UserContext.current().getAccount(); + + //Verify network id + NetworkVO network = _networkConfigDao.findById(networkId); + if (network == null) { + throw new InvalidParameterValueException("unable to find network " + networkId); + } + + //Perform permission check + if (account != null) { + if (!isAdmin(account.getType())) { + if (network.getAccountId() != account.getId()) { + throw new PermissionDeniedException("Account " + account.getAccountName() + " does not own network id=" + networkId + ", permission denied"); + } + } else if (!(account.getType() == Account.ACCOUNT_TYPE_ADMIN) && !_domainDao.isChildDomain(account.getDomainId(), _accountDao.findById(network.getAccountId()).getId())) { + throw new PermissionDeniedException("Unable to delete network " + networkId + ", permission denied."); + } + } + + //Don't allow to remove network if there are non-destroyed vms using it + List nics = _nicDao.listByNetworkId(networkId); + for (NicVO nic : nics) { + UserVm vm = _vmDao.findById(nic.getId()); + if (vm.getState() != State.Destroyed || vm.getState() != State.Expunging || vm.getState() != State.Error) { + throw new CloudRuntimeException("Can't delete a network; make sure that all vms using the network are destroyed"); + } + } + + //for regular user don't allow to remove network when it's in any other states but allocated + if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) { + if (network.getState() != Network.State.Allocated) { + throw new InvalidParameterValueException("Non-admin user can delete network in " + Network.State.Allocated + " state only."); + } + } else { + if (!(network.getState() == Network.State.Allocated || network.getState() == Network.State.Setup)) { + throw new InvalidParameterValueException("Can delete network in " + Network.State.Allocated + " and " + Network.State.Setup + " states only."); + } + } + + //remove all the vlans associated with the network + Transaction txn = Transaction.currentTxn(); + try { + //remove corresponding vlans + List vlans = _vlanDao.listVlansByNetworkId(networkId); + for (VlanVO vlan : vlans) { + boolean result = _configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId()); + if (result == false) { + txn.rollback(); + throw new CloudRuntimeException("Unable to delete a network: failed to delete corresponding vlan with id " + vlan.getId()); + } + } + + //remove networks + _networkConfigDao.remove(networkId); + + txn.commit(); + return true; + } catch (Exception ex) { + txn.rollback(); + s_logger.warn("Unexpected exception during deleting a network ", ex); + return false; + } finally { + txn.close(); + } + + } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 8f5f838eee6..d99d06369e4 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -62,6 +62,12 @@ public class NetworkVO implements Network { @Column(name="guest_type") GuestIpType guestType; + @Column(name="name") + String name; + + @Column(name="display_text") + String displayText;; + @Column(name="broadcast_uri") URI broadcastUri; @@ -131,12 +137,13 @@ public class NetworkVO implements Network { this.guestType = guestType; } - public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related) { - this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related); + public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText) { + this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText); this.gateway = that.getGateway(); this.dns1 = that.getDns1(); this.dns2 = that.getDns2(); this.cidr = that.getCidr(); + this.broadcastUri = that.getBroadcastUri(); this.guruName = guruName; this.state = that.getState(); if (state == null) { @@ -153,13 +160,17 @@ public class NetworkVO implements Network { * @param dataCenterId * @param domainId * @param accountId + * @param name + * @param displayText */ - public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related) { + public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText) { this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId); this.domainId = domainId; this.accountId = accountId; this.related = related; this.id = id; + this.name = name; + this.displayText = displayText; } @Override @@ -299,8 +310,24 @@ public class NetworkVO implements Network { this.dns2 = dns; } + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } - + @Override + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + @Override public boolean equals(Object obj) { if (!(obj instanceof NetworkVO)) { diff --git a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java index 96311314f45..e134aca6033 100644 --- a/server/src/com/cloud/network/configuration/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/GuestNetworkGuru.java @@ -101,10 +101,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { String[] cidrTuple = guestNetworkCidr.split("\\/"); config.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]))); config.setCidr(guestNetworkCidr); - config.setDns1(dc.getDns1()); - config.setDns2(dc.getDns2()); } + config.setDns1(dc.getDns1()); + config.setDns2(dc.getDns2()); + if (userSpecified.getBroadcastUri() != null) { config.setBroadcastUri(userSpecified.getBroadcastUri()); config.setState(State.Setup); diff --git a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java index 45cae3ec1f2..6a3c903513a 100644 --- a/server/src/com/cloud/network/configuration/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/configuration/PublicNetworkGuru.java @@ -16,14 +16,14 @@ import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.network.Network; +import com.cloud.network.NetworkManager; +import com.cloud.network.NetworkVO; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import com.cloud.network.Network; -import com.cloud.network.NetworkVO; -import com.cloud.network.NetworkManager; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.NetworkOffering; import com.cloud.resource.Resource.ReservationStrategy; @@ -87,8 +87,6 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { if (nic == null) { nic = new NicProfile(ReservationStrategy.Create, null, null, null, null); - } else { - nic.setStrategy(ReservationStrategy.Create); } String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); @@ -97,6 +95,12 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { DataCenter dc = _dcDao.findById(config.getDataCenterId()); getIp(nic, dc, vm); + if (nic.getIp4Address() == null) { + nic.setStrategy(ReservationStrategy.Start); + } else { + nic.setStrategy(ReservationStrategy.Create); + } + return nic; } @@ -104,7 +108,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { public void reserve(NicProfile nic, Network configuration, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (nic.getIp4Address() == null) { getIp(nic, dest.getDataCenter(), vm); - } + } } @Override diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index aa6a90c51f1..1206f070a56 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -2047,7 +2047,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute if (s_logger.isDebugEnabled()) { s_logger.debug("Starting a router for network configurations: virtual=" + guestConfig + " in " + dest); } - assert guestConfig.getState() == Network.State.Implemented : "Network is not yet fully implemented: " + guestConfig; + assert guestConfig.getState() == Network.State.Implemented || guestConfig.getState() == Network.State.Setup : "Network is not yet fully implemented: " + guestConfig; assert guestConfig.getTrafficType() == TrafficType.Guest; DataCenterDeployment plan = new DataCenterDeployment(dcId); @@ -2068,11 +2068,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan).get(0); + NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan, null, null).get(0); List> networks = new ArrayList>(3); NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork).get(0); - List publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan); + List publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan, null, null); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); //defaultNic.setIp4Address(sourceNatIp); diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index b7fa1c8002a..f758a66d658 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -81,6 +81,12 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name="tags") String tags; + @Column(name="shared") + boolean isShared; + + @Column(name="default") + boolean isDefault; + @Column(name=GenericDao.REMOVED_COLUMN) Date removed; @@ -134,14 +140,6 @@ public class NetworkOfferingVO implements NetworkOffering { return removed; } - public Long getServiceOfferingId() { - return serviceOfferingId; - } - - public void setServiceOfferingId(long serviceOfferingId) { - this.serviceOfferingId = serviceOfferingId; - } - @Override public Integer getConcurrentConnections() { return concurrentConnections; @@ -190,14 +188,33 @@ public class NetworkOfferingVO implements NetworkOffering { this.systemOnly = systemOnly; } - public void setServiceOfferingId(Long serviceOfferingId) { - this.serviceOfferingId = serviceOfferingId; - } public void setRemoved(Date removed) { this.removed = removed; } + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + public void setServiceOfferingId(long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + @Override + public boolean isShared() { + return isShared; + } + + public void setShared(boolean isShared) { + this.isShared = isShared; + } + + @Override + public boolean isDefault() { + return isDefault; + } + @Override public boolean getSpecifyVlan() { return specifyVlan; @@ -207,7 +224,7 @@ public class NetworkOfferingVO implements NetworkOffering { this.created = created; } - public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections) { + public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isShared, boolean isDefault) { this.name = name; this.displayText = displayText; this.guestIpType = type; @@ -217,13 +234,16 @@ public class NetworkOfferingVO implements NetworkOffering { this.trafficType = trafficType; this.systemOnly = systemOnly; this.specifyVlan = specifyVlan; + this.isDefault = isDefault; + this.isShared = isShared; } public NetworkOfferingVO(ServiceOfferingVO offering) { - this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null); + this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false, false); this.serviceOfferingId = offering.getId(); } + /** * Network Offering for all system vms. * @param name @@ -231,7 +251,7 @@ public class NetworkOfferingVO implements NetworkOffering { * @param type */ public NetworkOfferingVO(String name, TrafficType trafficType, GuestIpType type) { - this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null); + this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null, false, false); } @Override diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index bd544fc3f05..b93bf3c15dd 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -741,9 +741,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan).get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan).get(0), null)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null)); } SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId()); diff --git a/server/src/com/cloud/vm/NicVO.java b/server/src/com/cloud/vm/NicVO.java index 3e0e1481fff..3b45bd4c92c 100644 --- a/server/src/com/cloud/vm/NicVO.java +++ b/server/src/com/cloud/vm/NicVO.java @@ -95,6 +95,10 @@ public class NicVO implements Nic { @Column(name="default_nic") boolean defaultNic; + + @Column(name="strategy") + @Enumerated(value=EnumType.STRING) + ReservationStrategy strategy; public NicVO(String reserver, long instanceId, long configurationId) { this.reserver = reserver; @@ -230,6 +234,11 @@ public class NicVO implements Nic { this.reservationId = id; } + + public void setReservationStrategy(ReservationStrategy strategy) { + this.strategy = strategy; + } + public void setDeviceId(int deviceId) { this.deviceId = deviceId; } @@ -254,7 +263,7 @@ public class NicVO implements Nic { @Override public ReservationStrategy getReservationStrategy() { - return ReservationStrategy.Start; + return strategy; } @Override diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index c68285901b7..4033f5853ee 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -134,15 +134,19 @@ import com.cloud.network.IpAddrAllocator; import com.cloud.network.LoadBalancerVMMapVO; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.LoadBalancerVMMapDao; +import com.cloud.network.dao.NetworkDao; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.security.NetworkGroupManager; import com.cloud.network.security.NetworkGroupVO; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; @@ -246,10 +250,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM @Inject VMTemplateHostDao _vmTemplateHostDao; @Inject NetworkGroupManager _networkGroupMgr; @Inject ServiceOfferingDao _serviceOfferingDao; + @Inject NetworkOfferingDao _networkOfferingDao; @Inject EventDao _eventDao = null; @Inject InstanceGroupDao _vmGroupDao; @Inject InstanceGroupVMMapDao _groupVMMapDao; @Inject VmManager _itMgr; + @Inject NetworkDao _networkDao; private IpAddrAllocator _IpAllocator; ScheduledExecutorService _executor = null; @@ -846,7 +852,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM if (s_logger.isDebugEnabled()) { s_logger.debug("Starting VM: " + vmId); } - + State state = vm.getState(); if (state == State.Running) { if (s_logger.isDebugEnabled()) { @@ -1043,6 +1049,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM } else { bits = template.getBits(); } + +// NetworkVO vmNetwork = _networkDao.findById(Long.valueOf(vm.getVnet())); +// NetworkOfferingVO vmNetworkOffering = _networkOfferingDao.findById(vmNetwork.getNetworkOfferingId()); StartCommand cmdStart = new StartCommand(vm, vm.getInstanceName(), offering, offering.getRateMbps(), offering.getMulticastRateMbps(), router, storageIps, vol.getFolder(), vm.getVnet(), utilization, cpuWeight, vols, mirroredVols, bits, isoPath, bootFromISO, guestOSDescription); if (Storage.ImageFormat.ISO.equals(template.getFormat()) || template.isRequiresHvm()) { @@ -3497,6 +3506,34 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM @Override @DB public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException { Account caller = UserContext.current().getAccount(); + String accountName = cmd.getAccountName(); + Long domainId = cmd.getDomainId(); + Account userAccount = null; + Long accountId = null; + List networkList = cmd.getNetworkIds(); + + if ((caller == null) || isAdmin(caller.getType())) { + if (domainId != null) { + if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(), domainId)) { + throw new PermissionDeniedException("Failed to deploy VM, invalid domain id (" + domainId + ") given."); + } + if (accountName != null) { + userAccount = _accountDao.findActiveAccount(accountName, domainId); + if (userAccount == null) { + throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); + } + accountId = userAccount.getId(); + } + } else { + accountId = ((caller != null) ? caller.getId() : null); + } + } else { + accountId = caller.getId(); + } + + if (accountId == null) { + throw new InvalidParameterValueException("No valid account specified for deploying a virtual machine."); + } AccountVO owner = _accountDao.findById(cmd.getAccountId()); if (owner == null || owner.getRemoved() != null) { @@ -3605,12 +3642,25 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM s_logger.debug("Allocating in the DB for vm"); - List configs = _networkMgr.setupNetworkConfiguration(owner, offering, plan); - List> networks = new ArrayList>(); - for (NetworkVO config : configs) { - networks.add(new Pair(config, null)); + if (networkList == null || networkList.isEmpty()) { + throw new InvalidParameterValueException("NetworkIds have to be specified"); + } + + List> networks = new ArrayList>(); + for (Long networkId : networkList) { + NetworkVO network = _networkDao.findById(networkId); + if (network == null) { + throw new InvalidParameterValueException("Unable to find network by id " + networkId); + } else { + if (network.getAccountId() != Account.ACCOUNT_ID_SYSTEM && network.getAccountId() != accountId) { + throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied"); + } else if (network.getTrafficType() != TrafficType.Guest) { + throw new InvalidParameterValueException("Unable to create a vm using network which traffic type is " + network.getTrafficType() + ". " + + "Only Guest traffic type is acceptes"); + } + networks.add(new Pair(network, null)); + } } - long id = _vmDao.getNextInSequence(Long.class, "id"); diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java index 81576b4d041..4d68174be11 100644 --- a/server/src/com/cloud/vm/dao/NicDao.java +++ b/server/src/com/cloud/vm/dao/NicDao.java @@ -12,4 +12,6 @@ public interface NicDao extends GenericDao { List listBy(long instanceId); List listIpAddressInNetworkConfiguration(long networkConfigId); + + List listByNetworkId(long networkId); } diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index 3e43214e99f..3345e3fc30a 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -18,6 +18,7 @@ import com.cloud.vm.NicVO; public class NicDaoImpl extends GenericDaoBase implements NicDao { private final SearchBuilder InstanceSearch; private final GenericSearchBuilder IpSearch; + private final SearchBuilder NetworkSearch; protected NicDaoImpl() { super(); @@ -31,6 +32,10 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { IpSearch.and("nc", IpSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); IpSearch.and("address", IpSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL); IpSearch.done(); + + NetworkSearch = createSearchBuilder(); + NetworkSearch.and("networkId", NetworkSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + NetworkSearch.done(); } @Override @@ -46,4 +51,11 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { sc.setParameters("nc", networkConfigId); return customSearch(sc, null); } + + @Override + public List listByNetworkId(long networkId) { + SearchCriteria sc = NetworkSearch.create(); + sc.setParameters("networkId", networkId); + return listBy(sc); + } } diff --git a/setup/db/create-index-fk.sql b/setup/db/create-index-fk.sql index 1dd3b1bc61a..efa8c2e9b7c 100755 --- a/setup/db/create-index-fk.sql +++ b/setup/db/create-index-fk.sql @@ -265,3 +265,5 @@ ALTER TABLE `cloud`.`remote_access_vpn` ADD INDEX `i_remote_access_vpn_addr`(`vp ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `fk_vpn_users___account_id` FOREIGN KEY `fk_vpn_users__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`vpn_users` ADD INDEX `i_vpn_users_username`(`username`); ALTER TABLE `cloud`.`vpn_users` ADD UNIQUE `i_vpn_users__account_id__username`(`account_id`, `username`); + +ALTER TABLE `cloud`.`vlan` ADD CONSTRAINT `fk_vlan__network_offering_id` FOREIGN KEY `fk_vlan__network_offering_id` (`network_offering_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 1742d7c66b6..e2350de4893 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -112,6 +112,7 @@ CREATE TABLE `cloud`.`op_networks`( CREATE TABLE `cloud`.`networks` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `name` varchar(255) COMMENT 'name for this network', + `display_text` varchar(255) COMMENT 'display text for this network', `traffic_type` varchar(32) NOT NULL COMMENT 'type of traffic going through this network', `broadcast_domain_type` varchar(32) NOT NULL COMMENT 'type of broadcast domain used', `broadcast_uri` varchar(255) COMMENT 'broadcast domain specifier', @@ -164,6 +165,7 @@ CREATE TABLE `cloud`.`nics` ( `network_id` bigint unsigned NOT NULL COMMENT 'network configuration id', `mode` varchar(32) COMMENT 'mode of getting ip address', `state` varchar(32) NOT NULL COMMENT 'state of the creation', + `strategy` varchar(32) NOT NULL COMMENT 'reservation strategy', `reserver_name` varchar(255) COMMENT 'Name of the component that reserved the ip address', `reservation_id` varchar(64) COMMENT 'id for the reservation', `device_id` int(10) COMMENT 'device id for the network when plugged into the virtual machine', @@ -189,6 +191,8 @@ CREATE TABLE `cloud`.`network_offerings` ( `service_offering_id` bigint unsigned UNIQUE COMMENT 'service offering id that this network offering is tied to', `created` datetime NOT NULL COMMENT 'time the entry was created', `removed` datetime DEFAULT NULL COMMENT 'time the entry was removed', + `shared` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 if network is shared, 1 if network dedicated', + `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network is default', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -339,6 +343,7 @@ CREATE TABLE `cloud`.`vlan` ( `description` varchar(255), `vlan_type` varchar(255), `data_center_id` bigint unsigned NOT NULL, + `network_id` bigint unsigned COMMENT 'id of corresponding network offering', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;