From 978c2f414affcbc616e118e85b51c01273da29f5 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 16 May 2012 12:52:32 -0700 Subject: [PATCH 01/64] Initial checkin for VPC feature: 1) Added API frameworks for the feature. New commands: * CreateVPCCmd * ListVPCsCmd * DeleteVPCCmd * UpdateVPCCmd * CreateVPCOfferingCmd * UpdateVPCOfferingCmd * DeleteVPCOfferingCmd * ListVPCOfferingsCmd 2) New db tables: * `cloud`.`vpc` * `cloud`.`vpc_offerings` * `cloud`.`vpc_offering_service_map` and corresponding VO/Dao objects. Added vpc_id field to `cloud.`networks` table - not null when network belongs to VPC 3) New Manager and Service interfaces- VpcManager/VpcService 4) Automatically create new VpcOffering (if doesn't exist) on system start 5) New Action events: * VPC.CREATE * VPC.UPDATE * VPC.DELETE * VPC.OFFERING.CREATE * VPC.OFFERING.UPDATE * VPC.OFFERING.DELETE --- api/src/com/cloud/api/ApiConstants.java | 2 + api/src/com/cloud/api/BaseCmd.java | 3 + api/src/com/cloud/api/ResponseGenerator.java | 16 + .../com/cloud/api/commands/CreateVPCCmd.java | 155 +++++ .../api/commands/CreateVPCOfferingCmd.java | 116 ++++ .../com/cloud/api/commands/DeleteVPCCmd.java | 93 +++ .../api/commands/DeleteVPCOfferingCmd.java | 89 +++ .../api/commands/ListVPCOfferingsCmd.java | 113 ++++ .../com/cloud/api/commands/ListVPCsCmd.java | 148 +++++ .../com/cloud/api/commands/UpdateVPCCmd.java | 106 +++ .../api/commands/UpdateVPCOfferingCmd.java | 107 +++ .../api/response/VpcOfferingResponse.java | 77 +++ .../com/cloud/api/response/VpcResponse.java | 143 ++++ api/src/com/cloud/event/EventTypes.java | 10 + api/src/com/cloud/network/Network.java | 5 + api/src/com/cloud/network/NetworkProfile.java | 7 + api/src/com/cloud/network/NetworkService.java | 2 + .../VirtualNetworkApplianceService.java | 6 +- api/src/com/cloud/network/vpc/Vpc.java | 51 ++ .../com/cloud/network/vpc/VpcOffering.java | 41 ++ api/src/com/cloud/network/vpc/VpcService.java | 105 +++ api/src/com/cloud/storage/StorageService.java | 9 +- client/tomcatconf/commands.properties.in | 14 + server/src/com/cloud/api/ApiDBUtils.java | 14 +- .../src/com/cloud/api/ApiResponseHelper.java | 87 +++ server/src/com/cloud/api/ApiServer.java | 3 +- .../configuration/ConfigurationManager.java | 22 +- .../ConfigurationManagerImpl.java | 35 +- .../DefaultComponentLibrary.java | 18 +- server/src/com/cloud/network/IPAddressVO.java | 1 + .../com/cloud/network/NetworkManagerImpl.java | 27 +- server/src/com/cloud/network/NetworkVO.java | 8 + .../src/com/cloud/network/dao/NetworkDao.java | 6 +- .../com/cloud/network/dao/NetworkDaoImpl.java | 34 +- .../VirtualNetworkApplianceManager.java | 44 +- .../VirtualNetworkApplianceManagerImpl.java | 71 +- .../src/com/cloud/network/vpc/Dao/VpcDao.java | 29 + .../com/cloud/network/vpc/Dao/VpcDaoImpl.java | 56 ++ .../cloud/network/vpc/Dao/VpcOfferingDao.java | 30 + .../network/vpc/Dao/VpcOfferingDaoImpl.java | 68 ++ .../vpc/Dao/VpcOfferingServiceMapDao.java | 34 + .../vpc/Dao/VpcOfferingServiceMapDaoImpl.java | 90 +++ .../src/com/cloud/network/vpc/VpcManager.java | 61 ++ .../com/cloud/network/vpc/VpcManagerImpl.java | 608 ++++++++++++++++++ .../network/vpc/VpcOfferingServiceMapVO.java | 87 +++ .../com/cloud/network/vpc/VpcOfferingVO.java | 143 ++++ server/src/com/cloud/network/vpc/VpcVO.java | 164 +++++ .../dao/NetworkOfferingServiceMapDao.java | 5 + .../dao/NetworkOfferingServiceMapDaoImpl.java | 5 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 2 +- .../vm/MockVirtualMachineManagerImpl.java | 18 + setup/db/create-schema.sql | 52 ++ wscript | 2 +- 53 files changed, 3094 insertions(+), 148 deletions(-) create mode 100644 api/src/com/cloud/api/commands/CreateVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/commands/DeleteVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java create mode 100644 api/src/com/cloud/api/commands/ListVPCsCmd.java create mode 100644 api/src/com/cloud/api/commands/UpdateVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/response/VpcOfferingResponse.java create mode 100644 api/src/com/cloud/api/response/VpcResponse.java create mode 100644 api/src/com/cloud/network/vpc/Vpc.java create mode 100644 api/src/com/cloud/network/vpc/VpcOffering.java create mode 100644 api/src/com/cloud/network/vpc/VpcService.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/VpcManager.java create mode 100644 server/src/com/cloud/network/vpc/VpcManagerImpl.java create mode 100644 server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java create mode 100644 server/src/com/cloud/network/vpc/VpcOfferingVO.java create mode 100644 server/src/com/cloud/network/vpc/VpcVO.java diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index f604262aa32..3d4f64b446d 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -345,6 +345,8 @@ public class ApiConstants { public static final String VSM_USERNAME = "vsmusername"; public static final String VSM_PASSWORD = "vsmpassword"; public static final String VSM_IPADDRESS = "vsmipaddress"; + public static final String VPC_OFF_ID = "vpcofferingid"; + public static final String NETWORK = "network"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/BaseCmd.java b/api/src/com/cloud/api/BaseCmd.java index 9fe4dd5f84f..75f9d7a090e 100755 --- a/api/src/com/cloud/api/BaseCmd.java +++ b/api/src/com/cloud/api/BaseCmd.java @@ -40,6 +40,7 @@ import com.cloud.network.firewall.FirewallService; import com.cloud.network.lb.LoadBalancingRulesService; import com.cloud.network.rules.RulesService; import com.cloud.network.security.SecurityGroupService; +import com.cloud.network.vpc.VpcService; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.projects.Project; import com.cloud.projects.ProjectService; @@ -123,6 +124,7 @@ public abstract class BaseCmd { public static ResourceLimitService _resourceLimitService; public static IdentityService _identityService; public static StorageNetworkService _storageNetworkService; + public static VpcService _vpcService; static void setComponents(ResponseGenerator generator) { ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); @@ -150,6 +152,7 @@ public abstract class BaseCmd { _resourceLimitService = locator.getManager(ResourceLimitService.class); _identityService = locator.getManager(IdentityService.class); _storageNetworkService = locator.getManager(StorageNetworkService.class); + _vpcService = locator.getManager(VpcService.class); } public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 9bf0a1cc1e7..cc10908d597 100755 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -70,6 +70,8 @@ import com.cloud.api.response.UserVmResponse; import com.cloud.api.response.VirtualRouterProviderResponse; import com.cloud.api.response.VlanIpRangeResponse; import com.cloud.api.response.VolumeResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.api.response.VpcResponse; import com.cloud.api.response.VpnUsersResponse; import com.cloud.api.response.ZoneResponse; import com.cloud.async.AsyncJob; @@ -103,6 +105,8 @@ import com.cloud.network.rules.StickinessPolicy; import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupRules; import com.cloud.network.security.SecurityRule; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcOffering; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; @@ -276,4 +280,16 @@ public interface ResponseGenerator { * @return */ Long getIdentiyId(String tableName, String token); + + /** + * @param offering + * @return + */ + VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering); + + /** + * @param vpc + * @return + */ + VpcResponse createVpcResponse(Vpc vpc); } diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java new file mode 100644 index 00000000000..59efff6cbcd --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -0,0 +1,155 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.UserContext; + +/** + * @author Alena Prokharchyk + */ +public class CreateVPCCmd extends BaseAsyncCreateCmd{ + public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName()); + private static final String s_name = "createvpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the VPC. " + + "Must be used with the domainId parameter.") + private String accountName; + + @IdentityMapper(entityTableName="domain") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the VPC. " + + "If used with the account parameter returns the VPC associated with the account for the specified domain.") + private Long domainId; + + @IdentityMapper(entityTableName="data_center") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone") + private Long zoneId; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " + + "the VPC") + private String displayText; + + @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, required=true, description="the cidr of the VPC. All VPC " + + "guest networks' cidrs should be within this CIDR") + private String cidr; + + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") + private Long vpcOffering; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Long getZoneId() { + return zoneId; + } + + public String getVpcName() { + return vpcName; + } + + public String getCidr() { + return cidr; + } + + public String getDisplayText() { + return displayText; + } + + public Long getVpcOffering() { + return vpcOffering; + } + + @Override + public void create() throws ResourceAllocationException { + Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr()); + if (vpc != null) { + this.setEntityId(vpc.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC"); + } + } + + @Override + public void execute() { + //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc) + Vpc vpc = _vpcService.getVpc(this.getEntityId()); + if (vpc != null) { + VpcResponse response = _responseGenerator.createVpcResponse(vpc); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC"); + } + } + + @Override + public String getEntityTable() { + return "vpc"; + } + + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_CREATE; + } + + + @Override + public String getEventDescription() { + return "creating VPC. Id: " + getEntityId(); + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Long accountId = finalyzeAccountId(accountName, domainId, null, true); + if (accountId == null) { + return UserContext.current().getCaller().getId(); + } + + return accountId; + } +} diff --git a/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java b/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java new file mode 100644 index 00000000000..b8411810f6d --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java @@ -0,0 +1,116 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{ + public static final Logger s_logger = Logger.getLogger(CreateVPCOfferingCmd.class.getName()); + private static final String _name = "createvpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the vpc offering") + private String vpcOfferingName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " + + "the vpc offering") + private String displayText; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, required=true, collectionType=CommandType.STRING, + description="services supported by the vpc offering") + private List supportedServices; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcOfferingName() { + return vpcOfferingName; + } + + public String getDisplayText() { + return displayText; + } + + public List getSupportedServices() { + return supportedServices; + } + + + @Override + public void create() throws ResourceAllocationException { + VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices()); + if (vpcOff != null) { + this.setEntityId(vpcOff.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC offering"); + } + } + + @Override + public void execute() { + VpcOffering vpc = _vpcService.getVpcOffering(this.getEntityId()); + if (vpc != null) { + VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC offering"); + } + } + + @Override + public String getEntityTable() { + return "vpc_offerings"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_OFFERING_CREATE; + } + + @Override + public String getEventDescription() { + return "creating VPC offering. Id: " + getEntityId(); + } + + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} diff --git a/api/src/com/cloud/api/commands/DeleteVPCCmd.java b/api/src/com/cloud/api/commands/DeleteVPCCmd.java new file mode 100644 index 00000000000..d4ad1ae3208 --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteVPCCmd.java @@ -0,0 +1,93 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class DeleteVPCCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteVPCCmd.class.getName()); + private static final String s_name = "deletevpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the VPC") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting VPC id=" + getId(); + } + + @Override + public void execute() { + boolean result = _vpcService.deleteVpc(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Vpc vpc = _entityMgr.findById(Vpc.class, getId()); + if (vpc != null) { + return vpc.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + +} diff --git a/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java new file mode 100644 index 00000000000..b32b17ba3ab --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java @@ -0,0 +1,89 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class DeleteVPCOfferingCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteVPCOfferingCmd.class.getName()); + private static final String s_name = "deletevpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + boolean result = _vpcService.deleteVpcOffering(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC offering"); + } + } + + @Override + public String getEventType(){ + return EventTypes.EVENT_VPC_OFFERING_DELETE; + } + + + @Override + public String getEventDescription() { + return "Deleting VPC offering id=" + getId(); + } + + +} diff --git a/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java b/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java new file mode 100644 index 00000000000..adb96354105 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java @@ -0,0 +1,113 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +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.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.network.vpc.VpcOffering; + +/** + * @author Alena Prokharchyk + */ +public class ListVPCOfferingsCmd extends BaseListCmd{ + public static final Logger s_logger = Logger.getLogger(ListVPCOfferingsCmd.class.getName()); + private static final String _name = "listvpcofferingsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC offerings by id") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list VPC offerings by name") + private String vpcOffName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="list VPC offerings by display text") + private String displayText; + + @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if need to list only default " + + "VPC offerings. Default value is false") + private Boolean isDefault; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, + description="list VPC offerings supporting certain services") + private List supportedServices; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPC offerings by state") + private String state; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public String getVpcOffName() { + return vpcOffName; + } + + public String getDisplayText() { + return displayText; + } + + public Boolean getIsDefault() { + return isDefault; + } + + public List getSupportedServices() { + return supportedServices; + } + + public String getState() { + return state; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute(){ + List offerings = _vpcService.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(), + getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal()); + ListResponse response = new ListResponse(); + List offeringResponses = new ArrayList(); + for (VpcOffering offering : offerings) { + VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering); + offeringResponses.add(offeringResponse); + } + + response.setResponses(offeringResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + + + @Override + public String getCommandName() { + return _name; + } + +} diff --git a/api/src/com/cloud/api/commands/ListVPCsCmd.java b/api/src/com/cloud/api/commands/ListVPCsCmd.java new file mode 100644 index 00000000000..bda292ac603 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListVPCsCmd.java @@ -0,0 +1,148 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +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.BaseListAccountResourcesCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.VpcResponse; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.Vpc; + +/** + * @author Alena Prokharchyk + */ +public class ListVPCsCmd extends BaseListAccountResourcesCmd{ + public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName()); + private static final String s_name = "listvpcsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC by id") + private Long id; + + @IdentityMapper(entityTableName="data_center") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list by zone") + private Long zoneId; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list by name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="List by display text of " + + "the VPC") + private String displayText; + + @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, description="list by cidr of the VPC. All VPC " + + "guest networks' cidrs should be within this CIDR") + private String cidr; + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, description="list by ID of the VPC offering") + private Long VpcOffId; + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " + + "Must be used with the domainId parameter.") + private String accountName; + + @IdentityMapper(entityTableName="domain") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="list by domain ID associated with the VPC. " + + "If used with the account parameter returns the VPC associated with the account for the specified domain.") + private Long domainId; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, + description="list VPC supporting certain services") + private List supportedServices; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPCs by state") + private String state; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Long getZoneId() { + return zoneId; + } + + public String getVpcName() { + return vpcName; + } + + public String getCidr() { + return cidr; + } + + public String getDisplayText() { + return displayText; + } + + public Long getVpcOffId() { + return VpcOffId; + } + + public Long getId() { + return id; + } + + public List getSupportedServices() { + return supportedServices; + } + + public String getState() { + return state; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + List vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), + getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(), + this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(), this.listAll()); + ListResponse response = new ListResponse(); + List offeringResponses = new ArrayList(); + for (Vpc vpc : vpcs) { + VpcResponse offeringResponse = _responseGenerator.createVpcResponse(vpc); + offeringResponses.add(offeringResponse); + } + + response.setResponses(offeringResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + + @Override + public String getCommandName() { + return s_name; + } + +} diff --git a/api/src/com/cloud/api/commands/UpdateVPCCmd.java b/api/src/com/cloud/api/commands/UpdateVPCCmd.java new file mode 100644 index 00000000000..80babfc1a4d --- /dev/null +++ b/api/src/com/cloud/api/commands/UpdateVPCCmd.java @@ -0,0 +1,106 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class UpdateVPCCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName()); + private static final String _name = "updatevpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC") + private String displayText; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcName() { + return vpcName; + } + + public String getDisplayText() { + return displayText; + } + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + Vpc vpc = _entityMgr.findById(Vpc.class, getId()); + if (vpc != null) { + return vpc.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText()); + if (result != null) { + VpcResponse response = _responseGenerator.createVpcResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC"); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating VPC id=" + getId(); + } +} diff --git a/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java new file mode 100644 index 00000000000..a31a8acb29b --- /dev/null +++ b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java @@ -0,0 +1,107 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class UpdateVPCOfferingCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(UpdateVPCOfferingCmd.class.getName()); + private static final String _name = "updatevpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC offering") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC offering") + private String vpcOffName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC offering") + private String displayText; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering") + private String state; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcOfferingName() { + return vpcOffName; + } + + public String getDisplayText() { + return displayText; + } + + public Long getId() { + return id; + } + + public String getState() { + return state; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + VpcOffering result = _vpcService.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState()); + if (result != null) { + VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC offering"); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_OFFERING_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating VPC offering id=" + getId(); + } +} diff --git a/api/src/com/cloud/api/response/VpcOfferingResponse.java b/api/src/com/cloud/api/response/VpcOfferingResponse.java new file mode 100644 index 00000000000..8fe536181a1 --- /dev/null +++ b/api/src/com/cloud/api/response/VpcOfferingResponse.java @@ -0,0 +1,77 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.response; + +import java.util.Date; +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.cloud.utils.IdentityProxy; +import com.google.gson.annotations.SerializedName; + +/** + * @author Alena Prokharchyk + */ +@SuppressWarnings("unused") +public class VpcOfferingResponse extends BaseResponse{ + @SerializedName("id") @Param(description="the id of the vpc offering") + private final IdentityProxy id = new IdentityProxy("vpc_offerings"); + + @SerializedName(ApiConstants.NAME) @Param(description="the name of the vpc offering") + private String name; + + @SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description="an alternate display text of the vpc offering.") + private String displayText; + + @SerializedName(ApiConstants.CREATED) @Param(description="the date this vpc offering was created") + private Date created; + + @SerializedName(ApiConstants.IS_DEFAULT) @Param(description="true if vpc offering is default, false otherwise") + private Boolean isDefault; + + @SerializedName(ApiConstants.STATE) @Param(description="state of the vpc offering. Can be Disabled/Enabled") + private String state; + + @SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class) + private List services; + + + public void setId(Long id) { + this.id.setValue(id); + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + public void setServices(List services) { + this.services = services; + } + + public void setState(String state) { + this.state = state; + } +} diff --git a/api/src/com/cloud/api/response/VpcResponse.java b/api/src/com/cloud/api/response/VpcResponse.java new file mode 100644 index 00000000000..3ba92808422 --- /dev/null +++ b/api/src/com/cloud/api/response/VpcResponse.java @@ -0,0 +1,143 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.response; + +import java.util.Date; +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.cloud.utils.IdentityProxy; +import com.google.gson.annotations.SerializedName; + +/** + * @author Alena Prokharchyk + */ + +@SuppressWarnings("unused") +public class VpcResponse extends BaseResponse implements ControlledEntityResponse{ + @SerializedName("id") @Param(description="the id of the VPC") + private final IdentityProxy id = new IdentityProxy("vpc"); + + @SerializedName(ApiConstants.NAME) @Param(description="the name of the VPC") + private String name; + + @SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description="an alternate display text of the VPC.") + private String displayText; + + @SerializedName(ApiConstants.STATE) @Param(description="state of the VPC. Can be Disabled/Enabled") + private String state; + + @SerializedName(ApiConstants.ZONE_ID) @Param(description="zone id of the vpc") + private IdentityProxy zoneId = new IdentityProxy("data_center"); + + @SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class) + private List services; + + @SerializedName(ApiConstants.CIDR) @Param(description="the cidr the VPC") + private String cidr; + + @SerializedName(ApiConstants.VPC_OFF_ID) @Param(description="vpc offering id the VPC is created from") + private IdentityProxy vpcOfferingId = new IdentityProxy("vpc_offerings"); + + @SerializedName(ApiConstants.CREATED) @Param(description="the date this VPC was created") + private Date created; + + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner of the VPC") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the VPC") + private IdentityProxy projectId = new IdentityProxy("projects"); + + @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the VPC") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the VPC owner") + private IdentityProxy domainId = new IdentityProxy("domain"); + + @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the owner") + private String domain; + + @SerializedName(ApiConstants.NETWORK) @Param(description="the list of networks belongign to the VPC", responseObject = NetworkResponse.class) + private List networks; + + + public void setId(Long id) { + this.id.setValue(id); + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setServices(List services) { + this.services = services; + } + + public void setState(String state) { + this.state = state; + } + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(Long projectId) { + this.projectId.setValue(projectId); + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(Long domainId) { + this.domainId.setValue(domainId); + } + + @Override + public void setDomainName(String domainName) { + this.domain = domainName; + } + + public void setZoneId(Long zoneId) { + this.zoneId.setValue(zoneId); + } + + public void setCidr(String cidr) { + this.cidr = cidr; + } + + public void setVpcOfferingId(Long vpcOfferingId) { + this.vpcOfferingId.setValue(vpcOfferingId); + } + + public List getNetworks() { + return networks; + } + + public void setNetworks(List networks) { + this.networks = networks; + } +} diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index ea3cb3e0d0e..75fe38e05f7 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -252,4 +252,14 @@ public class EventTypes { public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_ADD = "PHYSICAL.FIREWALL.ADD"; public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_DELETE = "PHYSICAL.FIREWALL.DELETE"; public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_CONFIGURE = "PHYSICAL.FIREWALL.CONFIGURE"; + + // VPC + public static final String EVENT_VPC_CREATE = "VPC.CREATE"; + public static final String EVENT_VPC_UPDATE = "VPC.UPDATE"; + public static final String EVENT_VPC_DELETE = "VPC.DELETE"; + + + public static final String EVENT_VPC_OFFERING_CREATE = "VPC.OFFERING.CREATE"; + public static final String EVENT_VPC_OFFERING_UPDATE = "VPC.OFFERING.UPDATE"; + public static final String EVENT_VPC_OFFERING_DELETE = "VPC.OFFERING.DELETE"; } diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index e8394961b2b..426f34bb488 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -279,4 +279,9 @@ public interface Network extends ControlledEntity { boolean isRestartRequired(); boolean getSpecifyIpRanges(); + + /** + * @return + */ + long getVpcId(); } diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index 8c965e12abe..7a578d0eb5c 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -43,6 +43,7 @@ public class NetworkProfile implements Network { private ACLType aclType; private boolean restartRequired; private boolean specifyIpRanges; + private Long vpcId; public NetworkProfile(Network network) { this.id = network.getId(); @@ -67,6 +68,7 @@ public class NetworkProfile implements Network { this.aclType = network.getAclType(); this.restartRequired = network.isRestartRequired(); this.specifyIpRanges = network.getSpecifyIpRanges(); + this.vpcId = network.getVpcId(); } public String getDns1() { @@ -206,4 +208,9 @@ public class NetworkProfile implements Network { return false; } + @Override + public long getVpcId() { + return vpcId; + } + } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 162104417ee..fe82d3fff8a 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -129,5 +129,7 @@ public interface NetworkService { List> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd); List getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner); + + List listNetworksByVpc(long vpcId); } diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index 0a964b4dcee..e68d6d91f1e 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -26,7 +26,8 @@ public interface VirtualNetworkApplianceService { * the command specifying router's id * @return DomainRouter object */ - VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; /** * Reboots domain router @@ -35,7 +36,8 @@ public interface VirtualNetworkApplianceService { * the command specifying router's id * @return router if successful */ - VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; VirtualRouter upgradeRouter(UpgradeRouterCmd cmd); diff --git a/api/src/com/cloud/network/vpc/Vpc.java b/api/src/com/cloud/network/vpc/Vpc.java new file mode 100644 index 00000000000..88fee8c76b5 --- /dev/null +++ b/api/src/com/cloud/network/vpc/Vpc.java @@ -0,0 +1,51 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.List; + +import com.cloud.acl.ControlledEntity; +import com.cloud.network.Network; +import com.cloud.network.Network.Service; + + +/** + * @author Alena Prokharchyk + */ +public interface Vpc extends ControlledEntity{ + public enum State { + Enabled, + Disabled + } + + public static final String _supportedProviders = Network.Provider.VirtualRouter.getName(); + + boolean readyToUse(); + + long getId(); + + String getUuid(); + + String getName(); + + long getZoneId(); + + String getCidr(); + + State getState(); + + long getVpcOfferingId(); + + String getDisplayText(); + +} diff --git a/api/src/com/cloud/network/vpc/VpcOffering.java b/api/src/com/cloud/network/vpc/VpcOffering.java new file mode 100644 index 00000000000..5531f55a998 --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcOffering.java @@ -0,0 +1,41 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + + +/** + * @author Alena Prokharchyk + */ +public interface VpcOffering { + public enum State { + Disabled, + Enabled + } + + public static final String defaultVPCOfferingName = "Default VPC offering"; + + long getId(); + + String getUuid(); + + String getName(); + + String getUniqueName(); + + String getDisplayText(); + + State getState(); + + boolean isDefault(); + +} diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java new file mode 100644 index 00000000000..faf2845006c --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -0,0 +1,105 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.cloud.network.Network; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; + +/** + * @author Alena Prokharchyk + */ +public interface VpcService { + + public VpcOffering getVpcOffering(long vpcOfferingId); + + public VpcOffering createVpcOffering(String name, String displayText, List supportedServices); + + public Vpc getVpc(long vpcId); + + public Vpc createVpc(long zoneId, String name, String cidr, long ownerId); + + public List getVpcNetworks(long vpcId); + + Map> getVpcOffSvcProvidersMap(long vpcOffId); + + List listVpcOfferings(Long id, String name, String displayText, List supportedServicesStr, + Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal); + + /** + * @param offId + * @return + */ + public boolean deleteVpcOffering(long offId); + + /** + * @param vpcOffId + * @param vpcOfferingName + * @param displayText + * @param state + * @return + */ + public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state); + + /** + * @param zoneId + * @param vpcOffId + * @param vpcOwnerId + * @param vpcName + * @param displayText + * @param cidr + * @return + */ + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr); + + /** + * @param vpcId + * @return + */ + public boolean deleteVpc(long vpcId); + + /** + * @param vpcId + * @param vpcName + * @param displayText + * @return + */ + public Vpc updateVpc(long vpcId, String vpcName, String displayText); + + /** + * @param id + * @param vpcName + * @param displayText + * @param supportedServicesStr + * @param cidr + * @param state TODO + * @param accountName + * @param domainId + * @param keyword + * @param startIndex + * @param pageSizeVal + * @param zoneId TODO + * @param isRecursive TODO + * @param listAll TODO + * @param vpc + * @return + */ + public List listVpcs(Long id, String vpcName, String displayText, + List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, + String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll); + +} diff --git a/api/src/com/cloud/storage/StorageService.java b/api/src/com/cloud/storage/StorageService.java index 7553f9e84b2..4fa097ee50f 100644 --- a/api/src/com/cloud/storage/StorageService.java +++ b/api/src/com/cloud/storage/StorageService.java @@ -43,7 +43,8 @@ public interface StorageService{ * @throws ResourceUnavailableException * TODO */ - StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException; + StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, + UnknownHostException, ResourceUnavailableException; /** * Creates the database object for a volume based on the given criteria @@ -88,7 +89,8 @@ public interface StorageService{ * @throws InsufficientCapacityException * TODO */ - public StoragePool preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException, InsufficientCapacityException; + public StoragePool preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException, + InsufficientCapacityException; /** * Complete maintenance for primary storage @@ -99,7 +101,8 @@ public interface StorageService{ * @throws ResourceUnavailableException * TODO */ - public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException; + public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) + throws ResourceUnavailableException; public StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException; diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 3a3571895e0..68c896c030b 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -332,3 +332,17 @@ updateStorageNetworkIpRange=com.cloud.api.commands.UpdateStorageNetworkIpRangeCm addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1 listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1 deleteNetworkDevice=com.cloud.api.commands.DeleteNetworkDeviceCmd;1 + + +### VPC commands +createVPC=com.cloud.api.commands.CreateVPCCmd;15 +listVPCs=com.cloud.api.commands.ListVPCsCmd;15 +deleteVPC=com.cloud.api.commands.DeleteVPCCmd;15 +updateVPC=com.cloud.api.commands.UpdateVPCCmd;15 + + +#### VPC offering commands +createVPCOffering=com.cloud.api.commands.CreateVPCOfferingCmd;1 +updateVPCOffering=com.cloud.api.commands.UpdateVPCOfferingCmd;1 +deleteVPCOffering=com.cloud.api.commands.DeleteVPCOfferingCmd;1 +listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15 diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 2404535221d..319dbe407f1 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -49,6 +49,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; import com.cloud.network.LoadBalancerVO; +import com.cloud.network.Network; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -68,6 +69,7 @@ import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.SecurityGroupVO; import com.cloud.network.security.dao.SecurityGroupDao; +import com.cloud.network.vpc.VpcManager; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -91,8 +93,8 @@ import com.cloud.storage.UploadVO; import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateSwiftVO; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.VolumeHostVO; import com.cloud.storage.Volume.Type; +import com.cloud.storage.VolumeHostVO; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSCategoryDao; @@ -187,6 +189,7 @@ public class ApiDBUtils { private static AccountDetailsDao _accountDetailsDao; private static NetworkDomainDao _networkDomainDao; private static HighAvailabilityManager _haMgr; + private static VpcManager _vpcMgr; static { _ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name); @@ -240,6 +243,7 @@ public class ApiDBUtils { _accountDetailsDao = locator.getDao(AccountDetailsDao.class); _networkDomainDao = locator.getDao(NetworkDomainDao.class); _haMgr = locator.getManager(HighAvailabilityManager.class); + _vpcMgr = locator.getManager(VpcManager.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -743,4 +747,12 @@ public class ApiDBUtils { public static String getHaTag() { return _haMgr.getHaTag(); } + + public static Map> listVpcOffServices(long vpcOffId) { + return _vpcMgr.getVpcOffSvcProvidersMap(vpcOffId); + } + + public static List listVpcNetworks(long vpcId) { + return _networkMgr.listNetworksByVpc(vpcId); + } } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 3984ec5bad4..079aa039d2a 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -91,6 +91,8 @@ import com.cloud.api.response.UserVmResponse; import com.cloud.api.response.VirtualRouterProviderResponse; import com.cloud.api.response.VlanIpRangeResponse; import com.cloud.api.response.VolumeResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.api.response.VpcResponse; import com.cloud.api.response.VpnUsersResponse; import com.cloud.api.response.ZoneResponse; import com.cloud.async.AsyncJob; @@ -143,6 +145,8 @@ import com.cloud.network.security.SecurityGroupRules; import com.cloud.network.security.SecurityGroupVO; import com.cloud.network.security.SecurityRule; import com.cloud.network.security.SecurityRule.SecurityRuleType; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcOffering; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; @@ -3394,5 +3398,88 @@ public class ApiResponseHelper implements ResponseGenerator { public Long getIdentiyId(String tableName, String token) { return ApiDispatcher.getIdentiyId(tableName, token); } + + + @Override + public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) { + VpcOfferingResponse response = new VpcOfferingResponse(); + response.setId(offering.getId()); + response.setName(offering.getName()); + response.setDisplayText(offering.getDisplayText()); + response.setIsDefault(offering.isDefault()); + response.setState(offering.getState().name()); + + Map> serviceProviderMap = ApiDBUtils.listVpcOffServices(offering.getId()); + List serviceResponses = new ArrayList(); + for (Service service : serviceProviderMap.keySet()) { + ServiceResponse svcRsp = new ServiceResponse(); + // skip gateway service + if (service == Service.Gateway) { + continue; + } + svcRsp.setName(service.getName()); + List providers = new ArrayList(); + for (Provider provider : serviceProviderMap.get(service)) { + if (provider != null) { + ProviderResponse providerRsp = new ProviderResponse(); + providerRsp.setName(provider.getName()); + providers.add(providerRsp); + } + } + svcRsp.setProviders(providers); + + serviceResponses.add(svcRsp); + } + response.setServices(serviceResponses); + response.setObjectName("vpcoffering"); + return response; + } + + + @Override + public VpcResponse createVpcResponse(Vpc vpc) { + VpcResponse response = new VpcResponse(); + response.setId(vpc.getId()); + response.setName(vpc.getName()); + response.setDisplayText(vpc.getDisplayText()); + response.setState(vpc.getState().name()); + response.setVpcOfferingId(vpc.getVpcOfferingId()); + response.setCidr(vpc.getCidr()); + response.setZoneId(vpc.getZoneId()); + + Map> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId()); + List serviceResponses = new ArrayList(); + for (Service service : serviceProviderMap.keySet()) { + ServiceResponse svcRsp = new ServiceResponse(); + // skip gateway service + if (service == Service.Gateway) { + continue; + } + svcRsp.setName(service.getName()); + List providers = new ArrayList(); + for (Provider provider : serviceProviderMap.get(service)) { + if (provider != null) { + ProviderResponse providerRsp = new ProviderResponse(); + providerRsp.setName(provider.getName()); + providers.add(providerRsp); + } + } + svcRsp.setProviders(providers); + + serviceResponses.add(svcRsp); + } + + List networkResponses = new ArrayList(); + List networks = ApiDBUtils.listVpcNetworks(vpc.getId()); + for (Network network : networks) { + NetworkResponse ntwkRsp = createNetworkResponse(network); + networkResponses.add(ntwkRsp); + } + + response.setNetworks(networkResponses); + response.setServices(serviceResponses); + response.setObjectName("vpcoffering"); + return response; + } } diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index d13e67ae301..ebb914c075d 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -500,7 +500,8 @@ public class ApiServer implements HttpRequestHandler { asyncCmd.setStartEventId(startEventId); // save the scheduled event - Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), + Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, + asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), startEventId); if (startEventId == 0) { // There was no create event before, set current event id as start eventId diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 85cdf34cf24..29de7bf4ba2 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -164,11 +164,12 @@ public interface ConfigurationManager extends ConfigurationService, Manager { /** * Creates a new network offering - * * @param name * @param displayText * @param trafficType * @param tags + * @param specifyVlan + * ; * @param networkRate * TODO * @param serviceProviderMap @@ -180,19 +181,18 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @param systemOnly * TODO * @param serviceOfferingId + * @param conserveMode + * ; * @param specifyIpRanges * TODO * @param id - * @param specifyVlan - * ; - * @param conserveMode - * ; + * * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, - Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, - Map> serviceCapabilityMap, boolean specifyIpRanges); + NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map> serviceProviderMap, + boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map> serviceCapabilityMap, + boolean specifyIpRanges); Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; @@ -226,4 +226,10 @@ public interface ConfigurationManager extends ConfigurationService, Manager { AllocationState findClusterAllocationState(ClusterVO cluster); + /** + * @param tags + * @return + */ + String cleanupTags(String tags); + } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 359b8baeabf..7466342da8a 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -108,7 +108,6 @@ import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.TrafficType; -import com.cloud.api.commands.MarkDefaultZoneForAccountCmd; import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.dao.FirewallRulesDao; @@ -139,8 +138,8 @@ import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.swift.SwiftManager; import com.cloud.test.IPRangeConfig; import com.cloud.user.Account; -import com.cloud.user.AccountVO; import com.cloud.user.AccountManager; +import com.cloud.user.AccountVO; import com.cloud.user.ResourceLimitService; import com.cloud.user.User; import com.cloud.user.UserContext; @@ -2542,7 +2541,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return tags; } - private String cleanupTags(String tags) { + @Override + public String cleanupTags(String tags) { if (tags != null) { String[] tokens = tags.split(","); StringBuilder t = new StringBuilder(); @@ -2875,7 +2875,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering") public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) { - Long userId = UserContext.current().getCallerUserId(); String name = cmd.getNetworkOfferingName(); String displayText = cmd.getDisplayText(); String tags = cmd.getTags(); @@ -2982,7 +2981,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Set providers = new HashSet(); // in Acton, don't allow to specify more than 1 provider per service if (svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) { - throw new InvalidParameterValueException("In the current release only one provider can be specified for the service"); + throw new InvalidParameterValueException("In the current release only one provider can be " + + "specified for the service"); } for (String prvNameStr : svcPrv.get(serviceStr)) { // check if provider is supported @@ -3013,7 +3013,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } serviceProviderMap.put(service, providers); } else { - throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network offering, can't add a provider to it"); + throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + + "offering, can't add a provider to it"); } } } @@ -3047,8 +3048,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap); serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap); - // if Firewall service is missing, and Juniper is a provider for any other service or VR is StaticNat/PF provider, add Firewall - // service/provider combination + // if Firewall service is missing, add Firewall service/provider combination if (firewallProvider != null) { s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName()); Set firewallProviderSet = new HashSet(); @@ -3056,8 +3056,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura serviceProviderMap.put(Service.Firewall, firewallProviderSet); } - return createNetworkOffering(userId, name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, - false, serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges); + return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, + serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges); } void validateLoadBalancerServiceCapabilities(Map lbServiceCapabilityMap) { @@ -3137,9 +3137,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override @DB - public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, - Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, - Long serviceOfferingId, boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges) { + public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, + Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, + boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges) { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); @@ -3201,13 +3201,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if ((sourceNatServiceCapabilityMap != null) && (!sourceNatServiceCapabilityMap.isEmpty())) { String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes); if (sourceNatType != null) { - _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType); + _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + Capability.SupportedSourceNatTypes, sourceNatType); sharedSourceNat = sourceNatType.contains("perzone"); } String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter); if (param != null) { - _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param); + _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + Capability.RedundantRouter, param); redundantRouter = param.contains("true"); } } @@ -3221,7 +3223,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, + networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges); if (serviceOfferingId != null) { diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index f9d74ceaa72..d7325cc2b83 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -45,6 +45,7 @@ import com.cloud.dao.EntityManagerImpl; import com.cloud.dc.ClusterDetailsDaoImpl; import com.cloud.dc.dao.AccountVlanMapDaoImpl; import com.cloud.dc.dao.ClusterDaoImpl; +import com.cloud.dc.dao.ClusterVSMMapDaoImpl; import com.cloud.dc.dao.DataCenterDaoImpl; import com.cloud.dc.dao.DataCenterIpAddressDaoImpl; import com.cloud.dc.dao.DcDetailsDaoImpl; @@ -70,11 +71,9 @@ import com.cloud.maint.dao.AgentUpgradeDaoImpl; import com.cloud.network.ExternalLoadBalancerUsageManagerImpl; import com.cloud.network.NetworkManagerImpl; import com.cloud.network.StorageNetworkManagerImpl; +import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; import com.cloud.network.dao.ExternalFirewallDeviceDaoImpl; import com.cloud.network.dao.ExternalLoadBalancerDeviceDaoImpl; -import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; -import com.cloud.dc.dao.ClusterVSMMapDaoImpl; -import com.cloud.network.dao.PortProfileDaoImpl; import com.cloud.network.dao.FirewallRulesCidrsDaoImpl; import com.cloud.network.dao.FirewallRulesDaoImpl; import com.cloud.network.dao.IPAddressDaoImpl; @@ -91,16 +90,17 @@ import com.cloud.network.dao.NetworkServiceMapDaoImpl; import com.cloud.network.dao.PhysicalNetworkDaoImpl; import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl; import com.cloud.network.dao.PhysicalNetworkTrafficTypeDaoImpl; +import com.cloud.network.dao.PortProfileDaoImpl; import com.cloud.network.dao.RemoteAccessVpnDaoImpl; import com.cloud.network.dao.VirtualRouterProviderDaoImpl; import com.cloud.network.dao.VpnUserDaoImpl; +import com.cloud.network.element.CiscoNexusVSMElement; +import com.cloud.network.element.CiscoNexusVSMElementService; import com.cloud.network.element.F5ExternalLoadBalancerElement; import com.cloud.network.element.F5ExternalLoadBalancerElementService; import com.cloud.network.element.JuniperSRXExternalFirewallElement; import com.cloud.network.element.JuniperSRXFirewallElementService; import com.cloud.network.element.NetscalerElement; -import com.cloud.network.element.CiscoNexusVSMElement; -import com.cloud.network.element.CiscoNexusVSMElementService; import com.cloud.network.element.NetscalerLoadBalancerElementService; import com.cloud.network.element.VirtualRouterElement; import com.cloud.network.element.VirtualRouterElementService; @@ -121,6 +121,10 @@ import com.cloud.network.security.dao.SecurityGroupRulesDaoImpl; import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl; import com.cloud.network.security.dao.SecurityGroupWorkDaoImpl; import com.cloud.network.security.dao.VmRulesetLogDaoImpl; +import com.cloud.network.vpc.VpcManagerImpl; +import com.cloud.network.vpc.Dao.VpcDaoImpl; +import com.cloud.network.vpc.Dao.VpcOfferingDaoImpl; +import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDaoImpl; import com.cloud.network.vpn.RemoteAccessVpnManagerImpl; import com.cloud.offerings.dao.NetworkOfferingDaoImpl; import com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl; @@ -327,6 +331,9 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("NetworkServiceMapDao", NetworkServiceMapDaoImpl.class); addDao("StorageNetworkIpAddressDao", StorageNetworkIpAddressDaoImpl.class); addDao("StorageNetworkIpRangeDao", StorageNetworkIpRangeDaoImpl.class); + addDao("VpcDao", VpcDaoImpl.class); + addDao("VpcOfferingDao", VpcOfferingDaoImpl.class); + addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class); } @Override @@ -383,6 +390,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addManager("StorageNetworkManager", StorageNetworkManagerImpl.class); addManager("ExternalLoadBalancerUsageManager", ExternalLoadBalancerUsageManagerImpl.class); addManager("HA Manager", HighAvailabilityManagerImpl.class); + addManager("VPC Manager", VpcManagerImpl.class); } @Override diff --git a/server/src/com/cloud/network/IPAddressVO.java b/server/src/com/cloud/network/IPAddressVO.java index 9ed071f774d..2b7d084d552 100644 --- a/server/src/com/cloud/network/IPAddressVO.java +++ b/server/src/com/cloud/network/IPAddressVO.java @@ -28,6 +28,7 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import com.cloud.api.Identity; +import com.cloud.network.IpAddress; import com.cloud.utils.net.Ip; /** diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c0160eed9a5..5b24cb17d44 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1245,29 +1245,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO offering = null; if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, - null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, + true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, - null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, + defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", - TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, + null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, - true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, + Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -1295,8 +1295,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag serviceCapabilityMap.put(Service.StaticNat, eip); if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, - true, Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, + Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true); offering.setState(NetworkOffering.State.Enabled); offering.setDedicatedLB(false); _networkOfferingDao.update(offering.getId(), offering); @@ -1914,7 +1914,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); } - + for (NetworkElement element : _networkElements) { if (s_logger.isDebugEnabled()) { s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); @@ -6462,4 +6462,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return null; } + + @Override + public List listNetworksByVpc(long vpcId) { + return _networksDao.listByVpc(vpcId); + } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 4dae61a7871..f4121322825 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -75,6 +75,9 @@ public class NetworkVO implements Network, Identity { @Column(name="network_offering_id") long networkOfferingId; + + @Column(name="vpc_id") + long vpcId; @Column(name="physical_network_id") Long physicalNetworkId; @@ -473,4 +476,9 @@ public class NetworkVO implements Network, Identity { public boolean getSpecifyIpRanges() { return specifyIpRanges; } + + @Override + public long getVpcId() { + return vpcId; + } } diff --git a/server/src/com/cloud/network/dao/NetworkDao.java b/server/src/com/cloud/network/dao/NetworkDao.java index df74f238409..299f5ee8a26 100644 --- a/server/src/com/cloud/network/dao/NetworkDao.java +++ b/server/src/com/cloud/network/dao/NetworkDao.java @@ -70,8 +70,6 @@ public interface NetworkDao extends GenericDao { void addDomainToNetwork(long networkId, long domainId, Boolean subdomainAccess); - Long getNetworkCountByOfferingId(long offeringId); - List listByPhysicalNetwork(long physicalNetworkId); List listSecurityGroupEnabledNetworks(); @@ -95,5 +93,9 @@ public interface NetworkDao extends GenericDao { long countNetworksUserCanCreate(long ownerId); List listSourceNATEnabledNetworks(long accountId, long dataCenterId, GuestType type); + + int getNetworkCountByVpcId(long vpcId); + + List listByVpc(long vpcId); } diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java index f907ce8116b..8fa107c8710 100644 --- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -56,7 +56,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N final SearchBuilder AccountNetworkSearch; final SearchBuilder ZoneBroadcastUriSearch; final SearchBuilder ZoneSecurityGroupSearch; - final GenericSearchBuilder CountByOfferingId; + final GenericSearchBuilder CountBy; final SearchBuilder PhysicalNetworkSearch; final SearchBuilder SecurityGroupSearch; final GenericSearchBuilder NetworksRegularUserCanCreateSearch; @@ -88,6 +88,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N AllFieldsSearch.and("related", AllFieldsSearch.entity().getRelated(), Op.EQ); AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), Op.EQ); AllFieldsSearch.and("physicalNetwork", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); + AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); AccountSearch = createSearchBuilder(); @@ -126,11 +127,12 @@ public class NetworkDaoImpl extends GenericDaoBase implements N ZoneSecurityGroupSearch.join("services", join1, ZoneSecurityGroupSearch.entity().getId(), join1.entity().getNetworkId(), JoinBuilder.JoinType.INNER); ZoneSecurityGroupSearch.done(); - CountByOfferingId = createSearchBuilder(Long.class); - CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId()); - CountByOfferingId.and("offeringId", CountByOfferingId.entity().getNetworkOfferingId(), Op.EQ); - CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL); - CountByOfferingId.done(); + CountBy = createSearchBuilder(Integer.class); + CountBy.select(null, Func.COUNT, CountBy.entity().getId()); + CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ); + CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ); + CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); + CountBy.done(); PhysicalNetworkSearch = createSearchBuilder(); PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ); @@ -363,14 +365,16 @@ public class NetworkDaoImpl extends GenericDaoBase implements N NetworkDomainVO domain = new NetworkDomainVO(networkId, domainId, subdomainAccess); _domainsDao.persist(domain); } - + + @Override - public Long getNetworkCountByOfferingId(long offeringId) { - SearchCriteria sc = CountByOfferingId.create(); - sc.setParameters("offeringId", offeringId); - List results = customSearch(sc, null); + public int getNetworkCountByVpcId(long vpcId) { + SearchCriteria sc = CountBy.create(); + sc.setParameters("vpcId", vpcId); + List results = customSearch(sc, null); return results.get(0); } + @Override public List listSecurityGroupEnabledNetworks() { @@ -458,5 +462,13 @@ public class NetworkDaoImpl extends GenericDaoBase implements N sc.setJoinParameters("services", "service", Service.SourceNat.getName()); return listBy(sc); } + + @Override + public List listByVpc(long vpcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcId", vpcId); + + return listBy(sc, null); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 052cd0f7389..5c40161ee32 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -24,7 +24,6 @@ import com.cloud.network.PublicIpAddress; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VirtualNetworkApplianceService; import com.cloud.network.VpnUser; -import com.cloud.network.Network.Provider; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; import com.cloud.user.Account; @@ -33,7 +32,6 @@ import com.cloud.uservm.UserVm; import com.cloud.utils.component.Manager; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; -import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile; /** @@ -58,35 +56,41 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA * @param routers TODO * */ - boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; - - boolean getRouterStatistics(long vmId, Map netStats, Map diskStats); - - List getRouters(long accountId, long zoneId); + boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + List routers) throws ResourceUnavailableException; + + List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + Map params, boolean isRedundant) throws InsufficientCapacityException, + ResourceUnavailableException, ConcurrentOperationException; - List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException; + boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException; - boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; - - boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; + boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException; - boolean associateIP (Network network, final List ipAddress, List routers) throws ResourceUnavailableException; + boolean associateIP (Network network, final List ipAddress, + List routers) throws ResourceUnavailableException; - boolean applyFirewallRules(Network network, final List rules, List routers) throws ResourceUnavailableException; + boolean applyFirewallRules(Network network, final List rules, + List routers) throws ResourceUnavailableException; List getRoutersForNetwork(long networkId); - String[] applyVpnUsers(Network network, List users, List routers) throws ResourceUnavailableException; + String[] applyVpnUsers(Network network, List users, List routers) + throws ResourceUnavailableException; - VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException; + VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) + throws ConcurrentOperationException, ResourceUnavailableException; String getDnsBasicZoneUpdate(); - boolean applyStaticNats(Network network, final List rules, List routers) throws ResourceUnavailableException; + boolean applyStaticNats(Network network, final List rules, List routers) + throws ResourceUnavailableException; - boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; + boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + List routers) throws ResourceUnavailableException; - boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; - - long getDefaultVirtualRouterServiceOfferingId(); + boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + List routers) throws ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index c85b3c7ca31..7a898a0de82 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -95,7 +95,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; -import com.cloud.event.dao.EventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConnectionException; @@ -132,7 +131,6 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.VpnUser; import com.cloud.network.VpnUserVO; import com.cloud.network.addr.PublicIp; -import com.cloud.network.dao.FirewallRulesCidrsDao; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; @@ -163,13 +161,11 @@ import com.cloud.resource.ResourceManager; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.GuestOSVO; -import com.cloud.storage.StorageManager; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume.Type; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VMTemplateDao; -import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -214,13 +210,13 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; -import com.cloud.vm.dao.VMInstanceDao; /** * VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances available in the Cloud Stack. */ @Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class }) -public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, VirtualMachineGuru, Listener { +public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, + VirtualMachineGuru, Listener { private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class); String _name; @@ -245,24 +241,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject UserStatisticsDao _userStatsDao = null; @Inject - VolumeDao _volsDao = null; - @Inject HostDao _hostDao = null; @Inject - EventDao _eventDao = null; - @Inject ConfigurationDao _configDao; @Inject HostPodDao _podDao = null; @Inject - VMTemplateHostDao _vmTemplateHostDao = null; - @Inject UserStatsLogDao _userStatsLogDao = null; @Inject AgentManager _agentMgr; @Inject - StorageManager _storageMgr; - @Inject AlertManager _alertMgr; @Inject AccountManager _accountMgr; @@ -273,8 +261,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject UserVmDao _userVmDao; @Inject - FirewallRulesDao _firewallRulesDao; - @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; @@ -299,14 +285,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject RemoteAccessVpnDao _vpnDao; @Inject - VMInstanceDao _instanceDao; - @Inject NicDao _nicDao; @Inject VolumeDao _volumeDao = null; @Inject - FirewallRulesCidrsDao _firewallCidrsDao; - @Inject UserVmDetailsDao _vmDetailsDao; @Inject ClusterDao _clusterDao; @@ -343,12 +325,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian ScheduledExecutorService _networkStatsUpdateExecutor; Account _systemAcct; - - @Override - public List getRouters(long accountId, long dataCenterId) { - return _routerDao.findBy(accountId, dataCenterId); - } - + @Override public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) { ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey); @@ -542,26 +519,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - @Override - public boolean getRouterStatistics(final long vmId, final Map netStats, final Map diskStats) { - final DomainRouterVO router = _routerDao.findById(vmId); - - if (router == null || router.getState() != State.Running || router.getHostId() == null) { - return true; - } - - /* - * final GetVmStatsCommand cmd = new GetVmStatsCommand(router, router.getInstanceName()); final Answer answer = - * _agentMgr.easySend(router.getHostId(), cmd); if (answer == null) { return false; } - * - * final GetVmStatsAnswer stats = (GetVmStatsAnswer)answer; - * - * netStats.putAll(stats.getNetworkStats()); diskStats.putAll(stats.getDiskStats()); - */ - - return true; - } - @Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true) public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Account caller = UserContext.current().getCaller(); @@ -908,10 +865,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Exception while trying to acquire network stats lock", e); } finally { scanLock.releaseRef(); - } - + } } - } @@ -1110,9 +1065,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - public static boolean isAdmin(short accountType) { - return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)); - } + private final int DEFAULT_PRIORITY = 100; private final int DEFAULT_DELTA = 2; @@ -1477,7 +1430,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, + public List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + Map params, boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); @@ -1489,7 +1443,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || + guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork; assert guestNetwork.getTrafficType() == TrafficType.Guest; @@ -2940,14 +2895,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - @Override - public long getDefaultVirtualRouterServiceOfferingId() { - if (_offering != null) { - return _offering.getId(); - } - return 0; - } - private String getRouterControlIp(long routerId) { String routerControlIpAddress = null; List nics = _nicDao.listByVmId(routerId); diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDao.java b/server/src/com/cloud/network/vpc/Dao/VpcDao.java new file mode 100644 index 00000000000..e95b6674de1 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcDao.java @@ -0,0 +1,29 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import com.cloud.network.vpc.VpcVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcDao extends GenericDao{ + + /** + * @param offId + * @return + */ + int getVpcCountByOfferingId(long offId); + +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java new file mode 100644 index 00000000000..4e32541e39f --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java @@ -0,0 +1,56 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import java.util.List; + +import javax.ejb.Local; + +import com.cloud.network.vpc.VpcVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = VpcDao.class) +@DB(txn = false) +public class VpcDaoImpl extends GenericDaoBase implements VpcDao{ + final GenericSearchBuilder CountByOfferingId; + + + protected VpcDaoImpl() { + super(); + + CountByOfferingId = createSearchBuilder(Integer.class); + CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId()); + CountByOfferingId.and("offeringId", CountByOfferingId.entity().getVpcOfferingId(), Op.EQ); + CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL); + CountByOfferingId.done(); + } + + + @Override + public int getVpcCountByOfferingId(long offId) { + SearchCriteria sc = CountByOfferingId.create(); + sc.setParameters("offeringId", offId); + List results = customSearch(sc, null); + return results.get(0); + } +} + diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java new file mode 100644 index 00000000000..b5c8b47933d --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java @@ -0,0 +1,30 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import com.cloud.network.vpc.VpcOfferingVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcOfferingDao extends GenericDao{ + /** + * Returns the VPC offering that matches the unique name. + * + * @param uniqueName + * name + * @return VpcOfferingVO + */ + VpcOfferingVO findByUniqueName(String uniqueName); +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java new file mode 100644 index 00000000000..0a152344c69 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java @@ -0,0 +1,68 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import javax.ejb.Local; + +import com.cloud.network.vpc.VpcOfferingVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; + +/** + * @author Alena Prokharchyk + */ +@Local(value = VpcOfferingDao.class) +@DB(txn = false) +public class VpcOfferingDaoImpl extends GenericDaoBase implements VpcOfferingDao{ + final SearchBuilder AllFieldsSearch; + + + protected VpcOfferingDaoImpl() { + super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ); + AllFieldsSearch.and("uName", AllFieldsSearch.entity().getUniqueName(), Op.EQ); + AllFieldsSearch.and("displayText", AllFieldsSearch.entity().getDisplayText(), Op.EQ); + AllFieldsSearch.done(); + + } + + @Override + @DB + public boolean remove(Long vpcOffId) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + VpcOfferingVO offering = findById(vpcOffId); + offering.setUniqueName(null); + update(vpcOffId, offering); + boolean result = super.remove(vpcOffId); + txn.commit(); + return result; + } + + + @Override + public VpcOfferingVO findByUniqueName(String uniqueName) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("uName", uniqueName); + + return findOneBy(sc); + } +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java new file mode 100644 index 00000000000..74246aef67e --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java @@ -0,0 +1,34 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import java.util.List; + +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOfferingServiceMapVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcOfferingServiceMapDao extends GenericDao{ + + List listByVpcOffId(long vpcOffId); + + /** + * @param networkOfferingId + * @param services + * @return + */ + boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service[] services); +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java new file mode 100644 index 00000000000..cbbf1d5e43e --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java @@ -0,0 +1,90 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import java.util.List; + +import javax.ejb.Local; + +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOfferingServiceMapVO; +import com.cloud.offerings.NetworkOfferingServiceMapVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +/** + * @author Alena Prokharchyk + */ +@Local(value = VpcOfferingServiceMapDao.class) +@DB(txn = false) +public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase implements VpcOfferingServiceMapDao{ + final SearchBuilder AllFieldsSearch; + final SearchBuilder MultipleServicesSearch; + + + protected VpcOfferingServiceMapDaoImpl() { + super(); + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("vpcOffId", AllFieldsSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ); + AllFieldsSearch.done(); + + + MultipleServicesSearch = createSearchBuilder(); + MultipleServicesSearch.and("vpcOffId", MultipleServicesSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN); + MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ); + MultipleServicesSearch.done(); + } + + @Override + public List listByVpcOffId(long vpcOffId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcOffId", vpcOffId); + return listBy(sc); + } + + + @Override + public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) { + SearchCriteria sc = MultipleServicesSearch.create(); + sc.setParameters("vpcOffId", networkOfferingId); + + if (services != null) { + String[] servicesStr = new String[services.length]; + + int i = 0; + for (Service service : services) { + servicesStr[i] = service.getName(); + i++; + } + + sc.setParameters("service", (Object[])servicesStr); + } + + List offeringServices = listBy(sc); + + if (services != null) { + if (offeringServices.size() == services.length) { + return true; + } + } else if (!offeringServices.isEmpty()) { + return true; + } + + return false; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java new file mode 100644 index 00000000000..a7adf9c6895 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -0,0 +1,61 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOffering.State; +import com.cloud.user.Account; + + +/** + * @author Alena Prokharchyk + */ +public interface VpcManager extends VpcService{ + + /** + * @param name + * @param displayText + * @param svcProviderMap + * @param isDefault + * @param state TODO + * @return + */ + VpcOffering createVpcOffering(String name, String displayText, Map> svcProviderMap, + boolean isDefault, State state); + + /** + * @param vpcOffId + * @param services + * @return + */ + boolean areServicesSupportedByVpcOffering(long vpcOffId, Service[] services); + + /** + * @param zoneId + * @param vpcOffId + * @param vpcOwner + * @param vpcName + * @param displayText + * @param cidr + * @return + */ + Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr); + + List getSupportedServices(); + +} diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java new file mode 100644 index 00000000000..108b4871531 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -0,0 +1,608 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.configuration.ConfigurationManager; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenter; +import com.cloud.event.ActionEvent; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.UnsupportedServiceException; +import com.cloud.network.Network; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.vpc.VpcOffering.State; +import com.cloud.network.vpc.Dao.VpcDao; +import com.cloud.network.vpc.Dao.VpcOfferingDao; +import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao; +import com.cloud.org.Grouping; +import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.user.UserContext; +import com.cloud.utils.Ternary; +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.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.net.NetUtils; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = { VpcManager.class, VpcService.class }) +public class VpcManagerImpl implements VpcManager, Manager{ + private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class); + @Inject + VpcOfferingDao _vpcOffDao; + @Inject + VpcOfferingServiceMapDao _vpcOffSvcMapDao; + @Inject + VpcDao _vpcDao; + @Inject + ConfigurationDao _configDao; + @Inject + ConfigurationManager _configMgr; + @Inject + AccountManager _accountMgr; + @Inject + NetworkDao _ntwkDao; + + String _name; + + @Override + @DB + public boolean configure(String name, Map params) throws ConfigurationException { + _name = name; + + //configure default vpc offering + Transaction txn = Transaction.currentTxn(); + txn.start(); + + if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) { + s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName); + + Map> svcProviderMap = new HashMap>(); + Set provider = new HashSet(); + provider.add(Provider.VirtualRouter); + for (Service svc : getSupportedServices()) { + svcProviderMap.put(svc, provider); + } + createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, + true, State.Enabled); + } + + txn.commit(); + + return true; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } + + @Override + public String getName() { + return _name; + } + + @Override + public Vpc createVpc(long zoneId, String name, String cidr, long ownerId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getVpcNetworks(long vpcId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public VpcOffering getVpcOffering(long vpcOffId) { + return _vpcOffDao.findById(vpcOffId); + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering") + public VpcOffering createVpcOffering(String name, String displayText, List supportedServices) { + Map> svcProviderMap = new HashMap>(); + Set defaultProviders = new HashSet(); + defaultProviders.add(Provider.VirtualRouter); + + boolean sourceNatSvc = false; + boolean firewallSvs = false; + // populate the services first + for (String serviceName : supportedServices) { + // validate if the service is supported + Service service = Network.Service.getService(serviceName); + if (service == null || service == Service.Gateway) { + throw new InvalidParameterValueException("Invalid service " + serviceName); + } + + //don't allow security group service for vpc + if (service == Service.SecurityGroup) { + throw new UnsupportedServiceException("Service " + Service.SecurityGroup.getName() + " is not supported by VPC"); + } + svcProviderMap.put(service, defaultProviders); + } + + if (!sourceNatSvc) { + s_logger.debug("Automatically adding source nat service to the list of VPC services"); + svcProviderMap.put(Service.SourceNat, defaultProviders); + } + + if (!firewallSvs) { + s_logger.debug("Automatically adding firewall service to the list of VPC services"); + svcProviderMap.put(Service.Firewall, defaultProviders); + } + + svcProviderMap.put(Service.Gateway, defaultProviders); + + return createVpcOffering(name, displayText, svcProviderMap, false, null); + } + + + @Override + @DB + public VpcOffering createVpcOffering(String name, String displayText, Map> svcProviderMap, boolean isDefault, State state) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + // create vpc offering object + VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault); + + if (state != null) { + offering.setState(state); + } + s_logger.debug("Adding vpc offering " + offering); + offering = _vpcOffDao.persist(offering); + // populate services and providers + if (svcProviderMap != null) { + for (Network.Service service : svcProviderMap.keySet()) { + Set providers = svcProviderMap.get(service); + if (providers != null && !providers.isEmpty()) { + for (Network.Provider provider : providers) { + VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider); + _vpcOffSvcMapDao.persist(offService); + s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName()); + } + } else { + throw new InvalidParameterValueException("Provider is missing for the VPC offering service " + service.getName()); + } + } + } + + + + txn.commit(); + + UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name); + return offering; + } + + + + @Override + public Vpc getVpc(long vpcId) { + return _vpcDao.findById(vpcId); + } + + @Override + public Map> getVpcOffSvcProvidersMap(long vpcOffId) { + Map> serviceProviderMap = new HashMap>(); + List map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId); + + for (VpcOfferingServiceMapVO instance : map) { + String service = instance.getService(); + Set providers; + providers = serviceProviderMap.get(service); + if (providers == null) { + providers = new HashSet(); + } + providers.add(Provider.getProvider(instance.getProvider())); + serviceProviderMap.put(Service.getService(service), providers); + } + + return serviceProviderMap; + } + + + @Override + public List listVpcOfferings(Long id, String name, String displayText, List supportedServicesStr, + Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal) { + Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, startIndex, pageSizeVal); + SearchCriteria sc = _vpcOffDao.createSearchCriteria(); + + if (keyword != null) { + SearchCriteria ssc = _vpcOffDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + + if (displayText != null) { + sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); + } + + if (isDefault != null) { + sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); + } + + if (state != null) { + sc.addAnd("state", SearchCriteria.Op.EQ, state); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + + List offerings = _vpcOffDao.search(sc, searchFilter); + + // filter by supported services + boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); + + if (listBySupportedServices) { + List supportedOfferings = new ArrayList(); + Service[] supportedServices = null; + + if (listBySupportedServices) { + supportedServices = new Service[supportedServicesStr.size()]; + int i = 0; + for (String supportedServiceStr : supportedServicesStr) { + Service service = Service.getService(supportedServiceStr); + if (service == null) { + throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); + } else { + supportedServices[i] = service; + } + i++; + } + } + + for (VpcOfferingVO offering : offerings) { + if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) { + supportedOfferings.add(offering); + } + } + + return supportedOfferings; + } else { + return offerings; + } + } + + @Override + public boolean areServicesSupportedByVpcOffering(long vpcOffId, Service... services) { + return (_vpcOffSvcMapDao.areServicesSupportedByNetworkOffering(vpcOffId, services)); + } + + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_DELETE, eventDescription = "deleting vpc offering") + public boolean deleteVpcOffering(long offId) { + UserContext.current().setEventDetails(" Id: " + offId); + + // Verify vpc offering id + VpcOfferingVO offering = _vpcOffDao.findById(offId); + if (offering == null) { + throw new InvalidParameterValueException("unable to find vpc offering " + offId); + } + + // Don't allow to delete default vpc offerings + if (offering.isDefault() == true) { + throw new InvalidParameterValueException("Default network offering can't be deleted"); + } + + // don't allow to delete vpc offering if it's in use by existing vpcs (the offering can be disabled though) + int vpcCount = _vpcDao.getVpcCountByOfferingId(offId); + if (vpcCount > 0) { + throw new InvalidParameterValueException("Can't delete vpc offering " + offId + " as its used by " + vpcCount + " vpcs. " + + "To make the network offering unavaiable, disable it"); + } + + if (_vpcOffDao.remove(offId)) { + return true; + } else { + return false; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering") + public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) { + UserContext.current().setEventDetails(" Id: " + vpcOffId); + + // Verify input parameters + VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId); + if (offeringToUpdate == null) { + throw new InvalidParameterValueException("Unable to find vpc offering " + vpcOffId); + } + + VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId); + + if (vpcOfferingName != null) { + offering.setName(vpcOfferingName); + } + + if (displayText != null) { + offering.setDisplayText(displayText); + } + + + if (state != null) { + boolean validState = false; + for (VpcOffering.State st : VpcOffering.State.values()) { + if (st.name().equalsIgnoreCase(state)) { + validState = true; + offering.setState(st); + } + } + if (!validState) { + throw new InvalidParameterValueException("Incorrect state value: " + state); + } + } + + if (_vpcOffDao.update(vpcOffId, offering)) { + s_logger.debug("Updated VPC offeirng id=" + vpcOffId); + return _vpcOffDao.findById(vpcOffId); + } else { + return null; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc") + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr) { + Account caller = UserContext.current().getCaller(); + Account owner = _accountMgr.getAccount(vpcOwnerId); + + //Verify that caller can perform actions in behalf of vpc owner + _accountMgr.checkAccess(caller, null, true, owner); + + // Validate vpc offering + VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); + if (vpcOff == null) { + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find vpc offering by specified id"); + ex.addProxyObject("vpc_offerings", vpcOffId, "vpcOfferingId"); + throw ex; + } + + //Validate zone + DataCenter zone = _configMgr.getZone(zoneId); + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { + // See DataCenterVO.java + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); + ex.addProxyObject("data_center", zone.getId(), "zoneId"); + throw ex; + } + + //validate cidr + return createVpc(zoneId, vpcOffId, owner, vpcName, displayText, cidr); + } + + @Override + public Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr) { + if (!NetUtils.isValidCIDR(cidr)) { + throw new InvalidParameterValueException("Invalid CIDR specified " + cidr); + } + + VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr); + vpc = _vpcDao.persist(vpc); + + if (vpc != null) { + s_logger.debug("Created VPC " + vpc); + } else { + s_logger.debug("Failed to create VPC"); + } + return vpc; + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") + public boolean deleteVpc(long vpcId) { + UserContext.current().setEventDetails(" Id: " + vpcId); + + // Verify vpc id + VpcVO vpc = _vpcDao.findById(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); + } + + // don't allow to delete vpc if it's in use by existing networks + int networksCount = _ntwkDao.getNetworkCountByVpcId(vpcId); + if (networksCount > 0) { + throw new InvalidParameterValueException("Can't delete VPC " + vpcId + " as its used by " + networksCount + " networks"); + } + + if (_vpcDao.remove(vpcId)) { + return true; + } else { + return false; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc") + public Vpc updateVpc(long vpcId, String vpcName, String displayText) { + UserContext.current().setEventDetails(" Id: " + vpcId); + + // Verify input parameters + VpcVO vpcToUpdate = _vpcDao.findById(vpcId); + if (vpcToUpdate == null) { + throw new InvalidParameterValueException("Unable to find vpc offering " + vpcId); + } + + VpcVO vpc = _vpcDao.createForUpdate(vpcId); + + if (vpcName != null) { + vpc.setName(vpcName); + } + + if (displayText != null) { + vpc.setDisplayText(displayText); + } + + if (_vpcDao.update(vpcId, vpc)) { + s_logger.debug("Updated VPC id=" + vpcId); + return _vpcDao.findById(vpcId); + } else { + return null; + } + } + + + @Override + public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, + String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, + Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll) { + Account caller = UserContext.current().getCaller(); + List permittedAccounts = new ArrayList(); + + Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); + _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, + listAll, false); + domainId = domainIdRecursiveListProject.first(); + isRecursive = domainIdRecursiveListProject.second(); + ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + Filter searchFilter = new Filter(VpcVO.class, "created", false, startIndex, pageSizeVal); + + SearchBuilder sb = _vpcDao.createSearchBuilder(); + _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + + sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("displayText", sb.entity().getDisplayText(), SearchCriteria.Op.LIKE); + sb.and("vpcOfferingId", sb.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); + + + // now set the SC criteria... + SearchCriteria sc = sb.create(); + _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + + if (keyword != null) { + SearchCriteria ssc = _vpcDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (vpcName != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + vpcName + "%"); + } + + if (displayText != null) { + sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (vpcOffId != null) { + sc.addAnd("vpcOfferingId", SearchCriteria.Op.EQ, vpcOffId); + } + + if (zoneId != null) { + sc.addAnd("zoneId", SearchCriteria.Op.EQ, zoneId); + } + + if (state != null) { + sc.addAnd("state", SearchCriteria.Op.EQ, state); + } + + List vpcs = _vpcDao.search(sc, searchFilter); + + // filter by supported services + boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !vpcs.isEmpty()); + + if (listBySupportedServices) { + List supportedVpcs = new ArrayList(); + Service[] supportedServices = null; + + if (listBySupportedServices) { + supportedServices = new Service[supportedServicesStr.size()]; + int i = 0; + for (String supportedServiceStr : supportedServicesStr) { + Service service = Service.getService(supportedServiceStr); + if (service == null) { + throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); + } else { + supportedServices[i] = service; + } + i++; + } + } + + for (VpcVO vpc : vpcs) { + if (areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), supportedServices)) { + supportedVpcs.add(vpc); + } + } + + return supportedVpcs; + } else { + return vpcs; + } + } + + @Override + public List getSupportedServices() { + List services = new ArrayList(); + services.add(Network.Service.Dhcp); + services.add(Network.Service.Dns); + services.add(Network.Service.UserData); + services.add(Network.Service.Firewall); + services.add(Network.Service.PortForwarding); + services.add(Network.Service.Lb); + services.add(Network.Service.SourceNat); + services.add(Network.Service.StaticNat); + services.add(Network.Service.Gateway); + services.add(Network.Service.Vpn); + return services; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java b/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java new file mode 100644 index 00000000000..ffe8533cdf9 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java @@ -0,0 +1,87 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc_offering_service_map") +public class VpcOfferingServiceMapVO { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + long id; + + @Column(name="vpc_offering_id") + long vpcOfferingId; + + @Column(name="service") + String service; + + @Column(name="provider") + String provider; + + @Column(name=GenericDao.CREATED_COLUMN) + Date created; + + public long getId() { + return id; + } + + public long getVpcOfferingId() { + return vpcOfferingId; + } + + public String getService() { + return service; + } + + public String getProvider() { + return provider; + } + + public Date getCreated() { + return created; + } + + public VpcOfferingServiceMapVO() { + } + + public VpcOfferingServiceMapVO(long vpcOfferingId, Service service, Provider provider) { + this.vpcOfferingId = vpcOfferingId; + this.service = service.getName(); + if (provider != null) { + this.provider = provider.getName(); + } + } + + public String toString() { + StringBuilder buf = new StringBuilder("[VPC Offering Service["); + return buf.append(vpcOfferingId).append("-").append(service).append("-").append(provider).append("]").toString(); + } +} diff --git a/server/src/com/cloud/network/vpc/VpcOfferingVO.java b/server/src/com/cloud/network/vpc/VpcOfferingVO.java new file mode 100644 index 00000000000..86b698e6b05 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcOfferingVO.java @@ -0,0 +1,143 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc_offerings") +public class VpcOfferingVO implements VpcOffering{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name="uuid") + private String uuid; + + @Column(name = "name") + String name; + + @Column(name = "unique_name") + String uniqueName; + + @Column(name = "display_text") + String displayText; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + State state = State.Disabled; + + @Column(name = "default") + boolean isDefault = false; + + @Column(name = GenericDao.REMOVED_COLUMN) + Date removed; + + @Column(name = GenericDao.CREATED_COLUMN) + Date created; + + public VpcOfferingVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public VpcOfferingVO(String name, String displayText) { + this.name = name; + this.displayText = displayText; + this.uniqueName = name; + this.uuid = UUID.randomUUID().toString(); + this.state = State.Disabled; + } + + public VpcOfferingVO(String name, String displayText, boolean isDefault) { + this(name, displayText); + this.isDefault = isDefault; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getUniqueName() { + return uniqueName; + } + + @Override + public String getDisplayText() { + return displayText; + } + + @Override + public State getState() { + return state; + } + + @Override + public boolean isDefault() { + return isDefault; + } + + public void setUniqueName(String uniqueName) { + this.uniqueName = uniqueName; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("[VPC Offering ["); + return buf.append(id).append("-").append(name).append("]").toString(); + } + + + public void setName(String name) { + this.name = name; + } + + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + + public void setState(State state) { + this.state = state; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java new file mode 100644 index 00000000000..65ad5c64727 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -0,0 +1,164 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.api.Identity; +import com.cloud.network.Network; +import com.cloud.network.Network.Service; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc") +public class VpcVO implements Vpc, Identity { + @Id + @Column(name="id") + long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name = "display_text") + String displayText; + + @Column(name="zone_id") + long zoneId; + + @Column(name="cidr") + private String cidr = null; + + @Column(name="domain_id") + Long domainId = null; + + @Column(name="account_id") + Long accountId = null; + + @Column(name="state") + @Enumerated(value=EnumType.STRING) + State state; + + @Column(name="vpc_offering_id") + long vpcOfferingId; + + @Column(name=GenericDao.REMOVED_COLUMN) + Date removed; + + @Column(name=GenericDao.CREATED_COLUMN) + Date created; + + public VpcVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr) { + this.zoneId = zoneId; + this.name = name; + this.displayText = displayText; + this.accountId = accountId; + this.domainId = domainId; + this.cidr = cidr; + this.uuid = UUID.randomUUID().toString(); + this.state = State.Enabled; + this.vpcOfferingId = vpcOffId; + } + + @Override + public boolean readyToUse() { + return state == State.Enabled; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + @Override + public long getZoneId() { + return zoneId; + } + + @Override + public String getCidr() { + return cidr; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public long getVpcOfferingId() { + return vpcOfferingId; + } + + public Date getRemoved() { + return removed; + } + + @Override + public String getDisplayText() { + return displayText; + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + +} diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java index 2ab4507d765..8ef8922f799 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java @@ -26,10 +26,15 @@ import com.cloud.utils.db.GenericDao; */ public interface NetworkOfferingServiceMapDao extends GenericDao { boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services); + List listByNetworkOfferingId(long networkOfferingId); + void deleteByOfferingId(long networkOfferingId); + List listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service); + boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider); + List listServicesForNetworkOffering(long networkOfferingId); } diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java index 28eed904e43..f47112c3cde 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java @@ -17,12 +17,9 @@ import java.util.List; import javax.ejb.Local; -import com.cloud.exception.UnsupportedServiceException; -import com.cloud.network.NetworkServiceMapVO; -import com.cloud.network.Network.Service; import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.offerings.NetworkOfferingServiceMapVO; -import com.cloud.offerings.NetworkOfferingVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 9a3d6712db9..47189d5331e 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -152,7 +152,6 @@ import com.cloud.storage.GuestOSVO; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; import com.cloud.storage.Storage; -import com.cloud.storage.VolumeHostVO; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.TemplateType; @@ -166,6 +165,7 @@ import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateZoneVO; import com.cloud.storage.Volume; import com.cloud.storage.Volume.Type; +import com.cloud.storage.VolumeHostVO; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSDao; diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java index ea4950ba2b0..5a65a6d13f9 100755 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java @@ -217,4 +217,22 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager { return null; } + /* (non-Javadoc) + * @see com.cloud.vm.VirtualMachineManager#checkIfCanUpgrade(com.cloud.vm.VirtualMachine, long) + */ + @Override + public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see com.cloud.vm.VirtualMachineManager#upgradeVmDb(long, long) + */ + @Override + public boolean upgradeVmDb(long vmId, long serviceOfferingId) { + // TODO Auto-generated method stub + return false; + } + } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 1d60955c8d4..cc0e34c6ea4 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -208,12 +208,14 @@ CREATE TABLE `cloud`.`networks` ( `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', `specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network provides an ability to define ip ranges', + `vpc_id` bigint unsigned COMMENT 'vpc this network belongs to', PRIMARY KEY (`id`), CONSTRAINT `fk_networks__network_offering_id` FOREIGN KEY (`network_offering_id`) REFERENCES `network_offerings`(`id`), CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`), CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), + CONSTRAINT `fk_networks__vpc_id` FOREIGN KEY(`vpc_id`) REFERENCES `vpc`(`id`), CONSTRAINT `uc_networks__uuid` UNIQUE (`uuid`), INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2125,4 +2127,54 @@ CREATE TABLE `cloud`.`port_profile` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`vpc` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) NOT NULL, + `name` varchar(255) COMMENT 'vpc name', + `display_text` varchar(255) COMMENT 'vpc display text', + `cidr` varchar(18) COMMENT 'vpc cidr', + `vpc_offering_id` bigint unsigned NOT NULL COMMENT 'vpc offering id that this vpc is created from', + `zone_id` bigint unsigned NOT NULL COMMENT 'the id of the zone this Vpc belongs to', + `state` varchar(32) NOT NULL COMMENT 'state of the VP (can be Enabled and Disabled)', + `domain_id` bigint unsigned NOT NULL COMMENT 'domain the vpc belongs to', + `account_id` bigint unsigned NOT NULL COMMENT 'owner of this vpc', + `removed` datetime COMMENT 'date removed if not null', + `created` datetime NOT NULL COMMENT 'date created', + PRIMARY KEY (`id`), + INDEX `i_vpc__removed`(`removed`), + CONSTRAINT `fk_vpc__zone_id` FOREIGN KEY `fk_vpc__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), + CONSTRAINT `fk_vpc__account_id` FOREIGN KEY `fk_vpc__account_id` (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_vpc__domain_id` FOREIGN KEY `fk_vpc__domain_id` (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`vpc_offerings` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) NOT NULL, + `unique_name` varchar(64) UNIQUE COMMENT 'unique name of the vpc offering', + `name` varchar(255) COMMENT 'vpc name', + `display_text` varchar(255) COMMENT 'display text', + `state` char(32) COMMENT 'state of the vpc offering that has Disabled value by default', + `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if vpc offering is default', + `removed` datetime COMMENT 'date removed if not null', + `created` datetime NOT NULL COMMENT 'date created', + PRIMARY KEY (`id`), + INDEX `i_vpc__removed`(`removed`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`vpc_offering_service_map` ( + `id` bigint unsigned NOT NULL auto_increment, + `vpc_offering_id` bigint unsigned NOT NULL COMMENT 'vpc_offering_id', + `service` varchar(255) NOT NULL COMMENT 'service', + `provider` varchar(255) COMMENT 'service provider', + `created` datetime COMMENT 'date created', + PRIMARY KEY (`id`), + CONSTRAINT `fk_vpc_offering_service_map__vpc_offering_id` FOREIGN KEY(`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`) ON DELETE CASCADE, + UNIQUE (`vpc_offering_id`, `service`, `provider`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + SET foreign_key_checks = 1; + diff --git a/wscript b/wscript index 4d063ad6ffe..75e79b4ae9b 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-15T19:32:03Z' +VERSION = '3.0.3.2012-05-18T01:05:37Z' APPNAME = 'cloud' import shutil,os From 492e41c462e2e20cd67ed9523373b91ca771528b Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 18 May 2012 17:23:05 -0700 Subject: [PATCH 02/64] Removed network_id reference from domain_router table as now VirtualRouter can be associated with multiple networks (VPC case). Code modifications were done accordingly to the places where this field was used. Router->Networks (one to many) are held in router_network_ref table now --- api/src/com/cloud/network/Network.java | 2 +- api/src/com/cloud/network/NetworkProfile.java | 2 +- .../com/cloud/vm/VirtualMachineProfile.java | 2 +- core/src/com/cloud/vm/DomainRouterVO.java | 17 +- .../DefaultComponentLibrary.java | 1 + server/src/com/cloud/network/NetworkVO.java | 4 +- .../cloud/network/RouterNetworkDaoImpl.java | 43 + .../com/cloud/network/RouterNetworkVO.java | 68 ++ .../network/element/VirtualRouterElement.java | 2 +- .../lb/ElasticLoadBalancerManagerImpl.java | 18 +- .../VirtualNetworkApplianceManagerImpl.java | 755 +++++++++--------- .../src/com/cloud/vm/dao/DomainRouterDao.java | 24 +- .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 112 ++- setup/db/create-schema.sql | 11 + wscript | 2 +- 15 files changed, 634 insertions(+), 429 deletions(-) create mode 100644 server/src/com/cloud/network/RouterNetworkDaoImpl.java create mode 100644 server/src/com/cloud/network/RouterNetworkVO.java diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 426f34bb488..26d2164e870 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -283,5 +283,5 @@ public interface Network extends ControlledEntity { /** * @return */ - long getVpcId(); + Long getVpcId(); } diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index 7a578d0eb5c..065529c4dfa 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -209,7 +209,7 @@ public class NetworkProfile implements Network { } @Override - public long getVpcId() { + public Long getVpcId() { return vpcId; } diff --git a/api/src/com/cloud/vm/VirtualMachineProfile.java b/api/src/com/cloud/vm/VirtualMachineProfile.java index 8f863d9032e..ea714c2d80c 100644 --- a/api/src/com/cloud/vm/VirtualMachineProfile.java +++ b/api/src/com/cloud/vm/VirtualMachineProfile.java @@ -36,7 +36,7 @@ public interface VirtualMachineProfile { public static final Param VmPassword = new Param("VmPassword"); public static final Param ControlNic = new Param("ControlNic"); - public static final Param ReProgramNetwork = new Param("RestartNetwork"); + public static final Param ReProgramGuestNetworks = new Param("RestartNetwork"); public static final Param PxeSeverType = new Param("PxeSeverType"); public static final Param HaTag = new Param("HaTag"); diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 42c14c64e1a..dcf41485904 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -44,9 +44,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { @Column(name="guest_ip_address") private String guestIpAddress; - - @Column(name="network_id") - long networkId; @Column(name="is_redundant_router") boolean isRedundantRouter; @@ -83,15 +80,14 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { long guestOSId, long domainId, long accountId, - long networkId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, - boolean haEnabled, boolean stopPending) { + boolean haEnabled, + boolean stopPending) { super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; - this.networkId = networkId; this.isRedundantRouter = isRedundantRouter; this.priority = priority; this.redundantState = redundantState; @@ -108,16 +104,15 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { long guestOSId, long domainId, long accountId, - long networkId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, - boolean stopPending, VirtualMachine.Type vmType) { + boolean stopPending, + VirtualMachine.Type vmType) { super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; - this.networkId = networkId; this.isRedundantRouter = isRedundantRouter; this.priority = priority; this.redundantState = redundantState; @@ -140,10 +135,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { public void setPublicNetmask(String publicNetmask) { this.publicNetmask = publicNetmask; } - - public long getNetworkId() { - return networkId; - } public void setGuestIpAddress(String routerIpAddress) { this.guestIpAddress = routerIpAddress; diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index d7325cc2b83..9afa3223a18 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -70,6 +70,7 @@ import com.cloud.maint.UpgradeManagerImpl; import com.cloud.maint.dao.AgentUpgradeDaoImpl; import com.cloud.network.ExternalLoadBalancerUsageManagerImpl; import com.cloud.network.NetworkManagerImpl; +import com.cloud.network.RouterNetworkDaoImpl; import com.cloud.network.StorageNetworkManagerImpl; import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; import com.cloud.network.dao.ExternalFirewallDeviceDaoImpl; diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index f4121322825..959070e3f6b 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -77,7 +77,7 @@ public class NetworkVO implements Network, Identity { long networkOfferingId; @Column(name="vpc_id") - long vpcId; + Long vpcId; @Column(name="physical_network_id") Long physicalNetworkId; @@ -478,7 +478,7 @@ public class NetworkVO implements Network, Identity { } @Override - public long getVpcId() { + public Long getVpcId() { return vpcId; } } diff --git a/server/src/com/cloud/network/RouterNetworkDaoImpl.java b/server/src/com/cloud/network/RouterNetworkDaoImpl.java new file mode 100644 index 00000000000..9cbd308733d --- /dev/null +++ b/server/src/com/cloud/network/RouterNetworkDaoImpl.java @@ -0,0 +1,43 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network; + +import java.util.List; + +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; + +/** + * @author Alena Prokharchyk + */ +public class RouterNetworkDaoImpl extends GenericDaoBase implements GenericDao{ + protected final GenericSearchBuilder RouterNetworksSearch; + + public RouterNetworkDaoImpl() { + super(); + + RouterNetworksSearch = createSearchBuilder(Long.class); + RouterNetworksSearch.selectField(RouterNetworksSearch.entity().getNetworkId()); + RouterNetworksSearch.and("routerId", RouterNetworksSearch.entity().getRouterId(), Op.EQ); + RouterNetworksSearch.done(); + } + + public List getRouterNetworks(long routerId) { + SearchCriteria sc = RouterNetworksSearch.create(); + sc.setParameters("routerId", routerId); + return customSearch(sc, null); + } +} diff --git a/server/src/com/cloud/network/RouterNetworkVO.java b/server/src/com/cloud/network/RouterNetworkVO.java new file mode 100644 index 00000000000..bcbdc940f94 --- /dev/null +++ b/server/src/com/cloud/network/RouterNetworkVO.java @@ -0,0 +1,68 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.network.Network.GuestType; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="router_network_ref") +public class RouterNetworkVO{ + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + long id; + + @Column(name="router_id") + long routerId; + + @Column(name="network_id") + long networkId; + + @Column(name="guest_type") + @Enumerated(value=EnumType.STRING) + Network.GuestType guestType; + + protected RouterNetworkVO() { + } + + public RouterNetworkVO(long routerId, long networkId, GuestType guestType) { + this.networkId = networkId; + this.routerId = routerId; + this.guestType = guestType; + } + + + public long getRouterId() { + return routerId; + } + + public long getNetworkId() { + return networkId; + } + + public Network.GuestType getGuestType() { + return guestType; + } +} diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index d69ad6f17cc..7defe1016ed 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -155,7 +155,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } Map params = new HashMap(1); - params.put(VirtualMachineProfile.Param.ReProgramNetwork, true); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), params, offering.getRedundantRouter()); diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index a5d9a39c547..6655a6e4bf5 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -224,7 +224,7 @@ public class ElasticLoadBalancerManagerImpl implements Pod pod = podId == null?null:_podDao.findById(podId); Map params = new HashMap( 1); - params.put(VirtualMachineProfile.Param.ReProgramNetwork, true); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); Account owner = _accountService.getActiveAccountByName("system", new Long(1)); DeployDestination dest = new DeployDestination(dc, pod, null, null); s_logger.debug("About to deploy ELB vm "); @@ -513,7 +513,7 @@ public class ElasticLoadBalancerManagerImpl implements } elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm); + template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm); elbVm.setRole(Role.LB); elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner); //TODO: create usage stats @@ -801,7 +801,17 @@ public class ElasticLoadBalancerManagerImpl implements @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { DomainRouterVO elbVm = profile.getVirtualMachine(); - NetworkVO network = _networkDao.findById(elbVm.getNetworkId()); + + List elbNics = profile.getNics(); + Long guestNtwkId = null; + for (NicProfile routerNic : elbNics) { + if (routerNic.getTrafficType() == TrafficType.Guest) { + guestNtwkId = routerNic.getNetworkId(); + break; + } + } + + NetworkVO guestNetwork = _networkDao.findById(guestNtwkId); DataCenter dc = dest.getDataCenter(); @@ -847,7 +857,7 @@ public class ElasticLoadBalancerManagerImpl implements controlNic = nic; } } - String domain = network.getNetworkDomain(); + String domain = guestNetwork.getNetworkDomain(); if (domain != null) { buf.append(" domain=" + domain); } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 7a898a0de82..ca0df9b5f21 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -477,41 +477,47 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian final Transaction txn = Transaction.currentTxn(); try { txn.start(); - final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString()); - if (userStats != null) { - final RebootAnswer sa = (RebootAnswer) answer; - final Long received = sa.getBytesReceived(); - long netBytes = 0; - if (received != null) { - if (received.longValue() >= userStats.getCurrentBytesReceived()) { - netBytes = received.longValue(); + //FIXME!!! - UserStats command should grab bytesSent/Received for all guest interfaces of the VR + List routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); + for (Long guestNtwkId : routerGuestNtwkIds) { + final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNtwkId, null, router.getId(), router.getType().toString()); + if (userStats != null) { + final RebootAnswer sa = (RebootAnswer) answer; + final Long received = sa.getBytesReceived(); + long netBytes = 0; + if (received != null) { + if (received.longValue() >= userStats.getCurrentBytesReceived()) { + netBytes = received.longValue(); + } else { + netBytes = userStats.getCurrentBytesReceived() + received; + } } else { - netBytes = userStats.getCurrentBytesReceived() + received; + netBytes = userStats.getCurrentBytesReceived(); } - } else { - netBytes = userStats.getCurrentBytesReceived(); - } - userStats.setCurrentBytesReceived(0); - userStats.setNetBytesReceived(userStats.getNetBytesReceived() + netBytes); + userStats.setCurrentBytesReceived(0); + userStats.setNetBytesReceived(userStats.getNetBytesReceived() + netBytes); - final Long sent = sa.getBytesSent(); + final Long sent = sa.getBytesSent(); - if (sent != null) { - if (sent.longValue() >= userStats.getCurrentBytesSent()) { - netBytes = sent.longValue(); + if (sent != null) { + if (sent.longValue() >= userStats.getCurrentBytesSent()) { + netBytes = sent.longValue(); + } else { + netBytes = userStats.getCurrentBytesSent() + sent; + } } else { - netBytes = userStats.getCurrentBytesSent() + sent; + netBytes = userStats.getCurrentBytesSent(); } + userStats.setNetBytesSent(userStats.getNetBytesSent() + netBytes); + userStats.setCurrentBytesSent(0); + _userStatsDao.update(userStats.getId(), userStats); + s_logger.debug("Successfully updated user statistics as a part of domR " + router + " reboot/stop"); } else { - netBytes = userStats.getCurrentBytesSent(); + s_logger.warn("User stats were not created for account " + router.getAccountId() + " and dc " + router.getDataCenterIdToDeployIn()); } - userStats.setNetBytesSent(userStats.getNetBytesSent() + netBytes); - userStats.setCurrentBytesSent(0); - _userStatsDao.update(userStats.getId(), userStats); - s_logger.debug("Successfully updated user statistics as a part of domR " + router + " reboot/stop"); - } else { - s_logger.warn("User stats were not created for account " + router.getAccountId() + " and dc " + router.getDataCenterIdToDeployIn()); } + txn.commit(); } catch (final Exception e) { txn.rollback(); @@ -749,66 +755,73 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (DomainRouterVO router : routers) { String privateIP = router.getPrivateIpAddress(); + if (privateIP != null) { - final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName()); - UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString()); - NetworkUsageAnswer answer = null; - try { - answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd); - } catch (Exception e) { - s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId(), e); - continue; - } + List routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); - if (answer != null) { - if (!answer.getResult()) { - s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId() + "; details: " + answer.getDetails()); + for (Long guestNtwkId : routerGuestNtwkIds) { + final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName()); + UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(), + router.getDataCenterIdToDeployIn(), guestNtwkId, null, router.getId(), router.getType().toString()); + NetworkUsageAnswer answer = null; + try { + answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd); + } catch (Exception e) { + s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId(), e); continue; } - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) { - s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics"); + + if (answer != null) { + if (!answer.getResult()) { + s_logger.warn("Error while collecting network stats from router: "+router.getInstanceName()+" from host: "+router.getHostId() + "; details: " + answer.getDetails()); continue; } - txn.start(); - UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), router.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - s_logger.warn("unable to find stats for account: " + router.getAccountId()); - continue; - } - - if(previousStats != null - && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){ - s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent()); - continue; - } - - if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesReceived() - + " Stored: " + stats.getCurrentBytesReceived()); + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) { + s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics"); + continue; } - stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); - } - stats.setCurrentBytesReceived(answer.getBytesReceived()); - if (stats.getCurrentBytesSent() > answer.getBytesSent()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesSent() - + " Stored: " + stats.getCurrentBytesSent()); + txn.start(); + UserStatisticsVO stats = _statsDao.lock(router.getAccountId(), + router.getDataCenterIdToDeployIn(), guestNtwkId, null, router.getId(), router.getType().toString()); + if (stats == null) { + s_logger.warn("unable to find stats for account: " + router.getAccountId()); + continue; } - stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent()); + + if(previousStats != null + && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){ + s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent()); + continue; + } + + if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesReceived() + + " Stored: " + stats.getCurrentBytesReceived()); + } + stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); + } + stats.setCurrentBytesReceived(answer.getBytesReceived()); + if (stats.getCurrentBytesSent() > answer.getBytesSent()) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesSent() + + " Stored: " + stats.getCurrentBytesSent()); + } + stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent()); + } + stats.setCurrentBytesSent(answer.getBytesSent()); + _statsDao.update(stats.getId(), stats); + txn.commit(); + } catch (Exception e) { + txn.rollback(); + s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent()); + } finally { + txn.close(); } - stats.setCurrentBytesSent(answer.getBytesSent()); - _statsDao.update(stats.getId(), stats); - txn.commit(); - } catch (Exception e) { - txn.rollback(); - s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent()); - } finally { - txn.close(); } - } + } } } } catch (Exception e) { @@ -993,36 +1006,40 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (!router.getIsRedundantRouter()) { continue; } - long networkId = router.getNetworkId(); - if (checkedNetwork.contains(networkId)) { - continue; - } - checkedNetwork.add(networkId); - List checkingRouters = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER); - if (checkingRouters.size() != 2) { - continue; - } - DomainRouterVO masterRouter = null; - DomainRouterVO backupRouter = null; - for (DomainRouterVO r : checkingRouters) { - if (r.getRedundantState() == RedundantState.MASTER) { - if (masterRouter == null) { - masterRouter = r; - } else { - //Duplicate master! We give up, until the admin fix duplicate MASTER issue - break; - } - } else if (r.getRedundantState() == RedundantState.BACKUP) { - if (backupRouter == null) { - backupRouter = r; - } else { - break; + + List routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); + + for (Long routerGuestNtwkId : routerGuestNtwkIds) { + if (checkedNetwork.contains(routerGuestNtwkId)) { + continue; + } + checkedNetwork.add(routerGuestNtwkId); + List checkingRouters = _routerDao.listByNetworkAndRole(routerGuestNtwkId, Role.VIRTUAL_ROUTER); + if (checkingRouters.size() != 2) { + continue; + } + DomainRouterVO masterRouter = null; + DomainRouterVO backupRouter = null; + for (DomainRouterVO r : checkingRouters) { + if (r.getRedundantState() == RedundantState.MASTER) { + if (masterRouter == null) { + masterRouter = r; + } else { + //Duplicate master! We give up, until the admin fix duplicate MASTER issue + break; + } + } else if (r.getRedundantState() == RedundantState.BACKUP) { + if (backupRouter == null) { + backupRouter = r; + } else { + break; + } } } - } - if (masterRouter != null && backupRouter != null) { - if (getRealPriority(masterRouter) - DEFAULT_DELTA + 1 != getRealPriority(backupRouter) || backupRouter.getIsPriorityBumpUp()) { - recoverRedundantNetwork(masterRouter, backupRouter); + if (masterRouter != null && backupRouter != null) { + if (getRealPriority(masterRouter) - DEFAULT_DELTA + 1 != getRealPriority(backupRouter) || backupRouter.getIsPriorityBumpUp()) { + recoverRedundantNetwork(masterRouter, backupRouter); + } } } } @@ -1031,26 +1048,30 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian private void checkDuplicateMaster(List routers) { Map networkRouterMaps = new HashMap(); for (DomainRouterVO router : routers) { - if (router.getRedundantState() == RedundantState.MASTER) { - if (networkRouterMaps.containsKey(router.getNetworkId())) { - DomainRouterVO dupRouter = networkRouterMaps.get(router.getNetworkId()); - String title = "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName(); - String context = "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " - + dupRouter.getHostName() + ", id: " + router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. "; + List routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); + + for (Long routerGuestNtwkId : routerGuestNtwkIds) { + if (router.getRedundantState() == RedundantState.MASTER) { + if (networkRouterMaps.containsKey(routerGuestNtwkId)) { + DomainRouterVO dupRouter = networkRouterMaps.get(routerGuestNtwkId); + String title = "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName(); + String context = "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " + + dupRouter.getHostName() + ", id: " + router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. "; - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterIdToDeployIn(), router.getPodIdToDeployIn(), title, context); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterIdToDeployIn(), dupRouter.getPodIdToDeployIn(), title, context); - } else { - networkRouterMaps.put(router.getNetworkId(), router); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterIdToDeployIn(), router.getPodIdToDeployIn(), title, context); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterIdToDeployIn(), dupRouter.getPodIdToDeployIn(), title, context); + } else { + networkRouterMaps.put(routerGuestNtwkId, router); + } } - } + } } } @Override public void run() { try { - final List routers = _routerDao.listVirtualByHostId(null); + final List routers = _routerDao.listIsolatedByHostId(null); s_logger.debug("Found " + routers.size() + " routers. "); updateRoutersRedundantState(routers); @@ -1321,7 +1342,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, offerHA, false); + template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, offerHA, false); router.setRole(Role.VIRTUAL_ROUTER); router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); } catch (InsufficientCapacityException ex) { @@ -1477,93 +1498,44 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, + ReservationContext context) { + DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); + //1) Set router details DomainRouterVO router = profile.getVirtualMachine(); Map details = _vmDetailsDao.findDetails(router.getId()); router.setDetails(details); - NetworkVO network = _networkDao.findById(router.getNetworkId()); - - String type = null; - String dhcpRange = null; - String rpFilter = " "; - DataCenter dc = dest.getDataCenter(); - DataCenterVO dcVO = _dcDao.findById(dc.getId()); - _dcDao.loadDetails(dcVO); - - if (dc.getNetworkType() == NetworkType.Advanced) { - String cidr = network.getCidr(); - if (cidr != null) { - dhcpRange = NetUtils.getDhcpRange(cidr); - } - } - - String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key()); - if (rpValue != null && rpValue.equalsIgnoreCase("true")) { - _disable_rp_filter = true; - }else - { - _disable_rp_filter = false; - } - - boolean publicNetwork = false; - if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VirtualRouter)) { - publicNetwork = true; - } - if (!publicNetwork) { - type = "dhcpsrvr"; - } else { - type = "router"; - if (_disable_rp_filter) { - rpFilter=" disable_rp_filter=true"; - } - } - + + //2) Prepare boot loader elements related with Public/Control networks + StringBuilder buf = profile.getBootArgsBuilder(); - buf.append(" template=domP type=" + type+rpFilter); + buf.append(" template=domP"); buf.append(" name=").append(profile.getHostName()); if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); } - boolean isRedundant = router.getIsRedundantRouter(); - if (isRedundant) { - buf.append(" redundant_router=1"); - List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - try { - int priority = getUpdatedPriority(network, routers, router); - router.setPriority(priority); - } catch (InsufficientVirtualNetworkCapcityException e) { - s_logger.error("Failed to get update priority!", e); - throw new CloudRuntimeException("Failed to get update priority!"); - } - } NicProfile controlNic = null; String defaultDns1 = null; String defaultDns2 = null; - + for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); + if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getGateway()); defaultDns1 = nic.getDns1(); defaultDns2 = nic.getDns2(); + } - if (dc.getNetworkType() == NetworkType.Basic) { - long cidrSize = NetUtils.getCidrSize(nic.getNetmask()); - String cidr = NetUtils.getCidrSubNet(nic.getGateway(), cidrSize); - if (cidr != null) { - dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); - } - } - } if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); } else if (nic.getTrafficType() == TrafficType.Control) { - + controlNic = nic; // DOMR control command is sent over management server in VMware if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { if (s_logger.isInfoEnabled()) { @@ -1589,46 +1561,124 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" sshonguest=true"); } } - - controlNic = nic; - } else if (nic.getTrafficType() == TrafficType.Guest && isRedundant) { - Network net = _networkMgr.getNetwork(nic.getNetworkId()); - buf.append(" guestgw=").append(net.getGateway()); - String brd = NetUtils.long2Ip(NetUtils.ip2Long(nic.getIp4Address()) | ~NetUtils.ip2Long(nic.getNetmask())); - buf.append(" guestbrd=").append(brd); - buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(nic.getNetmask())); - buf.append(" router_pr=").append(router.getPriority()); + } else if (nic.getTrafficType() == TrafficType.Guest) { + //build bootloader parameter for the guest + createGuestBootLoadArgs(profile, nic, defaultDns1, defaultDns2); } } - - if (dhcpRange != null) { - buf.append(" dhcprange=" + dhcpRange); + + if (controlNic == null) { + throw new CloudRuntimeException("Didn't start a control port"); } - String domain = network.getNetworkDomain(); - if (domain != null) { - buf.append(" domain=" + domain); - } - String domain_suffix = dcVO.getDetail(ZoneConfig.DnsSearchOrder.getName()); + + + String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName()); if (domain_suffix != null) { buf.append(" dnssearchorder=").append(domain_suffix); } -// if (!network.isDefault() && network.getGuestType() == Network.GuestType.Shared) { -// buf.append(" defaultroute=false"); -// -// String virtualNetworkElementNicIP = _networkMgr.getIpOfNetworkElementInVirtualNetwork(network.getAccountId(), network.getDataCenterId()); -// if (network.getGuestType() != Network.GuestType.Shared && virtualNetworkElementNicIP != null) { -// defaultDns1 = virtualNetworkElementNicIP; -// } else { -// s_logger.debug("No Virtual network found for account id=" + network.getAccountId() + " so setting dns to the dns of the network id=" + network.getId()); -// } -// } else { -// buf.append(" defaultroute=true"); -// } + if (profile.getHypervisorType() == HypervisorType.VMware) { + buf.append(" extra_pubnics=" + _routerExtraPublicNics); + } + + - boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VirtualRouter); - boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VirtualRouter); - /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response to return DNS server rather than + if (s_logger.isDebugEnabled()) { + s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + } + + return true; + } + + protected void createGuestBootLoadArgs(VirtualMachineProfile profile, NicProfile nic, + String defaultDns1, String defaultDns2) { + long guestNetworkId = nic.getNetworkId(); + NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + DomainRouterVO router = profile.getVirtualMachine(); + String type = null; + String dhcpRange = null; + String rpFilter = " "; + DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); + + if (dc.getNetworkType() == NetworkType.Advanced) { + String cidr = guestNetwork.getCidr(); + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); + } + } + + String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key()); + if (rpValue != null && rpValue.equalsIgnoreCase("true")) { + _disable_rp_filter = true; + }else { + _disable_rp_filter = false; + } + + boolean publicNetwork = false; + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { + publicNetwork = true; + } + + if (!publicNetwork) { + type = "dhcpsrvr"; + } else { + type = "router"; + if (_disable_rp_filter) { + rpFilter=" disable_rp_filter=true"; + } + } + + StringBuilder buf = profile.getBootArgsBuilder(); + buf.append(" type=" + type + rpFilter); + + boolean isRedundant = router.getIsRedundantRouter(); + if (isRedundant) { + buf.append(" redundant_router=1"); + List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); + try { + int priority = getUpdatedPriority(guestNetwork, routers, router); + router.setPriority(priority); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + } + + if (nic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { + long cidrSize = NetUtils.getCidrSize(nic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(nic.getGateway(), cidrSize); + if (cidr != null) { + dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); + } + } + + if (dhcpRange != null) { + buf.append(" dhcprange=" + dhcpRange); + } + + if (isRedundant) { + Network net = _networkMgr.getNetwork(nic.getNetworkId()); + buf.append(" guestgw=").append(net.getGateway()); + String brd = NetUtils.long2Ip(NetUtils.ip2Long(nic.getIp4Address()) | ~NetUtils.ip2Long(nic.getNetmask())); + buf.append(" guestbrd=").append(brd); + buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(nic.getNetmask())); + buf.append(" router_pr=").append(router.getPriority()); + } + + String domain = guestNetwork.getNetworkDomain(); + if (domain != null) { + buf.append(" domain=" + domain); + } + + boolean dnsProvided = false; + boolean dhcpProvided = false; + if (nic.getTrafficType() == TrafficType.Guest) { + //FiXME - for multiple guest network case this should be set individually + dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); + } + /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response + * to return DNS server rather than * virtual router itself. */ if (dnsProvided || dhcpProvided) { buf.append(" dns1=").append(defaultDns1); @@ -1647,20 +1697,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" useextdns=true"); } } - - if(profile.getHypervisorType() == HypervisorType.VMware) { - buf.append(" extra_pubnics=" + _routerExtraPublicNics); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); - } - - if (controlNic == null) { - throw new CloudRuntimeException("Didn't start a control port"); - } - - return true; } @Override @@ -1726,9 +1762,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIp4Address(), router.getHostName(), "create")); // restart network if restartNetwork = false is not specified in profile parameters - boolean reprogramNetwork = true; - if (profile.getParameter(Param.ReProgramNetwork) != null && (Boolean) profile.getParameter(Param.ReProgramNetwork) == false) { - reprogramNetwork = false; + boolean reprogramGuestNtwks = true; + if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) { + reprogramGuestNtwks = false; } VirtualRouterProvider vrProvider = _vrProviderDao.findById(router.getElementId()); @@ -1739,137 +1775,140 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (provider == null) { throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString()); } + + List routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); + for (Long guestNetworkId : routerGuestNtwkIds) { + if (reprogramGuestNtwks) { + s_logger.debug("Resending ipAssoc, port forwarding, load balancing rules as a part of Virtual router start"); + long ownerId = router.getAccountId(); + long zoneId = router.getDataCenterIdToDeployIn(); - if (reprogramNetwork) { - s_logger.debug("Resending ipAssoc, port forwarding, load balancing rules as a part of Virtual router start"); - long networkId = router.getNetworkId(); - long ownerId = router.getAccountId(); - long zoneId = router.getDataCenterIdToDeployIn(); - - final List userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null, networkId); - List allPublicIps = new ArrayList(); - if (userIps != null && !userIps.isEmpty()) { - for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); - allPublicIps.add(publicIp); + final List userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null, guestNetworkId); + List allPublicIps = new ArrayList(); + if (userIps != null && !userIps.isEmpty()) { + for (IPAddressVO userIp : userIps) { + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); + allPublicIps.add(publicIp); + } } - } - - //Get public Ips that should be handled by router - Network network = _networkDao.findById(networkId); - Map> ipToServices = _networkMgr.getIpToServices(allPublicIps, false, false); - Map> providerToIpList = _networkMgr.getProviderToIpList(network, ipToServices); - // Only cover virtual router for now, if ELB use it this need to be modified - ArrayList publicIps = providerToIpList.get(Provider.VirtualRouter); + + //Get public Ips that should be handled by router + Network network = _networkDao.findById(guestNetworkId); + Map> ipToServices = _networkMgr.getIpToServices(allPublicIps, false, false); + Map> providerToIpList = _networkMgr.getProviderToIpList(network, ipToServices); + // Only cover virtual router for now, if ELB use it this need to be modified + ArrayList publicIps = providerToIpList.get(Provider.VirtualRouter); - s_logger.debug("Found " + publicIps.size() + " ip(s) to apply as a part of domR " + router + " start."); + s_logger.debug("Found " + publicIps.size() + " ip(s) to apply as a part of domR " + router + " start."); - if (!publicIps.isEmpty()) { + if (!publicIps.isEmpty()) { - List vpns = new ArrayList(); - List pfRules = new ArrayList(); - List staticNatFirewallRules = new ArrayList(); - List staticNats = new ArrayList(); - List firewallRules = new ArrayList(); + List vpns = new ArrayList(); + List pfRules = new ArrayList(); + List staticNatFirewallRules = new ArrayList(); + List staticNats = new ArrayList(); + List firewallRules = new ArrayList(); - // Re-apply public ip addresses - should come before PF/LB/VPN - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.Firewall, provider)) { - createAssociateIPCommands(router, publicIps, cmds, 0); - } - - //Get information about all the rules (StaticNats and StaticNatRules; PFVPN to reapply on domR start) - for (PublicIp ip : publicIps) { - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.PortForwarding, provider)) { - pfRules.addAll(_pfRulesDao.listForApplication(ip.getId())); - } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.StaticNat, provider)) { - staticNatFirewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.StaticNat)); - } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.Firewall, provider)) { - firewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.Firewall)); + // Re-apply public ip addresses - should come before PF/LB/VPN + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.Firewall, provider)) { + createAssociateIPCommands(router, publicIps, cmds, 0); } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.Vpn, provider)) { - RemoteAccessVpn vpn = _vpnDao.findById(ip.getId()); - if (vpn != null) { - vpns.add(vpn); + //Get information about all the rules (StaticNats and StaticNatRules; PFVPN to reapply on domR start) + for (PublicIp ip : publicIps) { + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.PortForwarding, provider)) { + pfRules.addAll(_pfRulesDao.listForApplication(ip.getId())); + } + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.StaticNat, provider)) { + staticNatFirewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.StaticNat)); + } + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.Firewall, provider)) { + firewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.Firewall)); + } + + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.Vpn, provider)) { + RemoteAccessVpn vpn = _vpnDao.findById(ip.getId()); + if (vpn != null) { + vpns.add(vpn); + } + } + + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.StaticNat, provider)) { + if (ip.isOneToOneNat()) { + String dstIp = _networkMgr.getIpInNetwork(ip.getAssociatedWithVmId(), guestNetworkId); + StaticNatImpl staticNat = new StaticNatImpl(ip.getAccountId(), ip.getDomainId(), guestNetworkId, ip.getId(), dstIp, false); + staticNats.add(staticNat); + } } } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.StaticNat, provider)) { - if (ip.isOneToOneNat()) { - String dstIp = _networkMgr.getIpInNetwork(ip.getAssociatedWithVmId(), networkId); - StaticNatImpl staticNat = new StaticNatImpl(ip.getAccountId(), ip.getDomainId(), networkId, ip.getId(), dstIp, false); - staticNats.add(staticNat); + //Re-apply static nats + s_logger.debug("Found " + staticNats.size() + " static nat(s) to apply as a part of domR " + router + " start."); + if (!staticNats.isEmpty()) { + createApplyStaticNatCommands(staticNats, router, cmds); + } + + //Re-apply firewall rules + s_logger.debug("Found " + staticNats.size() + " firewall rule(s) to apply as a part of domR " + router + " start."); + if (!firewallRules.isEmpty()) { + createFirewallRulesCommands(firewallRules, router, cmds); + } + + // Re-apply port forwarding rules + s_logger.debug("Found " + pfRules.size() + " port forwarding rule(s) to apply as a part of domR " + router + " start."); + if (!pfRules.isEmpty()) { + createApplyPortForwardingRulesCommands(pfRules, router, cmds); + } + + // Re-apply static nat rules + s_logger.debug("Found " + staticNatFirewallRules.size() + " static nat rule(s) to apply as a part of domR " + router + " start."); + if (!staticNatFirewallRules.isEmpty()) { + List staticNatRules = new ArrayList(); + for (FirewallRule rule : staticNatFirewallRules) { + staticNatRules.add(_rulesMgr.buildStaticNatRule(rule, false)); + } + createApplyStaticNatRulesCommands(staticNatRules, router, cmds); + } + + // Re-apply vpn rules + s_logger.debug("Found " + vpns.size() + " vpn(s) to apply as a part of domR " + router + " start."); + if (!vpns.isEmpty()) { + for (RemoteAccessVpn vpn : vpns) { + createApplyVpnCommands(vpn, router, cmds); } } - } - //Re-apply static nats - s_logger.debug("Found " + staticNats.size() + " static nat(s) to apply as a part of domR " + router + " start."); - if (!staticNats.isEmpty()) { - createApplyStaticNatCommands(staticNats, router, cmds); - } - - //Re-apply firewall rules - s_logger.debug("Found " + staticNats.size() + " firewall rule(s) to apply as a part of domR " + router + " start."); - if (!firewallRules.isEmpty()) { - createFirewallRulesCommands(firewallRules, router, cmds); - } - - // Re-apply port forwarding rules - s_logger.debug("Found " + pfRules.size() + " port forwarding rule(s) to apply as a part of domR " + router + " start."); - if (!pfRules.isEmpty()) { - createApplyPortForwardingRulesCommands(pfRules, router, cmds); - } - - // Re-apply static nat rules - s_logger.debug("Found " + staticNatFirewallRules.size() + " static nat rule(s) to apply as a part of domR " + router + " start."); - if (!staticNatFirewallRules.isEmpty()) { - List staticNatRules = new ArrayList(); - for (FirewallRule rule : staticNatFirewallRules) { - staticNatRules.add(_rulesMgr.buildStaticNatRule(rule, false)); + List lbs = _loadBalancerDao.listByNetworkId(guestNetworkId); + List lbRules = new ArrayList(); + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.Lb, provider)) { + // Re-apply load balancing rules + for (LoadBalancerVO lb : lbs) { + List dstList = _lbMgr.getExistingDestinations(lb.getId()); + List policyList = _lbMgr.getStickinessPolicies(lb.getId()); + LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList); + lbRules.add(loadBalancing); + } } - createApplyStaticNatRulesCommands(staticNatRules, router, cmds); - } - // Re-apply vpn rules - s_logger.debug("Found " + vpns.size() + " vpn(s) to apply as a part of domR " + router + " start."); - if (!vpns.isEmpty()) { - for (RemoteAccessVpn vpn : vpns) { - createApplyVpnCommands(vpn, router, cmds); + s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of domR " + router + " start."); + if (!lbRules.isEmpty()) { + createApplyLoadBalancingRulesCommands(lbRules, router, cmds); } } - - List lbs = _loadBalancerDao.listByNetworkId(networkId); - List lbRules = new ArrayList(); - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.Lb, provider)) { - // Re-apply load balancing rules - for (LoadBalancerVO lb : lbs) { - List dstList = _lbMgr.getExistingDestinations(lb.getId()); - List policyList = _lbMgr.getStickinessPolicies(lb.getId()); - LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList); - lbRules.add(loadBalancing); - } - } - - s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of domR " + router + " start."); - if (!lbRules.isEmpty()) { - createApplyLoadBalancingRulesCommands(lbRules, router, cmds); - } + } - } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.Dhcp, provider)) { - // Resend dhcp - s_logger.debug("Reapplying dhcp entries as a part of domR " + router + " start..."); - createDhcpEntryCommandsForVMs(router, cmds); - } + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.Dhcp, provider)) { + // Resend dhcp + s_logger.debug("Reapplying dhcp entries as a part of domR " + router + " start..."); + createDhcpEntryCommandsForVMs(router, cmds, guestNetworkId); + } - if (_networkMgr.isProviderSupportServiceInNetwork(router.getNetworkId(), Service.UserData, provider)) { - // Resend user data - s_logger.debug("Reapplying vm data (userData and metaData) entries as a part of domR " + router + " start..."); - createVmDataCommandForVMs(router, cmds); + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetworkId, Service.UserData, provider)) { + // Resend user data + s_logger.debug("Reapplying vm data (userData and metaData) entries as a part of domR " + router + " start..."); + createVmDataCommandForVMs(router, cmds, guestNetworkId); + } } return true; @@ -1878,6 +1917,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { DomainRouterVO router = profile.getVirtualMachine(); + + //Get guest nic info + List routerNics = profile.getNics(); + Network guestNetwork = null; + for (NicProfile routerNic : routerNics) { + if (routerNic.getTrafficType() == TrafficType.Guest) { + guestNetwork = _networkMgr.getNetwork(routerNic.getNetworkId()); + break; + } + } + boolean result = true; Answer answer = cmds.getAnswer("checkSsh"); @@ -1902,7 +1952,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } else { router.setTemplateVersion(versionAnswer.getTemplateVersion()); router.setScriptsVersion(versionAnswer.getScriptsVersion()); - router = _routerDao.persist(router); + router = _routerDao.persist(router, guestNetwork); } } @@ -2113,15 +2163,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public DomainRouterVO persist(DomainRouterVO router) { DomainRouterVO virtualRouter = _routerDao.persist(router); - // Creating stats entry for router - UserStatisticsVO stats = _userStatsDao.findBy(virtualRouter.getAccountId(), virtualRouter.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating user statistics for the account: " + virtualRouter.getAccountId() + " Router Id: " + router.getId()); - } - stats = new UserStatisticsVO(virtualRouter.getAccountId(), virtualRouter.getDataCenterIdToDeployIn(), null, router.getId(), router.getType().toString(), router.getNetworkId()); - _userStatsDao.persist(stats); - } return virtualRouter; } @@ -2237,9 +2278,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); Map params = new HashMap(); if (reprogramNetwork) { - params.put(Param.ReProgramNetwork, true); + params.put(Param.ReProgramGuestNetworks, true); } else { - params.put(Param.ReProgramNetwork, false); + params.put(Param.ReProgramGuestNetworks, false); } VirtualRouter virtualRouter = startVirtualRouter(router, user, caller, params); if(virtualRouter == null){ @@ -2460,9 +2501,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } - private void createVmDataCommandForVMs(DomainRouterVO router, Commands cmds) { - long networkId = router.getNetworkId(); - List vms = _userVmDao.listByNetworkIdAndStates(networkId, State.Running, State.Migrating, State.Stopping); + private void createVmDataCommandForVMs(DomainRouterVO router, Commands cmds, long guestNetworkId) { + List vms = _userVmDao.listByNetworkIdAndStates(guestNetworkId, State.Running, State.Migrating, State.Stopping); DataCenterVO dc = _dcDao.findById(router.getDataCenterIdToDeployIn()); for (UserVmVO vm : vms) { boolean createVmData = true; @@ -2471,7 +2511,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } if (createVmData) { - NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId()); + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(guestNetworkId, vm.getId()); if (nic != null) { s_logger.debug("Creating user data entry for vm " + vm + " on domR " + router); createVmDataCommand(router, vm, nic, null, cmds); @@ -2503,9 +2543,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian cmds.addCommand("dhcp", dhcpCommand); } - private void createDhcpEntryCommandsForVMs(DomainRouterVO router, Commands cmds) { - long networkId = router.getNetworkId(); - List vms = _userVmDao.listByNetworkIdAndStates(networkId, State.Running, State.Migrating, State.Stopping); + private void createDhcpEntryCommandsForVMs(DomainRouterVO router, Commands cmds, long guestNetworkId) { + List vms = _userVmDao.listByNetworkIdAndStates(guestNetworkId, State.Running, State.Migrating, State.Stopping); DataCenterVO dc = _dcDao.findById(router.getDataCenterIdToDeployIn()); for (UserVmVO vm : vms) { boolean createDhcp = true; @@ -2513,7 +2552,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian createDhcp = false; } if (createDhcp) { - NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId()); + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(guestNetworkId, vm.getId()); if (nic != null) { s_logger.debug("Creating dhcp entry for vm " + vm + " on domR " + router + "."); createDhcpEntryCommand(router, vm, nic, cmds); @@ -2859,7 +2898,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { UserContext context = UserContext.current(); context.setAccountId(1); - List routers = _routerDao.listVirtualByHostId(host.getId()); + List routers = _routerDao.listIsolatedByHostId(host.getId()); for (DomainRouterVO router : routers) { if (router.isStopPending()) { State state = router.getState(); diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index af5cd32fc99..2afc5af5279 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -64,16 +64,7 @@ public interface DomainRouterDao extends GenericDao { * @param hostId id of the host. null if to get all. * @return list of DomainRouterVO */ - public List listVirtualByHostId(Long hostId); - - /** - * list virtual machine routers by host id. exclude destroyed, stopped, expunging VM, - * pass in null to get all - * virtual machine routers. - * @param hostId id of the host. null if to get all. - * @return list of DomainRouterVO - */ - public List listVirtualUpByHostId(Long hostId); + public List listIsolatedByHostId(Long hostId); /** * Find the list of domain routers for a domain @@ -101,4 +92,17 @@ public interface DomainRouterDao extends GenericDao { List listByNetworkAndRole(long networkId, Role role); List listByElementId(long elementId); + + /** + * Persists the domain router instance + creates the reference to the guest network (if not null) + * @param guestNetwork TODO + * @return + */ + DomainRouterVO persist(DomainRouterVO router, Network guestNetwork); + + /** + * @param routerId + * @return + */ + List getRouterNetworks(long routerId); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 1f28c3ad547..66ba8b65f52 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -16,15 +16,16 @@ import java.util.List; import javax.ejb.Local; -import org.apache.log4j.Logger; - import com.cloud.host.HostVO; import com.cloud.host.dao.HostDaoImpl; import com.cloud.network.Network; -import com.cloud.network.NetworkVO; -import com.cloud.network.dao.NetworkDaoImpl; +import com.cloud.network.RouterNetworkDaoImpl; +import com.cloud.network.RouterNetworkVO; import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.user.UserStatisticsVO; +import com.cloud.user.dao.UserStatisticsDaoImpl; import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; @@ -37,15 +38,16 @@ import com.cloud.vm.VirtualMachine.State; @Local(value = { DomainRouterDao.class }) public class DomainRouterDaoImpl extends GenericDaoBase implements DomainRouterDao { - private static final Logger s_logger = Logger.getLogger(DomainRouterDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected final SearchBuilder IdNetworkIdStatesSearch; protected final SearchBuilder HostUpSearch; protected final SearchBuilder StateNetworkTypeSearch; protected final SearchBuilder OutsidePodSearch; - NetworkDaoImpl _networksDao = ComponentLocator.inject(NetworkDaoImpl.class); HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class); + RouterNetworkDaoImpl _routerNetworkDao = ComponentLocator.inject(RouterNetworkDaoImpl.class); + UserStatisticsDaoImpl _userStatsDao = ComponentLocator.inject(UserStatisticsDaoImpl.class); + protected DomainRouterDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -56,37 +58,49 @@ public class DomainRouterDaoImpl extends GenericDaoBase im AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ); AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ); AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); - AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + SearchBuilder joinRouterNetwork = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork.and("networkId", joinRouterNetwork.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.join("networkRouter", joinRouterNetwork, joinRouterNetwork.entity().getRouterId(), AllFieldsSearch.entity().getId(), JoinType.INNER); AllFieldsSearch.and("podId", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ); AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ); AllFieldsSearch.done(); IdNetworkIdStatesSearch = createSearchBuilder(); IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ); - IdNetworkIdStatesSearch.and("network", IdNetworkIdStatesSearch.entity().getNetworkId(), Op.EQ); + SearchBuilder joinRouterNetwork1 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork1.and("networkId", joinRouterNetwork1.entity().getNetworkId(), Op.EQ); + IdNetworkIdStatesSearch.join("networkRouter", joinRouterNetwork1, joinRouterNetwork1.entity().getRouterId(), IdNetworkIdStatesSearch.entity().getId(), JoinType.INNER); IdNetworkIdStatesSearch.and("states", IdNetworkIdStatesSearch.entity().getState(), Op.IN); IdNetworkIdStatesSearch.done(); HostUpSearch = createSearchBuilder(); HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ); HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.NIN); - SearchBuilder joinNetwork = _networksDao.createSearchBuilder(); - joinNetwork.and("type", joinNetwork.entity().getGuestType(), Op.EQ); - HostUpSearch.join("network", joinNetwork, joinNetwork.entity().getId(), HostUpSearch.entity().getNetworkId(), JoinType.INNER); + SearchBuilder joinRouterNetwork3 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork3.and("networkId", joinRouterNetwork3.entity().getNetworkId(), Op.EQ); + joinRouterNetwork3.and("type", joinRouterNetwork3.entity().getGuestType(), Op.EQ); + HostUpSearch.join("networkRouter", joinRouterNetwork3, joinRouterNetwork3.entity().getRouterId(), HostUpSearch.entity().getId(), JoinType.INNER); HostUpSearch.done(); - + StateNetworkTypeSearch = createSearchBuilder(); StateNetworkTypeSearch.and("state", StateNetworkTypeSearch.entity().getState(), Op.EQ); - SearchBuilder joinStateNetwork = _networksDao.createSearchBuilder(); - joinStateNetwork.and("type", joinStateNetwork.entity().getGuestType(), Op.EQ); - StateNetworkTypeSearch.join("network", joinStateNetwork, joinStateNetwork.entity().getId(), StateNetworkTypeSearch.entity().getNetworkId(), JoinType.INNER); + SearchBuilder joinRouterNetwork4 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork4.and("networkId", joinRouterNetwork4.entity().getNetworkId(), Op.EQ); + joinRouterNetwork4.and("type", joinRouterNetwork4.entity().getGuestType(), Op.EQ); + StateNetworkTypeSearch.join("networkRouter", joinRouterNetwork4, joinRouterNetwork4.entity().getRouterId(), StateNetworkTypeSearch.entity().getId(), JoinType.INNER); + SearchBuilder joinHost = _hostsDao.createSearchBuilder(); joinHost.and("mgmtServerId", joinHost.entity().getManagementServerId(), Op.EQ); - StateNetworkTypeSearch.join("host", joinHost, joinHost.entity().getId(), StateNetworkTypeSearch.entity().getHostId(), JoinType.INNER); + StateNetworkTypeSearch.join("host", joinHost, joinHost.entity().getId(), + StateNetworkTypeSearch.entity().getHostId(), JoinType.INNER); StateNetworkTypeSearch.done(); - + + OutsidePodSearch = createSearchBuilder(); - OutsidePodSearch.and("network", OutsidePodSearch.entity().getNetworkId(), Op.EQ); + SearchBuilder joinRouterNetwork2 = _routerNetworkDao.createSearchBuilder(); + joinRouterNetwork2.and("networkId", joinRouterNetwork2.entity().getNetworkId(), Op.EQ); + OutsidePodSearch.join("networkRouter", joinRouterNetwork2, joinRouterNetwork2.entity().getRouterId(), + OutsidePodSearch.entity().getId(), JoinType.INNER); OutsidePodSearch.and("podId", OutsidePodSearch.entity().getPodIdToDeployIn(), Op.NEQ); OutsidePodSearch.and("state", OutsidePodSearch.entity().getState(), Op.EQ); OutsidePodSearch.and("role", OutsidePodSearch.entity().getRole(), Op.EQ); @@ -150,23 +164,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase im } @Override - public List listVirtualByHostId(Long hostId) { + public List listIsolatedByHostId(Long hostId) { SearchCriteria sc = HostUpSearch.create(); if (hostId != null) { sc.setParameters("host", hostId); } - sc.setJoinParameters("network", "type", Network.GuestType.Isolated); - return listBy(sc); - } - - @Override - public List listVirtualUpByHostId(Long hostId) { - SearchCriteria sc = HostUpSearch.create(); - if (hostId != null) { - sc.setParameters("host", hostId); - } - sc.setParameters("states", State.Destroyed, State.Stopped, State.Expunging); - sc.setJoinParameters("network", "type", Network.GuestType.Isolated); + sc.setJoinParameters("networkRouter", "type", Network.GuestType.Isolated); return listBy(sc); } @@ -180,7 +183,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List findByNetwork(long networkId) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("network", networkId); + sc.setParameters("networkId", networkId); return listBy(sc); } @@ -195,7 +198,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listActive(long networkId) { SearchCriteria sc = IdNetworkIdStatesSearch.create(); - sc.setParameters("network", networkId); + sc.setParameters("networkId", networkId); sc.setParameters("states", State.Running, State.Migrating, State.Stopping, State.Starting); return listBy(sc); } @@ -204,7 +207,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im public List listByStateAndNetworkType(State state, Network.GuestType type, long mgmtSrvrId) { SearchCriteria sc = StateNetworkTypeSearch.create(); sc.setParameters("state", state); - sc.setJoinParameters("network", "type", type); + sc.setJoinParameters("networkRouter", "type", type); sc.setJoinParameters("host", "mgmtServerId", mgmtSrvrId); return listBy(sc); } @@ -212,7 +215,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List findByNetworkOutsideThePod(long networkId, long podId, State state, Role role) { SearchCriteria sc = OutsidePodSearch.create(); - sc.setParameters("network", networkId); + sc.setParameters("networkId", networkId); sc.setParameters("podId", podId); sc.setParameters("state", state); sc.setParameters("role", role); @@ -222,7 +225,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listByNetworkAndPodAndRole(long networkId, long podId, Role role) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("network", networkId); + sc.setParameters("networkId", networkId); sc.setParameters("podId", podId); sc.setParameters("role", role); return listBy(sc); @@ -231,7 +234,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listByNetworkAndRole(long networkId, Role role) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("network", networkId); + sc.setParameters("networkId", networkId); sc.setParameters("role", role); return listBy(sc); } @@ -242,4 +245,39 @@ public class DomainRouterDaoImpl extends GenericDaoBase im sc.setParameters("elementId", elementId); return listBy(sc); } + + @Override + @DB + public DomainRouterVO persist(DomainRouterVO router, Network guestNetwork) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + + // 1) create network + DomainRouterVO newRouter = super.persist(router); + // 2) add router to the network + addRouterToNetwork(router.getId(), guestNetwork); + // 3) create user stats entry + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } + + txn.commit(); + return newRouter; + } + + + protected void addRouterToNetwork(long routerId, Network guestNetwork) { + RouterNetworkVO routerNtwkMap = new RouterNetworkVO(routerId, guestNetwork.getId(), guestNetwork.getGuestType()); + _routerNetworkDao.persist(routerNtwkMap); + } + + @Override + public List getRouterNetworks(long routerId) { + return _routerNetworkDao.getRouterNetworks(routerId); + } + } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index cc0e34c6ea4..2771ab6710e 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2176,5 +2176,16 @@ CREATE TABLE `cloud`.`vpc_offering_service_map` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`router_network_ref` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `router_id` bigint unsigned NOT NULL COMMENT 'router id', + `network_id` bigint unsigned NOT NULL COMMENT 'network id', + `guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated', + PRIMARY KEY (`id`), + CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + SET foreign_key_checks = 1; diff --git a/wscript b/wscript index 75e79b4ae9b..dde2e24aba9 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-18T01:05:37Z' +VERSION = '3.0.3.2012-05-19T00:20:25Z' APPNAME = 'cloud' import shutil,os From 0e1b5901dce6d6a6f0083530442fac9efdf31d27 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 18 May 2012 18:20:29 -0700 Subject: [PATCH 03/64] Set networkId as a join parameter in DomainRouterDaoImpl as networkId was moved to the helper table --- server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java | 10 +++++----- setup/db/create-schema.sql | 1 - wscript | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 66ba8b65f52..eb670cb3af1 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -183,7 +183,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List findByNetwork(long networkId) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkRouter", "networkId", networkId); return listBy(sc); } @@ -198,7 +198,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listActive(long networkId) { SearchCriteria sc = IdNetworkIdStatesSearch.create(); - sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("states", State.Running, State.Migrating, State.Stopping, State.Starting); return listBy(sc); } @@ -215,7 +215,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List findByNetworkOutsideThePod(long networkId, long podId, State state, Role role) { SearchCriteria sc = OutsidePodSearch.create(); - sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("podId", podId); sc.setParameters("state", state); sc.setParameters("role", role); @@ -225,7 +225,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listByNetworkAndPodAndRole(long networkId, long podId, Role role) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("podId", podId); sc.setParameters("role", role); return listBy(sc); @@ -234,7 +234,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listByNetworkAndRole(long networkId, Role role) { SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("networkId", networkId); + sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("role", role); return listBy(sc); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 2771ab6710e..92782ed79e3 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -1071,7 +1071,6 @@ CREATE TABLE `cloud`.`domain_router` ( `public_netmask` varchar(15) COMMENT 'netmask used for the domR', `guest_netmask` varchar(15) COMMENT 'netmask used for the guest network', `guest_ip_address` char(40) COMMENT ' ip address in the guest network', - `network_id` bigint unsigned NOT NULL COMMENT 'network configuration that this domain router belongs to', `is_redundant_router` int(1) unsigned NOT NULL COMMENT 'if in redundant router mode', `priority` int(4) unsigned COMMENT 'priority of router in the redundant router mode', `is_priority_bumpup` int(1) unsigned NOT NULL COMMENT 'if the priority has been bumped up', diff --git a/wscript b/wscript index dde2e24aba9..d9cefcf9323 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-19T00:20:25Z' +VERSION = '3.0.3.2012-05-19T01:23:44Z' APPNAME = 'cloud' import shutil,os From f204185841127a3eb723f3638cc6355a09e55090 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Wed, 16 May 2012 13:04:57 -0700 Subject: [PATCH 04/64] CS-14929: Exception while creating a port forwarding rule on an acquired ip CS-14943: Unable to deploy VM due to Unable to identify the provider by name CiscoNexus1000vVSM Description: Ignore the CiscoNexus1000vVSM provider when checking for providers when applying port forwarding rules. --- server/src/com/cloud/network/NetworkManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 5b24cb17d44..fae5b5f0eca 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -3205,7 +3205,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NetworkElement ne : _networkElements) { Provider provider = Network.Provider.getProvider(ne.getName()); if (provider == null) { - if (ne.getName().equalsIgnoreCase("Ovs") || ne.getName().equalsIgnoreCase("BareMetal")) { + if (ne.getName().equalsIgnoreCase("Ovs") || ne.getName().equalsIgnoreCase("BareMetal") + || ne.getName().equalsIgnoreCase("CiscoNexus1000vVSM")) { continue; } throw new CloudRuntimeException("Unable to identify the provider by name " + ne.getName()); From e4458cf5b733078fed6db30bc64c6b0eace55217 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 21 May 2012 14:29:34 -0700 Subject: [PATCH 05/64] 1) Added start logic to the VPC 2) VirtualRouterManagerImpl - refactored deployVirtualRouter method 3) Added vpcId to domain_router/user_ip_address tables and corresponding vo objects --- .../com/cloud/api/commands/CreateVPCCmd.java | 18 +- api/src/com/cloud/network/IpAddress.java | 10 + .../cloud/network/element/NetworkElement.java | 16 +- .../element/UserDataServiceProvider.java | 1 - .../cloud/network/element/VpcProvider.java | 35 + .../cloud/network/router/VirtualRouter.java | 4 + .../com/cloud/network/vpc/VpcOffering.java | 5 + api/src/com/cloud/network/vpc/VpcService.java | 16 +- core/src/com/cloud/vm/DomainRouterVO.java | 8 + .../DefaultComponentLibrary.java | 3 +- server/src/com/cloud/network/IPAddressVO.java | 14 +- .../src/com/cloud/network/NetworkManager.java | 7 + .../com/cloud/network/NetworkManagerImpl.java | 6 +- .../network/element/VirtualRouterElement.java | 63 +- .../VirtualNetworkApplianceManager.java | 2 +- .../VirtualNetworkApplianceManagerImpl.java | 614 ++++++++++-------- .../VpcVirtualNetworkApplianceManager.java | 45 ++ ...VpcVirtualNetworkApplianceManagerImpl.java | 112 ++++ .../network/vpc/Dao/VpcOfferingDaoImpl.java | 2 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 56 +- .../com/cloud/network/vpc/VpcOfferingVO.java | 16 +- .../src/com/cloud/vm/dao/DomainRouterDao.java | 6 + .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 9 + setup/db/create-schema.sql | 11 +- wscript | 2 +- 25 files changed, 772 insertions(+), 309 deletions(-) create mode 100644 api/src/com/cloud/network/element/VpcProvider.java create mode 100644 server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java create mode 100644 server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java index 59efff6cbcd..b8e2fe3bb6c 100644 --- a/api/src/com/cloud/api/commands/CreateVPCCmd.java +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -22,7 +22,10 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.VpcResponse; import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.Vpc; import com.cloud.user.UserContext; @@ -111,7 +114,20 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ @Override public void execute() { //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc) - Vpc vpc = _vpcService.getVpc(this.getEntityId()); + Vpc vpc = null; + try { + vpc = _vpcService.startVpc(this.getEntityId()); + } catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } catch (InsufficientCapacityException ex) { + s_logger.info(ex); + s_logger.trace(ex); + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + } if (vpc != null) { VpcResponse response = _responseGenerator.createVpcResponse(vpc); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/network/IpAddress.java b/api/src/com/cloud/network/IpAddress.java index 0a4c2e4671d..416dcb7f919 100644 --- a/api/src/com/cloud/network/IpAddress.java +++ b/api/src/com/cloud/network/IpAddress.java @@ -76,4 +76,14 @@ public interface IpAddress extends ControlledEntity { boolean getSystem(); + /** + * @return + */ + Long getVpcId(); + + /** + * @param vpcId + */ + void setVpcId(Long vpcId); + } diff --git a/api/src/com/cloud/network/element/NetworkElement.java b/api/src/com/cloud/network/element/NetworkElement.java index e18a34f6308..c6845d3d346 100644 --- a/api/src/com/cloud/network/element/NetworkElement.java +++ b/api/src/com/cloud/network/element/NetworkElement.java @@ -52,7 +52,8 @@ public interface NetworkElement extends Adapter { * @return true if network configuration is now usable; false if not; null if not handled by this element. * @throws InsufficientNetworkCapacityException TODO */ - boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * Prepare for a nic to be added into this network. @@ -66,7 +67,9 @@ public interface NetworkElement extends Adapter { * @throws ResourceUnavailableException * @throws InsufficientNetworkCapacityException */ - boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; /** * A nic is released from this network. @@ -78,7 +81,8 @@ public interface NetworkElement extends Adapter { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; + boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; /** * The network is being shutdown. @@ -89,7 +93,8 @@ public interface NetworkElement extends Adapter { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException; + boolean shutdown(Network network, ReservationContext context, boolean cleanup) + throws ConcurrentOperationException, ResourceUnavailableException; /** * The network is being destroyed. @@ -114,7 +119,8 @@ public interface NetworkElement extends Adapter { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; + boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException; /** * This should return true if out of multiple services provided by this element, only some can be enabled. If all the services MUST be provided, this should return false. diff --git a/api/src/com/cloud/network/element/UserDataServiceProvider.java b/api/src/com/cloud/network/element/UserDataServiceProvider.java index 59c64bb965d..7ffbe9548a0 100644 --- a/api/src/com/cloud/network/element/UserDataServiceProvider.java +++ b/api/src/com/cloud/network/element/UserDataServiceProvider.java @@ -17,7 +17,6 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; -import com.cloud.uservm.UserVm; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java new file mode 100644 index 00000000000..86f70ea53d9 --- /dev/null +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -0,0 +1,35 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.element; + +import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientNetworkCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.Vpc; +import com.cloud.vm.ReservationContext; + +/** + * @author Alena Prokharchyk + */ +public interface VpcProvider extends NetworkElement{ + /** + * Start vpc element as specified + * @param vpc fully specified vpc configuration. + * @throws InsufficientNetworkCapacityException TODO + */ + boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + +} diff --git a/api/src/com/cloud/network/router/VirtualRouter.java b/api/src/com/cloud/network/router/VirtualRouter.java index 34ed9c12445..02aafefeca9 100755 --- a/api/src/com/cloud/network/router/VirtualRouter.java +++ b/api/src/com/cloud/network/router/VirtualRouter.java @@ -34,4 +34,8 @@ public interface VirtualRouter extends VirtualMachine { String getPublicIpAddress(); boolean isStopPending(); void setStopPending(boolean stopPending); + /** + * @return + */ + Long getVpcId(); } diff --git a/api/src/com/cloud/network/vpc/VpcOffering.java b/api/src/com/cloud/network/vpc/VpcOffering.java index 5531f55a998..167cdced8bb 100644 --- a/api/src/com/cloud/network/vpc/VpcOffering.java +++ b/api/src/com/cloud/network/vpc/VpcOffering.java @@ -38,4 +38,9 @@ public interface VpcOffering { boolean isDefault(); + /** + * @return + */ + Long getServiceOfferingId(); + } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index faf2845006c..682c0c6feec 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -16,6 +16,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -30,9 +33,7 @@ public interface VpcService { public VpcOffering createVpcOffering(String name, String displayText, List supportedServices); public Vpc getVpc(long vpcId); - - public Vpc createVpc(long zoneId, String name, String cidr, long ownerId); - + public List getVpcNetworks(long vpcId); Map> getVpcOffSvcProvidersMap(long vpcOffId); @@ -102,4 +103,13 @@ public interface VpcService { List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll); + /** + * @param vpcId + * @return + * @throws InsufficientCapacityException + * @throws ResourceUnavailableException + * @throws ConcurrentOperationException + */ + Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index dcf41485904..43d851dcd76 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -71,6 +71,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { @Column(name="scripts_version") private String scriptsVersion; + @Column(name="vpc_id") + private Long vpcId; + public DomainRouterVO(long id, long serviceOfferingId, long elementId, @@ -240,4 +243,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { public void setScriptsVersion(String scriptsVersion) { this.scriptsVersion = scriptsVersion; } + + @Override + public Long getVpcId() { + return vpcId; + } } diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 9afa3223a18..7a2c5b2c5b3 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -70,7 +70,6 @@ import com.cloud.maint.UpgradeManagerImpl; import com.cloud.maint.dao.AgentUpgradeDaoImpl; import com.cloud.network.ExternalLoadBalancerUsageManagerImpl; import com.cloud.network.NetworkManagerImpl; -import com.cloud.network.RouterNetworkDaoImpl; import com.cloud.network.StorageNetworkManagerImpl; import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; import com.cloud.network.dao.ExternalFirewallDeviceDaoImpl; @@ -113,6 +112,7 @@ import com.cloud.network.ovs.OvsTunnelManagerImpl; import com.cloud.network.ovs.dao.OvsTunnelInterfaceDaoImpl; import com.cloud.network.ovs.dao.OvsTunnelNetworkDaoImpl; import com.cloud.network.router.VirtualNetworkApplianceManagerImpl; +import com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl; import com.cloud.network.rules.RulesManagerImpl; import com.cloud.network.rules.dao.PortForwardingRulesDaoImpl; import com.cloud.network.security.SecurityGroupManagerImpl2; @@ -392,6 +392,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addManager("ExternalLoadBalancerUsageManager", ExternalLoadBalancerUsageManagerImpl.class); addManager("HA Manager", HighAvailabilityManagerImpl.class); addManager("VPC Manager", VpcManagerImpl.class); + addManager("VpcVirtualRouterManager", VpcVirtualNetworkApplianceManagerImpl.class); } @Override diff --git a/server/src/com/cloud/network/IPAddressVO.java b/server/src/com/cloud/network/IPAddressVO.java index 2b7d084d552..ea69b592ff8 100644 --- a/server/src/com/cloud/network/IPAddressVO.java +++ b/server/src/com/cloud/network/IPAddressVO.java @@ -28,7 +28,6 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import com.cloud.api.Identity; -import com.cloud.network.IpAddress; import com.cloud.utils.net.Ip; /** @@ -101,6 +100,9 @@ public class IPAddressVO implements IpAddress, Identity { @Transient @Column(name="domain_id") private Long domainId = null; + + @Column(name="vpc_id") + private Long vpcId; protected IPAddressVO() { this.uuid = UUID.randomUUID().toString(); @@ -272,4 +274,14 @@ public class IPAddressVO implements IpAddress, Identity { public void setSystem(boolean isSystem) { this.system = isSystem; } + + @Override + public Long getVpcId() { + return vpcId; + } + + @Override + public void setVpcId(Long vpcId) { + this.vpcId = vpcId; + } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 2577440d298..bdd07175b5b 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -36,6 +36,7 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; +import com.cloud.network.element.NetworkElement; import com.cloud.network.element.RemoteAccessVPNServiceProvider; import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; @@ -307,4 +308,10 @@ public interface NetworkManager extends NetworkService { String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware); String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware); + + /** + * @param providerName + * @return + */ + NetworkElement getElementImplementingProvider(String providerName); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index fae5b5f0eca..838332e5765 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -326,6 +326,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag private static HashMap> s_serviceToImplementedProvidersMap = new HashMap>(); private static HashMap s_providerToNetworkElementMap = new HashMap(); + @Override public NetworkElement getElementImplementingProvider(String providerName) { String elementName = s_providerToNetworkElementMap.get(providerName); NetworkElement element = _networkElements.get(elementName); @@ -1770,12 +1771,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, NetworkVO network, NetworkOfferingVO offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { // If this is a 1) guest virtual network 2) network has sourceNat service 3) network offering does not support a -// Shared source NAT rule, + // Shared source NAT rule, // associate a source NAT IP (if one isn't already associated with the network) boolean sharedSourceNat = offering.getSharedSourceNat(); - if (network.getGuestType() == Network.GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && !sharedSourceNat) { + if (network.getGuestType() == Network.GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) + && !sharedSourceNat) { List ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true); if (ips.isEmpty()) { diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 7defe1016ed..76db8516a59 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -55,12 +55,14 @@ import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.LbStickinessMethod; import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType; import com.cloud.network.rules.PortForwardingRule; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.StaticNat; +import com.cloud.network.vpc.Vpc; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -85,8 +87,9 @@ import com.cloud.vm.dao.UserVmDao; import com.google.gson.Gson; @Local(value = NetworkElement.class) -public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, - LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer { +public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, + UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, + LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, VpcProvider { private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class); private static final Map> capabilities = setCapabilities(); @@ -121,6 +124,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl ConfigurationDao _configDao; @Inject VirtualRouterProviderDao _vrProviderDao; + @Inject + VpcVirtualNetworkApplianceManager _vpcRouterMgr; protected boolean canHandle(Network network, Service service) { Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); @@ -139,7 +144,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } } else { if (!_networkMgr.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) { - s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + " in the network " + network); + s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + + " in the network " + network); return false; } } @@ -148,8 +154,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, + public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) + throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { + if (offering.isSystemOnly()) { return false; } @@ -157,13 +165,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), params, offering.getRedundantRouter()); + _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), params, + offering.getRedundantRouter()); return true; } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) { return false; @@ -183,7 +194,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile) vm; - List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), offering.getRedundantRouter()); + List routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), + uservm.getParameters(), offering.getRedundantRouter()); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); } @@ -195,7 +207,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(config, Service.Firewall)) { List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual router doesn't exist in the network " + config.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + + "router doesn't exist in the network " + config.getId()); return true; } @@ -265,10 +278,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl expire = value; } if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) { - throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire); + throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + + " Cause: expire is not in timeformat: " + expire); } if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) { - throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize); + throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + + " Cause: tablesize is not in size format: " + tablesize); } } else if (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) { @@ -294,7 +309,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } if ((length != null) && (!containsOnlyNumbers(length, null))) { - throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length); + throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + + " Cause: length is not a number: " + length); } if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) { throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime); @@ -321,7 +337,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(network, Service.Lb)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + + "router doesn't exist in the network " + network.getId()); return true; } @@ -372,7 +389,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(network, Service.Vpn)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't " + + "exist in the network " + network.getId()); return true; } return _routerMgr.deleteRemoteAccessVpn(network, vpn, routers); @@ -394,7 +412,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual " + + "router doesn't exist in the network " + network.getId()); return true; } @@ -724,7 +743,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when -// network.dns.basiczone.updates is set to "all" + // network.dns.basiczone.updates is set to "all" Long podId = dest.getPod().getId(); if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER); @@ -772,7 +791,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when -// network.dns.basiczone.updates is set to "all" + // network.dns.basiczone.updates is set to "all" Long podId = dest.getPod().getId(); if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER); @@ -823,4 +842,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl public IpDeployer getIpDeployer(Network network) { return this; } + + @Override + public boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + + Map params = new HashMap(1); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); + + _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); + + return true; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 5c40161ee32..f6d83c3f865 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -59,7 +59,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; - List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + List deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index ca0df9b5f21..a27c25ed2a5 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -98,6 +98,7 @@ import com.cloud.event.EventTypes; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConnectionException; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; @@ -310,7 +311,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian int _routerStatsInterval = 300; int _routerCheckInterval = 30; - private ServiceOfferingVO _offering; + protected ServiceOfferingVO _offering; private String _dnsBasicZoneUpdates = "all"; private boolean _disable_rp_filter = false; @@ -403,7 +404,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian // Check that the service offering being upgraded to has the same storage pool preference as the VM's current service // offering if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) { - throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getUseLocalStorage() + " is different from " + throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + + newServiceOffering.getUseLocalStorage() + " is different from " + "curruent local storage status: " + currentServiceOffering.getUseLocalStorage()); } @@ -526,7 +528,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true) - public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { Account caller = UserContext.current().getCaller(); // verify parameters @@ -540,7 +543,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian // Can reboot domain router only in Running state if (router == null || router.getState() != State.Running) { s_logger.warn("Unable to reboot, virtual router is not in the right state " + router.getState()); - throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterIdToDeployIn()); + throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), + DataCenter.class, router.getDataCenterIdToDeployIn()); } UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); @@ -603,7 +607,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this); boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); - _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true, VirtualMachine.Type.DomainRouter, true); + _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, + null, true, null, useLocalStorage, true, null, true, VirtualMachine.Type.DomainRouter, true); _offering.setUniqueName(ServiceOffering.routerDefaultOffUniqueName); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); @@ -671,7 +676,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian endDate = cal.getTime().getTime(); } - _networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), (endDate - System.currentTimeMillis()), (_usageAggregationRange * 60 * 1000), TimeUnit.MILLISECONDS); + _networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), (endDate - System.currentTimeMillis()), + (_usageAggregationRange * 60 * 1000), TimeUnit.MILLISECONDS); if (_routerCheckInterval > 0) { _checkExecutor.scheduleAtFixedRate(new CheckRouterTask(), _routerCheckInterval, _routerCheckInterval, TimeUnit.SECONDS); @@ -699,7 +705,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return VirtualMachineName.getRouterId(vmName); } - private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, + private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, + String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String publicKey) { VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName); @@ -791,14 +798,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } if(previousStats != null - && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){ - s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent()); + && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) + || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){ + s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " + + "Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent()); continue; } if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesReceived() + s_logger.debug("Received # of bytes that's less than the last one. " + + "Assuming something went wrong and persisting it. Router: " + + answer.getRouterName()+" Reported: " + answer.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived()); } stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); @@ -806,7 +818,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian stats.setCurrentBytesReceived(answer.getBytesReceived()); if (stats.getCurrentBytesSent() > answer.getBytesSent()) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesSent() + s_logger.debug("Received # of bytes that's less than the last one. " + + "Assuming something went wrong and persisting it. Router: " + + answer.getRouterName()+" Reported: " + answer.getBytesSent() + " Stored: " + stats.getCurrentBytesSent()); } stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent()); @@ -816,7 +830,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent()); + s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent()); } finally { txn.close(); } @@ -1139,7 +1154,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (HostVO h : hosts) { if (h.getStatus() == Status.Up) { - s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " + cv.getId() + " to start domain router for OVM"); + s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " + + cv.getId() + " to start domain router for OVM"); return h.getHypervisorType(); } } @@ -1147,21 +1163,44 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String errMsg = "Cannot find an available cluster in Pod " + podId - + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod with Ovm cluster. And there is at least one host in UP status in that cluster."; + + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, " + + "please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod" + + " with Ovm cluster. And there is at least one host in UP status in that cluster."; throw new CloudRuntimeException(errMsg); } @DB - protected List findOrDeployVirtualRouters(Network guestNetwork, DeployDestination dest, Account owner, boolean isRedundant, Map params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + protected List findOrDeployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, + boolean isRedundant, Map params) throws ConcurrentOperationException, + InsufficientCapacityException, ResourceUnavailableException { + + assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || + guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + + guestNetwork; + assert guestNetwork.getTrafficType() == TrafficType.Guest; Network network = _networkDao.acquireInLockTable(guestNetwork.getId()); if (network == null) { throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); } + + //Check if providers are supported in the physical networks + VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter; + Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); + PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString()); + if (provider == null) { + throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId); + } + VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type); + if (vrProvider == null) { + throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString()+ " as service provider " + provider.getId()); + } + + if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { + owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); + } - long dcId = dest.getDataCenter().getId(); - DataCenterDeployment plan = new DataCenterDeployment(dcId); - boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMgr.areServicesSupportedInNetwork(guestNetwork.getId(), Service.SecurityGroup)) && guestNetwork.getTrafficType() == TrafficType.Guest; + //Check if public network has to be sest on VR boolean publicNetwork = false; if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { publicNetwork = true; @@ -1170,211 +1209,50 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.error("Didn't support redundant virtual router without public network!"); return null; } - List routers; - Long podId = null; - if (isPodBased) { - Pod pod = dest.getPod(); - if (pod != null) { - podId = pod.getId(); + + + //1) Get deployment plan and find out the list of routers + boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || + _networkMgr.areServicesSupportedInNetwork(guestNetwork.getId(), Service.SecurityGroup)) + && guestNetwork.getTrafficType() == TrafficType.Guest; + Pair> planAndRouters = getDeploymentPlanAndRouters(isPodBased, dest, guestNetwork.getId()); + DeploymentPlan plan = planAndRouters.first(); + List routers = planAndRouters.second(); + + //2) Figure out required routers count + int routerCount = 1; + if (isRedundant) { + routerCount = 2; + } + + /* If it is the single router network, then keep it untouched */ + for (DomainRouterVO router : routers) { + if (!router.getIsRedundantRouter()) { + routerCount = 1; } } + + /* If old network is redundant but new is single router, then routers.size() = 2 but routerCount = 1 */ + if (routers.size() >= routerCount || (isPodBased)) { + return routers; + } + + if (routers.size() >= 5) { + s_logger.error("Too much redundant routers!"); + } - if (publicNetwork) { - routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); - } else { - if (isPodBased && podId != null) { - routers = _routerDao.listByNetworkAndPodAndRole(guestNetwork.getId(), podId, Role.VIRTUAL_ROUTER); - plan = new DataCenterDeployment(dcId, podId, null, null, null, null); - } else { - routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); - plan = new DataCenterDeployment(dcId); - } + Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); + if (offeringId == null) { + offeringId = _offering.getId(); } - + + //3) Deploy Virtual Router(s) try { - int routerCount = 1; - if (isRedundant) { - routerCount = 2; - } - - /* If it is the single router network, then keep it untouched */ - for (DomainRouterVO router : routers) { - if (!router.getIsRedundantRouter()) { - routerCount = 1; - } - } - - /* If old network is redundant but new is single router, then routers.size() = 2 but routerCount = 1 */ - if (routers.size() >= routerCount || (isPodBased && podId == null)) { - return routers; - } - - if (routers.size() >= 5) { - s_logger.error("Too much redundant routers!"); - } - - NicProfile defaultNic = new NicProfile(); - //if source nat service is supported by the network, get the source nat ip address - if (publicNetwork) { - PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountMgr.getSystemUser().getId()); - defaultNic.setDefaultNic(true); - defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); - defaultNic.setGateway(sourceNatIp.getGateway()); - defaultNic.setNetmask(sourceNatIp.getNetmask()); - defaultNic.setMacAddress(sourceNatIp.getMacAddress()); - defaultNic.setBroadcastType(BroadcastDomainType.Vlan); - defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setDeviceId(2); - } - int count = routerCount - routers.size(); - for (int i = 0; i < count; i++) { - long id = _routerDao.getNextInSequence(Long.class, "id"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating the router " + id); - } - - DomainRouterVO router = null; - - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - - List> networks = new ArrayList>(3); - if (publicNetwork) { - NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); - networks.add(new Pair(publicNetworks.get(0), defaultNic)); - } - - String defaultNetworkStartIp = null; - if (guestNetwork.getCidr() != null && !publicNetwork) { - String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); - if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { - defaultNetworkStartIp = startIp; - } else if (s_logger.isDebugEnabled()){ - s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ip address from the range"); - } - } - - NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); - if (publicNetwork) { - if (isRedundant) { - gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null)); - } else { - gatewayNic.setIp4Address(guestNetwork.getGateway()); - } - gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri()); - gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); - gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri()); - gatewayNic.setMode(guestNetwork.getMode()); - String gatewayCidr = guestNetwork.getCidr(); - gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); - } else { - gatewayNic.setDefaultNic(true); - } - - networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); - networks.add(new Pair(controlConfig, null)); - - Long offering_id = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); - if (offering_id == null) { - offering_id = _offering.getId(); - } - VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter; - Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); - PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString()); - if (provider == null) { - throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId); - } - VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type); - if (vrProvider == null) { - throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString()+ " as service provider " + provider.getId()); - } - ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(offering_id); - - //Router is the network element, we don't know the hypervisor type yet. - //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up - List supportedHypervisors = new ArrayList(); - HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); - if (defaults != HypervisorType.None) { - supportedHypervisors.add(defaults); - } - - if (dest.getCluster() != null) { - if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { - supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); - } else { - supportedHypervisors.add(dest.getCluster().getHypervisorType()); - } - } else { - supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, podId); - } - - if (supportedHypervisors.isEmpty()) { - if (podId != null) { - throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod ", Pod.class, podId); - } - throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId()); - } - - int allocateRetry = 0; - int startRetry = 0; - - - for (Iterator iter = supportedHypervisors.iterator();iter.hasNext();) { - HypervisorType hType = iter.next(); - try { - s_logger.debug("Allocating the domR with the hypervisor type " + hType); - VMTemplateVO template = _templateDao.findRoutingTemplate(hType); - - if (template == null) { - s_logger.debug(hType + " won't support system vm, skip it"); - continue; - } - - boolean offerHA = routerOffering.getOfferHA(); - /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ - if (isRedundant) { - offerHA = false; - } - - router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, offerHA, false); - router.setRole(Role.VIRTUAL_ROUTER); - router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); - } catch (InsufficientCapacityException ex) { - if (allocateRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to allocate the domR with hypervisor type " + hType + ", retrying one more time"); - continue; - } else { - throw ex; - } - } finally { - allocateRetry++; - } - - try { - router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params); - break; - } catch (InsufficientCapacityException ex) { - if (startRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", destroying it and recreating one more time"); - //destroy the router - destroyRouter(router.getId()); - continue; - } else { - throw ex; - } - } finally { - startRetry++; - } - } - + DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, + vrProvider, offeringId); routers.add(router); - } } finally { if (network != null) { @@ -1384,7 +1262,202 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return routers; } - private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map params) throws StorageUnavailableException, InsufficientCapacityException, + protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, + boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, + VirtualRouterProvider vrProvider, long svcOffId) throws ConcurrentOperationException, + InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, + StorageUnavailableException, ResourceUnavailableException { + + long id = _routerDao.getNextInSequence(Long.class, "id"); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Creating the router " + id + " in datacenter " + dest.getDataCenter()); + } + + //1) Create router networks + List> networks = createRouterNetworks(owner, setupPublicNetwork, guestNetwork, + isRedundant, plan); + + + ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); + + //2) Router is the network element, we don't know the hypervisor type yet. + //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up + List supportedHypervisors = new ArrayList(); + HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); + if (defaults != HypervisorType.None) { + supportedHypervisors.add(defaults); + } + + if (dest.getCluster() != null) { + if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { + supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); + } else { + supportedHypervisors.add(dest.getCluster().getHypervisorType()); + } + } else { + supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, + plan.getPodId()); + } + + if (supportedHypervisors.isEmpty()) { + if (plan.getPodId() != null) { + throw new InsufficientServerCapacityException("Unable to create virtual router, " + + "there are no clusters in the pod ", Pod.class, plan.getPodId()); + } + throw new InsufficientServerCapacityException("Unable to create virtual router, " + + "there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId()); + } + + int allocateRetry = 0; + int startRetry = 0; + DomainRouterVO router = null; + for (Iterator iter = supportedHypervisors.iterator();iter.hasNext();) { + HypervisorType hType = iter.next(); + try { + s_logger.debug("Allocating the domR with the hypervisor type " + hType); + VMTemplateVO template = _templateDao.findRoutingTemplate(hType); + + if (template == null) { + s_logger.debug(hType + " won't support system vm, skip it"); + continue; + } + + boolean offerHA = routerOffering.getOfferHA(); + /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ + if (isRedundant) { + offerHA = false; + } + + router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), + VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, + RedundantState.UNKNOWN, offerHA, false); + router.setRole(Role.VIRTUAL_ROUTER); + router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); + } catch (InsufficientCapacityException ex) { + if (allocateRetry < 2 && iter.hasNext()) { + s_logger.debug("Failed to allocate the domR with hypervisor type " + hType + ", retrying one more time"); + continue; + } else { + throw ex; + } + } finally { + allocateRetry++; + } + + try { + router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params); + break; + } catch (InsufficientCapacityException ex) { + if (startRetry < 2 && iter.hasNext()) { + s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", destroying it and recreating one more time"); + //destroy the router + destroyRouter(router.getId()); + continue; + } else { + throw ex; + } + } finally { + startRetry++; + } + } + return router; + } + + protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, + Network guestNetwork, boolean isRedundant, DeploymentPlan plan) throws ConcurrentOperationException, + InsufficientAddressCapacityException { + //Form networks + //1) Public network + List> networks = new ArrayList>(3); + if (setupPublicNetwork) { + s_logger.debug("Adding nic for Virtual Router in Public network "); + //if source nat service is supported by the network, get the source nat ip address + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountMgr.getSystemUser().getId()); + NicProfile defaultNic = new NicProfile(); + defaultNic.setDefaultNic(true); + defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); + defaultNic.setGateway(sourceNatIp.getGateway()); + defaultNic.setNetmask(sourceNatIp.getNetmask()); + defaultNic.setMacAddress(sourceNatIp.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setDeviceId(2); + NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + networks.add(new Pair(publicNetworks.get(0), defaultNic)); + } + + //2) Control network + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + s_logger.debug("Adding nic for Virtual Router in Control network "); + networks.add(new Pair(controlConfig, null)); + + //3) Guest network + if (guestNetwork != null) { + String defaultNetworkStartIp = null; + s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); + if (guestNetwork.getCidr() != null && !setupPublicNetwork) { + String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); + if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { + defaultNetworkStartIp = startIp; + } else if (s_logger.isDebugEnabled()){ + s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + + " is already allocated, can't use it for domain router; will get random ip address from the range"); + } + } + + NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); + if (setupPublicNetwork) { + if (isRedundant) { + gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null)); + } else { + gatewayNic.setIp4Address(guestNetwork.getGateway()); + } + gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri()); + gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); + gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri()); + gatewayNic.setMode(guestNetwork.getMode()); + String gatewayCidr = guestNetwork.getCidr(); + gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); + } else { + gatewayNic.setDefaultNic(true); + } + networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); + } + + return networks; + } + + + protected Pair> getDeploymentPlanAndRouters(boolean isPodBased, + DeployDestination dest, long guestNetworkId) { + long dcId = dest.getDataCenter().getId(); + List routers = null; + DeploymentPlan plan = new DataCenterDeployment(dcId); + if (isPodBased) { + Pod pod = dest.getPod(); + Long podId = null; + if (pod != null) { + podId = pod.getId(); + } else { + throw new CloudRuntimeException("Pod id is expected in deployment destination"); + } + routers = _routerDao.listByNetworkAndPodAndRole(guestNetworkId, podId, Role.VIRTUAL_ROUTER); + plan = new DataCenterDeployment(dcId, podId, null, null, null, null); + } else { + routers = _routerDao.listByNetworkAndRole(guestNetworkId, Role.VIRTUAL_ROUTER); + } + + return new Pair>(plan, routers); + } + + + private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map params) + throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) { @@ -1451,25 +1524,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + public List deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { - if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { - owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); - } + ConcurrentOperationException, ResourceUnavailableException { - if(dest != null){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Starting a router for " + guestNetwork + " in datacenter:" + dest.getDataCenter()); - } - } + List routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params); - assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || - guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " - + guestNetwork; - assert guestNetwork.getTrafficType() == TrafficType.Guest; + return startRouters(params, routers); + } - List routers = findOrDeployVirtualRouters(guestNetwork, dest, owner, isRedundant, params); + protected List startRouters(Map params, List routers) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, + ResourceUnavailableException { List runningRouters = null; if (routers != null) { @@ -1974,16 +2039,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override - public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException { + public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException { if (routers == null || routers.isEmpty()) { s_logger.warn("Failed to start remote access VPN: no router found for account and zone"); - throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", + DataCenter.class, network.getDataCenterId()); } for (VirtualRouter router : routers) { if (router.getState() != State.Running) { s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState()); - throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + + router.getState(), DataCenter.class, network.getDataCenterId()); } Commands cmds = new Commands(OnError.Stop); @@ -1997,16 +2065,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } Answer answer = cmds.getAnswer("users"); if (!answer.getResult()) { - s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterIdToDeployIn() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterIdToDeployIn() + + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails()); - throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterIdToDeployIn() + " for account " + vpn.getAccountId() + " on domR: " + throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + + router.getDataCenterIdToDeployIn() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn()); } answer = cmds.getAnswer("startVpn"); if (!answer.getResult()) { - s_logger.error("Unable to start vpn in zone " + router.getDataCenterIdToDeployIn() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + s_logger.error("Unable to start vpn in zone " + router.getDataCenterIdToDeployIn() + " for account " + + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails()); - throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterIdToDeployIn() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterIdToDeployIn() + + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn()); } @@ -2016,7 +2088,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override - public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException { + public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException { if (routers == null || routers.isEmpty()) { s_logger.warn("Failed to delete remote access VPN: no router found for account and zone"); throw new ResourceUnavailableException("Failed to delete remote access VPN", DataCenter.class, network.getDataCenterId()); @@ -2028,7 +2101,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian Commands cmds = new Commands(OnError.Continue); IpAddress ip = _networkMgr.getIp(vpn.getServerAddressId()); - RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); + RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(), + vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); @@ -2044,7 +2118,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian continue; } else { s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState()); - throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + + router.getState(), DataCenter.class, network.getDataCenterId()); } } @@ -2052,7 +2127,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } - private DomainRouterVO start(DomainRouterVO router, User user, Account caller, Map params, DeploymentPlan planToDeploy) throws StorageUnavailableException, InsufficientCapacityException, + private DomainRouterVO start(DomainRouterVO router, User user, Account caller, Map params, DeploymentPlan planToDeploy) + throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting router " + router); if (_itMgr.start(router, params, user, caller, planToDeploy) != null) { @@ -2087,7 +2163,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean podLevelException = false; //for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope - if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { + if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User + && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { podLevelException = true; } @@ -2140,7 +2217,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean podLevelException = false; //for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope - if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { + if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User + && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { podLevelException = true; } @@ -2171,7 +2249,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public String[] applyVpnUsers(Network network, List users, List routers) throws ResourceUnavailableException { if (routers == null || routers.isEmpty()) { s_logger.warn("Failed to add/remove VPN users: no router found for account and zone"); - throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + + network.getId(), DataCenter.class, network.getDataCenterId()); } boolean agentResults = true; @@ -2179,7 +2258,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (DomainRouterVO router : routers) { if (router.getState() != State.Running) { s_logger.warn("Failed to add/remove VPN users: router not in running state"); - throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + + router.getState(), DataCenter.class, network.getDataCenterId()); } Commands cmds = new Commands(OnError.Continue); @@ -2243,7 +2323,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException { + public VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ResourceUnavailableException, + InsufficientCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); @@ -2342,7 +2423,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String vmGuestAddress = null; - IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat()); + IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, + sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat()); ip.setTrafficType(network.getTrafficType()); ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network)); @@ -2463,7 +2545,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian IpAddress ip = _networkMgr.getIp(vpn.getServerAddressId()); - RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(true, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); + RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(true, ip.getAddress().addr(), + vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); @@ -2548,7 +2631,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian DataCenterVO dc = _dcDao.findById(router.getDataCenterIdToDeployIn()); for (UserVmVO vm : vms) { boolean createDhcp = true; - if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue() && _dnsBasicZoneUpdates.equalsIgnoreCase("pod")) { + if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue() + && _dnsBasicZoneUpdates.equalsIgnoreCase("pod")) { createDhcp = false; } if (createDhcp) { @@ -2601,10 +2685,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return; } if (!connectedRouters.get(0).getIsRedundantRouter()) { - throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, connectedRouters.get(0).getDataCenterIdToDeployIn()); + throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", + DataCenter.class, connectedRouters.get(0).getDataCenterIdToDeployIn()); } if (!disconnectedRouters.get(0).getIsRedundantRouter()) { - throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, disconnectedRouters.get(0).getDataCenterIdToDeployIn()); + throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", + DataCenter.class, disconnectedRouters.get(0).getDataCenterIdToDeployIn()); } DomainRouterVO connectedRouter = (DomainRouterVO)connectedRouters.get(0); @@ -2754,7 +2840,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException; } - private boolean applyRules(Network network, List routers, String typeString, boolean isPodLevelException, Long podId, boolean failWhenDisconnect, RuleApplier applier) throws ResourceUnavailableException { + private boolean applyRules(Network network, List routers, String typeString, + boolean isPodLevelException, Long podId, boolean failWhenDisconnect, RuleApplier applier) throws ResourceUnavailableException { if (routers == null || routers.isEmpty()) { s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId()); throw new ResourceUnavailableException("Unable to apply " + typeString , DataCenter.class, network.getDataCenterId()); @@ -2776,10 +2863,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (router.isStopPending()) { if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) { - throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", + throw new ResourceUnavailableException("Unable to process due to the stop pending router " + + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterIdToDeployIn()); } - s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend"); + s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + + typeString + " commands to the backend"); continue; } try { @@ -2795,17 +2884,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (isZoneBasic && isPodLevelException) { throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId); } - throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterIdToDeployIn()); + throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, + router.getDataCenterIdToDeployIn()); } } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) { - s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend"); + s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + + ", so not sending apply " + typeString + " commands to the backend"); } else { s_logger.warn("Unable to apply " + typeString +", virtual router is not in the right state " + router.getState()); if (isZoneBasic && isPodLevelException) { - throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId); + throw new ResourceUnavailableException("Unable to apply " + typeString + + ", virtual router is not in the right state", Pod.class, podId); } - throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn()); + throw new ResourceUnavailableException("Unable to apply " + typeString + + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn()); } } @@ -2860,7 +2953,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian rulesTO = new ArrayList(); for (StaticNat rule : rules) { IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId()); - StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false); + StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, + null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false); rulesTO.add(ruleTO); } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java new file mode 100644 index 00000000000..13df4f3f6ff --- /dev/null +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -0,0 +1,45 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.router; + +import java.util.List; +import java.util.Map; + +import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.VirtualMachineProfile.Param; + +/** + * @author Alena Prokharchyk + */ +public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{ + + /** + * @param vpc + * @param dest + * @param owner + * @param params + * @return + * @throws InsufficientCapacityException + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map params) throws InsufficientCapacityException, ConcurrentOperationException, + ResourceUnavailableException; + +} diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java new file mode 100644 index 00000000000..e2287a58f35 --- /dev/null +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -0,0 +1,112 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.router; + +import java.util.List; +import java.util.Map; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.deploy.DataCenterDeployment; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.VirtualRouterProvider; +import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.Dao.VpcDao; +import com.cloud.network.vpc.Dao.VpcOfferingDao; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.component.Inject; +import com.cloud.utils.db.DB; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.VirtualMachineProfile.Param; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = { VpcVirtualNetworkApplianceManager.class}) +public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ + private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); + + @Inject + VpcDao _vpcDao = null; + @Inject + VpcOfferingDao _vpcOffDao = null; + + @Override + public List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, + Map params) throws InsufficientCapacityException, + ConcurrentOperationException, ResourceUnavailableException { + + List routers = findOrDeployVirtualRouterInVpc(vpc, dest, owner, params); + + return startRouters(params, routers); + } + + @DB + protected List findOrDeployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, + Map params) throws ConcurrentOperationException, + InsufficientCapacityException, ResourceUnavailableException { + + Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId()); + if (vpcLock == null) { + throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId()); + } + + //1) Get deployment plan and find out the list of routers + Pair> planAndRouters = getDeploymentPlanAndRouters(vpc.getId(), dest); + DeploymentPlan plan = planAndRouters.first(); + List routers = planAndRouters.second(); + + //2) Return routers if exist + if (routers.size() >= 1) { + return routers; + } + + Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId(); + if (offeringId == null) { + offeringId = _offering.getId(); + } + + //3) Deploy Virtual Router + try { + //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs + VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(1, VirtualRouterProviderType.VirtualRouter); + DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, + vrProvider, offeringId); + routers.add(router); + + } finally { + if (vpcLock != null) { + _vpcDao.releaseFromLockTable(vpc.getId()); + } + } + return routers; + } + + protected Pair> getDeploymentPlanAndRouters(long vpcId,DeployDestination dest) { + long dcId = dest.getDataCenter().getId(); + + DeploymentPlan plan = new DataCenterDeployment(dcId); + List routers = _routerDao.listRoutersByVpcId(vpcId); + + return new Pair>(plan, routers); + } +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java index 0a152344c69..b5e6c6ede8a 100644 --- a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java @@ -40,6 +40,7 @@ public class VpcOfferingDaoImpl extends GenericDaoBase impl AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ); AllFieldsSearch.and("uName", AllFieldsSearch.entity().getUniqueName(), Op.EQ); AllFieldsSearch.and("displayText", AllFieldsSearch.entity().getDisplayText(), Op.EQ); + AllFieldsSearch.and("svcOffId", AllFieldsSearch.entity().getServiceOfferingId(), Op.EQ); AllFieldsSearch.done(); } @@ -62,7 +63,6 @@ public class VpcOfferingDaoImpl extends GenericDaoBase impl public VpcOfferingVO findByUniqueName(String uniqueName) { SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("uName", uniqueName); - return findOneBy(sc); } } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 108b4871531..7fb6bc646ce 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -27,15 +27,22 @@ import org.apache.log4j.Logger; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenter; +import com.cloud.deploy.DeployDestination; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; +import com.cloud.network.NetworkManager; import com.cloud.network.dao.NetworkDao; +import com.cloud.network.element.NetworkElement; +import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -44,6 +51,7 @@ import com.cloud.org.Grouping; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.user.Account; import com.cloud.user.AccountManager; +import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.utils.Ternary; import com.cloud.utils.component.Inject; @@ -53,7 +61,10 @@ import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.ReservationContextImpl; /** * @author Alena Prokharchyk @@ -76,6 +87,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ AccountManager _accountMgr; @Inject NetworkDao _ntwkDao; + @Inject + NetworkManager _ntwkMgr; String _name; @@ -100,7 +113,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled); } - + txn.commit(); return true; @@ -121,12 +134,6 @@ public class VpcManagerImpl implements VpcManager, Manager{ return _name; } - @Override - public Vpc createVpc(long zoneId, String name, String cidr, long ownerId) { - // TODO Auto-generated method stub - return null; - } - @Override public List getVpcNetworks(long vpcId) { // TODO Auto-generated method stub @@ -185,7 +192,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ Transaction txn = Transaction.currentTxn(); txn.start(); // create vpc offering object - VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault); + VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault, null); if (state != null) { offering.setState(state); @@ -399,7 +406,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ Account owner = _accountMgr.getAccount(vpcOwnerId); //Verify that caller can perform actions in behalf of vpc owner - _accountMgr.checkAccess(caller, null, true, owner); + _accountMgr.checkAccess(caller, null, false, owner); // Validate vpc offering VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); @@ -605,4 +612,35 @@ public class VpcManagerImpl implements VpcManager, Manager{ services.add(Network.Service.Vpn); return services; } + + @Override + public Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + UserContext ctx = UserContext.current(); + Account caller = ctx.getCaller(); + User callerUser = _accountMgr.getActiveUser(ctx.getCallerUserId()); + + //check if vpc exists + Vpc vpc = getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + } + + //permission check + _accountMgr.checkAccess(caller, null, false, vpc); + + DataCenter dc = _configMgr.getZone(vpc.getZoneId()); + + DeployDestination dest = new DeployDestination(dc, null, null, null); + ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId())); + + //deploy provider + if (((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VirtualRouter.getName())).startVpc(vpc, dest, context)) { + s_logger.debug("Vpc " + vpc + " has started succesfully"); + return getVpc(vpc.getId()); + } else { + throw new CloudRuntimeException("Failed to start vpc " + vpc); + //FIXME - add cleanup logic here + } + + } } diff --git a/server/src/com/cloud/network/vpc/VpcOfferingVO.java b/server/src/com/cloud/network/vpc/VpcOfferingVO.java index 86b698e6b05..2b96f2047dc 100644 --- a/server/src/com/cloud/network/vpc/VpcOfferingVO.java +++ b/server/src/com/cloud/network/vpc/VpcOfferingVO.java @@ -64,20 +64,24 @@ public class VpcOfferingVO implements VpcOffering{ @Column(name = GenericDao.CREATED_COLUMN) Date created; + @Column(name = "service_offering_id") + Long serviceOfferingId; + public VpcOfferingVO() { this.uuid = UUID.randomUUID().toString(); } - public VpcOfferingVO(String name, String displayText) { + public VpcOfferingVO(String name, String displayText, Long serviceOfferingId) { this.name = name; this.displayText = displayText; this.uniqueName = name; + this.serviceOfferingId = serviceOfferingId; this.uuid = UUID.randomUUID().toString(); this.state = State.Disabled; } - public VpcOfferingVO(String name, String displayText, boolean isDefault) { - this(name, displayText); + public VpcOfferingVO(String name, String displayText, boolean isDefault, Long serviceOfferingId) { + this(name, displayText, serviceOfferingId); this.isDefault = isDefault; } @@ -136,8 +140,12 @@ public class VpcOfferingVO implements VpcOffering{ this.displayText = displayText; } - public void setState(State state) { this.state = state; } + + @Override + public Long getServiceOfferingId() { + return serviceOfferingId; + } } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 2afc5af5279..350ea1d0206 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -105,4 +105,10 @@ public interface DomainRouterDao extends GenericDao { * @return */ List getRouterNetworks(long routerId); + + /** + * @param vpcId + * @return + */ + List listRoutersByVpcId(long vpcId); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index eb670cb3af1..23ecea990f1 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -63,6 +63,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im AllFieldsSearch.join("networkRouter", joinRouterNetwork, joinRouterNetwork.entity().getRouterId(), AllFieldsSearch.entity().getId(), JoinType.INNER); AllFieldsSearch.and("podId", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ); AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ); + AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); IdNetworkIdStatesSearch = createSearchBuilder(); @@ -280,4 +281,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase im return _routerNetworkDao.getRouterNetworks(routerId); } + @Override + public List listRoutersByVpcId(long vpcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcId", vpcId); + sc.setParameters("role", Role.VIRTUAL_ROUTER); + return listBy(sc); + } + } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 92782ed79e3..13b98902ede 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -920,6 +920,7 @@ CREATE TABLE `cloud`.`user_ip_address` ( `network_id` bigint unsigned COMMENT 'network this public ip address is associated with', `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id that this configuration is based on', `is_system` int(1) unsigned NOT NULL default '0', + `vpc_id` bigint unsigned COMMENT 'vpc the ip address is associated with', PRIMARY KEY (`id`), UNIQUE (`public_ip_address`, `source_network_id`), CONSTRAINT `fk_user_ip_address__source_network_id` FOREIGN KEY (`source_network_id`) REFERENCES `networks`(`id`), @@ -930,6 +931,7 @@ CREATE TABLE `cloud`.`user_ip_address` ( CONSTRAINT `fk_user_ip_address__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, CONSTRAINT `uc_user_ip_address__uuid` UNIQUE (`uuid`), CONSTRAINT `fk_user_ip_address__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_user_ip_address__vpc_id` FOREIGN KEY (`vpc_id`) REFERENCES `vpc`(`id`) ON DELETE CASCADE, INDEX `i_user_ip_address__allocated`(`allocated`), INDEX `i_user_ip_address__source_nat`(`source_nat`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -1079,9 +1081,11 @@ CREATE TABLE `cloud`.`domain_router` ( `role` varchar(64) NOT NULL COMMENT 'type of role played by this router', `template_version` varchar(100) COMMENT 'template version', `scripts_version` varchar(100) COMMENT 'scripts version', + `vpc_id` bigint unsigned COMMENT 'correlated virtual router vpc ID', PRIMARY KEY (`id`), CONSTRAINT `fk_domain_router__id` FOREIGN KEY `fk_domain_router__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_domain_router__element_id` FOREIGN KEY `fk_domain_router__element_id`(`element_id`) REFERENCES `virtual_router_providers`(`id`) + CONSTRAINT `fk_domain_router__element_id` FOREIGN KEY `fk_domain_router__element_id`(`element_id`) REFERENCES `virtual_router_providers`(`id`), + CONSTRAINT `fk_domain_router__vpc_id` FOREIGN KEY `fk_domain_router__vpc_id`(`vpc_id`) REFERENCES `vpc`(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COMMENT = 'information about the domR instance'; CREATE TABLE `cloud`.`upload` ( @@ -2158,11 +2162,12 @@ CREATE TABLE `cloud`.`vpc_offerings` ( `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if vpc offering is default', `removed` datetime COMMENT 'date removed if not null', `created` datetime NOT NULL COMMENT 'date created', + `service_offering_id` bigint unsigned COMMENT 'service offering id that virtual router is tied to', PRIMARY KEY (`id`), - INDEX `i_vpc__removed`(`removed`) + INDEX `i_vpc__removed`(`removed`), + CONSTRAINT `fk_vpc_offerings__service_offering_id` FOREIGN KEY `fk_vpc_offerings__service_offering_id` (`service_offering_id`) REFERENCES `service_offering`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `cloud`.`vpc_offering_service_map` ( `id` bigint unsigned NOT NULL auto_increment, `vpc_offering_id` bigint unsigned NOT NULL COMMENT 'vpc_offering_id', diff --git a/wscript b/wscript index d9cefcf9323..9eb9470e1eb 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-19T01:23:44Z' +VERSION = '3.0.3.2012-05-21T20:55:19Z' APPNAME = 'cloud' import shutil,os From 1fab93a8fb86440160cb863d3a6bd52004e9e630 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 21 May 2012 17:04:35 -0700 Subject: [PATCH 06/64] Start Virtual Router as a part of VPC start --- .../ExternalFirewallDeviceManagerImpl.java | 2 +- .../src/com/cloud/network/NetworkManager.java | 33 ++-- .../com/cloud/network/NetworkManagerImpl.java | 170 ++++++++++++------ .../src/com/cloud/network/addr/PublicIp.java | 16 ++ .../VirtualNetworkApplianceManagerImpl.java | 67 +++---- ...VpcVirtualNetworkApplianceManagerImpl.java | 6 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 6 +- .../cloud/network/MockNetworkManagerImpl.java | 4 +- wscript | 2 +- 9 files changed, 197 insertions(+), 109 deletions(-) diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java index 6a300a5170e..debf66aa75d 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java @@ -380,7 +380,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl IPAddressVO sourceNatIp = null; if (!sharedSourceNat) { // Get the source NAT IP address for this network - List sourceNatIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(network.getAccountId(), zoneId, true, null); + List sourceNatIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(network.getAccountId(), zoneId, true, null); if (sourceNatIps.size() != 1) { String errorMsg = "External firewall was unable to find the source NAT IP address for account " + account.getAccountName(); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index bdd07175b5b..6d3d44c98d8 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -42,6 +42,7 @@ import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; +import com.cloud.network.vpc.Vpc; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.user.Account; @@ -77,17 +78,6 @@ public interface NetworkManager extends NetworkService { PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; - /** - * assigns a source nat ip address to an account within a network. - * - * @param owner - * @param network - * @param callerId - * @return - * @throws ConcurrentOperationException - * @throws InsufficientAddressCapacityException - */ - PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException; /** * Do all of the work of releasing public ip addresses. Note that if this method fails, there can be side effects. @@ -113,7 +103,7 @@ public interface NetworkManager extends NetworkService { * TODO * @return - list of IP addresses */ - List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); + List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException; @@ -314,4 +304,23 @@ public interface NetworkManager extends NetworkService { * @return */ NetworkElement getElementImplementingProvider(String providerName); + + /** + * @param owner + * @param guestNetwork + * @return + * @throws ConcurrentOperationException + * @throws InsufficientAddressCapacityException + */ + PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param owner + * @param vpc + * @return + * @throws ConcurrentOperationException + * @throws InsufficientAddressCapacityException + */ + PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 838332e5765..e3569069def 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -149,6 +149,7 @@ import com.cloud.network.rules.StaticNat; import com.cloud.network.rules.StaticNatRule; import com.cloud.network.rules.StaticNatRuleImpl; import com.cloud.network.rules.dao.PortForwardingRulesDao; +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; @@ -353,11 +354,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { - return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem); + return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem, null); } @DB - public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem) + public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, + Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId) throws InsufficientAddressCapacityException { StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); Transaction txn = Transaction.currentTxn(); @@ -383,8 +385,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // for direct network take ip addresses only from the vlans belonging to the network if (vlanUse == VlanType.DirectAttached) { - sc.setJoinParameters("vlan", "networkId", networkId); - errorMessage.append(", network id=" + networkId); + sc.setJoinParameters("vlan", "networkId", guestNetworkId); + errorMessage.append(", network id=" + guestNetworkId); } sc.setJoinParameters("vlan", "type", vlanUse); @@ -427,7 +429,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating); if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) { - addr.setAssociatedWithNetworkId(networkId); + addr.setAssociatedWithNetworkId(guestNetworkId); + addr.setVpcId(vpcId); } _ipAddressDao.update(addr.getId(), addr); @@ -472,17 +475,80 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } - + + @Override + public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { + long dcId = vpc.getZoneId(); + + List addrs = listPublicIpsAssignedToVpc(owner.getId(), true, vpc.getId()); + + PublicIp ipToReturn = null; + if (!addrs.isEmpty()) { + IPAddressVO sourceNatIp = null; + // Account already has ip addresses + for (IPAddressVO addr : addrs) { + if (addr.isSourceNat()) { + sourceNatIp = addr; + break; + } + } + + assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + + "account=" + owner.getId() + "; vpc=" + vpc; + ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); + } else { + ipToReturn = assignSourceNatIpAddress(owner, null, vpc.getId(), dcId); + } + + return ipToReturn; + } + + @Override + public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { + assert (guestNetwork.getTrafficType() != null) : "You're asking for a source nat but your network " + + "can't participate in source nat. What do you have to say for yourself?"; + long dcId = guestNetwork.getDataCenterId(); + List addrs = listPublicIpsAssignedToGuestNtwk(owner.getId(), dcId, null, guestNetwork.getId()); + + PublicIp ipToReturn = null; + if (!addrs.isEmpty()) { + IPAddressVO sourceNatIp = null; + // Account already has ip addresses + for (IPAddressVO addr : addrs) { + if (addr.isSourceNat()) { + sourceNatIp = addr; + break; + } + } + + assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + + "account=" + owner.getId() + "; guestNetwork=" + guestNetwork; + ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); + } else { + ipToReturn = assignSourceNatIpAddress(owner, guestNetwork.getId(), null, dcId); + } + + return ipToReturn; + } + @DB - public PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException { - assert (network.getTrafficType() != null) : "You're asking for a source nat but your network can't participate in source nat. What do you have to say for yourself?"; + public PublicIp assignSourceNatIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId) + throws ConcurrentOperationException, InsufficientAddressCapacityException { - long dcId = network.getDataCenterId(); long ownerId = owner.getId(); - + + // Check that the maximum number of public IPs for the given accountId will not be exceeded + try { + _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip); + } catch (ResourceAllocationException ex) { + s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner); + throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded."); + } + PublicIp ip = null; - Transaction txn = Transaction.currentTxn(); try { txn.start(); @@ -499,48 +565,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); } - - IPAddressVO sourceNat = null; - List addrs = listPublicIpAddressesInVirtualNetwork(ownerId, dcId, null, network.getId()); - if (addrs.size() == 0) { - - // Check that the maximum number of public IPs for the given accountId will not be exceeded - try { - _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip); - } catch (ResourceAllocationException ex) { - s_logger.warn("Failed to allocate resource of type " + ex.getResourceType() + " for account " + owner); - throw new AccountLimitException("Maximum number of public IP addresses for account: " + owner.getAccountName() + " has been exceeded."); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("assigning a new ip address in " + dcId + " to " + owner); - } - - // If account has Account specific ip ranges, try to allocate ip from there - Long vlanId = null; - List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId); - if (maps != null && !maps.isEmpty()) { - vlanId = maps.get(0).getVlanDbId(); - } - - ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, network.getId(), true, false, null, false); - sourceNat = ip.ip(); - - markPublicIpAsAllocated(sourceNat); - _ipAddressDao.update(sourceNat.getId(), sourceNat); - } else { - // Account already has ip addresses - for (IPAddressVO addr : addrs) { - if (addr.isSourceNat()) { - sourceNat = addr; - break; - } - } - - assert (sourceNat != null) : "How do we get a bunch of ip addresses but none of them are source nat? account=" + ownerId + "; dc=" + dcId; - ip = new PublicIp(sourceNat, _vlanDao.findById(sourceNat.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNat.getMacAddress())); + + // If account has Account specific ip ranges, try to allocate ip from there + Long vlanId = null; + List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId); + if (maps != null && !maps.isEmpty()) { + vlanId = maps.get(0).getVlanDbId(); } + ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, guestNtwkId, + true, false, null, false, vpcId); + IPAddressVO sourceNatIp = ip.ip(); + + markPublicIpAsAllocated(sourceNatIp); + _ipAddressDao.update(sourceNatIp.getId(), sourceNatIp); + txn.commit(); return ip; } finally { @@ -1009,8 +1048,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // Check that network belongs to IP owner - skip this check for Basic zone as there is just one guest network, -// and it - // belongs to the system + // and it belongs to the system if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != ipOwner.getId()) { throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); } @@ -1056,14 +1094,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!sharedSourceNat) { // First IP address should be source nat when it's being associated with Guest Virtual network - List addrs = listPublicIpAddressesInVirtualNetwork(ownerId, zone.getId(), true, networkId); + List addrs = listPublicIpsAssignedToGuestNtwk(ownerId, zone.getId(), true, networkId); if (addrs.isEmpty() && network.getGuestType() == Network.GuestType.Isolated) { isSourceNat = true; } } - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isSystem); + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), + isSourceNat, assign, null, isSystem, network.getVpcId()); if (ip == null) { InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId()); @@ -1337,6 +1376,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag IpAddressSearch = _ipAddressDao.createSearchBuilder(); IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ); IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); + IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ); IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ); SearchBuilder virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ); @@ -1408,7 +1448,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { SearchCriteria sc = IpAddressSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("dataCenterId", dcId); @@ -1423,6 +1463,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return _ipAddressDao.search(sc, null); } + + protected List listPublicIpsAssignedToVpc(long accountId, Boolean sourceNat, long vpcId) { + SearchCriteria sc = IpAddressSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("vpcId", vpcId); + + if (sourceNat != null) { + sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); + } + sc.setJoinParameters("virtualNetworkVlanSB", "vlanType", VlanType.VirtualNetwork); + + return _ipAddressDao.search(sc, null); + } @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) @@ -1601,7 +1654,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nics.add(vo); Integer networkRate = getNetworkRate(config.getId(), vm.getId()); - vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), + vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, + isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), network.first()))); } @@ -1783,7 +1837,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ips.isEmpty()) { s_logger.debug("Creating a source nat ip for " + network); Account owner = _accountMgr.getAccount(network.getAccountId()); - assignSourceNatIpAddress(owner, network, context.getCaller().getId()); + assignSourceNatIpAddressToGuestNetwork(owner, network); } } diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java index 5322674e19b..11948e5c836 100644 --- a/server/src/com/cloud/network/addr/PublicIp.java +++ b/server/src/com/cloud/network/addr/PublicIp.java @@ -180,4 +180,20 @@ public class PublicIp implements PublicIpAddress { public boolean getSystem() { return _addr.getSystem(); } + + /* (non-Javadoc) + * @see com.cloud.network.IpAddress#getVpcId() + */ + @Override + public Long getVpcId() { + return _addr.getVpcId(); + } + + /* (non-Javadoc) + * @see com.cloud.network.IpAddress#setVpcId(java.lang.Long) + */ + @Override + public void setVpcId(Long vpcId) { + _addr.setVpcId(vpcId); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a27c25ed2a5..c1da734abcf 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1249,9 +1249,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //3) Deploy Virtual Router(s) try { int count = routerCount - routers.size(); + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, - vrProvider, offeringId); + vrProvider, offeringId, sourceNatIp); routers.add(router); } } finally { @@ -1264,7 +1265,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, - VirtualRouterProvider vrProvider, long svcOffId) throws ConcurrentOperationException, + VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1275,7 +1276,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //1) Create router networks List> networks = createRouterNetworks(owner, setupPublicNetwork, guestNetwork, - isRedundant, plan); + isRedundant, plan, sourceNatIp); ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); @@ -1365,38 +1366,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, - Network guestNetwork, boolean isRedundant, DeploymentPlan plan) throws ConcurrentOperationException, + Network guestNetwork, boolean isRedundant, DeploymentPlan plan, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException { //Form networks - //1) Public network List> networks = new ArrayList>(3); - if (setupPublicNetwork) { - s_logger.debug("Adding nic for Virtual Router in Public network "); - //if source nat service is supported by the network, get the source nat ip address - PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountMgr.getSystemUser().getId()); - NicProfile defaultNic = new NicProfile(); - defaultNic.setDefaultNic(true); - defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); - defaultNic.setGateway(sourceNatIp.getGateway()); - defaultNic.setNetmask(sourceNatIp.getNetmask()); - defaultNic.setMacAddress(sourceNatIp.getMacAddress()); - defaultNic.setBroadcastType(BroadcastDomainType.Vlan); - defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setDeviceId(2); - NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); - networks.add(new Pair(publicNetworks.get(0), defaultNic)); - } - - //2) Control network - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - s_logger.debug("Adding nic for Virtual Router in Control network "); - networks.add(new Pair(controlConfig, null)); - //3) Guest network + //1) Guest network if (guestNetwork != null) { String defaultNetworkStartIp = null; s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); @@ -1409,6 +1384,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian " is already allocated, can't use it for domain router; will get random ip address from the range"); } } + + NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); if (setupPublicNetwork) { @@ -1428,6 +1405,31 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); } + + //2) Control network + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + s_logger.debug("Adding nic for Virtual Router in Control network "); + networks.add(new Pair(controlConfig, null)); + + //3) Public network + if (setupPublicNetwork) { + s_logger.debug("Adding nic for Virtual Router in Public network "); + //if source nat service is supported by the network, get the source nat ip address + NicProfile defaultNic = new NicProfile(); + defaultNic.setDefaultNic(true); + defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); + defaultNic.setGateway(sourceNatIp.getGateway()); + defaultNic.setNetmask(sourceNatIp.getNetmask()); + defaultNic.setMacAddress(sourceNatIp.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); + NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + networks.add(new Pair(publicNetworks.get(0), defaultNic)); + } return networks; } @@ -1566,6 +1568,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); + _dcDao.loadDetails(dc); //1) Set router details DomainRouterVO router = profile.getVirtualMachine(); @@ -1848,7 +1851,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian long ownerId = router.getAccountId(); long zoneId = router.getDataCenterIdToDeployIn(); - final List userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null, guestNetworkId); + final List userIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(ownerId, zoneId, null, guestNetworkId); List allPublicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index e2287a58f35..55b6070459e 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -27,6 +27,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; +import com.cloud.network.addr.PublicIp; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -65,6 +66,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian Map params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + s_logger.debug("Deploying Virtual Router in VPC "+ vpc); Vpc vpcLock = _vpcDao.acquireInLockTable(vpc.getId()); if (vpcLock == null) { throw new ConcurrentOperationException("Unable to lock vpc " + vpc.getId()); @@ -89,8 +91,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian try { //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(1, VirtualRouterProviderType.VirtualRouter); + + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, - vrProvider, offeringId); + vrProvider, offeringId, sourceNatIp); routers.add(router); } finally { diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 7fb6bc646ce..5241057a516 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -31,17 +31,19 @@ import com.cloud.deploy.DeployDestination; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; 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.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; +import com.cloud.network.IPAddressVO; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; +import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.NetworkDao; -import com.cloud.network.element.NetworkElement; import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.network.vpc.Dao.VpcDao; @@ -641,6 +643,6 @@ public class VpcManagerImpl implements VpcManager, Manager{ throw new CloudRuntimeException("Failed to start vpc " + vpc); //FIXME - add cleanup logic here } - } + } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index d2f01b109d6..a96c596bc27 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -180,7 +180,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override - public PublicIp assignSourceNatIpAddress(Account owner, Network network, long callerId) throws ConcurrentOperationException, InsufficientAddressCapacityException { + public PublicIp assignSourceNatIpAddress(Account owner, Network guestNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { // TODO Auto-generated method stub return null; } @@ -192,7 +192,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { // TODO Auto-generated method stub return null; } diff --git a/wscript b/wscript index 9eb9470e1eb..71b15e2fa85 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-21T20:55:19Z' +VERSION = '3.0.3.2012-05-22T00:32:35Z' APPNAME = 'cloud' import shutil,os From 891b6486e4630898ddfe54dfbbfd4740f95147ad Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 21 May 2012 17:40:44 -0700 Subject: [PATCH 07/64] Deploy VR as a part of VPC: set elementId to the VR element id of the first physical network in the zone by now. TODO - add logic for handling the case when VR has 1 to many element ids relationship --- .../router/VpcVirtualNetworkApplianceManagerImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 55b6070459e..68c9bdba894 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -25,9 +25,11 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; +import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -50,6 +52,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian VpcDao _vpcDao = null; @Inject VpcOfferingDao _vpcOffDao = null; + @Inject + PhysicalNetworkDao _pNtwkDao = null; @Override public List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, @@ -90,7 +94,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //3) Deploy Virtual Router try { //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs - VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(1, VirtualRouterProviderType.VirtualRouter); + List pNtwks = _pNtwkDao.listByZone(vpc.getZoneId()); + + VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(pNtwks.get(0).getId(), VirtualRouterProviderType.VirtualRouter); PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, From 675bad3eed400b2c2d1665f7a92479059148e9c8 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 21 May 2012 18:01:25 -0700 Subject: [PATCH 08/64] Add type and rpcfilter to the virtual router bootload arguments even when there is no guest network is being configured. --- .../VirtualNetworkApplianceManagerImpl.java | 124 +++++++++--------- wscript | 2 +- 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index c1da734abcf..08ba413de22 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1372,6 +1372,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian List> networks = new ArrayList>(3); //1) Guest network + boolean hasGuestNetwork = false; if (guestNetwork != null) { String defaultNetworkStartIp = null; s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); @@ -1404,16 +1405,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian gatewayNic.setDefaultNic(true); } networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); + hasGuestNetwork = true; } - //2) Control network - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - s_logger.debug("Adding nic for Virtual Router in Control network "); - networks.add(new Pair(controlConfig, null)); - - //3) Public network + //2) Public network if (setupPublicNetwork) { s_logger.debug("Adding nic for Virtual Router in Public network "); //if source nat service is supported by the network, get the source nat ip address @@ -1426,11 +1421,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian defaultNic.setBroadcastType(BroadcastDomainType.Vlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); + if (hasGuestNetwork) { + defaultNic.setDeviceId(2); + } NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); networks.add(new Pair(publicNetworks.get(0), defaultNic)); } - + + //3) Control network + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + s_logger.debug("Adding nic for Virtual Router in Control network "); + networks.add(new Pair(controlConfig, null)); + return networks; } @@ -1588,6 +1593,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile controlNic = null; String defaultDns1 = null; String defaultDns2 = null; + boolean publicNetwork = false; for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); @@ -1632,6 +1638,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } else if (nic.getTrafficType() == TrafficType.Guest) { //build bootloader parameter for the guest createGuestBootLoadArgs(profile, nic, defaultDns1, defaultDns2); + } else if (nic.getTrafficType() == TrafficType.Public) { + publicNetwork = true; + } } @@ -1639,42 +1648,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new CloudRuntimeException("Didn't start a control port"); } - - String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName()); - if (domain_suffix != null) { - buf.append(" dnssearchorder=").append(domain_suffix); - } - - if (profile.getHypervisorType() == HypervisorType.VMware) { - buf.append(" extra_pubnics=" + _routerExtraPublicNics); - } - - - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); - } - - return true; - } - - protected void createGuestBootLoadArgs(VirtualMachineProfile profile, NicProfile nic, - String defaultDns1, String defaultDns2) { - long guestNetworkId = nic.getNetworkId(); - NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); - DomainRouterVO router = profile.getVirtualMachine(); - String type = null; - String dhcpRange = null; - String rpFilter = " "; - DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); - - if (dc.getNetworkType() == NetworkType.Advanced) { - String cidr = guestNetwork.getCidr(); - if (cidr != null) { - dhcpRange = NetUtils.getDhcpRange(cidr); - } - } - String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key()); if (rpValue != null && rpValue.equalsIgnoreCase("true")) { _disable_rp_filter = true; @@ -1682,11 +1655,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _disable_rp_filter = false; } - boolean publicNetwork = false; - if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { - publicNetwork = true; - } - + String rpFilter = " "; + String type = null; if (!publicNetwork) { type = "dhcpsrvr"; } else { @@ -1695,10 +1665,42 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian rpFilter=" disable_rp_filter=true"; } } + + buf.append(" type=" + type + rpFilter); + + String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName()); + if (domain_suffix != null) { + buf.append(" dnssearchorder=").append(domain_suffix); + } + + if (profile.getHypervisorType() == HypervisorType.VMware) { + buf.append(" extra_pubnics=" + _routerExtraPublicNics); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + } + + return true; + } + + protected void createGuestBootLoadArgs(VirtualMachineProfile profile, NicProfile guestNic, + String defaultDns1, String defaultDns2) { + long guestNetworkId = guestNic.getNetworkId(); + NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + DomainRouterVO router = profile.getVirtualMachine(); + String dhcpRange = null; + DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); + + if (dc.getNetworkType() == NetworkType.Advanced) { + String cidr = guestNetwork.getCidr(); + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); + } + } StringBuilder buf = profile.getBootArgsBuilder(); - buf.append(" type=" + type + rpFilter); - + boolean isRedundant = router.getIsRedundantRouter(); if (isRedundant) { buf.append(" redundant_router=1"); @@ -1712,9 +1714,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - if (nic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { - long cidrSize = NetUtils.getCidrSize(nic.getNetmask()); - String cidr = NetUtils.getCidrSubNet(nic.getGateway(), cidrSize); + if (guestNic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { + long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); if (cidr != null) { dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); } @@ -1725,11 +1727,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } if (isRedundant) { - Network net = _networkMgr.getNetwork(nic.getNetworkId()); + Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); buf.append(" guestgw=").append(net.getGateway()); - String brd = NetUtils.long2Ip(NetUtils.ip2Long(nic.getIp4Address()) | ~NetUtils.ip2Long(nic.getNetmask())); + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); buf.append(" guestbrd=").append(brd); - buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(nic.getNetmask())); + buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); buf.append(" router_pr=").append(router.getPriority()); } @@ -1740,10 +1742,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean dnsProvided = false; boolean dhcpProvided = false; - if (nic.getTrafficType() == TrafficType.Guest) { + if (guestNic.getTrafficType() == TrafficType.Guest) { //FiXME - for multiple guest network case this should be set individually - dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); + dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); } /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response * to return DNS server rather than diff --git a/wscript b/wscript index 71b15e2fa85..b99c3f9d463 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-22T00:32:35Z' +VERSION = '3.0.3.2012-05-22T00:59:20Z' APPNAME = 'cloud' import shutil,os From 9fb9149c992c80ccac79ce644e30c69c0396c7ed Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 22 May 2012 16:48:09 -0700 Subject: [PATCH 09/64] 1) Added new element - VpcVirtualRouterElement. Extends VirtualRouter + has plug/unplug nics support 2) Added services api support for plugging/unplugging the nics to VpcElement --- api/src/com/cloud/api/ApiConstants.java | 1 + .../cloud/api/commands/CreateNetworkCmd.java | 27 +- .../com/cloud/api/commands/CreateVPCCmd.java | 10 +- .../commands/UpdateNetworkOfferingCmd.java | 3 +- api/src/com/cloud/network/Network.java | 8 +- api/src/com/cloud/network/NetworkService.java | 40 ++- .../cloud/network/element/VpcProvider.java | 32 +++ api/src/com/cloud/network/vpc/VpcService.java | 3 +- .../com/cloud/offering/NetworkOffering.java | 2 + api/src/com/cloud/vm/NicProfile.java | 7 - api/src/com/cloud/vm/PluggableNics.java | 20 ++ api/src/com/cloud/vm/VirtualMachine.java | 2 + client/tomcatconf/components.xml.in | 1 + core/src/com/cloud/vm/DomainRouterVO.java | 5 + core/src/com/cloud/vm/VMInstanceVO.java | 5 + .../ConfigurationManagerImpl.java | 15 +- .../src/com/cloud/network/NetworkManager.java | 25 +- .../com/cloud/network/NetworkManagerImpl.java | 238 ++++++++++++++---- server/src/com/cloud/network/NetworkVO.java | 14 +- .../network/element/VirtualRouterElement.java | 138 ++++++---- .../element/VpcVirtualRouterElement.java | 154 ++++++++++++ .../cloud/network/guru/GuestNetworkGuru.java | 87 ++----- .../VirtualNetworkApplianceManagerImpl.java | 29 ++- .../VpcVirtualNetworkApplianceManager.java | 16 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 67 ++++- .../src/com/cloud/network/vpc/VpcManager.java | 16 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 126 +++++++++- server/src/com/cloud/network/vpc/VpcVO.java | 7 +- .../dao/NetworkOfferingServiceMapDao.java | 2 + .../dao/NetworkOfferingServiceMapDaoImpl.java | 15 ++ .../cloud/server/ConfigurationServerImpl.java | 33 ++- .../src/com/cloud/vm/UserVmManagerImpl.java | 25 +- .../src/com/cloud/vm/dao/DomainRouterDao.java | 4 +- .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 27 +- .../cloud/network/MockNetworkManagerImpl.java | 51 +++- setup/db/create-schema.sql | 1 + wscript | 2 +- 37 files changed, 991 insertions(+), 267 deletions(-) create mode 100644 api/src/com/cloud/vm/PluggableNics.java create mode 100644 server/src/com/cloud/network/element/VpcVirtualRouterElement.java diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 3d4f64b446d..65bc5e32c5a 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -347,6 +347,7 @@ public class ApiConstants { public static final String VSM_IPADDRESS = "vsmipaddress"; public static final String VPC_OFF_ID = "vpcofferingid"; public static final String NETWORK = "network"; + public static final String VPC_ID = "vpcid"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java index 7058165396c..a9e1291a782 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -58,16 +58,19 @@ public class CreateNetworkCmd extends BaseCmd { @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to") private Long physicalNetworkId; - @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network") + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " + + "for Shared networks and Isolated networks when it belongs to VPC") private String gateway; - @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network") + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " + + "for Shared networks and Isolated networks when it belongs to VPC") private String netmask; @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range") private String startIp; - @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP range. If not specified, will be defaulted to startIP") + @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" + + " range. If not specified, will be defaulted to startIP") private String endIp; @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") @@ -76,7 +79,9 @@ public class CreateNetworkCmd extends BaseCmd { @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") private String networkDomain; - @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network") + @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" + + " are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" + + " - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network") private String aclType; @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network") @@ -90,9 +95,13 @@ public class CreateNetworkCmd extends BaseCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network") private Long domainId; - @Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified") + @Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" + + " subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified") private Boolean subdomainAccess; + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to") + private Long vpcId; ///////////////////////////////////////////////////// @@ -154,7 +163,11 @@ public class CreateNetworkCmd extends BaseCmd { return subdomainAccess; } - public Long getZoneId() { + public Long getVpcId() { + return vpcId; + } + + public Long getZoneId() { Long physicalNetworkId = getPhysicalNetworkId(); if (physicalNetworkId == null && zoneId == null) { @@ -204,7 +217,7 @@ public class CreateNetworkCmd extends BaseCmd { @Override public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{ - Network result = _networkService.createNetwork(this); + Network result = _networkService.createGuestNetwork(this); if (result != null) { NetworkResponse response = _responseGenerator.createNetworkResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java index b8e2fe3bb6c..ec915ed4996 100644 --- a/api/src/com/cloud/api/commands/CreateVPCCmd.java +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -69,6 +69,9 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") private Long vpcOffering; + @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") + private String networkDomain; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -100,10 +103,15 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ public Long getVpcOffering() { return vpcOffering; } + + public String getNetworkDomain() { + return networkDomain; + } @Override public void create() throws ResourceAllocationException { - Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr()); + Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), + getCidr(), getNetworkDomain()); if (vpc != null) { this.setEntityId(vpc.getId()); } else { diff --git a/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java index 27ba31b2565..319f58f946e 100755 --- a/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java @@ -43,7 +43,8 @@ public class UpdateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the network offering") private String displayText; - @Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering") + @Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering." + + " Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering") private String availability; @Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the network offering, integer") diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 26d2164e870..5c643b25f7e 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -41,8 +41,11 @@ public interface Network extends ControlledEntity { public static final Service Dhcp = new Service("Dhcp"); public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification); public static final Service Gateway = new Service("Gateway"); - public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.TrafficStatistics); - public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps, Capability.SupportedStickinessMethods, Capability.ElasticLb); + public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, + Capability.MultipleIps, Capability.TrafficStatistics); + public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, + Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps, + Capability.SupportedStickinessMethods, Capability.ElasticLb); public static final Service UserData = new Service("UserData"); public static final Service SourceNat = new Service("SourceNat", Capability.SupportedSourceNatTypes, Capability.RedundantRouter); public static final Service StaticNat = new Service("StaticNat", Capability.ElasticIp); @@ -109,6 +112,7 @@ public interface Network extends ControlledEntity { public static final Provider ExternalGateWay = new Provider("ExternalGateWay", true); public static final Provider ElasticLoadBalancerVm = new Provider("ElasticLoadBalancerVm", false); public static final Provider SecurityGroupProvider = new Provider("SecurityGroupProvider", false); + public static final Provider VPCVirtualRouter = new Provider("VpcVirtualRouter", false); public static final Provider None = new Provider("None", false); private String name; diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index fe82d3fff8a..3b05d996250 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -32,12 +32,14 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.utils.Pair; +import com.cloud.vm.VirtualMachine; public interface NetworkService { List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner); - IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; + IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, + InsufficientAddressCapacityException, ConcurrentOperationException; /** * Associates a public IP address for a router. @@ -48,17 +50,20 @@ public interface NetworkService { * @throws ResourceAllocationException * , InsufficientCapacityException */ - IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException; + IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, + ConcurrentOperationException, ResourceUnavailableException; boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; - Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException; + Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, + ResourceAllocationException; List searchForNetworks(ListNetworksCmd cmd); boolean deleteNetwork(long networkId); - boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; int getActiveNicsInNetwork(long networkId); @@ -74,7 +79,8 @@ public interface NetworkService { Long getDedicatedNetworkDomain(long networkId); - Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr); + Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, + String domainSuffix, Long networkOfferingId, Boolean changeCidr); Integer getNetworkRate(long networkId, Long vmId); @@ -82,11 +88,14 @@ public interface NetworkService { Map> getNetworkOfferingServiceProvidersMap(long networkOfferingId); - PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List isolationMethods, String broadcastDomainRange, Long domainId, List tags, String name); + PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, + List isolationMethods, String broadcastDomainRange, Long domainId, List tags, String name); - List searchPhysicalNetworks(Long id, Long zoneId, String keyword, Long startIndex, Long pageSize, String name); + List searchPhysicalNetworks(Long id, Long zoneId, String keyword, + Long startIndex, Long pageSize, String name); - PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List tags, String newVnetRangeString, String state); + PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List tags, + String newVnetRangeString, String state); boolean deletePhysicalNetwork(Long id); @@ -94,9 +103,11 @@ public interface NetworkService { List listSupportedNetworkServiceProviders(String serviceName); - PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List enabledServices); + PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, + Long destinationPhysicalNetworkId, List enabledServices); - List listNetworkServiceProviders(Long physicalNetworkId, String name, String state, Long startIndex, Long pageSize); + List listNetworkServiceProviders(Long physicalNetworkId, String name, + String state, Long startIndex, Long pageSize); PhysicalNetworkServiceProvider updateNetworkServiceProvider(Long id, String state, List enabledServices); @@ -112,7 +123,8 @@ public interface NetworkService { long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType); - PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficType, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan); + PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficType, + String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan); PhysicalNetworkTrafficType getPhysicalNetworkTrafficType(Long id); @@ -131,5 +143,11 @@ public interface NetworkService { List getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner); List listNetworksByVpc(long vpcId); + + boolean addVmToNetwork(VirtualMachine vm, Network network); + + boolean removeVmFromNetwork(VirtualMachine vm, Network network); + + boolean isVmPartOfNetwork(long vmId, long ntwkId); } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 86f70ea53d9..7c352000324 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -17,8 +17,12 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; import com.cloud.network.vpc.Vpc; +import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; /** * @author Alena Prokharchyk @@ -31,5 +35,33 @@ public interface VpcProvider extends NetworkElement{ */ boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + + /** + * Prepare for a nic to be plugged into the network. + * @param network + * @param nic + * @param vm + * @param context + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientNetworkCapacityException + */ + boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * A nic is unplugged from this network. + * @param network + * @param nic + * @param vm + * @param context + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 682c0c6feec..2272464daf8 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -63,9 +63,10 @@ public interface VpcService { * @param vpcName * @param displayText * @param cidr + * @param networkDomain TODO * @return */ - public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr); + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain); /** * @param vpcId diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 195bc0d6926..8e8939d563a 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -42,6 +42,8 @@ public interface NetworkOffering { public final static String DefaultSharedNetworkOffering = "DefaultSharedNetworkOffering"; public final static String DefaultIsolatedNetworkOffering = "DefaultIsolatedNetworkOffering"; public final static String DefaultSharedEIPandELBNetworkOffering = "DefaultSharedNetscalerEIPandELBNetworkOffering"; + public final static String DefaultIsolatedNetworkOfferingForVpcNetworks = "DefaultIsolatedNetworkOfferingForVpcNetworks"; + long getId(); diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index 128e36172e8..ee6481d96f4 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -230,13 +230,6 @@ public class NicProfile { } } - public NicProfile(long id, BroadcastDomainType type, Mode mode, long vmId) { - this.id = id; - this.broadcastType = type; - this.mode = mode; - this.vmId = vmId; - } - public NicProfile(ReservationStrategy strategy, String ip4Address, String macAddress, String gateway, String netmask) { this.format = AddressFormat.Ip4; this.ip4Address = ip4Address; diff --git a/api/src/com/cloud/vm/PluggableNics.java b/api/src/com/cloud/vm/PluggableNics.java new file mode 100644 index 00000000000..3b6c34970f2 --- /dev/null +++ b/api/src/com/cloud/vm/PluggableNics.java @@ -0,0 +1,20 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.vm; + +/** + * @author Alena Prokharchyk + */ +public interface PluggableNics { + boolean canPlugNics(); +} diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java index d282aa6464f..9dc04c1ee0b 100755 --- a/api/src/com/cloud/vm/VirtualMachine.java +++ b/api/src/com/cloud/vm/VirtualMachine.java @@ -286,4 +286,6 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, S HypervisorType getHypervisorType(); public Map getDetails(); + + boolean canPlugNics(); } diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 48869b5daee..5a5bcac3e6e 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -142,6 +142,7 @@ + diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 43d851dcd76..f5cc8f9b260 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -248,4 +248,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { public Long getVpcId() { return vpcId; } + + @Override + public boolean canPlugNics() { + return true; + } } diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java index f9c57f5931e..2d9eeb6a00d 100644 --- a/core/src/com/cloud/vm/VMInstanceVO.java +++ b/core/src/com/cloud/vm/VMInstanceVO.java @@ -458,5 +458,10 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject offerings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) { - throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required); + throw new InvalidParameterValueException("System already has network offering id=" + + offerings.get(0).getId() + " with availability " + Availability.Required); } } offering.setAvailability(availability); @@ -3590,7 +3594,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } @Override - @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the default zone", async=true) + @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + + "default zone", async=true) public AccountVO markDefaultZone(String accountName, long domainId, long defaultZoneId) { // Check if the account exists diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6d3d44c98d8..839e18f7eed 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -152,8 +152,8 @@ public interface NetworkManager extends NetworkService { boolean destroyNetwork(long networkId, ReservationContext context); - Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, boolean isSecurityGroupEnabled, Long domainId, - PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException; + Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork physicalNetwork, + long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException; /** * @throws ResourceAllocationException TODO @@ -323,4 +323,25 @@ public interface NetworkManager extends NetworkService { * @throws InsufficientAddressCapacityException */ PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param accountId + * @param zoneId + * @return + */ + String getAccountNetworkDomain(long accountId, long zoneId); + + + /** + * @return + */ + String getDefaultNetworkDomain(); + + + /** + * @param networkId + * @return + */ + List getNtwkOffDistinctProviders(long networkId); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e3569069def..4ba627e00ba 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -150,6 +150,7 @@ import com.cloud.network.rules.StaticNatRule; import com.cloud.network.rules.StaticNatRuleImpl; import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcManager; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; @@ -302,6 +303,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkServiceMapDao _ntwkSrvcDao; @Inject StorageNetworkManager _stnwMgr; + @Inject + VpcManager _vpcMgr; private final HashMap _systemNetworks = new HashMap(5); @@ -1298,16 +1301,43 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _networkOfferingDao.update(offering.getId(), offering); } + Map> defaultINetworkOfferingProvidersForVpcNetwork = new HashMap>(); + defaultProviders.clear(); + defaultProviders.add(Network.Provider.VPCVirtualRouter); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Dhcp, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Dns, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.UserData, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Firewall, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Gateway, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Lb, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.SourceNat, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.StaticNat, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.PortForwarding, defaultProviders); + defaultINetworkOfferingProvidersForVpcNetwork.put(Service.Vpn, defaultProviders); + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, - null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, + "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, + null, false, Availability.Required, null, defaultINetworkOfferingProvidersForVpcNetwork, + true, Network.GuestType.Isolated, false, null, true, null, false); + offering.setState(NetworkOffering.State.Enabled); + _networkOfferingDao.update(offering.getId(), offering); + } + + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) { + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, + "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, + null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, + true, Network.GuestType.Isolated, false, null, true, null, false); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, - Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, + "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, + Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, + false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -1416,7 +1446,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Provider implementedProvider = element.getProvider(); if (implementedProvider != null) { if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) { - s_logger.error("Cannot start NetworkManager: Provider <-> NetworkElement must be a one-to-one map, multiple NetworkElements found for Provider: " + implementedProvider.getName()); + s_logger.error("Cannot start NetworkManager: Provider <-> NetworkElement must be a one-to-one map, " + + "multiple NetworkElements found for Provider: " + implementedProvider.getName()); return false; } s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName()); @@ -1485,8 +1516,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, + public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan + plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException { + Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { throw new ConcurrentOperationException("Unable to acquire lock on " + owner); @@ -1494,7 +1527,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag try { if (predefined == null - || (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && predefined.getBroadcastDomainType() != BroadcastDomainType.Vlan)) { + || (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null + && predefined.getBroadcastUri() == null && predefined.getBroadcastDomainType() != BroadcastDomainType.Vlan)) { List configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { if (s_logger.isDebugEnabled()) { @@ -1502,7 +1536,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } if (errorIfAlreadySetup) { - throw new InvalidParameterValueException("Found existing network configuration for offering " + offering + ": " + configs.get(0)); + throw new InvalidParameterValueException("Found existing network configuration for offering " + + offering + ": " + configs.get(0)); } else { return configs; } @@ -1516,7 +1551,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } if (errorIfAlreadySetup) { - throw new InvalidParameterValueException("Found existing network configuration for offering " + offering + ": " + configs.get(0)); + throw new InvalidParameterValueException("Found existing network configuration for offering " + + offering + ": " + configs.get(0)); } else { return configs; } @@ -1871,7 +1907,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - protected void prepareElement(NetworkElement element, NetworkVO network, NicProfile profile, VirtualMachineProfile vmProfile, + protected void prepareElement(NetworkElement element, NetworkVO network, + NicProfile profile, VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { element.prepare(network, profile, vmProfile, dest, context); @@ -2255,7 +2292,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NETWORK_CREATE, eventDescription = "creating network") - public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { + public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { Long networkOfferingId = cmd.getNetworkOfferingId(); String gateway = cmd.getGateway(); String startIP = cmd.getStartIp(); @@ -2265,7 +2302,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String vlanId = cmd.getVlan(); String name = cmd.getNetworkName(); String displayText = cmd.getDisplayText(); - Long userId = UserContext.current().getCallerUserId(); Account caller = UserContext.current().getCaller(); Long physicalNetworkId = cmd.getPhysicalNetworkId(); Long zoneId = cmd.getZoneId(); @@ -2273,6 +2309,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Long domainId = cmd.getDomainId(); boolean isDomainSpecific = false; Boolean subdomainAccess = cmd.getSubdomainAccess(); + Long vpcId = cmd.getVpcId(); // Validate network offering NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); @@ -2304,6 +2341,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ex.addProxyObject("data_center", zone.getId(), "zoneId"); throw ex; } + + //validate vpc + if (vpcId != null) { + Vpc vpc = _vpcMgr.getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + } + _accountMgr.checkAccess(caller, null, false, vpc); + } // Only domain and account ACL types are supported in Acton. ACLType aclType = null; @@ -2322,7 +2368,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } else if (ntwkOff.getGuestType() == GuestType.Shared) { if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) { - throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + ACLType.Account + " for network of type " + Network.GuestType.Shared); + throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + + ACLType.Account + " for network of type " + Network.GuestType.Shared); } } } else { @@ -2352,7 +2399,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (domainId != null) { if (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Shared) { - throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + TrafficType.Guest + " and guest type " + Network.GuestType.Shared); + throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + + TrafficType.Guest + " and guest type " + Network.GuestType.Shared); } DomainVO domain = _domainDao.findById(domainId); @@ -2413,7 +2461,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("Regular user can create a network only from the network offering having traffic type " + TrafficType.Guest + " and network type " + throw new InvalidParameterValueException("Regular user can create a network only from the network" + + " offering having traffic type " + TrafficType.Guest + " and network type " + Network.GuestType.Isolated + " with a service " + Service.SourceNat.getName() + " enabled"); } @@ -2445,7 +2494,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // 2) GuestType is Isolated, but SourceNat service is disabled boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && ((ntwkOff.getGuestType() == Network.GuestType.Shared) - || (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)))); + || (ntwkOff.getGuestType() == GuestType.Isolated && + !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)))); // Can add vlan range only to the network which allows it if (createVlan && !ntwkOff.getSpecifyIpRanges()) { @@ -2470,22 +2520,45 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); } - Network network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, false, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess); + //Create guest network + Network network = null; + if (vpcId != null) { + network = createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, + networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); + } else { + network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, + networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); + } if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) { // Create vlan ip range - _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId, false, null, startIP, endIP, gateway, netmask, vlanId, null); + _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId, + false, null, startIP, endIP, gateway, netmask, vlanId, null); } txn.commit(); return network; } + + public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, + String cidr, String vlanId, String networkDomain, Account owner, Long domainId, + PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId) + throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + + _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, + _vpcMgr.getVpc(vpcId)); + + return createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, + networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); + } @Override @DB - public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, boolean isSecurityGroupEnabled, - Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, + String cidr, String vlanId, String networkDomain, Account owner, Long domainId, + PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId) + throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); // this method supports only guest network creation @@ -2503,7 +2576,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Validate network offering if (ntwkOff.getState() != NetworkOffering.State.Enabled) { // see NetworkOfferingVO - InvalidParameterValueException ex = new InvalidParameterValueException("Can't use specified network offering id as its stat is not " + NetworkOffering.State.Enabled); + InvalidParameterValueException ex = new InvalidParameterValueException("Can't use specified network " + + "offering id as its stat is not " + NetworkOffering.State.Enabled); ex.addProxyObject("network_offerings", networkOfferingId, "networkOfferingId"); throw ex; } @@ -2511,7 +2585,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Validate physical network if (pNtwk.getState() != PhysicalNetwork.State.Enabled) { // see PhysicalNetworkVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is in incorrect state:" + pNtwk.getState()); + InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is" + + " in incorrect state:" + pNtwk.getState()); ex.addProxyObject("physical_network", pNtwk.getId(), "physicalNetworkId"); throw ex; } @@ -2527,12 +2602,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Only one guest network is supported in Basic zone List guestNetworks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Guest); if (!guestNetworks.isEmpty()) { - throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " + NetworkType.Basic); + throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " + + NetworkType.Basic); } // if zone is basic, only Shared network offerings w/o source nat service are allowed - if (!(ntwkOff.getGuestType() == GuestType.Shared && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() + if (!(ntwkOff.getGuestType() == GuestType.Shared && + !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { + throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of " + + "guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() + " service are allowed"); } @@ -2543,14 +2621,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (subdomainAccess == null) { subdomainAccess = true; } else if (!subdomainAccess) { - throw new InvalidParameterValueException("Subdomain access should be set to true for the guest network in the Basic zone"); + throw new InvalidParameterValueException("Subdomain access should be set to true for the" + + " guest network in the Basic zone"); } if (vlanId == null) { vlanId = Vlan.UNTAGGED; } else { if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) { - throw new InvalidParameterValueException("Only vlan " + Vlan.UNTAGGED + " can be created in the zone of type " + NetworkType.Basic); + throw new InvalidParameterValueException("Only vlan " + Vlan.UNTAGGED + " can be created in " + + "the zone of type " + NetworkType.Basic); } } @@ -2558,9 +2638,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (zone.isSecurityGroupEnabled()) { // Only Account specific Isolated network with sourceNat service disabled are allowed in security group // enabled zone - boolean allowCreation = (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)); + boolean allowCreation = (ntwkOff.getGuestType() == GuestType.Isolated + && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)); if (!allowCreation) { - throw new InvalidParameterValueException("Only Account specific Isolated network with sourceNat service disabled are allowed in security group enabled zone"); + throw new InvalidParameterValueException("Only Account specific Isolated network with sourceNat " + + "service disabled are allowed in security group enabled zone"); } } } @@ -2585,11 +2667,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // If networkDomain is not specified, take it from the global configuration if (areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) { - Map dnsCapabilities = getNetworkOfferingServiceCapabilities(_configMgr.getNetworkOffering(networkOfferingId), Service.Dns); + Map dnsCapabilities = getNetworkOfferingServiceCapabilities + (_configMgr.getNetworkOffering(networkOfferingId), Service.Dns); String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification); if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) { if (networkDomain != null) { - throw new InvalidParameterValueException("Domain name change is not supported by network offering id=" + networkOfferingId + " in zone id=" + zoneId); + throw new InvalidParameterValueException("Domain name change is not supported by network offering id=" + + networkOfferingId + " in zone id=" + zoneId); } } else { if (networkDomain == null) { @@ -2609,7 +2693,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // validate network domain if (!NetUtils.verifyDomainName(networkDomain)) { throw new InvalidParameterValueException( - "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " + + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\""); } } @@ -2620,9 +2705,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // limitation, remove after we introduce support for multiple ip ranges // with different Cidrs for the same Shared network boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && ntwkOff.getTrafficType() == TrafficType.Guest - && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))); + && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated + && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))); if (cidr == null && cidrRequired) { - throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of type " + Network.GuestType.Shared + " and network of type " + GuestType.Isolated + " with service " + throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" + + " type " + Network.GuestType.Shared + " and network of type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled"); } @@ -2663,13 +2750,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - List networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, aclType, subdomainAccess); + List networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, + aclType, subdomainAccess); Network network = null; if (networks == null || networks.isEmpty()) { throw new CloudRuntimeException("Fail to create a network"); } else { - if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) { + if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && + networks.get(0).getTrafficType() == TrafficType.Guest) { Network defaultGuestNetwork = networks.get(0); for (Network nw : networks) { if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) { @@ -3698,14 +3787,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public String getIpInNetwork(long vmId, long networkId) { Nic guestNic = getNicInNetwork(vmId, networkId); - assert (guestNic != null && guestNic.getIp4Address() != null) : "Vm doesn't belong to network associated with ipAddress or ip4 address is null"; + assert (guestNic != null && guestNic.getIp4Address() != null) : "Vm doesn't belong to network associated with " + + "ipAddress or ip4 address is null"; return guestNic.getIp4Address(); } @Override public String getIpInNetworkIncludingRemoved(long vmId, long networkId) { Nic guestNic = getNicInNetworkIncludingRemoved(vmId, networkId); - assert (guestNic != null && guestNic.getIp4Address() != null) : "Vm doesn't belong to network associated with ipAddress or ip4 address is null"; + assert (guestNic != null && guestNic.getIp4Address() != null) : "Vm doesn't belong to network associated with " + + "ipAddress or ip4 address is null"; return guestNic.getIp4Address(); } @@ -3734,8 +3825,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag createNetwork = true; } else if (networks.size() == 1) { guestNetwork = networks.get(0); - }else{ - throw new InvalidParameterValueException("Error, more than 1 Guest Isolated Networks with SourceNAT service enabled found for this account, cannot assosiate the IP range, please provide the network ID"); + } else { + throw new InvalidParameterValueException("Error, more than 1 Guest Isolated Networks with SourceNAT " + + "service enabled found for this account, cannot assosiate the IP range, please provide the network ID"); } } @@ -3743,20 +3835,26 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (createNetwork) { List requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (requiredOfferings.size() < 1) { - throw new CloudRuntimeException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as part of createVlanIpRange"); + throw new CloudRuntimeException("Unable to find network offering with availability=" + + Availability.Required + " to automatically create the network as part of createVlanIpRange"); } PhysicalNetwork physicalNetwork = translateZoneIdToPhysicalNetwork(zoneId); if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) { - s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of createVlanIpRange process"); - guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, null, null, owner, false, null, physicalNetwork, zoneId, - ACLType.Account, null); + s_logger.debug("Creating network for account " + owner + " from the network offering id=" + + requiredOfferings.get(0).getId() + " as a part of createVlanIpRange process"); + guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network" + , owner.getAccountName() + "-network", null, null, null, null, owner, null, physicalNetwork, + zoneId, ACLType.Account, + null, null); if (guestNetwork == null) { s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId); - throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId); + throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT " + + "service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId); } } else { - throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); + throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() + + " is not in " + NetworkOffering.State.Enabled); } } @@ -4372,7 +4470,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networkDomain; } - private String getAccountNetworkDomain(long accountId, long zoneId) { + @Override + public String getAccountNetworkDomain(long accountId, long zoneId) { String networkDomain = _accountDao.findById(accountId).getNetworkDomain(); if (networkDomain == null) { @@ -6524,4 +6623,49 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public List listNetworksByVpc(long vpcId) { return _networksDao.listByVpc(vpcId); } + + @Override + public String getDefaultNetworkDomain() { + return _networkDomain; + } + + @Override + public List getNtwkOffDistinctProviders(long networkId) { + List providerNames = _ntwkOfferingSrvcDao.getDistinctProviders(networkId); + List providers = new ArrayList(); + for (String providerName : providerNames) { + providers.add(Network.Provider.getProvider(providerName)); + } + + return providers; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkService#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) + */ + @Override + public boolean addVmToNetwork(VirtualMachine vm, Network network) { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkService#isVmPartOfNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) + */ + @Override + public boolean isVmPartOfNetwork(long vmId, long ntwkId) { + if (_nicDao.findByInstanceIdAndNetworkId(ntwkId, vmId) != null) { + return true; + } + return false; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkService#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) + */ + @Override + public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { + // TODO Auto-generated method stub + return false; + } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 959070e3f6b..80633044b37 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -160,7 +160,8 @@ public class NetworkVO implements Network, Identity { * @param dataCenterId * @param physicalNetworkId TODO */ - public NetworkVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, State state, long dataCenterId, Long physicalNetworkId) { + public NetworkVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, + State state, long dataCenterId, Long physicalNetworkId) { this.trafficType = trafficType; this.mode = mode; this.broadcastDomainType = broadcastDomainType; @@ -176,8 +177,11 @@ public class NetworkVO implements Network, Identity { this.uuid = UUID.randomUUID().toString(); } - public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { - this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges); + public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, + long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, + Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, + related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges); this.gateway = that.getGateway(); this.cidr = that.getCidr(); this.broadcastUri = that.getBroadcastUri(); @@ -206,7 +210,9 @@ public class NetworkVO implements Network, Identity { * @param specifyIpRanges TODO * @param dataCenterId */ - public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, + long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, + String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId); this.domainId = domainId; this.accountId = accountId; diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 76db8516a59..f5a18fdecf5 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -55,14 +55,12 @@ import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.router.VirtualRouter.Role; -import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.LbStickinessMethod; import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType; import com.cloud.network.rules.PortForwardingRule; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.StaticNat; -import com.cloud.network.vpc.Vpc; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -89,10 +87,10 @@ import com.google.gson.Gson; @Local(value = NetworkElement.class) public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, - LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, VpcProvider { + LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer { private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class); - private static final Map> capabilities = setCapabilities(); + protected static final Map> capabilities = setCapabilities(); @Inject NetworkDao _networksDao; @@ -124,8 +122,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl ConfigurationDao _configDao; @Inject VirtualRouterProviderDao _vrProviderDao; - @Inject - VpcVirtualNetworkApplianceManager _vpcRouterMgr; protected boolean canHandle(Network network, Service service) { Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); @@ -174,8 +170,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Override public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, - InsufficientCapacityException, ResourceUnavailableException { + throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) { return false; } @@ -188,16 +183,18 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (offering.isSystemOnly()) { return false; } - if (!_networkMgr.isProviderEnabledInPhysicalNetwork(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) { + if (!_networkMgr.isProviderEnabledInPhysicalNetwork(_networkMgr.getPhysicalNetworkId(network), getProvider().getName())) { return false; } @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile) vm; - List routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), + List routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, + _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), offering.getRedundantRouter()); if ((routers == null) || (routers.size() == 0)) { - throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); + throw new ResourceUnavailableException("Can't find at least one running router!", + DataCenter.class, network.getDataCenterId()); } return true; } @@ -313,7 +310,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl " Cause: length is not a number: " + length); } if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) { - throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime); + throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + + " Cause: holdtime is not in timeformat: " + holdTime); } } } @@ -359,7 +357,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(network, Service.Vpn)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router" + + " doesn't exist in the network " + network.getId()); return null; } return _routerMgr.applyVpnUsers(network, users, routers); @@ -374,7 +373,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(network, Service.Vpn)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't" + + " exist in the network " + network.getId()); return true; } return _routerMgr.startRemoteAccessVpn(network, vpn, routers); @@ -401,7 +401,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean applyIps(Network network, List ipAddress, Set services) throws ResourceUnavailableException { + public boolean applyIps(Network network, List ipAddress, Set services) + throws ResourceUnavailableException { boolean canHandle = true; for (Service service : services) { if (!canHandle(network, service)) { @@ -440,37 +441,61 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is loadbalancer cookie based stickiness method."); method.addParam("cookie-name", false, "Cookie name passed in http header by the LB to the client.", false); method.addParam("mode", false, - "Valid values: insert, rewrite, prefix. Default value: insert. In the insert mode cookie will be created by the LB. In other modes, cookie will be created by the server and LB modifies it.", false); + "Valid values: insert, rewrite, prefix. Default value: insert. In the insert mode cookie will be created" + + " by the LB. In other modes, cookie will be created by the server and LB modifies it.", false); method.addParam( "nocache", false, - "This option is recommended in conjunction with the insert mode when there is a cache between the client and HAProxy, as it ensures that a cacheable response will be tagged non-cacheable if a cookie needs to be inserted. This is important because if all persistence cookies are added on a cacheable home page for instance, then all customers will then fetch the page from an outer cache and will all share the same persistence cookie, leading to one server receiving much more traffic than others. See also the insert and postonly options. ", + "This option is recommended in conjunction with the insert mode when there is a cache between the client" + + " and HAProxy, as it ensures that a cacheable response will be tagged non-cacheable if a cookie needs " + + "to be inserted. This is important because if all persistence cookies are added on a cacheable home page" + + " for instance, then all customers will then fetch the page from an outer cache and will all share the " + + "same persistence cookie, leading to one server receiving much more traffic than others. See also the " + + "insert and postonly options. ", true); method.addParam( "indirect", false, - "When this option is specified in insert mode, cookies will only be added when the server was not reached after a direct access, which means that only when a server is elected after applying a load-balancing algorithm, or after a redispatch, then the cookie will be inserted. If the client has all the required information to connect to the same server next time, no further cookie will be inserted. In all cases, when the indirect option is used in insert mode, the cookie is always removed from the requests transmitted to the server. The persistence mechanism then becomes totally transparent from the application point of view.", + "When this option is specified in insert mode, cookies will only be added when the server was not reached" + + " after a direct access, which means that only when a server is elected after applying a load-balancing algorithm," + + " or after a redispatch, then the cookie will be inserted. If the client has all the required information" + + " to connect to the same server next time, no further cookie will be inserted. In all cases, when the " + + "indirect option is used in insert mode, the cookie is always removed from the requests transmitted to " + + "the server. The persistence mechanism then becomes totally transparent from the application point of view.", true); method.addParam( "postonly", false, - "This option ensures that cookie insertion will only be performed on responses to POST requests. It is an alternative to the nocache option, because POST responses are not cacheable, so this ensures that the persistence cookie will never get cached.Since most sites do not need any sort of persistence before the first POST which generally is a login request, this is a very efficient method to optimize caching without risking to find a persistence cookie in the cache. See also the insert and nocache options.", + "This option ensures that cookie insertion will only be performed on responses to POST requests. It is an" + + " alternative to the nocache option, because POST responses are not cacheable, so this ensures that the " + + "persistence cookie will never get cached.Since most sites do not need any sort of persistence before the" + + " first POST which generally is a login request, this is a very efficient method to optimize caching " + + "without risking to find a persistence cookie in the cache. See also the insert and nocache options.", true); method.addParam( "domain", false, - "This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter: a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host ending with that name. It is also possible to specify several domain names by invoking this option multiple times. Some browsers might have small limits on the number of domains, so be careful when doing that. For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.", + "This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter:" + + " a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host " + + "ending with that name. It is also possible to specify several domain names by invoking this option multiple" + + " times. Some browsers might have small limits on the number of domains, so be careful when doing that. " + + "For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.", false); methodList.add(method); method = new LbStickinessMethod(StickinessMethodType.AppCookieBased, - "This is App session based sticky method. Define session stickiness on an existing application cookie. It can be used only for a specific http traffic"); - method.addParam("cookie-name", false, "This is the name of the cookie used by the application and which LB will have to learn for each new session. Default value: Auto geneared based on ip", false); - method.addParam("length", false, "This is the max number of characters that will be memorized and checked in each cookie value. Default value:52", false); + "This is App session based sticky method. Define session stickiness on an existing application cookie. " + + "It can be used only for a specific http traffic"); + method.addParam("cookie-name", false, "This is the name of the cookie used by the application and which LB will " + + "have to learn for each new session. Default value: Auto geneared based on ip", false); + method.addParam("length", false, "This is the max number of characters that will be memorized and checked in " + + "each cookie value. Default value:52", false); method.addParam( "holdtime", false, - "This is the time after which the cookie will be removed from memory if unused. The value should be in the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid , cannot use th combinations like 20h30m. Default value:3h ", + "This is the time after which the cookie will be removed from memory if unused. The value should be in " + + "the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid," + + " cannot use th combinations like 20h30m. Default value:3h ", false); method.addParam( "request-learn", @@ -480,18 +505,25 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl method.addParam( "prefix", false, - "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.", + "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). " + + "The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.", true); method.addParam( "mode", false, - "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters : The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string : In this mode, the parser will look for the appsession in the query string.", + "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters " + + ": The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), " + + "which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string :" + + " In this mode, the parser will look for the appsession in the query string.", false); methodList.add(method); - method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based Stickiness method, it can be used for any type of protocol."); - method.addParam("tablesize", false, "Size of table to store source ip addresses. example: tablesize=200k or 300m or 400g. Default value:200k", false); - method.addParam("expire", false, "Entry in source ip table will expire after expire duration. units can be s,m,h,d . example: expire=30m 20s 50h 4d. Default value:3h", false); + method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based Stickiness method, " + + "it can be used for any type of protocol."); + method.addParam("tablesize", false, "Size of table to store source ip addresses. example: tablesize=200k or 300m" + + " or 400g. Default value:200k", false); + method.addParam("expire", false, "Entry in source ip table will expire after expire duration. units can be s,m,h,d ." + + " example: expire=30m 20s 50h 4d. Default value:3h", false); methodList.add(method); Gson gson = new Gson(); @@ -550,7 +582,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(config, Service.StaticNat)) { List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual router doesn't exist in the network " + config.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual " + + "router doesn't exist in the network " + config.getId()); return true; } @@ -561,7 +594,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) + throws ConcurrentOperationException, ResourceUnavailableException { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { return true; @@ -596,7 +630,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { + public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) + throws ResourceUnavailableException { if (!canHandle(network, null)) { return false; } @@ -648,7 +683,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (canHandle(network, Service.PortForwarding)) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual router doesn't exist in the network " + network.getId()); + s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + + "router doesn't exist in the network " + network.getId()); return true; } @@ -672,7 +708,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, + public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException { VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderType.VirtualRouter); if (element == null) { @@ -706,13 +743,15 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } @Override - public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.Dhcp)) { if (vm.getType() != VirtualMachine.Type.User) { @@ -726,7 +765,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { publicNetwork = true; } - boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && + boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic + || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && network.getTrafficType() == TrafficType.Guest; List routers; @@ -746,7 +786,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl // network.dns.basiczone.updates is set to "all" Long podId = dest.getPod().getId(); if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { - List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER); + List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), + podId, State.Running, Role.VIRTUAL_ROUTER); routers.addAll(allRunningRoutersOutsideThePod); } @@ -760,7 +801,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.UserData)) { if (vm.getType() != VirtualMachine.Type.User) { @@ -774,7 +816,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { publicNetwork = true; } - boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && + boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic + || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && network.getTrafficType() == TrafficType.Guest; List routers; @@ -794,7 +837,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl // network.dns.basiczone.updates is set to "all" Long podId = dest.getPod().getId(); if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { - List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER); + List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), + podId, State.Running, Role.VIRTUAL_ROUTER); routers.addAll(allRunningRoutersOutsideThePod); } @@ -842,16 +886,4 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl public IpDeployer getIpDeployer(Network network) { return this; } - - @Override - public boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { - - Map params = new HashMap(1); - params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - - _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); - - return true; - } } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java new file mode 100644 index 00000000000..83859834fa0 --- /dev/null +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -0,0 +1,154 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.element; + + +import java.util.HashMap; +import java.util.Map; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.NetworkService; +import com.cloud.network.router.VpcVirtualNetworkApplianceManager; +import com.cloud.network.vpc.Vpc; +import com.cloud.offering.NetworkOffering; +import com.cloud.utils.component.Inject; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; + +/** + * @author Alena Prokharchyk + */ +@Local(value = NetworkElement.class) +public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider{ + private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class); + @Inject + NetworkService _ntwkSvc; + @Inject + VpcVirtualNetworkApplianceManager _vpcElementMgr; + + private static final Map> capabilities = setCapabilities(); + + @Inject + VpcVirtualNetworkApplianceManager _vpcRouterMgr; + + @Override + public boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + + Map params = new HashMap(1); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); + + _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); + + return true; + } + + @Override + public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) + throws ResourceUnavailableException, ConcurrentOperationException, + InsufficientCapacityException { + + if (network.getVpcId() == null) { + s_logger.warn("Network " + network + " is not associated with any VPC"); + return false; + } + boolean success = super.implement(network, offering, dest, context); + + if (success) { + success = success && _vpcElementMgr.addVpcElementToNetwork(network); + } + + return success; + } + + @Override + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + + if (network.getVpcId() == null) { + s_logger.warn("Network " + network + " is not associated with any VPC"); + return false; + } + boolean success = super.prepare(network, nic, vm, dest, context); + + if (success) { + success = success && _vpcElementMgr.addVpcElementToNetwork(network); + } + + return success; + } + + @Override + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) + throws ConcurrentOperationException, ResourceUnavailableException { + + return _vpcElementMgr.removeVpcElementFromNetwork(network); + } + + @Override + public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException { + + return _vpcElementMgr.removeVpcElementFromNetwork(config); + } + + @Override + public Provider getProvider() { + return Provider.VPCVirtualRouter; + } + + private static Map> setCapabilities() { + Map> capabilities = VirtualRouterElement.capabilities; + + Map sourceNatCapabilities = capabilities.get(Service.SourceNat); + sourceNatCapabilities.put(Capability.RedundantRouter, "false"); + capabilities.put(Service.SourceNat, sourceNatCapabilities); + + return capabilities; + } + + @Override + public Map> getCapabilities() { + return capabilities; + } + + + @Override + public boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, + ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index f9977102b1f..f52a39c1b82 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -114,7 +114,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { protected boolean canHandle(NetworkOffering offering, DataCenter dc) { // This guru handles only Guest Isolated network that supports Source nat service - if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated) { + if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) + && offering.getGuestType() == Network.GuestType.Isolated) { return true; } else { s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); @@ -129,9 +130,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { return null; } - NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId()); + NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), + State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId()); if (userSpecified != null) { - if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) { + if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || + (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) { throw new InvalidParameterValueException("cidr and gateway must be specified together."); } @@ -185,54 +188,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } } -// @Override -// @DB -// public Ip4Address acquireIp4Address(Network network, Ip4Address requestedIp, String reservationId) { -// List ips = _nicDao.listIpAddressInNetwork(network.getId()); -// String[] cidr = network.getCidr().split("/"); -// Set allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1])); -// Set usedIps = new TreeSet(); -// -// if (requestedIp != null && requestedIp.equals(network.getGateway())) { -// s_logger.warn("Requested ip address " + requestedIp + " is used as a gateway address in network " + network); -// return null; -// } -// -// for (String ip : ips) { -// if (requestedIp != null && requestedIp.equals(ip)) { -// s_logger.warn("Requested ip address " + requestedIp + " is already in use in network " + network); -// return null; -// } -// -// usedIps.add(NetUtils.ip2Long(ip)); -// } -// if (usedIps.size() != 0) { -// allPossibleIps.removeAll(usedIps); -// } -// if (allPossibleIps.isEmpty()) { -// return null; -// } -// -// Long[] array = allPossibleIps.toArray(new Long[allPossibleIps.size()]); -// -// if (requestedIp != null) { -// //check that requested ip has the same cidr -// boolean isSameCidr = NetUtils.sameSubnetCIDR(requestedIp, NetUtils.long2Ip(array[0]), Integer.parseInt(cidr[1])); -// if (!isSameCidr) { -// s_logger.warn("Requested ip address " + requestedIp + " doesn't belong to the network " + network + " cidr"); -// return null; -// } else { -// return requestedIp; -// } -// } -// -// String result; -// do { -// result = NetUtils.long2Ip(array[_rand.nextInt(array.length)]); -// } while (result.split("\\.")[3].equals("1")); -// return result; -// } - public Ip4Address acquireIp4Address(Network network, Ip4Address requestedIp, String reservationId) { List ips = _nicDao.listIpAddressInNetwork(network.getId()); String[] cidr = network.getCidr().split("/"); @@ -303,17 +258,20 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { if (network.getBroadcastUri() == null) { String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId); if (vnet == null) { - throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId); + throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " + + "part of network " + network + " implement ", DataCenter.class, dcId); } implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet)); - EventUtils.saveEvent(UserContext.current().getCallerUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: "+vnet+ " Network Id: "+network.getId(), 0); + EventUtils.saveEvent(UserContext.current().getCallerUserId(), network.getAccountId(), + EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: "+vnet+ " Network Id: "+network.getId(), 0); } else { implemented.setBroadcastUri(network.getBroadcastUri()); } } @Override - public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException { + public Network implement(Network network, NetworkOffering offering, DeployDestination dest, + ReservationContext context) throws InsufficientVirtualNetworkCapcityException { assert (network.getState() == State.Implementing) : "Why are we implementing " + network; long dcId = dest.getDataCenter().getId(); @@ -321,7 +279,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { //get physical network id long physicalNetworkId = _networkMgr.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType()); - NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, + NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), + network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId); allocateVnet(network, implemented, dcId, physicalNetworkId, context.getReservationId()); @@ -337,10 +296,12 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling me when the traffic type is : " + network.getTrafficType(); + assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling" + + " me when the traffic type is : " + network.getTrafficType(); if (nic == null) { nic = new NicProfile(ReservationStrategy.Start, null, null, null, null); @@ -359,7 +320,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } else { guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); if (guestIp == null) { - throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP address for network " + network, DataCenter.class, dc.getId()); + throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + + " address for network " + network, DataCenter.class, dc.getId()); } nic.setIp4Address(guestIp); @@ -393,7 +355,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? "; @@ -412,8 +375,10 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { public void shutdown(NetworkProfile profile, NetworkOffering offering) { s_logger.debug("Releasing vnet for the network id=" + profile.getId()); if (profile.getBroadcastUri() != null && !offering.getSpecifyVlan()) { - _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId()); - EventUtils.saveEvent(UserContext.current().getCallerUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: " + _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), + profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId()); + EventUtils.saveEvent(UserContext.current().getCallerUserId(), profile.getAccountId(), + EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: " +profile.getBroadcastUri().getHost()+" for Network: "+profile.getId(), 0); profile.setBroadcastUri(null); } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 08ba413de22..2d8629bf78f 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1613,7 +1613,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian // DOMR control command is sent over management server in VMware if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { if (s_logger.isInfoEnabled()) { - s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() + s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: " + + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmt_host); } @@ -1637,10 +1638,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } else if (nic.getTrafficType() == TrafficType.Guest) { //build bootloader parameter for the guest - createGuestBootLoadArgs(profile, nic, defaultDns1, defaultDns2); + buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router)); } else if (nic.getTrafficType() == TrafficType.Public) { publicNetwork = true; - } } @@ -1684,11 +1684,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } - protected void createGuestBootLoadArgs(VirtualMachineProfile profile, NicProfile guestNic, - String defaultDns1, String defaultDns2) { + protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, + String defaultDns2, DomainRouterVO router) { long guestNetworkId = guestNic.getNetworkId(); NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); - DomainRouterVO router = profile.getVirtualMachine(); String dhcpRange = null; DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); @@ -1699,7 +1698,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - StringBuilder buf = profile.getBootArgsBuilder(); + StringBuilder buf = new StringBuilder(); boolean isRedundant = router.getIsRedundantRouter(); if (isRedundant) { @@ -1714,6 +1713,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } + if (guestNic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); @@ -1767,6 +1767,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" useextdns=true"); } } + + return buf; } @Override @@ -1985,16 +1987,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, + ReservationContext context) { DomainRouterVO router = profile.getVirtualMachine(); //Get guest nic info List routerNics = profile.getNics(); - Network guestNetwork = null; + List guestNetworks = new ArrayList(); for (NicProfile routerNic : routerNics) { if (routerNic.getTrafficType() == TrafficType.Guest) { - guestNetwork = _networkMgr.getNetwork(routerNic.getNetworkId()); - break; + guestNetworks.add(_networkMgr.getNetwork(routerNic.getNetworkId())); } } @@ -2018,11 +2020,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer; if (answer == null || !answer.getResult()) { /* Try to push on because it's not a critical error */ - s_logger.warn("Unable to get the template/scripts version of router " + router.getInstanceName() + " due to: " + versionAnswer.getDetails() + ", but we would continue"); + s_logger.warn("Unable to get the template/scripts version of router " + router.getInstanceName() + + " due to: " + versionAnswer.getDetails() + ", but we would continue"); } else { router.setTemplateVersion(versionAnswer.getTemplateVersion()); router.setScriptsVersion(versionAnswer.getScriptsVersion()); - router = _routerDao.persist(router, guestNetwork); + router = _routerDao.persist(router, guestNetworks); } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java index 13df4f3f6ff..a6679a03785 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -19,6 +19,7 @@ import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.vm.DomainRouterVO; @@ -39,7 +40,20 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map params) throws InsufficientCapacityException, ConcurrentOperationException, + List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map params) + throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; + /** + * @param network + * @return + */ + boolean addVpcElementToNetwork(Network network); + + /** + * @param network + * @return + */ + boolean removeVpcElementFromNetwork(Network network); + } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 68c9bdba894..7ef2de5070d 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -25,6 +25,8 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.NetworkService; import com.cloud.network.PhysicalNetwork; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; @@ -54,6 +56,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian VpcOfferingDao _vpcOffDao = null; @Inject PhysicalNetworkDao _pNtwkDao = null; + @Inject + NetworkService _ntwkService = null; @Override public List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, @@ -96,7 +100,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs List pNtwks = _pNtwkDao.listByZone(vpc.getZoneId()); - VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(pNtwks.get(0).getId(), VirtualRouterProviderType.VirtualRouter); + VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(pNtwks.get(0).getId(), + VirtualRouterProviderType.VirtualRouter); PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, @@ -111,7 +116,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return routers; } - protected Pair> getDeploymentPlanAndRouters(long vpcId,DeployDestination dest) { + protected Pair> getDeploymentPlanAndRouters(long vpcId, DeployDestination dest) { long dcId = dest.getDataCenter().getId(); DeploymentPlan plan = new DataCenterDeployment(dcId); @@ -119,4 +124,62 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return new Pair>(plan, routers); } + + @Override + public boolean addVpcElementToNetwork(Network network) { + boolean success = true; + Long vpcId = network.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping plug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _ntwkService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + + return success; + } + + @Override + public boolean removeVpcElementFromNetwork(Network network) { + boolean success = true; + Long vpcId = network.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part the network " + network); + continue; + } + //2) Call unplugNics in the network service + success = success && _ntwkService.removeVmFromNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + + return success; + } } diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index a7adf9c6895..19e268b1f12 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -16,9 +16,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.cloud.exception.ConcurrentOperationException; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.vpc.VpcOffering.State; +import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; @@ -52,10 +54,22 @@ public interface VpcManager extends VpcService{ * @param vpcName * @param displayText * @param cidr + * @param networkDomain TODO * @return */ - Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr); + Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr, String networkDomain); List getSupportedServices(); + /** + * @param guestNtwkOff + * @param cidr + * @param networkDomain + * @param networkOwner + * @param vpc TODO + * @return + * @throws ConcurrentOperationException + */ + void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, Vpc vpc) throws ConcurrentOperationException; + } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 5241057a516..ff3895ae257 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -31,24 +31,23 @@ import com.cloud.deploy.DeployDestination; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; 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.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; -import com.cloud.network.IPAddressVO; import com.cloud.network.Network; +import com.cloud.network.Network.GuestType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; -import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.NetworkDao; import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao; +import com.cloud.offering.NetworkOffering; import com.cloud.org.Grouping; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.user.Account; @@ -92,6 +91,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Inject NetworkManager _ntwkMgr; + private VpcProvider vpcElement = null; + String _name; @Override @@ -108,7 +109,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ Map> svcProviderMap = new HashMap>(); Set provider = new HashSet(); - provider.add(Provider.VirtualRouter); + provider.add(Provider.VPCVirtualRouter); for (Service svc : getSupportedServices()) { svcProviderMap.put(svc, provider); } @@ -152,7 +153,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ public VpcOffering createVpcOffering(String name, String displayText, List supportedServices) { Map> svcProviderMap = new HashMap>(); Set defaultProviders = new HashSet(); - defaultProviders.add(Provider.VirtualRouter); + defaultProviders.add(Provider.VPCVirtualRouter); boolean sourceNatSvc = false; boolean firewallSvs = false; @@ -403,7 +404,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc") - public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr) { + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, + String networkDomain) { Account caller = UserContext.current().getCaller(); Account owner = _accountMgr.getAccount(vpcOwnerId); @@ -427,17 +429,41 @@ public class VpcManagerImpl implements VpcManager, Manager{ throw ex; } - //validate cidr - return createVpc(zoneId, vpcOffId, owner, vpcName, displayText, cidr); + if (networkDomain == null) { + // 1) Get networkDomain from the corresponding account + networkDomain = _ntwkMgr.getAccountNetworkDomain(owner.getId(), zoneId); + + + // 2) If null, generate networkDomain using domain suffix from the global config variables + if (networkDomain == null) { + networkDomain = "cs" + Long.toHexString(owner.getId()) + _ntwkMgr.getDefaultNetworkDomain(); + } + } + + return createVpc(zoneId, vpcOffId, owner, vpcName, displayText, cidr, networkDomain); } @Override - public Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr) { + public Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr, + String networkDomain) { + + //Validate CIDR if (!NetUtils.isValidCIDR(cidr)) { throw new InvalidParameterValueException("Invalid CIDR specified " + cidr); } + + // validate network domain + if (!NetUtils.verifyDomainName(networkDomain)) { + throw new InvalidParameterValueException( + "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " + + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', " + + "the digits '0' through '9', " + + "and the hyphen ('-'); can't start or end with \"-\""); + } - VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr); + + VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr, + networkDomain); vpc = _vpcDao.persist(vpc); if (vpc != null) { @@ -616,7 +642,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ } @Override - public Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); User callerUser = _accountMgr.getActiveUser(ctx.getCallerUserId()); @@ -633,10 +660,11 @@ public class VpcManagerImpl implements VpcManager, Manager{ DataCenter dc = _configMgr.getZone(vpc.getZoneId()); DeployDestination dest = new DeployDestination(dc, null, null, null); - ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId())); + ReservationContext context = new ReservationContextImpl(null, null, callerUser, + _accountMgr.getAccount(vpc.getAccountId())); //deploy provider - if (((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VirtualRouter.getName())).startVpc(vpc, dest, context)) { + if (getVpcElement().startVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); return getVpc(vpc.getId()); } else { @@ -644,5 +672,77 @@ public class VpcManagerImpl implements VpcManager, Manager{ //FIXME - add cleanup logic here } } + + @Override + @DB + public void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, + Account networkOwner, Vpc vpc) throws ConcurrentOperationException { + + Vpc locked = _vpcDao.acquireInLockTable(vpc.getId()); + if (locked == null) { + throw new ConcurrentOperationException("Unable to acquire lock on " + vpc); + } + + try { + //1) CIDR is required + if (cidr == null) { + throw new InvalidParameterValueException("CIDR is required when create network for VPC"); + } + + //2) Network cidr should be within vpcCidr + if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) { + throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr"); + } + + //3) Network cidr shouldn't cross the cidr of other vpc network cidrs + List ntwks = _ntwkDao.listByVpc(vpc.getId()); + for (Network ntwk : ntwks) { + assert (cidr != null) : "Why the network cidr is null when it belongs to vpc?"; + + if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), vpc.getCidr()) + || NetUtils.isNetworkAWithinNetworkB(vpc.getCidr(), ntwk.getCidr())) { + throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk + + " belonging to the same vpc " + vpc); + } + } + + //4) vpc and network should belong to the same owner + if (vpc.getAccountId() != networkOwner.getId()) { + throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner); + } + + //5) Only Isolated networks with Source nat service enabled can be added to vpc + if (!(guestNtwkOff.getGuestType() == GuestType.Isolated + && _ntwkMgr.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.SourceNat))) { + + throw new InvalidParameterValueException("Only networks of type " + GuestType.Isolated + " with service " + Service.SourceNat + + " can be added as a part of VPC"); + } + + //6) Only VPC VR can be a provider for the network offering + List ntwkOffProviders = _ntwkMgr.getNtwkOffDistinctProviders(guestNtwkOff.getId()); + for (Provider provider : ntwkOffProviders) { + if (provider != Provider.VPCVirtualRouter) { + throw new InvalidParameterValueException("Only VPCVirtualRouter provider is supported in VPC network;" + + " while network offering " + guestNtwkOff + " has " + provider.getName() + " enabled."); + } + } + + //7) No redundant router support + if (guestNtwkOff.getRedundantRouter()) { + throw new InvalidParameterValueException("No redunant router support when network belnogs to VPC"); + } + } finally { + s_logger.debug("Releasing lock for " + locked); + _vpcDao.releaseFromLockTable(locked.getId()); + } + } + private VpcProvider getVpcElement() { + if (vpcElement == null) { + vpcElement = ((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())); + } + + return vpcElement; + } } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index 65ad5c64727..a20d5c2b9ae 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -74,11 +74,15 @@ public class VpcVO implements Vpc, Identity { @Column(name=GenericDao.CREATED_COLUMN) Date created; + @Column(name="network_domain") + String networkDomain; + public VpcVO() { this.uuid = UUID.randomUUID().toString(); } - public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr) { + public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr, + String networkDomain) { this.zoneId = zoneId; this.name = name; this.displayText = displayText; @@ -87,6 +91,7 @@ public class VpcVO implements Vpc, Identity { this.cidr = cidr; this.uuid = UUID.randomUUID().toString(); this.state = State.Enabled; + this.networkDomain = networkDomain; this.vpcOfferingId = vpcOffId; } diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java index 8ef8922f799..430c94de91b 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java @@ -36,6 +36,8 @@ public interface NetworkOfferingServiceMapDao extends GenericDao listServicesForNetworkOffering(long networkOfferingId); + + List getDistinctProviders(long offId); } diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java index f47112c3cde..c43220dd38b 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java @@ -34,6 +34,8 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase MultipleServicesSearch; final GenericSearchBuilder ProvidersSearch; final GenericSearchBuilder ServicesSearch; + final GenericSearchBuilder DistinctProvidersSearch; + protected NetworkOfferingServiceMapDaoImpl() { super(); @@ -59,6 +61,12 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase getDistinctProviders(long offId) { + SearchCriteria sc = DistinctProvidersSearch.create(); + sc.setParameters("offId", offId); + List results = customSearch(sc, null); + return results; + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 1b7737f906f..3c79e4e363b 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -952,7 +952,8 @@ public class ConfigurationServerImpl implements ConfigurationServer { defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering); for (Service service : defaultIsolatedSourceNatEnabledNetworkOfferingProviders.keySet()) { - NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service)); + NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO + (defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } @@ -991,6 +992,36 @@ public class ConfigurationServerImpl implements ConfigurationServer { s_logger.trace("Added service for the network offering: " + offService); } + // Offering #6 + NetworkOfferingVO defaultNetworkOfferingForVpcNetworks = new NetworkOfferingVO( + NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, + "Offering for Isolated Vpc networks with Source Nat service enabled", + TrafficType.Guest, + false, false, null, null, true, Availability.Required, + null, Network.GuestType.Isolated, true, false); + + defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled); + defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks); + + Map defaultVpcNetworkOfferingProviders = new HashMap(); + defaultVpcNetworkOfferingProviders.put(Service.Dhcp, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.Dns, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.UserData, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.Firewall, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.Gateway, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.Lb, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.SourceNat, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.StaticNat, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.PortForwarding, Provider.VPCVirtualRouter); + defaultVpcNetworkOfferingProviders.put(Service.Vpn, Provider.VPCVirtualRouter); + + for (Service service : defaultVpcNetworkOfferingProviders.keySet()) { + NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO + (defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service)); + _ntwkOfferingServiceMapDao.persist(offService); + s_logger.trace("Added service for the network offering: " + offService); + } + txn.commit(); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 47189d5331e..11000762ec1 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2189,9 +2189,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager List virtualNetworks = _networkMgr.listNetworksForAccount(owner.getId(), zone.getId(), Network.GuestType.Isolated); if (virtualNetworks.isEmpty()) { - s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of deployVM process"); - Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, - null, null, owner, false, null, physicalNetwork, zone.getId(), ACLType.Account, null); + s_logger.debug("Creating network for account " + owner + " from the network offering id=" + + requiredOfferings.get(0).getId() + " as a part of deployVM process"); + Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), + owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, + null, null, owner, null, physicalNetwork, zone.getId(), ACLType.Account, null, null); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Isolated networks are found for account " + owner + "; please specify networkIds"); @@ -3451,7 +3453,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager NetworkVO defaultNetwork = null; List requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (requiredOfferings.size() < 1) { - throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as a part of vm creation"); + throw new InvalidParameterValueException("Unable to find network offering with availability=" + + Availability.Required + " to automatically create the network as a part of vm creation"); } PhysicalNetwork physicalNetwork = _networkMgr.translateZoneIdToPhysicalNetwork(zone.getId()); @@ -3460,17 +3463,21 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager List virtualNetworks = _networkMgr.listNetworksForAccount(newAccount.getId(), zone.getId(), Network.GuestType.Isolated); if (virtualNetworks.isEmpty()) { - s_logger.debug("Creating network for account " + newAccount + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of deployVM process"); - Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), newAccount.getAccountName() + "-network", newAccount.getAccountName() + "-network", null, null, - null, null, newAccount, false, null, physicalNetwork, zone.getId(), ACLType.Account, null); + s_logger.debug("Creating network for account " + newAccount + " from the network offering id=" + + requiredOfferings.get(0).getId() + " as a part of deployVM process"); + Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), + newAccount.getAccountName() + "-network", newAccount.getAccountName() + "-network", null, null, + null, null, newAccount, null, physicalNetwork, zone.getId(), ACLType.Account, null, null); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { - throw new InvalidParameterValueException("More than 1 default Isolated networks are found for account " + newAccount + "; please specify networkIds"); + throw new InvalidParameterValueException("More than 1 default Isolated networks are found " + + "for account " + newAccount + "; please specify networkIds"); } else { defaultNetwork = virtualNetworks.get(0); } } else { - throw new InvalidParameterValueException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); + throw new InvalidParameterValueException("Required network offering id=" + + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); } applicableNetworks.add(defaultNetwork); diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 350ea1d0206..dfac0928843 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -95,10 +95,10 @@ public interface DomainRouterDao extends GenericDao { /** * Persists the domain router instance + creates the reference to the guest network (if not null) - * @param guestNetwork TODO + * @param guestNetworks TODO * @return */ - DomainRouterVO persist(DomainRouterVO router, Network guestNetwork); + DomainRouterVO persist(DomainRouterVO router, List guestNetworks); /** * @param routerId diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 23ecea990f1..11f982cfaed 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -249,23 +249,28 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override @DB - public DomainRouterVO persist(DomainRouterVO router, Network guestNetwork) { + public DomainRouterVO persist(DomainRouterVO router, List guestNetworks) { Transaction txn = Transaction.currentTxn(); txn.start(); // 1) create network DomainRouterVO newRouter = super.persist(router); - // 2) add router to the network - addRouterToNetwork(router.getId(), guestNetwork); - // 3) create user stats entry - UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), - guestNetwork.getId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), - router.getType().toString(), guestNetwork.getId()); - _userStatsDao.persist(stats); + + if (guestNetworks != null && !guestNetworks.isEmpty()) { + // 2) add router to the network + for (Network guestNetwork : guestNetworks) { + addRouterToNetwork(router.getId(), guestNetwork); + // 3) create user stats entry + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } + } } - + txn.commit(); return newRouter; } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index a96c596bc27..a07b2c564f2 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -44,11 +44,13 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; +import com.cloud.network.element.NetworkElement; import com.cloud.network.element.RemoteAccessVPNServiceProvider; import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; +import com.cloud.network.vpc.Vpc; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.user.Account; @@ -84,7 +86,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { + public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { // TODO Auto-generated method stub return null; } @@ -178,13 +180,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } - - @Override - public PublicIp assignSourceNatIpAddress(Account owner, Network guestNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - @Override public boolean releasePublicIpAddress(long id, long userId, Account caller) { // TODO Auto-generated method stub @@ -310,8 +305,8 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, boolean isSecurityGroupEnabled, - Long domainId, PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, + PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { // TODO Auto-generated method stub return null; } @@ -880,4 +875,40 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS // TODO Auto-generated method stub return null; } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkService#listNetworksByVpc(long) + */ + @Override + public List listNetworksByVpc(long vpcId) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkManager#getElementImplementingProvider(java.lang.String) + */ + @Override + public NetworkElement getElementImplementingProvider(String providerName) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkManager#assignSourceNatIpAddressToGuestNetwork(com.cloud.user.Account, com.cloud.network.Network) + */ + @Override + public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkManager#assignSourceNatIpAddressToVpc(com.cloud.user.Account, com.cloud.network.vpc.Vpc) + */ + @Override + public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { + // TODO Auto-generated method stub + return null; + } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 13b98902ede..08f2f8ce5c6 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2141,6 +2141,7 @@ CREATE TABLE `cloud`.`vpc` ( `state` varchar(32) NOT NULL COMMENT 'state of the VP (can be Enabled and Disabled)', `domain_id` bigint unsigned NOT NULL COMMENT 'domain the vpc belongs to', `account_id` bigint unsigned NOT NULL COMMENT 'owner of this vpc', + `network_domain` varchar(255) COMMENT 'network domain', `removed` datetime COMMENT 'date removed if not null', `created` datetime NOT NULL COMMENT 'date created', PRIMARY KEY (`id`), diff --git a/wscript b/wscript index b99c3f9d463..844085841e7 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-22T00:59:20Z' +VERSION = '3.0.3.2012-05-22T23:46:23Z' APPNAME = 'cloud' import shutil,os From 2014cb0febddfb332b650e943029ae6daf948012 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 23 May 2012 16:18:41 -0700 Subject: [PATCH 10/64] Plug nic support --- .../com/cloud/agent/api/PlugNicCommand.java | 50 +++ .../api/routing/SetFirewallRulesCommand.java | 2 - api/src/com/cloud/agent/api/to/NetworkTO.java | 1 - .../com/cloud/hypervisor/HypervisorGuru.java | 8 + api/src/com/cloud/network/NetworkService.java | 6 - .../cloud/network/element/VpcProvider.java | 27 -- .../VpcVirtualNetworkApplianceService.java | 43 ++ api/src/com/cloud/vm/Nic.java | 3 +- api/src/com/cloud/vm/UserVmService.java | 1 - core/src/com/cloud/vm/DomainRouterVO.java | 6 +- .../ConfigurationManagerImpl.java | 3 +- .../AgentBasedConsoleProxyManager.java | 22 + .../consoleproxy/ConsoleProxyManagerImpl.java | 20 +- .../cloud/hypervisor/HypervisorGuruBase.java | 3 +- .../src/com/cloud/network/NetworkManager.java | 40 +- .../com/cloud/network/NetworkManagerImpl.java | 381 ++++++++++-------- server/src/com/cloud/network/NetworkVO.java | 8 +- .../element/VpcVirtualRouterElement.java | 125 ++++-- .../cloud/network/guru/GuestNetworkGuru.java | 17 +- .../lb/ElasticLoadBalancerManagerImpl.java | 25 +- .../VirtualNetworkApplianceManagerImpl.java | 165 ++++---- .../VpcVirtualNetworkApplianceManager.java | 16 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 116 +++--- .../src/com/cloud/network/vpc/VpcManager.java | 8 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 5 +- .../com/cloud/network/vpc/VpcOfferingVO.java | 1 - server/src/com/cloud/network/vpc/VpcVO.java | 6 + .../cloud/server/ConfigurationServerImpl.java | 5 +- .../SecondaryStorageManagerImpl.java | 19 + .../src/com/cloud/vm/UserVmManagerImpl.java | 15 + .../src/com/cloud/vm/VirtualMachineGuru.java | 36 ++ .../com/cloud/vm/VirtualMachineManager.java | 20 + .../cloud/vm/VirtualMachineManagerImpl.java | 56 ++- .../src/com/cloud/vm/dao/DomainRouterDao.java | 6 + .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 36 +- .../cloud/network/MockNetworkManagerImpl.java | 2 +- wscript | 2 +- 37 files changed, 889 insertions(+), 416 deletions(-) create mode 100644 api/src/com/cloud/agent/api/PlugNicCommand.java create mode 100644 api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java diff --git a/api/src/com/cloud/agent/api/PlugNicCommand.java b/api/src/com/cloud/agent/api/PlugNicCommand.java new file mode 100644 index 00000000000..041d373b8eb --- /dev/null +++ b/api/src/com/cloud/agent/api/PlugNicCommand.java @@ -0,0 +1,50 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +import java.util.Map; + +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; + +/** + * @author Alena Prokharchyk + */ +public class PlugNicCommand extends Command { + public enum Param { + DhcpRange, + NetworkDomain + } + + VirtualMachineTO vm; + NicTO nic; + Map params; + + public VirtualMachineTO getVirtualMachine() { + return vm; + } + + @Override + public boolean executeInSequence() { + return true; + } + + protected PlugNicCommand() { + } + + public PlugNicCommand(VirtualMachineTO vm, NicTO nic, Map params) { + this.vm = vm; + this.nic = nic; + this.params = params; + } +} diff --git a/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java b/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java index 210acc35e65..f5011aa860f 100644 --- a/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java +++ b/api/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Set; import com.cloud.agent.api.to.FirewallRuleTO; -import com.cloud.agent.api.to.LoadBalancerTO; -import com.cloud.utils.StringUtils; /** * diff --git a/api/src/com/cloud/agent/api/to/NetworkTO.java b/api/src/com/cloud/agent/api/to/NetworkTO.java index 788e367a2dd..6a7ec1394a9 100644 --- a/api/src/com/cloud/agent/api/to/NetworkTO.java +++ b/api/src/com/cloud/agent/api/to/NetworkTO.java @@ -173,5 +173,4 @@ public class NetworkTO { public boolean isSecurityGroupEnabled() { return this.isSecurityGroupEnabled; } - } diff --git a/api/src/com/cloud/hypervisor/HypervisorGuru.java b/api/src/com/cloud/hypervisor/HypervisorGuru.java index 8d869d74fab..09cc3673e7a 100644 --- a/api/src/com/cloud/hypervisor/HypervisorGuru.java +++ b/api/src/com/cloud/hypervisor/HypervisorGuru.java @@ -13,9 +13,11 @@ package com.cloud.hypervisor; import com.cloud.agent.api.Command; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.component.Adapter; +import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @@ -45,4 +47,10 @@ public interface HypervisorGuru extends Adapter { * */ boolean trackVmHostChange(); + + /** + * @param profile + * @return + */ + NicTO toNicTO(NicProfile profile); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 3b05d996250..200aebfea69 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -32,7 +32,6 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine; public interface NetworkService { @@ -144,10 +143,5 @@ public interface NetworkService { List listNetworksByVpc(long vpcId); - boolean addVmToNetwork(VirtualMachine vm, Network network); - - boolean removeVmFromNetwork(VirtualMachine vm, Network network); - boolean isVmPartOfNetwork(long vmId, long ntwkId); - } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 7c352000324..246ac0bdf4c 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -36,32 +36,5 @@ public interface VpcProvider extends NetworkElement{ boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; - /** - * Prepare for a nic to be plugged into the network. - * @param network - * @param nic - * @param vm - * @param context - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientNetworkCapacityException - */ - boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; - - /** - * A nic is unplugged from this network. - * @param network - * @param nic - * @param vm - * @param context - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java new file mode 100644 index 00000000000..4de760ffba4 --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java @@ -0,0 +1,43 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.router.VirtualRouter; + +/** + * @author Alena Prokharchyk + */ +public interface VpcVirtualNetworkApplianceService { + + /** + * @param router + * @param network + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param router + * @param network + * @return + */ + boolean removeVmFromNetwork(VirtualRouter router, Network network); +} diff --git a/api/src/com/cloud/vm/Nic.java b/api/src/com/cloud/vm/Nic.java index 3bc92920fd8..d121034867c 100644 --- a/api/src/com/cloud/vm/Nic.java +++ b/api/src/com/cloud/vm/Nic.java @@ -31,7 +31,8 @@ public interface Nic { } public enum State implements FiniteState { - Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating( + Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), + Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating( "Resource is being deallocated"); String _description; diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 8b8eb205b36..5d4b668790c 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -50,7 +50,6 @@ import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; import com.cloud.uservm.UserVm; import com.cloud.utils.exception.ExecutionException; -import com.cloud.vm.VirtualMachineProfile.Param; public interface UserVmService { /** diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index f5cc8f9b260..7b03dd15144 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -88,7 +88,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, - boolean stopPending) { + boolean stopPending, Long vpcId) { super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; @@ -96,6 +96,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { this.redundantState = redundantState; this.isPriorityBumpUp = isPriorityBumpUp; this.stopPending = stopPending; + this.vpcId = vpcId; } public DomainRouterVO(long id, @@ -113,7 +114,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { RedundantState redundantState, boolean haEnabled, boolean stopPending, - VirtualMachine.Type vmType) { + VirtualMachine.Type vmType, Long vpcId) { super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; @@ -121,6 +122,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { this.redundantState = redundantState; this.isPriorityBumpUp = isPriorityBumpUp; this.stopPending = stopPending; + this.vpcId = vpcId; } public long getElementId() { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index dffb8cbda7d..1e7d09017cd 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1612,7 +1612,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura userNetwork.setBroadcastDomainType(broadcastDomainType); userNetwork.setNetworkDomain(networkDomain); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, + Domain.ROOT_DOMAIN, null, null, null); } } } diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index 72fb87a008d..983e90932c3 100755 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -29,13 +29,19 @@ import com.cloud.agent.api.GetVncPortCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupProxyCommand; import com.cloud.agent.api.StopAnswer; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.info.ConsoleProxyInfo; +import com.cloud.network.Network; import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; @@ -341,4 +347,20 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu @Override public void finalizeExpunge(ConsoleProxyVO proxy) { } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 612d2b69797..b6f4af4d091 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -41,6 +41,8 @@ import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.api.ServerApiException; import com.cloud.api.commands.DestroyConsoleProxyCmd; @@ -79,6 +81,7 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.keystore.KeystoreDao; import com.cloud.keystore.KeystoreManager; import com.cloud.keystore.KeystoreVO; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; @@ -90,7 +93,6 @@ import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.server.ManagementServer; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.servlet.ConsoleProxyServlet; @@ -1920,4 +1922,20 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return _hashKey; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index d62e3800542..2c3348427b7 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -35,7 +35,8 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis super(); } - protected NicTO toNicTO(NicProfile profile) { + @Override + public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 839e18f7eed..80346d998cb 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -109,7 +109,7 @@ public interface NetworkManager extends NetworkService { throws ConcurrentOperationException; List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException; + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException; List getSystemAccountNetworkOfferings(String... offeringNames); @@ -231,8 +231,6 @@ public interface NetworkManager extends NetworkService { boolean canElementEnableIndividualServices(Provider provider); - PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId); - boolean areServicesSupportedInNetwork(long networkId, Service... services); boolean isNetworkSystem(Network network); @@ -252,9 +250,6 @@ public interface NetworkManager extends NetworkService { void canProviderSupportServices(Map> providersMap); - PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork( - long physicalNetworkId); - List getPhysicalNetworkInfo(long dcId, HypervisorType hypervisorType); @@ -344,4 +339,37 @@ public interface NetworkManager extends NetworkService { * @return */ List getNtwkOffDistinctProviders(long networkId); + + + /** + * @param requested + * @param network + * @param isDefaultNic + * @param deviceId + * @param vm + * @return + * @throws InsufficientVirtualNetworkCapcityException + * @throws InsufficientAddressCapacityException + * @throws ConcurrentOperationException + */ + Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, + VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param vmProfile + * @param dest + * @param context + * @param nicId + * @param network + * @return + * @throws InsufficientVirtualNetworkCapcityException + * @throws InsufficientAddressCapacityException + * @throws ConcurrentOperationException + * @throws InsufficientCapacityException + * @throws ResourceUnavailableException + */ + NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 4ba627e00ba..dfb54f4ea4b 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -187,6 +187,7 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -1509,16 +1510,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, + String displayText, boolean isDefault) throws ConcurrentOperationException { - return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null); + return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null); } @Override @DB public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException { + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException { Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { @@ -1586,9 +1588,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Transaction txn = Transaction.currentTxn(); txn.start(); - NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, predefined.getNetworkDomain(), - offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges()); - networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); + NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), + related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), + plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId); + networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, + finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); if (domainId != null && aclType == ACLType.Domain) { _networksDao.addDomainToNetwork(id, domainId, subdomainAccess); @@ -1626,7 +1630,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { + public void allocate(VirtualMachineProfile vm, List> networks) + throws InsufficientCapacityException, ConcurrentOperationException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1635,64 +1640,53 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean[] deviceIds = new boolean[networks.size()]; Arrays.fill(deviceIds, false); - List nics = new ArrayList(networks.size()); - NicVO defaultNic = null; + List nics = new ArrayList(networks.size()); + NicProfile defaultNic = null; for (Pair network : networks) { NetworkVO config = network.first(); - NetworkGuru guru = _networkGurus.get(config.getGuruName()); NicProfile requested = network.second(); - if (requested != null && requested.getMode() == null) { - requested.setMode(config.getMode()); + + Boolean isDefaultNic = false; + if (vm != null && (requested != null && requested.isDefaultNic())) { + isDefaultNic = true; } - NicProfile profile = guru.allocate(config, requested, vm); - - if (vm != null && vm.getVirtualMachine().getType() == Type.User && (requested != null && requested.isDefaultNic())) { - profile.setDefaultNic(true); - } - - if (profile == null) { - continue; - } - - if (requested != null && requested.getMode() == null) { - profile.setMode(requested.getMode()); - } else { - profile.setMode(config.getMode()); - } - - NicVO vo = new NicVO(guru.getName(), vm.getId(), config.getId(), vm.getType()); - + while (deviceIds[deviceId] && deviceId < deviceIds.length) { deviceId++; } - - deviceId = applyProfileToNic(vo, profile, deviceId); - - vo = _nicDao.persist(vo); - - if (vo.isDefaultNic()) { - if (defaultNic != null) { - throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vo); - } - defaultNic = vo; + + Pair vmNicPair = allocateNic(requested, config, isDefaultNic, + deviceId, vm); + + NicProfile vmNic = vmNicPair.first(); + if (vmNic == null) { + continue; } - - int devId = vo.getDeviceId(); + + deviceId = vmNicPair.second(); + + int devId = vmNic.getDeviceId(); if (devId > deviceIds.length) { - throw new IllegalArgumentException("Device id for nic is too large: " + vo); + throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); } if (deviceIds[devId]) { - throw new IllegalArgumentException("Conflicting device id for two different nics: " + devId); + throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic); } deviceIds[devId] = true; - nics.add(vo); - - Integer networkRate = getNetworkRate(config.getId(), vm.getId()); - vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, - isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(), - network.first()))); + + if (vmNic.isDefaultNic()) { + if (defaultNic != null) { + throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + + defaultNic + "; nic 2 = " + vmNic); + } + defaultNic = vmNic; + } + + nics.add(vmNic); + vm.addNic(vmNic); + } if (nics.size() != networks.size()) { @@ -1706,6 +1700,49 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } + + + @DB + @Override + public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, + int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException, ConcurrentOperationException{ + + NetworkVO ntwkVO = _networksDao.findById(network.getId()); + s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network); + NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName()); + + if (requested != null && requested.getMode() == null) { + requested.setMode(network.getMode()); + } + NicProfile profile = guru.allocate(network, requested, vm); + if (isDefaultNic != null) { + profile.setDefaultNic(isDefaultNic); + } + + if (profile == null) { + return null; + } + + if (requested != null && requested.getMode() == null) { + profile.setMode(requested.getMode()); + } else { + profile.setMode(network.getMode()); + } + + NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType()); + + deviceId = applyProfileToNic(vo, profile, deviceId); + + vo = _nicDao.persist(vo); + + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); + NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), + network)); + + return new Pair(vmNic, Integer.valueOf(deviceId)); + } protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) { if (profile.getDeviceId() != null) { @@ -1791,7 +1828,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); - + return to; } @@ -1952,9 +1989,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vmProfile.getId()); // we have to implement default nics first - to ensure that default network elements start up first in multiple -// nics - // case) - // (need for setting DNS on Dhcp to domR's Ip4 address) + // nics case)(need for setting DNS on Dhcp to domR's Ip4 address) Collections.sort(nics, new Comparator() { @Override @@ -1968,59 +2003,74 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NicVO nic : nics) { Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); - NetworkGuru guru = implemented.first(); - NetworkVO network = implemented.second(); - Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); - NicProfile profile = null; - if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { - nic.setState(Nic.State.Reserving); - nic.setReservationId(context.getReservationId()); - _nicDao.update(nic.getId(), nic); - URI broadcastUri = nic.getBroadcastUri(); - if (broadcastUri == null) { - broadcastUri = network.getBroadcastUri(); - } - - URI isolationUri = nic.getIsolationUri(); - - profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.reserve(profile, network, vmProfile, dest, context); - nic.setIp4Address(profile.getIp4Address()); - nic.setAddressFormat(profile.getFormat()); - nic.setIp6Address(profile.getIp6Address()); - nic.setMacAddress(profile.getMacAddress()); - nic.setIsolationUri(profile.getIsolationUri()); - nic.setBroadcastUri(profile.getBroadCastUri()); - nic.setReserver(guru.getName()); - nic.setState(Nic.State.Reserved); - nic.setNetmask(profile.getNetmask()); - nic.setGateway(profile.getGateway()); - - if (profile.getStrategy() != null) { - nic.setReservationStrategy(profile.getStrategy()); - } - - updateNic(nic, network.getId(), 1); - } else { - profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.updateNicProfile(profile, network); - nic.setState(Nic.State.Reserved); - updateNic(nic, network.getId(), 1); - } - for (NetworkElement element : _networkElements) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); - } - prepareElement(element, network, profile, vmProfile, dest, context); - } - - profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); - guru.updateNicProfile(profile, network); + NetworkVO network = implemented.second(); + NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network); vmProfile.addNic(profile); } } + @Override + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination + dest, ReservationContext context, long nicId, NetworkVO network) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, + ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + + Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + NicVO nic = _nicDao.findById(nicId); + + NicProfile profile = null; + if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { + nic.setState(Nic.State.Reserving); + nic.setReservationId(context.getReservationId()); + _nicDao.update(nic.getId(), nic); + URI broadcastUri = nic.getBroadcastUri(); + if (broadcastUri == null) { + broadcastUri = network.getBroadcastUri(); + } + + URI isolationUri = nic.getIsolationUri(); + + profile = new NicProfile(nic, network, broadcastUri, isolationUri, + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + guru.reserve(profile, network, vmProfile, dest, context); + nic.setIp4Address(profile.getIp4Address()); + nic.setAddressFormat(profile.getFormat()); + nic.setIp6Address(profile.getIp6Address()); + nic.setMacAddress(profile.getMacAddress()); + nic.setIsolationUri(profile.getIsolationUri()); + nic.setBroadcastUri(profile.getBroadCastUri()); + nic.setReserver(guru.getName()); + nic.setState(Nic.State.Reserved); + nic.setNetmask(profile.getNetmask()); + nic.setGateway(profile.getGateway()); + + if (profile.getStrategy() != null) { + nic.setReservationStrategy(profile.getStrategy()); + } + + updateNic(nic, network.getId(), 1); + } else { + profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + guru.updateNicProfile(profile, network); + nic.setState(Nic.State.Reserved); + updateNic(nic, network.getId(), 1); + } + + for (NetworkElement element : _networkElements) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); + } + prepareElement(element, network, profile, vmProfile, dest, context); + } + + profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); + guru.updateNicProfile(profile, network); + return profile; + } + @Override public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest) { List nics = _nicDao.listByVmId(vm.getId()); @@ -2041,36 +2091,42 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vmProfile.getId()); for (NicVO nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); - if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { - Nic.State originalState = nic.getState(); - if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { - NetworkGuru guru = _networkGurus.get(network.getGuruName()); - nic.setState(Nic.State.Releasing); - _nicDao.update(nic.getId(), nic); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - if (guru.release(profile, vmProfile, nic.getReservationId())) { - applyProfileToNicForRelease(nic, profile); - nic.setState(Nic.State.Allocated); - if (originalState == Nic.State.Reserved) { - updateNic(nic, network.getId(), -1); - } else { - _nicDao.update(nic.getId(), nic); - } - } - // Perform release on network elements - for (NetworkElement element : _networkElements) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to release " + nic); - } - //NOTE: Context appear to never be used in release method - //implementations. Consider removing it from interface Element - element.release(network, profile, vmProfile, null); - } - - } else { + releaseNic(vmProfile, nic, network); + } + } + + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) + throws ConcurrentOperationException, ResourceUnavailableException { + if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { + Nic.State originalState = nic.getState(); + if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + nic.setState(Nic.State.Releasing); + _nicDao.update(nic.getId(), nic); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + if (guru.release(profile, vmProfile, nic.getReservationId())) { + applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); - updateNic(nic, network.getId(), -1); + if (originalState == Nic.State.Reserved) { + updateNic(nic, network.getId(), -1); + } else { + _nicDao.update(nic.getId(), nic); + } } + // Perform release on network elements + for (NetworkElement element : _networkElements) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Asking " + element.getName() + " to release " + nic); + } + //NOTE: Context appear to never be used in release method + //implementations. Consider removing it from interface Element + element.release(network, profile, vmProfile, null); + } + + } else { + nic.setState(Nic.State.Allocated); + updateNic(nic, network.getId(), -1); } } } @@ -2541,16 +2597,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return network; } - public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, + @DB + protected Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + //1) Validate if network can be created for VPC _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, _vpcMgr.getVpc(vpcId)); - return createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, + //2) Create network + Network guestNetwork = createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); + + //3) Add network to all VPC's routers + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (DomainRouterVO router : routers) { + s_logger.debug("Adding router " + router + " to network " + guestNetwork); + _routerDao.addRouterToNetwork(router, guestNetwork); + } + + return guestNetwork; } @Override @@ -2751,7 +2819,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } List networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, - aclType, subdomainAccess); + aclType, subdomainAccess, vpcId); Network network = null; if (networks == null || networks.isEmpty()) { @@ -4849,6 +4917,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // add security group provider to the physical network addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId()); + + // add VPCVirtualRouter as the defualt network service provider + addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId()); txn.commit(); return pNetwork; @@ -6166,7 +6237,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { // locate physicalNetwork with supported traffic type // We can make this assumptions based on the fact that Public/Management/Control traffic types are -// supported only in one physical network in the zone in 3.0 + // supported only in one physical network in the zone in 3.0 for (PhysicalNetworkVO pNtwk : pNtwks) { if (_pNTrafficTypeDao.isTrafficTypeSupported(pNtwk.getId(), network.getTrafficType())) { physicalNetworkId = pNtwk.getId(); @@ -6193,8 +6264,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networks.get(0); } - @Override - public PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) { + protected PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) { PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.VirtualRouter.getName(), null, null); // add instance of the provider @@ -6206,9 +6276,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return nsp; } + + protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long physicalNetworkId) { - @Override - public PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { + PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, + Network.Provider.VPCVirtualRouter.getName(), null, null); + + return nsp; + } + + protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.SecurityGroupProvider.getName(), null, null); @@ -6235,7 +6312,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NetworkOfferingServiceMapVO serviceMap : servicesMap) { if (svcProviders.containsKey(serviceMap.getService())) { // FIXME - right now we pick up the first provider from the list, need to add more logic based on -// provider load, etc + // provider load, etc continue; } @@ -6249,7 +6326,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // check that provider is supported if (checkPhysicalNetwork) { if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) { - throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't support service " + service + " in physical network id=" + physicalNetworkId); + throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " + + "support service " + service + " in physical network id=" + physicalNetworkId); } } @@ -6613,7 +6691,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); + s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); } } return null; @@ -6640,18 +6719,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return providers; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ - @Override - public boolean addVmToNetwork(VirtualMachine vm, Network network) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#isVmPartOfNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ @Override public boolean isVmPartOfNetwork(long vmId, long ntwkId) { if (_nicDao.findByInstanceIdAndNetworkId(ntwkId, vmId) != null) { @@ -6660,12 +6727,4 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return false; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) - */ - @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { - // TODO Auto-generated method stub - return false; - } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 80633044b37..03cec169510 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -179,9 +179,9 @@ public class NetworkVO implements Network, Identity { public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId, - Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) { this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId, - related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges); + related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges, vpcId); this.gateway = that.getGateway(); this.cidr = that.getCidr(); this.broadcastUri = that.getBroadcastUri(); @@ -208,11 +208,12 @@ public class NetworkVO implements Network, Identity { * @param guestType TODO * @param aclType TODO * @param specifyIpRanges TODO + * @param vpcId TODO * @param dataCenterId */ public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long domainId, long accountId, long related, String name, String displayText, - String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) { + String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) { this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId); this.domainId = domainId; this.accountId = accountId; @@ -225,6 +226,7 @@ public class NetworkVO implements Network, Identity { this.uuid = UUID.randomUUID().toString(); this.guestType = guestType; this.specifyIpRanges = specifyIpRanges; + this.vpcId = vpcId; } @Override diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 83859834fa0..712e90d3074 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -14,6 +14,7 @@ package com.cloud.network.element; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.ejb.Local; @@ -29,8 +30,10 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; +import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Inject; import com.cloud.vm.NicProfile; @@ -45,9 +48,10 @@ import com.cloud.vm.VirtualMachineProfile; public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider{ private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class); @Inject - NetworkService _ntwkSvc; + NetworkService _ntwkService; @Inject - VpcVirtualNetworkApplianceManager _vpcElementMgr; + VpcVirtualNetworkApplianceService _vpcElementService; + private static final Map> capabilities = setCapabilities(); @@ -71,17 +75,34 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { - if (network.getVpcId() == null) { + Long vpcId = network.getVpcId(); + if (vpcId == null) { s_logger.warn("Network " + network + " is not associated with any VPC"); return false; } + boolean success = super.implement(network, offering, dest, context); if (success) { - success = success && _vpcElementMgr.addVpcElementToNetwork(network); + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } } - - return success; + + return success; } @Override @@ -89,30 +110,92 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - if (network.getVpcId() == null) { + Long vpcId = network.getVpcId(); + if (vpcId == null) { s_logger.warn("Network " + network + " is not associated with any VPC"); return false; } + boolean success = super.prepare(network, nic, vm, dest, context); if (success) { - success = success && _vpcElementMgr.addVpcElementToNetwork(network); + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } } - return success; } @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - - return _vpcElementMgr.removeVpcElementFromNetwork(network); + boolean success = true; + Long vpcId = network.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part the network " + network); + continue; + } + //2) Call unplugNics in the network service + success = success && _vpcElementService.removeVmFromNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + + return success; } @Override public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException { - - return _vpcElementMgr.removeVpcElementFromNetwork(config); + boolean success = true; + Long vpcId = config.getVpcId(); + if (vpcId == null) { + s_logger.debug("Network " + config + " doesn't belong to any vpc, so skipping unplug nic part"); + return success; + } + + List routers = _routerDao.listRoutersByVpcId(vpcId); + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (!_ntwkService.isVmPartOfNetwork(router.getId(), config.getId())) { + s_logger.debug("Router " + router + " is not a part the network " + config); + continue; + } + //2) Call unplugNics in the network service + success = success && _vpcElementService.removeVmFromNetwork(router, config); + } + + if (!success) { + s_logger.warn("Failed to unplug nic in network " + config + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router in vpc id=" + vpcId); + } + + return success; } @Override @@ -135,20 +218,4 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return capabilities; } - - @Override - public boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile vm, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - } diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index f52a39c1b82..3407e329dec 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -42,11 +42,11 @@ import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkProfile; import com.cloud.network.NetworkVO; -import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; +import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.PhysicalNetworkDao; @@ -312,16 +312,21 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { if (nic.getIp4Address() == null) { nic.setBroadcastUri(network.getBroadcastUri()); nic.setIsolationUri(network.getBroadcastUri()); - nic.setGateway(network.getGateway()); String guestIp = null; if (network.getSpecifyIpRanges()) { _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp()); } else { - guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); - if (guestIp == null) { - throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + - " address for network " + network, DataCenter.class, dc.getId()); + //if Vm is router vm, set ip4 to the network gateway + if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) { + guestIp = network.getGateway(); + } else { + nic.setGateway(network.getGateway()); + guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); + if (guestIp == null) { + throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + + " address for network " + network, DataCenter.class, dc.getId()); + } } nic.setIp4Address(guestIp); diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 6655a6e4bf5..8c15d807b44 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -39,6 +39,8 @@ import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.api.commands.CreateLoadBalancerRuleCmd; import com.cloud.configuration.Config; @@ -512,8 +514,10 @@ public class ElasticLoadBalancerManagerImpl implements throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId()); } - elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm); + elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), + VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, + _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null); elbVm.setRole(Role.LB); elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner); //TODO: create usage stats @@ -984,7 +988,6 @@ public class ElasticLoadBalancerManagerImpl implements } - @Override public Long convertToId(String vmName) { if (!VirtualMachineName.isValidSystemVmName(vmName, _instance, _elbVmNamePrefix)) { @@ -993,4 +996,20 @@ public class ElasticLoadBalancerManagerImpl implements return VirtualMachineName.getSystemVmId(vmName); } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 2d8629bf78f..4490af64af6 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -67,8 +67,10 @@ import com.cloud.agent.api.routing.VpnUsersCfgCommand; import com.cloud.agent.api.to.FirewallRuleTO; import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.StaticNatRuleTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; import com.cloud.api.commands.UpgradeRouterCmd; @@ -1252,7 +1254,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, - vrProvider, offeringId, sourceNatIp); + vrProvider, offeringId, sourceNatIp, null); routers.add(router); } } finally { @@ -1265,7 +1267,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, - VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException, + VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp, Long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1332,7 +1334,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, - RedundantState.UNKNOWN, offerHA, false); + RedundantState.UNKNOWN, offerHA, false, vpcId); router.setRole(Role.VIRTUAL_ROUTER); router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); } catch (InsufficientCapacityException ex) { @@ -1374,8 +1376,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //1) Guest network boolean hasGuestNetwork = false; if (guestNetwork != null) { - String defaultNetworkStartIp = null; s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); + String defaultNetworkStartIp = null; if (guestNetwork.getCidr() != null && !setupPublicNetwork) { String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { @@ -1385,8 +1387,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian " is already allocated, can't use it for domain router; will get random ip address from the range"); } } - - NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); if (setupPublicNetwork) { @@ -1572,6 +1572,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + + boolean dnsProvided = true; + boolean dhcpProvided = true; DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); _dcDao.loadDetails(dc); @@ -1637,6 +1640,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } } else if (nic.getTrafficType() == TrafficType.Guest) { + dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); //build bootloader parameter for the guest buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router)); } else if (nic.getTrafficType() == TrafficType.Public) { @@ -1676,77 +1681,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (profile.getHypervisorType() == HypervisorType.VMware) { buf.append(" extra_pubnics=" + _routerExtraPublicNics); } + - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); - } - - return true; - } - - protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, - String defaultDns2, DomainRouterVO router) { - long guestNetworkId = guestNic.getNetworkId(); - NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); - String dhcpRange = null; - DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); - - if (dc.getNetworkType() == NetworkType.Advanced) { - String cidr = guestNetwork.getCidr(); - if (cidr != null) { - dhcpRange = NetUtils.getDhcpRange(cidr); - } - } - - StringBuilder buf = new StringBuilder(); - - boolean isRedundant = router.getIsRedundantRouter(); - if (isRedundant) { - buf.append(" redundant_router=1"); - List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); - try { - int priority = getUpdatedPriority(guestNetwork, routers, router); - router.setPriority(priority); - } catch (InsufficientVirtualNetworkCapcityException e) { - s_logger.error("Failed to get update priority!", e); - throw new CloudRuntimeException("Failed to get update priority!"); - } - } - - - if (guestNic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) { - long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); - String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); - if (cidr != null) { - dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); - } - } - - if (dhcpRange != null) { - buf.append(" dhcprange=" + dhcpRange); - } - - if (isRedundant) { - Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); - buf.append(" guestgw=").append(net.getGateway()); - String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); - buf.append(" guestbrd=").append(brd); - buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); - buf.append(" router_pr=").append(router.getPriority()); - } - - String domain = guestNetwork.getNetworkDomain(); - if (domain != null) { - buf.append(" domain=" + domain); - } - - boolean dnsProvided = false; - boolean dhcpProvided = false; - if (guestNic.getTrafficType() == TrafficType.Guest) { - //FiXME - for multiple guest network case this should be set individually - dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); - } /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response * to return DNS server rather than * virtual router itself. */ @@ -1767,6 +1703,67 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" useextdns=true"); } } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + } + + return true; + } + + protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, + String defaultDns2, DomainRouterVO router) { + long guestNetworkId = guestNic.getNetworkId(); + NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + String dhcpRange = null; + DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); + + StringBuilder buf = new StringBuilder(); + + boolean isRedundant = router.getIsRedundantRouter(); + if (isRedundant) { + buf.append(" redundant_router=1"); + List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); + try { + int priority = getUpdatedPriority(guestNetwork, routers, router); + router.setPriority(priority); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); + buf.append(" guestgw=").append(net.getGateway()); + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); + buf.append(" guestbrd=").append(brd); + buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); + buf.append(" router_pr=").append(router.getPriority()); + } + + //setup network domain + String domain = guestNetwork.getNetworkDomain(); + if (domain != null) { + buf.append(" domain=" + domain); + } + + //setup dhcp range + if (dc.getNetworkType() == NetworkType.Basic) { + if (guestNic.isDefaultNic()) { + long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); + if (cidr != null) { + dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); + } + } + } else if (dc.getNetworkType() == NetworkType.Advanced) { + String cidr = guestNetwork.getCidr(); + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); + } + } + + if (dhcpRange != null) { + buf.append(" dhcprange=" + dhcpRange); + } return buf; } @@ -3054,4 +3051,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return routerControlIpAddress; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java index a6679a03785..32da887f311 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -19,8 +19,8 @@ import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.user.Account; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.VirtualMachineProfile.Param; @@ -28,7 +28,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{ +public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{ /** * @param vpc @@ -44,16 +44,4 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; - /** - * @param network - * @return - */ - boolean addVpcElementToNetwork(Network network); - - /** - * @param network - * @return - */ - boolean removeVpcElementFromNetwork(Network network); - } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 7ef2de5070d..b24ea65c91a 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -12,6 +12,7 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.router; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,11 +20,19 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager.OnError; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.PlugNicCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.manager.Commands; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.NetworkService; @@ -33,21 +42,25 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; +import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -@Local(value = { VpcVirtualNetworkApplianceManager.class}) -public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ +@Local(value = { VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class,}) +public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements +VpcVirtualNetworkApplianceManager{ private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); @Inject @@ -105,7 +118,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, - vrProvider, offeringId, sourceNatIp); + vrProvider, offeringId, sourceNatIp, vpc.getId()); routers.add(router); } finally { @@ -126,60 +139,61 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } @Override - public boolean addVpcElementToNetwork(Network network) { - boolean success = true; - Long vpcId = network.getVpcId(); - if (vpcId == null) { - s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping plug nic part"); - return success; + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + + String networkDomain = network.getNetworkDomain(); + String cidr = network.getCidr(); + String dhcpRange = null; + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); } - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; - } - //2) Call plugNics in the network service - success = success && _ntwkService.addVmToNetwork(router, network); + boolean result = true; + + //FIXME - Anthony, here I send plug nic command + try { + Map params = new HashMap(); + params.put(PlugNicCommand.Param.NetworkDomain, networkDomain); + params.put(PlugNicCommand.Param.DhcpRange, dhcpRange); + + PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("plugnic", plugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + Answer plugNicAnswer = cmds.getAnswer(Answer.class); + if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { + s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); + result = false; + } + + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName(), dest.getHost().getId(), e); } - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - - return success; + return result; } - + @Override - public boolean removeVpcElementFromNetwork(Network network) { - boolean success = true; - Long vpcId = network.getVpcId(); - if (vpcId == null) { - s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); - return success; - } + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part the network " + network); - continue; - } - //2) Call unplugNics in the network service - success = success && _ntwkService.removeVmFromNetwork(router, network); - } - - if (!success) { - s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - - return success; + //FIXME - Anthony, add unplug nic agent command + return true; + } + + @Override + public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + return _itMgr.addVmToNetwork(router, network); + } + + + @Override + public boolean removeVmFromNetwork(VirtualRouter router, Network network) { + return _itMgr.removeVmFromNetwork(router, network); } } diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index 19e268b1f12..e6f025024de 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -19,6 +19,7 @@ import java.util.Set; import com.cloud.exception.ConcurrentOperationException; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; +import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; @@ -70,6 +71,11 @@ public interface VpcManager extends VpcService{ * @return * @throws ConcurrentOperationException */ - void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, Vpc vpc) throws ConcurrentOperationException; + void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, + Vpc vpc) throws ConcurrentOperationException; + /** + * @return + */ + VpcProvider getVpcElement(); } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index ff3895ae257..c8e7f042130 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -686,7 +686,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ try { //1) CIDR is required if (cidr == null) { - throw new InvalidParameterValueException("CIDR is required when create network for VPC"); + throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC"); } //2) Network cidr should be within vpcCidr @@ -738,7 +738,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ } } - private VpcProvider getVpcElement() { + @Override + public VpcProvider getVpcElement() { if (vpcElement == null) { vpcElement = ((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())); } diff --git a/server/src/com/cloud/network/vpc/VpcOfferingVO.java b/server/src/com/cloud/network/vpc/VpcOfferingVO.java index 2b96f2047dc..2109e1c0cd7 100644 --- a/server/src/com/cloud/network/vpc/VpcOfferingVO.java +++ b/server/src/com/cloud/network/vpc/VpcOfferingVO.java @@ -130,7 +130,6 @@ public class VpcOfferingVO implements VpcOffering{ return buf.append(id).append("-").append(name).append("]").toString(); } - public void setName(String name) { this.name = name; } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index a20d5c2b9ae..9f6c9379040 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -165,5 +165,11 @@ public class VpcVO implements Vpc, Identity { public void setDisplayText(String displayText) { this.displayText = displayText; } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("[VPC ["); + return buf.append(id).append("-").append(name).append("]").toString(); + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 3c79e4e363b..5bb1858f388 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -1076,8 +1076,9 @@ public class ConfigurationServerImpl implements ConfigurationServer { } if (broadcastDomainType != null) { - NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, - null, specifyIpRanges); + NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, + domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, + null, specifyIpRanges, null); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2()); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 6accab99594..470f363d39b 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -42,6 +42,8 @@ import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.capacity.dao.CapacityDao; import com.cloud.cluster.ClusterManager; @@ -68,6 +70,7 @@ import com.cloud.info.RunningHostCountInfo; import com.cloud.info.RunningHostInfoAgregator; import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.keystore.KeystoreManager; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; @@ -1412,4 +1415,20 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } return null; } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 11000762ec1..de0a237085f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3582,5 +3582,20 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return vm; } + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + } + + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + } } diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index f736310ebb8..f8355f580cf 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -13,9 +13,15 @@ package com.cloud.vm; import com.cloud.agent.api.StopAnswer; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; /** * A VirtualMachineGuru knows how to process a certain type of virtual machine. @@ -68,4 +74,34 @@ public interface VirtualMachineGuru { * @return id if the handler works for this vm and can parse id. null if not. */ Long convertToId(String vmName); + + /** + * Prepare for a nic to be plugged into the network. + * @param network + * @param nic + * @param vm + * @param context + * @param dest TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientNetworkCapacityException + */ + boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * A nic is unplugged from this network. + * @param network + * @param nic + * @param vm + * @param context + * @param dest TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 3387a8e22e7..a7f89ba5cd1 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -15,6 +15,7 @@ package com.cloud.vm; import java.util.List; import java.util.Map; +import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.AgentUnavailableException; @@ -26,6 +27,7 @@ import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Network; import com.cloud.network.NetworkVO; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; @@ -132,4 +134,22 @@ public interface VirtualMachineManager extends Manager { */ boolean upgradeVmDb(long vmId, long serviceOfferingId); + /** + * @param vm + * @param network + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param vm + * @param network + * @return + */ + boolean removeVmFromNetwork(VirtualMachine vm, Network network); + } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index b73d0fd8e48..c2809153240 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -57,6 +57,7 @@ import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.StartupRoutingCommand.VmState; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; import com.cloud.agent.manager.allocator.HostAllocator; @@ -103,6 +104,7 @@ import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.dao.NetworkDao; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; import com.cloud.resource.ResourceManager; @@ -217,6 +219,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene protected StoragePoolDao _storagePoolDao; @Inject protected HypervisorGuruManager _hvGuruMgr; + @Inject + protected NetworkDao _networkDao; @Inject(adapter = DeploymentPlanner.class) protected Adapters _planners; @@ -748,11 +752,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene reuseVolume = true; } - VirtualMachineTO vmTO = null; Commands cmds = null; vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx); - vmTO = hvGuru.implement(vmProfile); + VirtualMachineTO vmTO = hvGuru.implement(vmProfile); cmds = new Commands(OnError.Stop); cmds.addCommand(new StartCommand(vmTO)); @@ -2426,4 +2429,53 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene vmForUpdate.setServiceOfferingId(newSvcOff.getId()); return _vmDao.update(vmId, vmForUpdate); } + + @Override + public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + + VMInstanceVO vmVO = _vmDao.findById(vm.getId()); + NetworkVO networkVO = _networkDao.findById(network.getId()); + ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), + _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + null, null, null); + + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + Host host = _hostDao.findById(vm.getHostId()); + DeployDestination dest = new DeployDestination(dc, null, null, host); + + s_logger.debug("Adding vm " + vm + " to network " + network); + + //1) allocate nic + NicProfile nic = _networkMgr.allocateNic(null, network, false, + 100, vmProfile).first(); + + //2) Prepare nic + nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); + + //3) plug the nic to the vm + VirtualMachineGuru vmGuru = getVmGuru(vmVO); + + //4) Convert vmProfile to vmTO + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); + VirtualMachineTO vmTO = hvGuru.implement(vmProfile); + + //5) Convert nicProfile to NicTO + NicTO nicTO = hvGuru.toNicTO(nic); + + return vmGuru.plugNic(network, nicTO, vmTO, context, null); + + } + + @Override + public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { + //1) TODO - release the nic + + //2) TODO - unplug the nic + + return true; + } + } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index dfac0928843..36ee86ce329 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -111,4 +111,10 @@ public interface DomainRouterDao extends GenericDao { * @return */ List listRoutersByVpcId(long vpcId); + + /** + * @param routerId + * @param guestNetwork + */ + void addRouterToNetwork(DomainRouterVO router, Network guestNetwork); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 11f982cfaed..bac97751df3 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -47,7 +47,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class); RouterNetworkDaoImpl _routerNetworkDao = ComponentLocator.inject(RouterNetworkDaoImpl.class); UserStatisticsDaoImpl _userStatsDao = ComponentLocator.inject(UserStatisticsDaoImpl.class); - + protected final SearchBuilder VpcSearch; protected DomainRouterDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -65,6 +65,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase im AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ); AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); + + VpcSearch = createSearchBuilder(); + VpcSearch.and("role", VpcSearch.entity().getRole(), Op.EQ); + VpcSearch.and("vpcId", VpcSearch.entity().getVpcId(), Op.EQ); + VpcSearch.done(); IdNetworkIdStatesSearch = createSearchBuilder(); IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ); @@ -259,15 +264,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im if (guestNetworks != null && !guestNetworks.isEmpty()) { // 2) add router to the network for (Network guestNetwork : guestNetworks) { - addRouterToNetwork(router.getId(), guestNetwork); - // 3) create user stats entry - UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), - guestNetwork.getId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), - router.getType().toString(), guestNetwork.getId()); - _userStatsDao.persist(stats); - } + addRouterToNetwork(router, guestNetwork); } } @@ -275,10 +272,21 @@ public class DomainRouterDaoImpl extends GenericDaoBase im return newRouter; } - - protected void addRouterToNetwork(long routerId, Network guestNetwork) { - RouterNetworkVO routerNtwkMap = new RouterNetworkVO(routerId, guestNetwork.getId(), guestNetwork.getGuestType()); + @Override + @DB + public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) { + + //1) add router to network + RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); _routerNetworkDao.persist(routerNtwkMap); + //2) create user stats entry for the network + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } } @Override @@ -288,7 +296,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override public List listRoutersByVpcId(long vpcId) { - SearchCriteria sc = AllFieldsSearch.create(); + SearchCriteria sc = VpcSearch.create(); sc.setParameters("vpcId", vpcId); sc.setParameters("role", Role.VIRTUAL_ROUTER); return listBy(sc); diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index a07b2c564f2..1921c503d57 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -201,7 +201,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException { + ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException { // TODO Auto-generated method stub return null; } diff --git a/wscript b/wscript index 844085841e7..2e9f510fdd4 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-22T23:46:23Z' +VERSION = '3.0.3.2012-05-23T23:17:18Z' APPNAME = 'cloud' import shutil,os From aa0c0cb26082577d3e5660b5b012ecc3072dbb26 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 24 May 2012 15:33:52 -0700 Subject: [PATCH 11/64] Added support for network shutdown in VPC guest networks --- .../com/cloud/agent/api/PlugNicAnswer.java | 24 ++++ .../com/cloud/agent/api/PlugNicCommand.java | 4 + .../com/cloud/agent/api/UnPlugNicAnswer.java | 24 ++++ .../com/cloud/agent/api/UnPlugNicCommand.java | 45 ++++++++ .../cloud/network/element/VpcProvider.java | 8 ++ api/src/com/cloud/network/vpc/Vpc.java | 8 +- .../VpcVirtualNetworkApplianceService.java | 4 +- .../src/com/cloud/network/NetworkManager.java | 19 ++++ .../com/cloud/network/NetworkManagerImpl.java | 59 +++++++--- .../cloud/network/RouterNetworkDaoImpl.java | 15 +++ .../com/cloud/network/RouterNetworkVO.java | 4 + .../element/VpcVirtualRouterElement.java | 107 ++++++++++++------ ...VpcVirtualNetworkApplianceManagerImpl.java | 82 +++++++++----- server/src/com/cloud/network/vpc/VpcVO.java | 4 + .../com/cloud/vm/VirtualMachineManager.java | 4 +- .../cloud/vm/VirtualMachineManagerImpl.java | 63 +++++++++-- .../src/com/cloud/vm/dao/DomainRouterDao.java | 6 + .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 10 +- .../vm/MockVirtualMachineManagerImpl.java | 19 ++++ wscript | 2 +- 20 files changed, 414 insertions(+), 97 deletions(-) create mode 100644 api/src/com/cloud/agent/api/PlugNicAnswer.java create mode 100644 api/src/com/cloud/agent/api/UnPlugNicAnswer.java create mode 100644 api/src/com/cloud/agent/api/UnPlugNicCommand.java diff --git a/api/src/com/cloud/agent/api/PlugNicAnswer.java b/api/src/com/cloud/agent/api/PlugNicAnswer.java new file mode 100644 index 00000000000..3a76240ef22 --- /dev/null +++ b/api/src/com/cloud/agent/api/PlugNicAnswer.java @@ -0,0 +1,24 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +/** + * @author Alena Prokharchyk + */ +public class PlugNicAnswer extends Answer{ + public PlugNicAnswer() {} + + public PlugNicAnswer(PlugNicCommand cmd, boolean success, String result) { + super(cmd, success, result); + } +} diff --git a/api/src/com/cloud/agent/api/PlugNicCommand.java b/api/src/com/cloud/agent/api/PlugNicCommand.java index 041d373b8eb..f2f36cb56ef 100644 --- a/api/src/com/cloud/agent/api/PlugNicCommand.java +++ b/api/src/com/cloud/agent/api/PlugNicCommand.java @@ -34,6 +34,10 @@ public class PlugNicCommand extends Command { return vm; } + public NicTO getNic() { + return nic; + } + @Override public boolean executeInSequence() { return true; diff --git a/api/src/com/cloud/agent/api/UnPlugNicAnswer.java b/api/src/com/cloud/agent/api/UnPlugNicAnswer.java new file mode 100644 index 00000000000..cd87c722697 --- /dev/null +++ b/api/src/com/cloud/agent/api/UnPlugNicAnswer.java @@ -0,0 +1,24 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +/** + * @author Alena Prokharchyk + */ +public class UnPlugNicAnswer extends Answer{ + public UnPlugNicAnswer() {} + + public UnPlugNicAnswer(UnPlugNicCommand cmd, boolean success, String result) { + super(cmd, success, result); + } +} diff --git a/api/src/com/cloud/agent/api/UnPlugNicCommand.java b/api/src/com/cloud/agent/api/UnPlugNicCommand.java new file mode 100644 index 00000000000..26d9441092f --- /dev/null +++ b/api/src/com/cloud/agent/api/UnPlugNicCommand.java @@ -0,0 +1,45 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; + +/** + * @author Alena Prokharchyk + */ +public class UnPlugNicCommand extends Command{ + VirtualMachineTO vm; + NicTO nic; + + public VirtualMachineTO getVirtualMachine() { + return vm; + } + + public NicTO getNic() { + return nic; + } + + @Override + public boolean executeInSequence() { + return true; + } + + protected UnPlugNicCommand() { + } + + public UnPlugNicCommand(VirtualMachineTO vm, NicTO nic) { + this.vm = vm; + this.nic = nic; + } +} diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 246ac0bdf4c..9243836e667 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -35,6 +35,14 @@ public interface VpcProvider extends NetworkElement{ */ boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param vpc + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/Vpc.java b/api/src/com/cloud/network/vpc/Vpc.java index 88fee8c76b5..f62a15f3efe 100644 --- a/api/src/com/cloud/network/vpc/Vpc.java +++ b/api/src/com/cloud/network/vpc/Vpc.java @@ -12,11 +12,8 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.vpc; -import java.util.List; - import com.cloud.acl.ControlledEntity; import com.cloud.network.Network; -import com.cloud.network.Network.Service; /** @@ -47,5 +44,10 @@ public interface Vpc extends ControlledEntity{ long getVpcOfferingId(); String getDisplayText(); + +/** + * @return + */ +String getNetworkDomain(); } diff --git a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java index 4de760ffba4..08c3b21d087 100644 --- a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java @@ -38,6 +38,8 @@ public interface VpcVirtualNetworkApplianceService { * @param router * @param network * @return + * @throws ResourceUnavailableException + * @throws ConcurrentOperationException */ - boolean removeVmFromNetwork(VirtualRouter router, Network network); + boolean removeVmFromNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 80346d998cb..9c7b3878dca 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -49,6 +49,7 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; +import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; @@ -372,4 +373,22 @@ public interface NetworkManager extends NetworkService { */ NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; + + + /** + * @param vmProfile + * @param network + * @return TODO + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException; + + + /** + * @param vm + * @param network + */ + void removeNic(VirtualMachineProfile vm, Network network); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index dfb54f4ea4b..23a50dc5b61 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2011,11 +2011,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override + @DB public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + + Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicVO nic = _nicDao.findById(nicId); @@ -2079,7 +2082,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); vm.addNic(profile); } @@ -2094,6 +2098,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag releaseNic(vmProfile, nic, network); } } + + @Override + public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) + throws ConcurrentOperationException, ResourceUnavailableException { + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vmProfile.getId()); + releaseNic(vmProfile, nic, network); + + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + return profile; + } + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException { @@ -2274,15 +2290,27 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { - nic.setState(Nic.State.Deallocating); - _nicDao.update(nic.getId(), nic); - NetworkVO network = _networksDao.findById(nic.getNetworkId()); - NicProfile profile = new NicProfile(nic, network, null, null, null, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); - NetworkGuru guru = _networkGurus.get(network.getGuruName()); - guru.deallocate(network, profile, vm); - _nicDao.remove(nic.getId()); + removeNic(vm, nic); } } + + @Override + public void removeNic(VirtualMachineProfile vm, Network network) { + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getVirtualMachine().getId()); + removeNic(vm, nic); + } + + protected void removeNic(VirtualMachineProfile vm, NicVO nic) { + nic.setState(Nic.State.Deallocating); + _nicDao.update(nic.getId(), nic); + NetworkVO network = _networksDao.findById(nic.getNetworkId()); + NicProfile profile = new NicProfile(nic, network, null, null, null, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + guru.deallocate(network, profile, vm); + _nicDao.remove(nic.getId()); + s_logger.debug("Removed nic id=" + nic.getId()); + } @Override public void expungeNics(VirtualMachineProfile vm) { @@ -2603,21 +2631,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + Vpc vpc = _vpcMgr.getVpc(vpcId); //1) Validate if network can be created for VPC - _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, - _vpcMgr.getVpc(vpcId)); + _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, vpc); + + if (networkDomain == null) { + networkDomain = vpc.getNetworkDomain(); + } //2) Create network Network guestNetwork = createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); - //3) Add network to all VPC's routers - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (DomainRouterVO router : routers) { - s_logger.debug("Adding router " + router + " to network " + guestNetwork); - _routerDao.addRouterToNetwork(router, guestNetwork); - } - return guestNetwork; } diff --git a/server/src/com/cloud/network/RouterNetworkDaoImpl.java b/server/src/com/cloud/network/RouterNetworkDaoImpl.java index 9cbd308733d..dcb6583a313 100644 --- a/server/src/com/cloud/network/RouterNetworkDaoImpl.java +++ b/server/src/com/cloud/network/RouterNetworkDaoImpl.java @@ -17,6 +17,7 @@ import java.util.List; import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; @@ -25,6 +26,7 @@ import com.cloud.utils.db.SearchCriteria.Op; */ public class RouterNetworkDaoImpl extends GenericDaoBase implements GenericDao{ protected final GenericSearchBuilder RouterNetworksSearch; + protected final SearchBuilder AllFieldsSearch; public RouterNetworkDaoImpl() { super(); @@ -33,6 +35,11 @@ public class RouterNetworkDaoImpl extends GenericDaoBase RouterNetworksSearch.selectField(RouterNetworksSearch.entity().getNetworkId()); RouterNetworksSearch.and("routerId", RouterNetworksSearch.entity().getRouterId(), Op.EQ); RouterNetworksSearch.done(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("routerId", AllFieldsSearch.entity().getRouterId(), Op.EQ); + AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.done(); } public List getRouterNetworks(long routerId) { @@ -40,4 +47,12 @@ public class RouterNetworkDaoImpl extends GenericDaoBase sc.setParameters("routerId", routerId); return customSearch(sc, null); } + + public RouterNetworkVO findByRouterAndNetwork (long routerId, long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("routerId", routerId); + sc.setParameters("networkId", networkId); + return findOneBy(sc); + } + } diff --git a/server/src/com/cloud/network/RouterNetworkVO.java b/server/src/com/cloud/network/RouterNetworkVO.java index bcbdc940f94..629a5f438ee 100644 --- a/server/src/com/cloud/network/RouterNetworkVO.java +++ b/server/src/com/cloud/network/RouterNetworkVO.java @@ -65,4 +65,8 @@ public class RouterNetworkVO{ public Network.GuestType getGuestType() { return guestType; } + + public long getId() { + return id; + } } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 712e90d3074..8f6b43526b7 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -21,6 +21,7 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.dc.DataCenter; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -33,9 +34,11 @@ import com.cloud.network.NetworkService; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcService; import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Inject; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; @@ -51,6 +54,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc NetworkService _ntwkService; @Inject VpcVirtualNetworkApplianceService _vpcElementService; + @Inject + VpcService _vpcService; private static final Map> capabilities = setCapabilities(); @@ -70,6 +75,19 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return true; } + @Override + public boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { + List routers = _routerDao.listRoutersByVpcId(vpc.getId()); + if (routers == null || routers.isEmpty()) { + return true; + } + boolean result = true; + for (DomainRouterVO router : routers) { + result = result && (_routerMgr.destroyRouter(router.getId()) != null); + } + return result; + } + @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, @@ -81,26 +99,34 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - boolean success = super.implement(network, offering, dest, context); + Vpc vpc = _vpcService.getVpc(vpcId); - if (success) { - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; - } - //2) Call plugNics in the network service - success = success && _vpcElementService.addVmToNetwork(router, network); - } - - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } + Map params = new HashMap(1); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); + + List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); + if ((routers == null) || (routers.size() == 0)) { + throw new ResourceUnavailableException("Can't find at least one running router!", + DataCenter.class, network.getDataCenterId()); } + + boolean success = true; + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + return success; } @@ -116,26 +142,35 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - boolean success = super.prepare(network, nic, vm, dest, context); + Vpc vpc = _vpcService.getVpc(vpcId); - if (success) { - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; - } - //2) Call plugNics in the network service - success = success && _vpcElementService.addVmToNetwork(router, network); - } - - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } + Map params = new HashMap(1); + params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); + + List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); + if ((routers == null) || (routers.size() == 0)) { + throw new ResourceUnavailableException("Can't find at least one running router!", + DataCenter.class, network.getDataCenterId()); } + + boolean success = true; + for (VirtualRouter router : routers) { + //1) Check if router is already a part of the network + if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + continue; + } + //2) Call plugNics in the network service + success = success && _vpcElementService.addVmToNetwork(router, network); + } + + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + } + + return success; } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index b24ea65c91a..df1177d86a8 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -12,7 +12,6 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.router; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,19 +19,13 @@ import javax.ejb.Local; import org.apache.log4j.Logger; -import com.cloud.agent.AgentManager.OnError; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.agent.manager.Commands; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; -import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.NetworkService; @@ -152,27 +145,34 @@ VpcVirtualNetworkApplianceManager{ boolean result = true; + //add router to network + DomainRouterVO router = _routerDao.findById(vm.getId()); + s_logger.debug("Adding router " + router + " to network " + network); + _routerDao.addRouterToNetwork(router, network); + + //FIXME - Anthony, here I send plug nic command - try { - Map params = new HashMap(); - params.put(PlugNicCommand.Param.NetworkDomain, networkDomain); - params.put(PlugNicCommand.Param.DhcpRange, dhcpRange); - - PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params); - - Commands cmds = new Commands(OnError.Stop); - cmds.addCommand("plugnic", plugNicCmd); - _agentMgr.send(dest.getHost().getId(), cmds); - - Answer plugNicAnswer = cmds.getAnswer(Answer.class); - if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { - s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); - result = false; - } - - } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName(), dest.getHost().getId(), e); - } +// try { +// Map params = new HashMap(); +// params.put(PlugNicCommand.Param.NetworkDomain, networkDomain); +// params.put(PlugNicCommand.Param.DhcpRange, dhcpRange); +// +// PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params); +// +// Commands cmds = new Commands(OnError.Stop); +// cmds.addCommand("plugnic", plugNicCmd); +// _agentMgr.send(dest.getHost().getId(), cmds); +// +// PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); +// if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { +// s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); +// result = false; +// } +// +// } catch (OperationTimedoutException e) { +// throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName() + " in network " + network, +// dest.getHost().getId(), e); +// } return result; } @@ -182,7 +182,30 @@ VpcVirtualNetworkApplianceManager{ ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { //FIXME - Anthony, add unplug nic agent command - return true; + boolean result = true; +// try { +// UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic); +// Commands cmds = new Commands(OnError.Stop); +// cmds.addCommand("unplugnic", unplugNicCmd); +// _agentMgr.send(dest.getHost().getId(), cmds); +// +// UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); +// if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { +// s_logger.warn("Unable to unplug nic from vm " + vm.getHostName()); +// result = false; +// } +// +// } catch (OperationTimedoutException e) { +// throw new AgentUnavailableException("Unable to unplug nic from vm " + vm.getHostName() + " from network " + network, +// dest.getHost().getId(), e); +// } +// + if (result) { + s_logger.debug("Removing router " + vm.getHostName() + " from network " + network); + _routerDao.removeRouterFromNetwork(vm.getId(), network.getId()); + } + + return result; } @Override @@ -193,7 +216,8 @@ VpcVirtualNetworkApplianceManager{ @Override - public boolean removeVmFromNetwork(VirtualRouter router, Network network) { + public boolean removeVmFromNetwork(VirtualRouter router, Network network) + throws ConcurrentOperationException, ResourceUnavailableException { return _itMgr.removeVmFromNetwork(router, network); } } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index 9f6c9379040..ad12cc014d5 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -172,4 +172,8 @@ public class VpcVO implements Vpc, Identity { return buf.append(id).append("-").append(name).append("]").toString(); } + @Override + public String getNetworkDomain() { + return networkDomain; + } } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index a7f89ba5cd1..f43de6e1a8b 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -149,7 +149,9 @@ public interface VirtualMachineManager extends Manager { * @param vm * @param network * @return + * @throws ResourceUnavailableException + * @throws ConcurrentOperationException */ - boolean removeVmFromNetwork(VirtualMachine vm, Network network); + boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index c2809153240..798a977fabc 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2431,6 +2431,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override + @DB public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -2448,34 +2449,80 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene s_logger.debug("Adding vm " + vm + " to network " + network); + Transaction txn = Transaction.currentTxn(); + txn.start(); //1) allocate nic NicProfile nic = _networkMgr.allocateNic(null, network, false, 100, vmProfile).first(); + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + //2) Prepare nic nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); - //3) plug the nic to the vm - VirtualMachineGuru vmGuru = getVmGuru(vmVO); + s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); - //4) Convert vmProfile to vmTO + txn.commit(); + + //3) Convert vmProfile to vmTO HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - //5) Convert nicProfile to NicTO + //4) Convert nicProfile to NicTO NicTO nicTO = hvGuru.toNicTO(nic); - return vmGuru.plugNic(network, nicTO, vmTO, context, null); + //5) plug the nic to the vm + VirtualMachineGuru vmGuru = getVmGuru(vmVO); + + if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) { + s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); + return true; + } else { + s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); + return false; + } } @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { - //1) TODO - release the nic + public boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException { + VMInstanceVO vmVO = _vmDao.findById(vm.getId()); + NetworkVO networkVO = _networkDao.findById(network.getId()); + ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), + _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + null, null, null); + + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + Host host = _hostDao.findById(vm.getHostId()); + DeployDestination dest = new DeployDestination(dc, null, null, host); + + //1) Release the nic + NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO); //2) TODO - unplug the nic + VirtualMachineGuru vmGuru = getVmGuru(vmVO); - return true; + //3) Convert vmProfile to vmTO + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); + VirtualMachineTO vmTO = hvGuru.implement(vmProfile); + + //4) Convert nicProfile to NicTO + NicTO nicTO = hvGuru.toNicTO(nic); + + boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest); + //5) Unplug the nic + if (result) { + s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network ); + } else { + s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); + return false; + } + + //6) Remove the nic + _networkMgr.removeNic(vmProfile, network); + return result; } } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 36ee86ce329..3dd615b1906 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -117,4 +117,10 @@ public interface DomainRouterDao extends GenericDao { * @param guestNetwork */ void addRouterToNetwork(DomainRouterVO router, Network guestNetwork); + + /** + * @param routerId + * @param guestNetworkId + */ + void removeRouterFromNetwork(long routerId, long guestNetworkId); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index bac97751df3..a3285f03fcc 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -275,7 +275,8 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override @DB public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) { - + Transaction txn = Transaction.currentTxn(); + txn.start(); //1) add router to network RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); _routerNetworkDao.persist(routerNtwkMap); @@ -287,6 +288,13 @@ public class DomainRouterDaoImpl extends GenericDaoBase im router.getType().toString(), guestNetwork.getId()); _userStatsDao.persist(stats); } + txn.commit(); + } + + @Override + public void removeRouterFromNetwork(long routerId, long guestNetworkId) { + RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId); + _routerNetworkDao.remove(routerNtwkMap.getId()); } @Override diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java index 5a65a6d13f9..f72e7e85cfc 100755 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java @@ -29,6 +29,7 @@ import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Network; import com.cloud.network.NetworkVO; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; @@ -235,4 +236,22 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager { return false; } + /* (non-Javadoc) + * @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) + */ + @Override + public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) + */ + @Override + public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { + // TODO Auto-generated method stub + return false; + } + } diff --git a/wscript b/wscript index 2e9f510fdd4..474cf75e905 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-23T23:17:18Z' +VERSION = '3.0.3.2012-05-24T22:26:07Z' APPNAME = 'cloud' import shutil,os From d7f0689bcb0d420a0f33f727729f8b203586a59e Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 24 May 2012 16:12:45 -0700 Subject: [PATCH 12/64] Support for delete VPC --- .../com/cloud/api/commands/DeleteVPCCmd.java | 27 ++++++++++---- .../cloud/network/element/VpcProvider.java | 4 +-- api/src/com/cloud/network/vpc/VpcService.java | 14 +++++++- .../element/VpcVirtualRouterElement.java | 4 +-- .../com/cloud/network/vpc/VpcManagerImpl.java | 36 +++++++++++++++++-- wscript | 2 +- 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/api/src/com/cloud/api/commands/DeleteVPCCmd.java b/api/src/com/cloud/api/commands/DeleteVPCCmd.java index d4ad1ae3208..b85fadd6417 100644 --- a/api/src/com/cloud/api/commands/DeleteVPCCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVPCCmd.java @@ -22,6 +22,9 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; @@ -66,12 +69,24 @@ public class DeleteVPCCmd extends BaseAsyncCmd{ @Override public void execute() { - boolean result = _vpcService.deleteVpc(getId()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + try { + boolean result = _vpcService.deleteVpc(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + } + }catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } catch (InsufficientCapacityException ex) { + s_logger.info(ex); + s_logger.trace(ex); + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 9243836e667..e40d188f5e1 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -33,7 +33,7 @@ public interface VpcProvider extends NetworkElement{ * @param vpc fully specified vpc configuration. * @throws InsufficientNetworkCapacityException TODO */ - boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) + boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** @@ -42,7 +42,7 @@ public interface VpcProvider extends NetworkElement{ * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; + boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 2272464daf8..5c1ebb3ad4c 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -71,8 +71,11 @@ public interface VpcService { /** * @param vpcId * @return + * @throws InsufficientCapacityException + * @throws ResourceUnavailableException + * @throws ConcurrentOperationException */ - public boolean deleteVpc(long vpcId); + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * @param vpcId @@ -113,4 +116,13 @@ public interface VpcService { */ Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + /** + * @param vpcId + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 8f6b43526b7..89a297e0754 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -64,7 +64,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc VpcVirtualNetworkApplianceManager _vpcRouterMgr; @Override - public boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Map params = new HashMap(1); @@ -76,7 +76,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } @Override - public boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { List routers = _routerDao.listRoutersByVpcId(vpc.getId()); if (routers == null || routers.isEmpty()) { return true; diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index c8e7f042130..70c36ac2dac 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -476,7 +476,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") - public boolean deleteVpc(long vpcId) { + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { UserContext.current().setEventDetails(" Id: " + vpcId); // Verify vpc id @@ -490,6 +490,9 @@ public class VpcManagerImpl implements VpcManager, Manager{ if (networksCount > 0) { throw new InvalidParameterValueException("Can't delete VPC " + vpcId + " as its used by " + networksCount + " networks"); } + + //shutdown VPC + shutdownVpc(vpcId); if (_vpcDao.remove(vpcId)) { return true; @@ -664,7 +667,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ _accountMgr.getAccount(vpc.getAccountId())); //deploy provider - if (getVpcElement().startVpc(vpc, dest, context)) { + if (getVpcElement().implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); return getVpc(vpc.getId()); } else { @@ -673,6 +676,35 @@ public class VpcManagerImpl implements VpcManager, Manager{ } } + + @Override + public Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + UserContext ctx = UserContext.current(); + Account caller = ctx.getCaller(); + + //check if vpc exists + Vpc vpc = getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + } + + //permission check + _accountMgr.checkAccess(caller, null, false, vpc); + + //shutdown provider + boolean success = getVpcElement().shutdownVpc(vpc); + + //FIXME - once more features are added to vpc (gateway/firewall rules, etc - cleanup them here) + + if (success) { + s_logger.debug("Vpc " + vpc + " has been stopped succesfully"); + return getVpc(vpc.getId()); + } else { + throw new CloudRuntimeException("Failed to stop vpc " + vpc); + } + } + @Override @DB public void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, diff --git a/wscript b/wscript index 474cf75e905..1f58c524567 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-24T22:26:07Z' +VERSION = '3.0.3.2012-05-24T22:43:32Z' APPNAME = 'cloud' import shutil,os From fbdf10bac7d78f018ef1d0af200348875aba2e18 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 25 May 2012 12:04:10 -0700 Subject: [PATCH 13/64] 1) Added search by vpcId to listRouters/listNetworks Apis 2) Don't allow to add new networks/implement existing ones for VPC in Disabled state. Disabled state indicates that there was unsuccessful attempt to remove the VPC, and the further cleanup will be taken care of by cleanup thread. --- .../cloud/api/commands/ListNetworksCmd.java | 10 ++- .../cloud/api/commands/ListRoutersCmd.java | 9 ++- .../api/commands/UpdateVPCOfferingCmd.java | 3 +- .../api/response/DomainRouterResponse.java | 9 ++- .../cloud/api/response/NetworkResponse.java | 7 ++ .../cloud/network/element/VpcProvider.java | 4 - api/src/com/cloud/network/vpc/VpcService.java | 4 +- .../src/com/cloud/api/ApiResponseHelper.java | 3 + .../com/cloud/network/NetworkManagerImpl.java | 39 +++++---- .../com/cloud/network/dao/IPAddressDao.java | 3 + .../cloud/network/dao/IPAddressDaoImpl.java | 13 +++ .../element/VpcVirtualRouterElement.java | 12 ++- .../src/com/cloud/network/vpc/Dao/VpcDao.java | 7 ++ .../com/cloud/network/vpc/Dao/VpcDaoImpl.java | 26 +++++- .../src/com/cloud/network/vpc/VpcManager.java | 13 +++ .../com/cloud/network/vpc/VpcManagerImpl.java | 80 +++++++++++++++---- server/src/com/cloud/network/vpc/VpcVO.java | 4 - .../cloud/server/ManagementServerImpl.java | 13 ++- .../com/cloud/user/AccountManagerImpl.java | 36 +++++++-- wscript | 2 +- 20 files changed, 243 insertions(+), 54 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index e7bea4d2d2f..9197c548d78 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -67,6 +67,10 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd { @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges") private Boolean specifyIpRanges; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC") + private Long vpcId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -112,7 +116,11 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd { return specifyIpRanges; } - ///////////////////////////////////////////////////// + public Long getVpcId() { + return vpcId; + } + + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @Override diff --git a/api/src/com/cloud/api/commands/ListRoutersCmd.java b/api/src/com/cloud/api/commands/ListRoutersCmd.java index 2e713e66988..0fb4dcc65c9 100644 --- a/api/src/com/cloud/api/commands/ListRoutersCmd.java +++ b/api/src/com/cloud/api/commands/ListRoutersCmd.java @@ -18,7 +18,6 @@ import java.util.List; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.BaseListProjectAndAccountResourcesCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; @@ -63,6 +62,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd { @IdentityMapper(entityTableName="networks") @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id") private Long networkId; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC") + private Long vpcId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -95,6 +98,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd { public Long getNetworkId() { return networkId; } + + public Long getVpcId() { + return vpcId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java index a31a8acb29b..38a519b52f2 100644 --- a/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java @@ -46,7 +46,8 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd{ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC offering") private String displayText; - @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering") + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering; " + + "supported states - Enabled/Disabled") private String state; ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/response/DomainRouterResponse.java b/api/src/com/cloud/api/response/DomainRouterResponse.java index 10c50f5eeec..bd7e7d07d6f 100644 --- a/api/src/com/cloud/api/response/DomainRouterResponse.java +++ b/api/src/com/cloud/api/response/DomainRouterResponse.java @@ -15,8 +15,8 @@ package com.cloud.api.response; import java.util.Date; import com.cloud.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; +import com.cloud.utils.IdentityProxy; import com.cloud.vm.VirtualMachine.State; import com.google.gson.annotations.SerializedName; @@ -133,6 +133,9 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti @SerializedName("scriptsversion") @Param(description="the version of scripts") private String scriptsVersion; + @SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to") + private IdentityProxy vpcId = new IdentityProxy("vpc"); + @Override public Long getObjectId() { return getId(); @@ -301,4 +304,8 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti public void setProjectName(String projectName) { this.projectName = projectName; } + + public void setVpcId(Long vpcId) { + this.vpcId.setValue(vpcId); + } } diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java index 834248b8670..5cb2cb47a86 100644 --- a/api/src/com/cloud/api/response/NetworkResponse.java +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -127,6 +127,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes @SerializedName(ApiConstants.SPECIFY_IP_RANGES) @Param(description="true if network supports specifying ip ranges, false otherwise") private Boolean specifyIpRanges; + @SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to") + private IdentityProxy vpcId = new IdentityProxy("vpc"); + public void setId(Long id) { this.id.setValue(id); } @@ -268,4 +271,8 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes public void setSpecifyIpRanges(Boolean specifyIpRanges) { this.specifyIpRanges = specifyIpRanges; } + + public void setVpcId(Long vpcId) { + this.vpcId.setValue(vpcId); + } } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index e40d188f5e1..63d0ce5af2b 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -17,12 +17,8 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; import com.cloud.network.vpc.Vpc; -import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; /** * @author Alena Prokharchyk diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 5c1ebb3ad4c..e60a5a4224e 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -33,8 +33,10 @@ public interface VpcService { public VpcOffering createVpcOffering(String name, String displayText, List supportedServices); public Vpc getVpc(long vpcId); + + public Vpc getActiveVpc(long vpcId); - public List getVpcNetworks(long vpcId); + public List getVpcNetworks(long vpcId); Map> getVpcOffSvcProvidersMap(long vpcOffId); diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 079aa039d2a..187843c5720 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1650,6 +1650,8 @@ public class ApiResponseHelper implements ResponseGenerator { routerResponse.setDns1(zone.getDns1()); routerResponse.setDns2(zone.getDns2()); } + + routerResponse.setVpcId(router.getVpcId()); routerResponse.setObjectName("domainrouter"); return routerResponse; @@ -2884,6 +2886,7 @@ public class ApiResponseHelper implements ResponseGenerator { } response.setSpecifyIpRanges(network.getSpecifyIpRanges()); + response.setVpcId(network.getVpcId()); response.setObjectName("network"); return response; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 23a50dc5b61..21e1d54e984 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -187,7 +187,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.DomainRouterVO; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -1168,8 +1167,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _ipAddressDao.markAsUnavailable(ip.getId()); if (!applyIpAssociations(network, true)) { // if fail to apply ip assciations again, unassign ip address without updating resource -// count and - // generating usage event as there is no need to keep it in the db + // count and generating usage event as there is no need to keep it in the db _ipAddressDao.unassignIpAddress(ip.getId()); } } catch (Exception e) { @@ -1185,7 +1183,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public boolean releasePublicIpAddress(long addrId, long userId, Account caller) { boolean success = true; - // Cleanup all ip address resources - PF/LB/Static nat rules if (!cleanupIpResources(addrId, userId, caller)) { success = false; @@ -1213,10 +1210,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } catch (ResourceUnavailableException e) { throw new CloudRuntimeException("We should never get to here because we used true when applyIpAssociations", e); } + } else { + if (ip.getState() == IpAddress.State.Releasing) { + _ipAddressDao.unassignIpAddress(ip.getId()); + } } if (success) { - s_logger.debug("released a public ip id=" + addrId); + s_logger.debug("Released a public ip id=" + addrId); } return success; @@ -2428,9 +2429,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag //validate vpc if (vpcId != null) { - Vpc vpc = _vpcMgr.getVpc(vpcId); + Vpc vpc = _vpcMgr.getActiveVpc(vpcId); if (vpc == null) { - throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + throw new InvalidParameterValueException("Unable to find enabled vpc by id " + vpcId); } _accountMgr.checkAccess(caller, null, false, vpc); } @@ -2631,7 +2632,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { - Vpc vpc = _vpcMgr.getVpc(vpcId); + Vpc vpc = _vpcMgr.getActiveVpc(vpcId); //1) Validate if network can be created for VPC _vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, vpc); @@ -2895,6 +2896,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean listAll = cmd.listAll(); boolean isRecursive = cmd.isRecursive(); Boolean specifyIpRanges = cmd.getSpecifyIpRanges(); + Long vpcId = cmd.getVpcId(); // 1) default is system to false if not specified // 2) reset parameter to false if it's specified by the regular user @@ -3005,21 +3007,25 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (domainId != null) { networksToReturn .addAll(listDomainLevelNetworks( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId), searchFilter, domainId)); } if (!permittedAccounts.isEmpty()) { networksToReturn.addAll(listAccountSpecificNetworks( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId), searchFilter, permittedAccounts)); } else if (domainId == null || listAll) { networksToReturn.addAll(listAccountSpecificNetworksByDomainPath( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, path, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId), searchFilter, path, isRecursive)); } } else { - networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges), + networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, + guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId), searchFilter); } @@ -3049,8 +3055,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, - String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges) { + private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, + Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, + String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId) { SearchCriteria sc = sb.create(); if (isSystem != null) { @@ -3098,6 +3105,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (specifyIpRanges != null) { sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges); } + + if (vpcId != null) { + sc.addAnd("vpcId", SearchCriteria.Op.EQ, vpcId); + } return sc; } diff --git a/server/src/com/cloud/network/dao/IPAddressDao.java b/server/src/com/cloud/network/dao/IPAddressDao.java index 1b44b16ba9e..54867703f36 100755 --- a/server/src/com/cloud/network/dao/IPAddressDao.java +++ b/server/src/com/cloud/network/dao/IPAddressDao.java @@ -56,4 +56,7 @@ public interface IPAddressDao extends GenericDao { List listByPhysicalNetworkId(long physicalNetworkId); long countFreeIPs(); + + List listByAssociatedVpc(long vpcId, Boolean isSourceNat); + } diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java index 425c215c430..daa8c18b85b 100755 --- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -67,6 +67,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ); AllFieldsSearch.and("sourcenetwork", AllFieldsSearch.entity().getSourceNetworkId(), Op.EQ); AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); + AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); VlanDbIdSearchUnallocated = createSearchBuilder(); @@ -299,4 +300,16 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen sc.setJoinParameters("vlans", "vlanType", VlanType.VirtualNetwork); return customSearch(sc, null).get(0); } + + @Override + public List listByAssociatedVpc(long vpcId, Boolean isSourceNat) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcId", vpcId); + + if (isSourceNat != null) { + sc.setParameters("sourceNat", isSourceNat); + } + + return listBy(sc); + } } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 89a297e0754..4f352c86cd7 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -99,7 +99,11 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - Vpc vpc = _vpcService.getVpc(vpcId); + Vpc vpc = _vpcService.getActiveVpc(vpcId); + if (vpc == null) { + s_logger.warn("Unable to find Enabled VPC by id " + vpcId); + return false; + } Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); @@ -142,7 +146,11 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - Vpc vpc = _vpcService.getVpc(vpcId); + Vpc vpc = _vpcService.getActiveVpc(vpcId); + if (vpc == null) { + s_logger.warn("Unable to find Enabled VPC by id " + vpcId); + return false; + } Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDao.java b/server/src/com/cloud/network/vpc/Dao/VpcDao.java index e95b6674de1..75fd56e88b7 100644 --- a/server/src/com/cloud/network/vpc/Dao/VpcDao.java +++ b/server/src/com/cloud/network/vpc/Dao/VpcDao.java @@ -12,6 +12,9 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.vpc.Dao; +import java.util.List; + +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcVO; import com.cloud.utils.db.GenericDao; @@ -25,5 +28,9 @@ public interface VpcDao extends GenericDao{ * @return */ int getVpcCountByOfferingId(long offId); + + Vpc getActiveVpcById(long vpcId); + + List listByAccountId(long accountId); } diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java index 4e32541e39f..6d6b03c220b 100644 --- a/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java +++ b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java @@ -16,10 +16,13 @@ import java.util.List; import javax.ejb.Local; +import com.cloud.domain.Domain.State; +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; @@ -32,8 +35,8 @@ import com.cloud.utils.db.SearchCriteria.Op; @DB(txn = false) public class VpcDaoImpl extends GenericDaoBase implements VpcDao{ final GenericSearchBuilder CountByOfferingId; + final SearchBuilder AllFieldsSearch; - protected VpcDaoImpl() { super(); @@ -42,6 +45,12 @@ public class VpcDaoImpl extends GenericDaoBase implements VpcDao{ CountByOfferingId.and("offeringId", CountByOfferingId.entity().getVpcOfferingId(), Op.EQ); CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL); CountByOfferingId.done(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ); + AllFieldsSearch.done(); } @@ -52,5 +61,20 @@ public class VpcDaoImpl extends GenericDaoBase implements VpcDao{ List results = customSearch(sc, null); return results.get(0); } + + @Override + public Vpc getActiveVpcById(long vpcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("id", vpcId); + sc.setParameters("state", State.Active); + return findOneBy(sc); + } + + @Override + public List listByAccountId(long accountId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("accountId", accountId); + return listBy(sc, null); + } } diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index e6f025024de..fe8105876b5 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -17,6 +17,8 @@ import java.util.Map; import java.util.Set; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.element.VpcProvider; @@ -78,4 +80,15 @@ public interface VpcManager extends VpcService{ * @return */ VpcProvider getVpcElement(); + + List getVpcsForAccount(long accountId); + + /** + * @param vpc + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 70c36ac2dac..b8e5dd54049 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -36,11 +36,13 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; +import com.cloud.network.IPAddressVO; import com.cloud.network.Network; import com.cloud.network.Network.GuestType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; +import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; @@ -90,6 +92,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ NetworkDao _ntwkDao; @Inject NetworkManager _ntwkMgr; + @Inject + IPAddressDao _ipAddressDao; private VpcProvider vpcElement = null; @@ -138,9 +142,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ } @Override - public List getVpcNetworks(long vpcId) { - // TODO Auto-generated method stub - return null; + public List getVpcNetworks(long vpcId) { + return _ntwkDao.listByVpc(vpcId); } @Override @@ -226,12 +229,15 @@ public class VpcManagerImpl implements VpcManager, Manager{ return offering; } - - @Override public Vpc getVpc(long vpcId) { return _vpcDao.findById(vpcId); } + + @Override + public Vpc getActiveVpc(long vpcId) { + return _vpcDao.findById(vpcId); + } @Override public Map> getVpcOffSvcProvidersMap(long vpcOffId) { @@ -478,23 +484,47 @@ public class VpcManagerImpl implements VpcManager, Manager{ @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { UserContext.current().setEventDetails(" Id: " + vpcId); + Account caller = UserContext.current().getCaller(); // Verify vpc id - VpcVO vpc = _vpcDao.findById(vpcId); + Vpc vpc = getVpc(vpcId); if (vpc == null) { throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); } + + //verify permissions + _accountMgr.checkAccess(caller, null, false, vpc); - // don't allow to delete vpc if it's in use by existing networks - int networksCount = _ntwkDao.getNetworkCountByVpcId(vpcId); + return destroyVpc(vpc); + } + + @Override + public boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + UserContext ctx = UserContext.current(); + + //don't allow to delete vpc if it's in use by existing networks + int networksCount = _ntwkDao.getNetworkCountByVpcId(vpc.getId()); if (networksCount > 0) { - throw new InvalidParameterValueException("Can't delete VPC " + vpcId + " as its used by " + networksCount + " networks"); + throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks"); } - //shutdown VPC - shutdownVpc(vpcId); + //mark VPC as disabled + s_logger.debug("Updating VPC " + vpc + " with state " + Vpc.State.Disabled + " as a part of vpc delete"); + VpcVO vpcVO = _vpcDao.findById(vpc.getId()); + vpcVO.setState(Vpc.State.Disabled); + _vpcDao.update(vpc.getId(), vpcVO); - if (_vpcDao.remove(vpcId)) { + //shutdown VPC + shutdownVpc(vpc.getId()); + + //cleanup vpc resources + if (!cleanupVpcResources(vpc.getId(), ctx.getCaller(), ctx.getCallerUserId())) { + s_logger.warn("Failed to cleanup resources for vpc " + vpc); + return false; + } + + if (_vpcDao.remove(vpc.getId())) { return true; } else { return false; @@ -652,9 +682,9 @@ public class VpcManagerImpl implements VpcManager, Manager{ User callerUser = _accountMgr.getActiveUser(ctx.getCallerUserId()); //check if vpc exists - Vpc vpc = getVpc(vpcId); + Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { - throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + throw new InvalidParameterValueException("Unable to find Enabled vpc by id " + vpcId); } //permission check @@ -778,4 +808,26 @@ public class VpcManagerImpl implements VpcManager, Manager{ return vpcElement; } + + @Override + public List getVpcsForAccount(long accountId) { + return _vpcDao.listByAccountId(accountId); + } + + public boolean cleanupVpcResources(long vpcId, Account caller, long callerUserId) { + s_logger.debug("Cleaning up resources for vpc id=" + vpcId); + boolean success = true; + // release all ip addresses + List ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null); + s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup"); + for (IPAddressVO ipToRelease : ipsToRelease) { + success = success && _ntwkMgr.releasePublicIpAddress(ipToRelease.getId(), callerUserId, caller); + if (!success) { + s_logger.warn("Failed to cleanup ip " + ipToRelease + " as a part of vpc id=" + vpcId + " cleanup"); + } + } + + return success; + + } } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index ad12cc014d5..3d90f3ca8e7 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -12,9 +12,7 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.vpc; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import java.util.UUID; import javax.persistence.Column; @@ -25,8 +23,6 @@ import javax.persistence.Id; import javax.persistence.Table; import com.cloud.api.Identity; -import com.cloud.network.Network; -import com.cloud.network.Network.Service; import com.cloud.utils.db.GenericDao; /** diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index c98a2977db5..3d2a57571f2 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -160,7 +160,6 @@ import com.cloud.network.NetworkVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; -import com.cloud.offering.ServiceOffering; import com.cloud.org.Grouping.AllocationState; import com.cloud.projects.Project; import com.cloud.projects.Project.ListProjectResourcesCriteria; @@ -1552,6 +1551,7 @@ public class ManagementServerImpl implements ManagementServer { Long hostId = cmd.getHostId(); String keyword = cmd.getKeyword(); Long networkId = cmd.getNetworkId(); + Long vpcId = cmd.getVpcId(); Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); @@ -1572,6 +1572,7 @@ public class ManagementServerImpl implements ManagementServer { sb.and("dataCenterId", sb.entity().getDataCenterIdToDeployIn(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodIdToDeployIn(), SearchCriteria.Op.EQ); sb.and("hostId", sb.entity().getHostId(), SearchCriteria.Op.EQ); + sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); if (networkId != null) { SearchBuilder nicSearch = _nicDao.createSearchBuilder(); @@ -1598,24 +1599,34 @@ public class ManagementServerImpl implements ManagementServer { if (name != null) { sc.setParameters("name", "%" + name + "%"); } + if (id != null) { sc.setParameters("id", id); } + if (state != null) { sc.setParameters("state", state); } + if (zone != null) { sc.setParameters("dataCenterId", zone); } + if (pod != null) { sc.setParameters("podId", pod); } + if (hostId != null) { sc.setParameters("hostId", hostId); } + if (networkId != null) { sc.setJoinParameters("nicSearch", "networkId", networkId); } + + if (vpcId != null) { + sc.setParameters("vpcId", vpcId); + } return _routerDao.search(sc, searchFilter); } diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index fd9c9c2099e..3503d3f475d 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -77,6 +77,8 @@ import com.cloud.network.dao.RemoteAccessVpnDao; import com.cloud.network.dao.VpnUserDao; import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.dao.SecurityGroupDao; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcManager; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.projects.Project; import com.cloud.projects.Project.ListProjectResourcesCriteria; @@ -199,6 +201,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag private ProjectAccountDao _projectAccountDao; @Inject private IPAddressDao _ipAddressDao; + @Inject + private VpcManager _vpcMgr; private Adapters _userAuthenticators; @@ -572,20 +576,36 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag } } } + + //Delete all VPCs + boolean vpcsDeleted = true; + s_logger.debug("Deleting vpcs for account " + account.getId()); + List vpcs = _vpcMgr.getVpcsForAccount(account.getId()); + for (Vpc vpc : vpcs) { - // release ip addresses belonging to the account - List ipsToRelease = _ipAddressDao.listByAccount(accountId); - for (IpAddress ip : ipsToRelease) { - s_logger.debug("Releasing ip " + ip + " as a part of account id=" + accountId + " cleanup"); - if (!_networkMgr.releasePublicIpAddress(ip.getId(), callerUserId, caller)) { - s_logger.warn("Failed to release ip address " + ip + " as a part of account id=" + accountId + " clenaup"); + if (!_vpcMgr.destroyVpc(vpc)) { + s_logger.warn("Unable to destroy VPC " + vpc + " as a part of account id=" + accountId + " cleanup."); accountCleanupNeeded = true; + vpcsDeleted = false; + } else { + s_logger.debug("VPC " + vpc.getId() + " successfully deleted as a part of account id=" + accountId + " cleanup."); + } + } + + if (vpcsDeleted) { + // release ip addresses belonging to the account + List ipsToRelease = _ipAddressDao.listByAccount(accountId); + for (IpAddress ip : ipsToRelease) { + s_logger.debug("Releasing ip " + ip + " as a part of account id=" + accountId + " cleanup"); + if (!_networkMgr.releasePublicIpAddress(ip.getId(), callerUserId, caller)) { + s_logger.warn("Failed to release ip address " + ip + " as a part of account id=" + accountId + " clenaup"); + accountCleanupNeeded = true; + } } } // delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned - // up - // successfully + // up successfully if (networksDeleted) { if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)) { accountCleanupNeeded = true; diff --git a/wscript b/wscript index 1f58c524567..05a9a1061b6 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-24T22:43:32Z' +VERSION = '3.0.3.2012-05-25T21:12:57Z' APPNAME = 'cloud' import shutil,os From d3b1925e555864da93303399f19ab16ac1c41b1e Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 25 May 2012 15:34:51 -0700 Subject: [PATCH 14/64] 1) Added VPC restart support - new api command RestartVPC. The purpose of the call is to shutdown and start VPC including VPCVirtualRouter restart, rules re-implement, etc 2) Only networks created from offerings with conserveMode=false, can participate in VPC --- .../com/cloud/api/commands/CreateVPCCmd.java | 5 +- .../com/cloud/api/commands/DeleteVPCCmd.java | 4 - .../cloud/api/commands/ListNetworksCmd.java | 2 +- .../com/cloud/api/commands/ListVPCsCmd.java | 11 ++- .../com/cloud/api/commands/RestartVPCCmd.java | 95 +++++++++++++++++++ .../com/cloud/api/commands/UpdateVPCCmd.java | 2 +- .../com/cloud/api/response/VpcResponse.java | 13 +++ api/src/com/cloud/event/EventTypes.java | 1 + api/src/com/cloud/network/vpc/Vpc.java | 7 +- api/src/com/cloud/network/vpc/VpcService.java | 18 +++- client/tomcatconf/commands.properties.in | 2 +- .../src/com/cloud/api/ApiResponseHelper.java | 2 + .../src/com/cloud/network/vpc/VpcManager.java | 4 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 86 +++++++++++++---- server/src/com/cloud/network/vpc/VpcVO.java | 12 +++ setup/db/create-schema.sql | 1 + wscript | 2 +- 17 files changed, 228 insertions(+), 39 deletions(-) create mode 100644 api/src/com/cloud/api/commands/RestartVPCCmd.java diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java index ec915ed4996..7807a0ba2b6 100644 --- a/api/src/com/cloud/api/commands/CreateVPCCmd.java +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -124,7 +124,9 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc) Vpc vpc = null; try { - vpc = _vpcService.startVpc(this.getEntityId()); + if (_vpcService.startVpc(this.getEntityId())) { + vpc = _vpcService.getVpc(getEntityId()); + } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); @@ -136,6 +138,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ s_logger.trace(ex); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } + if (vpc != null) { VpcResponse response = _responseGenerator.createVpcResponse(vpc); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/DeleteVPCCmd.java b/api/src/com/cloud/api/commands/DeleteVPCCmd.java index b85fadd6417..5a80f29dce1 100644 --- a/api/src/com/cloud/api/commands/DeleteVPCCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVPCCmd.java @@ -83,10 +83,6 @@ public class DeleteVPCCmd extends BaseAsyncCmd{ } catch (ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); - } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index 9197c548d78..182bf815a02 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -62,7 +62,7 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd { @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services") private List supportedServices; - @Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list network offerings by restartRequired option") + @Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list networks by restartRequired") private Boolean restartRequired; @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges") diff --git a/api/src/com/cloud/api/commands/ListVPCsCmd.java b/api/src/com/cloud/api/commands/ListVPCsCmd.java index bda292ac603..5d1a090725d 100644 --- a/api/src/com/cloud/api/commands/ListVPCsCmd.java +++ b/api/src/com/cloud/api/commands/ListVPCsCmd.java @@ -24,7 +24,6 @@ import com.cloud.api.Parameter; import com.cloud.api.response.ListResponse; import com.cloud.api.response.VpcResponse; import com.cloud.network.vpc.Vpc; -import com.cloud.network.vpc.Vpc; /** * @author Alena Prokharchyk @@ -75,6 +74,9 @@ public class ListVPCsCmd extends BaseListAccountResourcesCmd{ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPCs by state") private String state; + @Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list VPCs by restartRequired option") + private Boolean restartRequired; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -119,6 +121,10 @@ public class ListVPCsCmd extends BaseListAccountResourcesCmd{ return state; } + public Boolean getRestartRequired() { + return restartRequired; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -127,7 +133,8 @@ public class ListVPCsCmd extends BaseListAccountResourcesCmd{ public void execute() { List vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(), - this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(), this.listAll()); + this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(), + this.listAll(), getRestartRequired()); ListResponse response = new ListResponse(); List offeringResponses = new ArrayList(); for (Vpc vpc : vpcs) { diff --git a/api/src/com/cloud/api/commands/RestartVPCCmd.java b/api/src/com/cloud/api/commands/RestartVPCCmd.java new file mode 100644 index 00000000000..a2ce626659b --- /dev/null +++ b/api/src/com/cloud/api/commands/RestartVPCCmd.java @@ -0,0 +1,95 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class RestartVPCCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(RestartVPCCmd.class.getName()); + private static final String _name = "restartvpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + Vpc vpc = _entityMgr.findById(Vpc.class, getId()); + if (vpc != null) { + return vpc.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + try { + boolean result = _vpcService.restartVpc(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart VPC"); + } + } catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } catch (InsufficientCapacityException ex) { + s_logger.info(ex); + s_logger.trace(ex); + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_RESTART; + } + + @Override + public String getEventDescription() { + return "restarting VPC id=" + getId(); + } +} diff --git a/api/src/com/cloud/api/commands/UpdateVPCCmd.java b/api/src/com/cloud/api/commands/UpdateVPCCmd.java index 80babfc1a4d..c4478625ee8 100644 --- a/api/src/com/cloud/api/commands/UpdateVPCCmd.java +++ b/api/src/com/cloud/api/commands/UpdateVPCCmd.java @@ -101,6 +101,6 @@ public class UpdateVPCCmd extends BaseAsyncCmd{ @Override public String getEventDescription() { - return "Updating VPC id=" + getId(); + return "updating VPC id=" + getId(); } } diff --git a/api/src/com/cloud/api/response/VpcResponse.java b/api/src/com/cloud/api/response/VpcResponse.java index 3ba92808422..84e339d776a 100644 --- a/api/src/com/cloud/api/response/VpcResponse.java +++ b/api/src/com/cloud/api/response/VpcResponse.java @@ -71,6 +71,11 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons @SerializedName(ApiConstants.NETWORK) @Param(description="the list of networks belongign to the VPC", responseObject = NetworkResponse.class) private List networks; + @SerializedName(ApiConstants.RESTART_REQUIRED) @Param(description="true network requires restart") + private Boolean restartRequired; + + @SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain") + private String networkDomain; public void setId(Long id) { this.id.setValue(id); @@ -140,4 +145,12 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons public void setNetworks(List networks) { this.networks = networks; } + + public void setRestartRequired(Boolean restartRequired) { + this.restartRequired = restartRequired; + } + + public void setNetworkDomain(String networkDomain) { + this.networkDomain = networkDomain; + } } diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 75fe38e05f7..aaf4441b6f0 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -257,6 +257,7 @@ public class EventTypes { public static final String EVENT_VPC_CREATE = "VPC.CREATE"; public static final String EVENT_VPC_UPDATE = "VPC.UPDATE"; public static final String EVENT_VPC_DELETE = "VPC.DELETE"; + public static final String EVENT_VPC_RESTART = "VPC.RESTART"; public static final String EVENT_VPC_OFFERING_CREATE = "VPC.OFFERING.CREATE"; diff --git a/api/src/com/cloud/network/vpc/Vpc.java b/api/src/com/cloud/network/vpc/Vpc.java index f62a15f3efe..da50066fa76 100644 --- a/api/src/com/cloud/network/vpc/Vpc.java +++ b/api/src/com/cloud/network/vpc/Vpc.java @@ -45,9 +45,8 @@ public interface Vpc extends ControlledEntity{ String getDisplayText(); -/** - * @return - */ -String getNetworkDomain(); + String getNetworkDomain(); + + boolean isRestartRequired(); } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index e60a5a4224e..9473d180867 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -77,7 +77,7 @@ public interface VpcService { * @throws ResourceUnavailableException * @throws ConcurrentOperationException */ - public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException; /** * @param vpcId @@ -102,12 +102,14 @@ public interface VpcService { * @param zoneId TODO * @param isRecursive TODO * @param listAll TODO + * @param restartRequired TODO * @param vpc * @return */ public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, - String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll); + String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, + Boolean restartRequired); /** * @param vpcId @@ -116,15 +118,21 @@ public interface VpcService { * @throws ResourceUnavailableException * @throws ConcurrentOperationException */ - Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * @param vpcId * @return * @throws ConcurrentOperationException * @throws ResourceUnavailableException - * @throws InsufficientCapacityException */ - Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException; + + /** + * @param id + * @return + * @throws InsufficientCapacityException + */ + boolean restartVpc(Long id) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; } diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 68c896c030b..9bc75b4124b 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -339,7 +339,7 @@ createVPC=com.cloud.api.commands.CreateVPCCmd;15 listVPCs=com.cloud.api.commands.ListVPCsCmd;15 deleteVPC=com.cloud.api.commands.DeleteVPCCmd;15 updateVPC=com.cloud.api.commands.UpdateVPCCmd;15 - +restartVPC=com.cloud.api.commands.RestartVPCCmd;15 #### VPC offering commands createVPCOffering=com.cloud.api.commands.CreateVPCOfferingCmd;1 diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 187843c5720..68764ff895b 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -3449,6 +3449,8 @@ public class ApiResponseHelper implements ResponseGenerator { response.setVpcOfferingId(vpc.getVpcOfferingId()); response.setCidr(vpc.getCidr()); response.setZoneId(vpc.getZoneId()); + response.setRestartRequired(vpc.isRestartRequired()); + response.setNetworkDomain(vpc.getNetworkDomain()); Map> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId()); List serviceResponses = new ArrayList(); diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index fe8105876b5..9612690122d 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -17,7 +17,6 @@ import java.util.Map; import java.util.Set; import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -88,7 +87,6 @@ public interface VpcManager extends VpcService{ * @return * @throws ConcurrentOperationException * @throws ResourceUnavailableException - * @throws InsufficientCapacityException */ - boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index b8e5dd54049..b17cf63a8d8 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -64,7 +64,6 @@ import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContextImpl; @@ -482,7 +481,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") - public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { UserContext.current().setEventDetails(" Id: " + vpcId); Account caller = UserContext.current().getCaller(); @@ -494,13 +493,12 @@ public class VpcManagerImpl implements VpcManager, Manager{ //verify permissions _accountMgr.checkAccess(caller, null, false, vpc); - + return destroyVpc(vpc); } @Override - public boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { + public boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { UserContext ctx = UserContext.current(); //don't allow to delete vpc if it's in use by existing networks @@ -516,7 +514,10 @@ public class VpcManagerImpl implements VpcManager, Manager{ _vpcDao.update(vpc.getId(), vpcVO); //shutdown VPC - shutdownVpc(vpc.getId()); + if (!shutdownVpc(vpc.getId())) { + s_logger.warn("Failed to shutdown vpc " + vpc + " as a part of vpc destroy process"); + return false; + } //cleanup vpc resources if (!cleanupVpcResources(vpc.getId(), ctx.getCaller(), ctx.getCallerUserId())) { @@ -535,12 +536,15 @@ public class VpcManagerImpl implements VpcManager, Manager{ @ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc") public Vpc updateVpc(long vpcId, String vpcName, String displayText) { UserContext.current().setEventDetails(" Id: " + vpcId); + Account caller = UserContext.current().getCaller(); // Verify input parameters VpcVO vpcToUpdate = _vpcDao.findById(vpcId); if (vpcToUpdate == null) { throw new InvalidParameterValueException("Unable to find vpc offering " + vpcId); } + + _accountMgr.checkAccess(caller, null, false, vpcToUpdate); VpcVO vpc = _vpcDao.createForUpdate(vpcId); @@ -564,7 +568,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Override public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, - Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll) { + Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired) { Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); @@ -586,6 +590,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ sb.and("vpcOfferingId", sb.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); + sb.and("restartRequired", sb.entity().isRestartRequired(), SearchCriteria.Op.EQ); // now set the SC criteria... @@ -622,6 +627,10 @@ public class VpcManagerImpl implements VpcManager, Manager{ if (state != null) { sc.addAnd("state", SearchCriteria.Op.EQ, state); } + + if (restartRequired != null) { + sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired); + } List vpcs = _vpcDao.search(sc, searchFilter); @@ -675,7 +684,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ } @Override - public Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, + public boolean startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); @@ -699,17 +708,17 @@ public class VpcManagerImpl implements VpcManager, Manager{ //deploy provider if (getVpcElement().implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); - return getVpc(vpc.getId()); + return true; } else { - throw new CloudRuntimeException("Failed to start vpc " + vpc); + s_logger.warn("Vpc " + vpc + " failed to start"); //FIXME - add cleanup logic here + return false; } } @Override - public Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { + public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); @@ -726,13 +735,12 @@ public class VpcManagerImpl implements VpcManager, Manager{ boolean success = getVpcElement().shutdownVpc(vpc); //FIXME - once more features are added to vpc (gateway/firewall rules, etc - cleanup them here) - if (success) { - s_logger.debug("Vpc " + vpc + " has been stopped succesfully"); - return getVpc(vpc.getId()); + s_logger.debug("Vpc " + vpc + " has been shutdown succesfully"); } else { - throw new CloudRuntimeException("Failed to stop vpc " + vpc); + s_logger.warn("Vpc " + vpc + " failed to shutdown"); } + return success; } @Override @@ -794,6 +802,12 @@ public class VpcManagerImpl implements VpcManager, Manager{ if (guestNtwkOff.getRedundantRouter()) { throw new InvalidParameterValueException("No redunant router support when network belnogs to VPC"); } + + //8) Conserve mode should be off + if (guestNtwkOff.isConserveMode()) { + throw new InvalidParameterValueException("Only networks with conserve mode Off can belong to VPC"); + } + } finally { s_logger.debug("Releasing lock for " + locked); _vpcDao.releaseFromLockTable(locked.getId()); @@ -830,4 +844,44 @@ public class VpcManagerImpl implements VpcManager, Manager{ return success; } + + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_RESTART, eventDescription = "restarting vpc") + public boolean restartVpc(Long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + Account caller = UserContext.current().getCaller(); + + // Verify input parameters + VpcVO vpc = _vpcDao.findById(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Unable to find vpc offering " + vpcId); + } + + _accountMgr.checkAccess(caller, null, false, vpc); + + s_logger.debug("Restarting VPC " + vpc); + boolean restartRequired = false; + try { + s_logger.debug("Shuttign down VPC " + vpc + " as a part of VPC restart process"); + if (!shutdownVpc(vpcId)) { + s_logger.warn("Failed to shutdown vpc as a part of VPC " + vpc + " restart process"); + restartRequired = true; + return false; + } + + s_logger.debug("Starting VPC " + vpc + " as a part of VPC restart process"); + if (!startVpc(vpcId)) { + s_logger.warn("Failed to start vpc as a part of VPC " + vpc + " restart process"); + restartRequired = true; + return false; + } + s_logger.debug("VPC " + vpc + " was restarted successfully"); + return true; + } finally { + s_logger.debug("Updating VPC " + vpc + " with restartRequired=" + restartRequired); + vpc.setRestartRequired(restartRequired); + _vpcDao.update(vpc.getId(), vpc); + } + } } diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java index 3d90f3ca8e7..212a124f9b7 100644 --- a/server/src/com/cloud/network/vpc/VpcVO.java +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -73,6 +73,9 @@ public class VpcVO implements Vpc, Identity { @Column(name="network_domain") String networkDomain; + @Column(name="restart_required") + boolean restartRequired = false; + public VpcVO() { this.uuid = UUID.randomUUID().toString(); } @@ -172,4 +175,13 @@ public class VpcVO implements Vpc, Identity { public String getNetworkDomain() { return networkDomain; } + + public void setRestartRequired(boolean restartRequired) { + this.restartRequired = restartRequired; + } + + @Override + public boolean isRestartRequired() { + return restartRequired; + } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 08f2f8ce5c6..be56b2ab35c 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2144,6 +2144,7 @@ CREATE TABLE `cloud`.`vpc` ( `network_domain` varchar(255) COMMENT 'network domain', `removed` datetime COMMENT 'date removed if not null', `created` datetime NOT NULL COMMENT 'date created', + `restart_required` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if restart is required for the VPC', PRIMARY KEY (`id`), INDEX `i_vpc__removed`(`removed`), CONSTRAINT `fk_vpc__zone_id` FOREIGN KEY `fk_vpc__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, diff --git a/wscript b/wscript index 05a9a1061b6..c31c87049c9 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-25T21:12:57Z' +VERSION = '3.0.3.2012-05-25T22:13:38Z' APPNAME = 'cloud' import shutil,os From a7c8354c7bd7534cc81551decdd13a7e2e641d3e Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 29 May 2012 10:31:46 -0700 Subject: [PATCH 15/64] Destroy VPC if it fails to start during the deployment --- .../com/cloud/api/commands/CreateVPCCmd.java | 1 - client/tomcatconf/commands.properties.in | 6 ++++ .../com/cloud/network/NetworkManagerImpl.java | 2 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 35 +++++++++++++++---- .../cloud/server/ConfigurationServerImpl.java | 2 +- wscript | 2 +- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java index 7807a0ba2b6..11c8ad6b2d9 100644 --- a/api/src/com/cloud/api/commands/CreateVPCCmd.java +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -121,7 +121,6 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ @Override public void execute() { - //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc) Vpc vpc = null; try { if (_vpcService.startVpc(this.getEntityId())) { diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 9bc75b4124b..6601d712d23 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -346,3 +346,9 @@ createVPCOffering=com.cloud.api.commands.CreateVPCOfferingCmd;1 updateVPCOffering=com.cloud.api.commands.UpdateVPCOfferingCmd;1 deleteVPCOffering=com.cloud.api.commands.DeleteVPCOfferingCmd;1 listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15 + +#### VPC gateway commands +createVPCGateway=com.cloud.api.commands.CreateVPCGatewayCmd;15 +listVPCGateways=com.cloud.api.commands.ListVPCGatewaysCmd;15 +deleteVPCGateway=com.cloud.api.commands.DeleteVPCGatewayCmd;15 + diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 21e1d54e984..e53783e986a 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1330,7 +1330,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, - true, Network.GuestType.Isolated, false, null, true, null, false); + true, Network.GuestType.Isolated, false, null, false, null, false); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index b17cf63a8d8..1d57e28be38 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -385,7 +385,6 @@ public class VpcManagerImpl implements VpcManager, Manager{ offering.setDisplayText(displayText); } - if (state != null) { boolean validState = false; for (VpcOffering.State st : VpcOffering.State.values()) { @@ -704,19 +703,42 @@ public class VpcManagerImpl implements VpcManager, Manager{ DeployDestination dest = new DeployDestination(dc, null, null, null); ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId())); + + boolean result = true; + try { + if (!startVpc(vpc, dest, context)) { + s_logger.warn("Failed to start vpc " + vpc); + result = false; + } + } catch (Exception ex) { + s_logger.warn("Failed to start vpc " + vpc + " due to ", ex); + result = false; + } finally { + //do cleanup + if (!result) { + s_logger.debug("Destroying vpc " + vpc + " that failed to start"); + if (destroyVpc(vpc)) { + s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start"); + } else { + s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start"); + } + } + } + return result; + } + protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { //deploy provider if (getVpcElement().implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); return true; } else { s_logger.warn("Vpc " + vpc + " failed to start"); - //FIXME - add cleanup logic here return false; } } - @Override public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { UserContext ctx = UserContext.current(); @@ -778,14 +800,16 @@ public class VpcManagerImpl implements VpcManager, Manager{ //4) vpc and network should belong to the same owner if (vpc.getAccountId() != networkOwner.getId()) { - throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner); + throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + + networkOwner); } //5) Only Isolated networks with Source nat service enabled can be added to vpc if (!(guestNtwkOff.getGuestType() == GuestType.Isolated && _ntwkMgr.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("Only networks of type " + GuestType.Isolated + " with service " + Service.SourceNat + + throw new InvalidParameterValueException("Only networks of type " + GuestType.Isolated + " with service " + + Service.SourceNat + " can be added as a part of VPC"); } @@ -842,7 +866,6 @@ public class VpcManagerImpl implements VpcManager, Manager{ } return success; - } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 5bb1858f388..88379e3528b 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -998,7 +998,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, - null, Network.GuestType.Isolated, true, false); + null, Network.GuestType.Isolated, false, false); defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled); defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks); diff --git a/wscript b/wscript index c31c87049c9..4235e5d658e 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-25T22:13:38Z' +VERSION = '3.0.3.2012-05-29T17:33:07Z' APPNAME = 'cloud' import shutil,os From 6a097ad3b6cfb2d87447337a8fbe1795beef9dc1 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 29 May 2012 11:27:26 -0700 Subject: [PATCH 16/64] Support for IPAssoc inside VPC --- .../api/commands/AssociateIPAddrCmd.java | 3 +- .../commands/ListPublicIpAddressesCmd.java | 8 ++ .../cloud/api/response/IPAddressResponse.java | 16 ++- .../src/com/cloud/api/ApiResponseHelper.java | 47 ++++---- .../ExternalFirewallDeviceManagerImpl.java | 8 +- .../src/com/cloud/network/NetworkManager.java | 17 ++- .../com/cloud/network/NetworkManagerImpl.java | 111 +++++++++++------- .../cloud/network/dao/IPAddressDaoImpl.java | 1 + .../VirtualNetworkApplianceManagerImpl.java | 6 +- .../cloud/server/ManagementServerImpl.java | 6 + .../cloud/network/MockNetworkManagerImpl.java | 2 +- wscript | 2 +- 12 files changed, 141 insertions(+), 86 deletions(-) diff --git a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java index 1c4793d363d..7a072577d7f 100644 --- a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java @@ -106,7 +106,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { DataCenter zone = _configService.getZone(zoneId); if (zone.getNetworkType() == NetworkType.Advanced) { - List networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId())); + List networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), + _accountService.getAccount(getEntityOwnerId())); if (networks.size() == 0) { String domain = _domainService.getDomain(getDomainId()).getName(); throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName()); diff --git a/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java b/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java index d853d65f5fd..60add46ff46 100644 --- a/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java +++ b/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java @@ -74,6 +74,10 @@ public class ListPublicIpAddressesCmd extends BaseListProjectAndAccountResources @Parameter(name=ApiConstants.IS_STATIC_NAT, type=CommandType.BOOLEAN, description="list only static nat ip addresses") private Boolean isStaticNat; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List ips belonging to the VPC") + private Long vpcId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -118,6 +122,10 @@ public class ListPublicIpAddressesCmd extends BaseListProjectAndAccountResources return isStaticNat; } + public Long getVpcId() { + return vpcId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/response/IPAddressResponse.java b/api/src/com/cloud/api/response/IPAddressResponse.java index 9c803881c22..1113dd3a0b1 100644 --- a/api/src/com/cloud/api/response/IPAddressResponse.java +++ b/api/src/com/cloud/api/response/IPAddressResponse.java @@ -92,16 +92,10 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR @SerializedName(ApiConstants.PURPOSE) @Param(description="purpose of the IP address. In Acton this value is not null for Ips with isSystem=true, and can have either StaticNat or LB value") private String purpose; + + @SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the ip belongs to") + private IdentityProxy vpcId = new IdentityProxy("vpc"); -/* - @SerializedName(ApiConstants.JOB_ID) @Param(description="shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the volume") - private IdentityProxy jobId = new IdentityProxy("async_job"); -*/ - -/* - @SerializedName(ApiConstants.JOB_STATUS) @Param(description="shows the current pending asynchronous job status") - private Integer jobStatus; -*/ public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; @@ -212,4 +206,8 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR public void setPurpose(String purpose) { this.purpose = purpose; } + + public void setVpcId(Long vpcId) { + this.vpcId.setValue(vpcId); + } } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 68764ff895b..9ad212bb34f 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -730,30 +730,30 @@ public class ApiResponseHelper implements ResponseGenerator { } @Override - public IPAddressResponse createIPAddressResponse(IpAddress ipAddress) { - VlanVO vlan = ApiDBUtils.findVlanById(ipAddress.getVlanId()); + public IPAddressResponse createIPAddressResponse(IpAddress ipAddr) { + VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId()); boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork); - long zoneId = ipAddress.getDataCenterId(); + long zoneId = ipAddr.getDataCenterId(); IPAddressResponse ipResponse = new IPAddressResponse(); - ipResponse.setId(ipAddress.getId()); - ipResponse.setIpAddress(ipAddress.getAddress().toString()); - if (ipAddress.getAllocatedTime() != null) { - ipResponse.setAllocated(ipAddress.getAllocatedTime()); + ipResponse.setId(ipAddr.getId()); + ipResponse.setIpAddress(ipAddr.getAddress().toString()); + if (ipAddr.getAllocatedTime() != null) { + ipResponse.setAllocated(ipAddr.getAllocatedTime()); } ipResponse.setZoneId(zoneId); - ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName()); - ipResponse.setSourceNat(ipAddress.isSourceNat()); - ipResponse.setIsSystem(ipAddress.getSystem()); + ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddr.getDataCenterId()).getName()); + ipResponse.setSourceNat(ipAddr.isSourceNat()); + ipResponse.setIsSystem(ipAddr.getSystem()); // get account information - populateOwner(ipResponse, ipAddress); + populateOwner(ipResponse, ipAddr); ipResponse.setForVirtualNetwork(forVirtualNetworks); - ipResponse.setStaticNat(ipAddress.isOneToOneNat()); + ipResponse.setStaticNat(ipAddr.isOneToOneNat()); - if (ipAddress.getAssociatedWithVmId() != null) { - UserVm vm = ApiDBUtils.findUserVmById(ipAddress.getAssociatedWithVmId()); + if (ipAddr.getAssociatedWithVmId() != null) { + UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId()); ipResponse.setVirtualMachineId(vm.getId()); ipResponse.setVirtualMachineName(vm.getHostName()); if (vm.getDisplayName() != null) { @@ -763,11 +763,12 @@ public class ApiResponseHelper implements ResponseGenerator { } } - ipResponse.setAssociatedNetworkId(ipAddress.getAssociatedWithNetworkId()); + ipResponse.setAssociatedNetworkId(ipAddr.getAssociatedWithNetworkId()); + ipResponse.setVpcId(ipAddr.getVpcId()); // Network id the ip is associated withif associated networkId is null, try to get this information from vlan - Long associatedNetworkId = ipAddress.getAssociatedWithNetworkId(); - Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddress.getVlanId()); + Long associatedNetworkId = ipAddr.getAssociatedWithNetworkId(); + Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId()); if (associatedNetworkId == null) { associatedNetworkId = vlanNetworkId; } @@ -783,18 +784,18 @@ public class ApiResponseHelper implements ResponseGenerator { } ipResponse.setNetworkId(networkId); - ipResponse.setState(ipAddress.getState().toString()); - ipResponse.setPhysicalNetworkId(ipAddress.getPhysicalNetworkId()); + ipResponse.setState(ipAddr.getState().toString()); + ipResponse.setPhysicalNetworkId(ipAddr.getPhysicalNetworkId()); // show this info to admin only Account account = UserContext.current().getCaller(); if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) { - ipResponse.setVlanId(ipAddress.getVlanId()); - ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanTag()); + ipResponse.setVlanId(ipAddr.getVlanId()); + ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddr.getVlanId()).getVlanTag()); } - if (ipAddress.getSystem()) { - if (ipAddress.isOneToOneNat()) { + if (ipAddr.getSystem()) { + if (ipAddr.isOneToOneNat()) { ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString()); } else { ipResponse.setPurpose(IpAddress.Purpose.Lb.toString()); diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java index debf66aa75d..ad7372bbc35 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java @@ -379,11 +379,13 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl IPAddressVO sourceNatIp = null; if (!sharedSourceNat) { - // Get the source NAT IP address for this network - List sourceNatIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(network.getAccountId(), zoneId, true, null); + // Get the source NAT IP address for this account + List sourceNatIps = _networkMgr.listPublicIpsAssignedToAccount(network.getAccountId(), + zoneId, true); if (sourceNatIps.size() != 1) { - String errorMsg = "External firewall was unable to find the source NAT IP address for account " + account.getAccountName(); + String errorMsg = "External firewall was unable to find the source NAT IP address for account " + + account.getAccountName(); s_logger.error(errorMsg); return true; } else { diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 9c7b3878dca..cdfa9aaeca1 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -96,15 +96,13 @@ public interface NetworkManager extends NetworkService { * * @param accountId * - account that the IP address should belong to - * @param dcId - * - zone that the IP address should belong to - * @param sourceNat - * - (optional) true if the IP address should be a source NAT address * @param associatedNetworkId * TODO + * @param sourceNat + * - (optional) true if the IP address should be a source NAT address * @return - list of IP addresses */ - List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId); + List listPublicIpsAssignedToGuestNtwk(long accountId, long associatedNetworkId, Boolean sourceNat); List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException; @@ -391,4 +389,13 @@ public interface NetworkManager extends NetworkService { */ void removeNic(VirtualMachineProfile vm, Network network); + + /** + * @param accountId + * @param dcId + * @param sourceNat + * @return + */ + List listPublicIpsAssignedToAccount(long accountId, long dcId, Boolean sourceNat); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e53783e986a..d7486f0e33d 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -432,7 +432,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating); if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) { + Network guestNtwk = getNetwork(guestNetworkId); addr.setAssociatedWithNetworkId(guestNetworkId); + addr.setVpcId(guestNtwk.getVpcId()); addr.setVpcId(vpcId); } @@ -484,21 +486,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { long dcId = vpc.getZoneId(); - List addrs = listPublicIpsAssignedToVpc(owner.getId(), true, vpc.getId()); + IPAddressVO sourceNatIp = getExistingSourceNat(owner.getId(), null, vpc.getId()); PublicIp ipToReturn = null; - if (!addrs.isEmpty()) { - IPAddressVO sourceNatIp = null; - // Account already has ip addresses - for (IPAddressVO addr : addrs) { - if (addr.isSourceNat()) { - sourceNatIp = addr; - break; - } - } - - assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + - "account=" + owner.getId() + "; vpc=" + vpc; + + if (sourceNatIp != null) { ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); } else { @@ -509,25 +501,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { + public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) + throws InsufficientAddressCapacityException, ConcurrentOperationException { assert (guestNetwork.getTrafficType() != null) : "You're asking for a source nat but your network " + "can't participate in source nat. What do you have to say for yourself?"; long dcId = guestNetwork.getDataCenterId(); - List addrs = listPublicIpsAssignedToGuestNtwk(owner.getId(), dcId, null, guestNetwork.getId()); + IPAddressVO sourceNatIp = getExistingSourceNat(owner.getId(), guestNetwork.getId(), guestNetwork.getVpcId()); + PublicIp ipToReturn = null; - if (!addrs.isEmpty()) { - IPAddressVO sourceNatIp = null; - // Account already has ip addresses - for (IPAddressVO addr : addrs) { - if (addr.isSourceNat()) { - sourceNatIp = addr; - break; - } - } - - assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + - "account=" + owner.getId() + "; guestNetwork=" + guestNetwork; + if (sourceNatIp != null) { ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); } else { @@ -729,7 +712,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ipToServices.put(ip, services); // if IP in allocating state then it will not have any rules attached so skip IPAssoc to network service -// provider + // provider if (ip.getState() == State.Allocating) { continue; } @@ -1045,8 +1028,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // In Advance zone only allow to do IP assoc for Isolated networks with source nat service enabled - if (zone.getNetworkType() == NetworkType.Advanced && !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + if (zone.getNetworkType() == NetworkType.Advanced && + !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) { + throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + Service.SourceNat.getName() + " enabled"); } @@ -1096,11 +1081,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean sharedSourceNat = offering.getSharedSourceNat(); if (!sharedSourceNat) { - // First IP address should be source nat when it's being associated with Guest Virtual network - List addrs = listPublicIpsAssignedToGuestNtwk(ownerId, zone.getId(), true, networkId); - - if (addrs.isEmpty() && network.getGuestType() == Network.GuestType.Isolated) { - isSourceNat = true; + if (getExistingSourceNat(ownerId, network.getId(), network.getVpcId()) == null) { + if (network.getGuestType() == GuestType.Isolated) { + isSourceNat = true; + } } } @@ -1128,6 +1112,34 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return ip; } + protected IPAddressVO getExistingSourceNat(long ownerId, Long networkId, Long vpcId) { + + List addrs = null; + if (vpcId != null) { + addrs = listPublicIpsAssignedToVpc(ownerId, true, vpcId); + } else if (networkId != null) { + addrs = listPublicIpsAssignedToGuestNtwk(ownerId, networkId, true); + } + + IPAddressVO sourceNatIp = null; + if (addrs.isEmpty()) { + return null; + } else { + // Account already has ip addresses + for (IPAddressVO addr : addrs) { + if (addr.isSourceNat()) { + sourceNatIp = addr; + return sourceNatIp; + } + } + + assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + + "account=" + ownerId + "; networkId=" + networkId + "; vpcId=" + vpcId; + } + + return sourceNatIp; + } + @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) @@ -1481,13 +1493,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long associatedNetworkId, Boolean sourceNat) { + SearchCriteria sc = IpAddressSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("associatedWithNetworkId", associatedNetworkId); + + if (sourceNat != null) { + sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); + } + sc.setJoinParameters("virtualNetworkVlanSB", "vlanType", VlanType.VirtualNetwork); + + return _ipAddressDao.search(sc, null); + } + + @Override + public List listPublicIpsAssignedToAccount(long accountId, long dcId, Boolean sourceNat) { SearchCriteria sc = IpAddressSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("dataCenterId", dcId); - if (associatedNetworkId != null) { - sc.setParameters("associatedWithNetworkId", associatedNetworkId); - } if (sourceNat != null) { sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); @@ -2164,7 +2187,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } @@ -2196,6 +2220,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ipVO.getAllocatedToAccountId() != null) { _accountMgr.checkAccess(caller, null, true, ipVO); } + + //if ip address is a source nat ip in vpc, fail to disassociate + if (ipVO.getVpcId() != null && ipVO.isSourceNat()) { + throw new InvalidParameterValueException("IP address id=" + ipAddressId + " is a source nat for VPC id=" + + ipVO.getVpcId() + " and can't be released"); + } Network associatedNetwork = getNetwork(ipVO.getAssociatedWithNetworkId()); @@ -3981,6 +4011,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setSourceNat(false); } addr.setAssociatedWithNetworkId(guestNetwork.getId()); + addr.setVpcId(guestNetwork.getVpcId()); addr.setAllocatedTime(new Date()); addr.setAllocatedInDomainId(owner.getDomainId()); addr.setAllocatedToAccountId(owner.getId()); diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java index daa8c18b85b..b2979b05684 100755 --- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -141,6 +141,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen address.setAssociatedWithVmId(null); address.setState(State.Free); address.setAssociatedWithNetworkId(null); + address.setVpcId(null); address.setSystem(false); update(ipAddressId, address); } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 4490af64af6..edf29d19f9d 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1850,13 +1850,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (reprogramGuestNtwks) { s_logger.debug("Resending ipAssoc, port forwarding, load balancing rules as a part of Virtual router start"); long ownerId = router.getAccountId(); - long zoneId = router.getDataCenterIdToDeployIn(); - final List userIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(ownerId, zoneId, null, guestNetworkId); + final List userIps = _networkMgr.listPublicIpsAssignedToGuestNtwk(ownerId, guestNetworkId, null); List allPublicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); allPublicIps.add(publicIp); } } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 3d2a57571f2..775414c807c 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1644,6 +1644,7 @@ public class ManagementServerImpl implements ManagementServer { Long ipId = cmd.getId(); Boolean sourceNat = cmd.getIsSourceNat(); Boolean staticNat = cmd.getIsStaticNat(); + Long vpcId = cmd.getVpcId(); Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); @@ -1671,6 +1672,7 @@ public class ManagementServerImpl implements ManagementServer { sb.and("associatedNetworkIdEq", sb.entity().getAssociatedWithNetworkId(), SearchCriteria.Op.EQ); sb.and("isSourceNat", sb.entity().isSourceNat(), SearchCriteria.Op.EQ); sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ); + sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); if (forLoadBalancing != null && (Boolean) forLoadBalancing) { SearchBuilder lbSearch = _loadbalancerDao.createSearchBuilder(); @@ -1713,6 +1715,10 @@ public class ManagementServerImpl implements ManagementServer { sc.setParameters("dataCenterId", zone); } + if (vpcId != null) { + sc.setParameters("vpcId", vpcId); + } + if (ipId != null) { sc.setParameters("id", ipId); } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 1921c503d57..b0fccf0bbab 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -187,7 +187,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public List listPublicIpsAssignedToGuestNtwk(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) { + public List listPublicIpsAssignedToGuestNtwk(long accountId, long associatedNetworkId, Boolean sourceNat) { // TODO Auto-generated method stub return null; } diff --git a/wscript b/wscript index 4235e5d658e..edf3a13850c 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-29T17:33:07Z' +VERSION = '3.0.3.2012-05-29T18:21:13Z' APPNAME = 'cloud' import shutil,os From ddae550a556b8b74294a82757307fe17f6520b1b Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 30 May 2012 19:38:25 -0700 Subject: [PATCH 17/64] AssociateIpAddress to VPC - the ip gets associated to the network only when the first rule for the ip gets created. When the last rule is removed for vpc ip, networkId is set to null --- .../api/commands/AssociateIPAddrCmd.java | 69 +++- .../api/commands/CreateFirewallRuleCmd.java | 19 +- .../commands/CreateLoadBalancerRuleCmd.java | 7 +- .../commands/CreatePortForwardingRuleCmd.java | 47 ++- .../commands/CreateRemoteAccessVpnCmd.java | 23 +- .../api/commands/DisassociateIPAddrCmd.java | 7 +- .../api/commands/EnableStaticNatCmd.java | 31 +- api/src/com/cloud/network/NetworkService.java | 32 +- .../com/cloud/network/rules/RulesService.java | 2 +- .../network/vpn/RemoteAccessVpnService.java | 2 +- .../ConfigurationManagerImpl.java | 2 +- ...ExternalLoadBalancerDeviceManagerImpl.java | 4 +- .../src/com/cloud/network/NetworkManager.java | 25 +- .../com/cloud/network/NetworkManagerImpl.java | 302 ++++++++++++------ .../network/firewall/FirewallManagerImpl.java | 69 +++- .../lb/ElasticLoadBalancerManagerImpl.java | 2 +- .../lb/LoadBalancingRulesManagerImpl.java | 21 +- .../cloud/network/rules/FirewallManager.java | 4 +- .../cloud/network/rules/RulesManagerImpl.java | 107 ++++--- .../com/cloud/network/vpc/VpcManagerImpl.java | 2 +- .../vpn/RemoteAccessVpnManagerImpl.java | 21 +- .../com/cloud/user/AccountManagerImpl.java | 2 +- .../cloud/network/MockNetworkManagerImpl.java | 9 +- wscript | 2 +- 24 files changed, 577 insertions(+), 234 deletions(-) diff --git a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java index 7a072577d7f..15c596be8cd 100644 --- a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java @@ -37,6 +37,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; import com.cloud.network.Network; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -49,24 +50,34 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account to associate with this IP address") + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, + description="the account to associate with this IP address") private String accountName; @IdentityMapper(entityTableName="domain") - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain to associate with this IP address") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, + description="the ID of the domain to associate with this IP address") private Long domainId; @IdentityMapper(entityTableName="data_center") - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the ID of the availability zone you want to acquire an public IP address from") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, + description="the ID of the availability zone you want to acquire an public IP address from") private Long zoneId; @IdentityMapper(entityTableName="networks") - @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="The network this ip address should be associated to.") + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, + description="The network this ip address should be associated to.") private Long networkId; @IdentityMapper(entityTableName="projects") - @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="Deploy vm for the project") + @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, + description="Deploy vm for the project") private Long projectId; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC you want the ip address to " + + "be associated with") + private Long vpcId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -90,18 +101,40 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { return UserContext.current().getCaller().getDomainId(); } - private Long getZoneId() { - return zoneId; + private long getZoneId() { + if (zoneId != null) { + return zoneId; + } else if (vpcId != null) { + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); + if (vpc != null) { + return vpc.getZoneId(); + } + } else if (networkId != null) { + Network ntwk = _entityMgr.findById(Network.class, networkId); + if (ntwk != null) { + return ntwk.getDataCenterId(); + } + } + + throw new InvalidParameterValueException("Unable to figure out zone to assign ip to"); + } + + public Long getVpcId() { + return vpcId; } public Long getNetworkId() { + if (vpcId != null) { + return null; + } + if (networkId != null) { return networkId; } Long zoneId = getZoneId(); if (zoneId == null) { - throw new InvalidParameterValueException("Either networkId or zoneId has to be specified"); + return null; } DataCenter zone = _configService.getZone(zoneId); @@ -110,7 +143,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { _accountService.getAccount(getEntityOwnerId())); if (networks.size() == 0) { String domain = _domainService.getDomain(getDomainId()).getName(); - throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName()); + throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + + " doesn't have virtual networks in zone=" + zone.getName()); } if (networks.size() < 1) { @@ -123,7 +157,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { } else { Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId); if (defaultGuestNetwork == null) { - throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId()); + throw new InvalidParameterValueException("Unable to find a default Guest network for account " + + getAccountName() + " in domain id=" + getDomainId()); } else { return defaultGuestNetwork.getId(); } @@ -169,7 +204,8 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException{ try { - IpAddress ip = _networkService.allocateIP(getNetworkId(), _accountService.getAccount(getEntityOwnerId()), false); + IpAddress ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), false, getZoneId()); + if (ip != null) { this.setEntityId(ip.getId()); } else { @@ -186,9 +222,16 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { } @Override - public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { + public void execute() throws ResourceUnavailableException, ResourceAllocationException, + ConcurrentOperationException, InsufficientCapacityException { UserContext.current().setEventDetails("Ip Id: " + getEntityId()); - IpAddress result = _networkService.associateIP(getEntityId()); + + IpAddress result = null; + + if (getVpcId() != null) { + result = _networkService.associateIP(getEntityId(), getNetworkId(), getVpcId()); + } + if (result != null) { IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result); ipResponse.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java b/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java index 24093d6be48..14ba4f3ab28 100644 --- a/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java @@ -72,6 +72,11 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "type of firewallrule: system/user") private String type; + @IdentityMapper(entityTableName="networks") + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, + description="The network of the vm the Firewall rule will be created for") + private Long networkId; + // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// // /////////////////////////////////////////////////// @@ -187,7 +192,19 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal @Override public long getNetworkId() { - throw new UnsupportedOperationException("Not yet implemented"); + IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId()); + Long ntwkId = null; + + if (ip.getAssociatedWithNetworkId() != null) { + ntwkId = ip.getAssociatedWithNetworkId(); + } else { + ntwkId = networkId; + } + if (ntwkId == null) { + throw new InvalidParameterValueException("Unable to create firewall rule for the ipAddress id=" + ipAddressId + + " as ip is not associated with any network and no networkId is passed in"); + } + return ntwkId; } @Override diff --git a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java b/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java index 0c052d3422a..b4aed0b68c3 100644 --- a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java @@ -167,9 +167,12 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements } } else { IpAddress ipAddr = _networkService.getIp(publicIpId); - return ipAddr.getAssociatedWithNetworkId(); + if (ipAddr.getAssociatedWithNetworkId() != null) { + return ipAddr.getAssociatedWithNetworkId(); + } else { + throw new InvalidParameterValueException("Ip address id=" + publicIpId + " is not associated with any network"); + } } - } public Integer getPublicPort() { diff --git a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java index 8acd1e18764..8bf3af82c2f 100644 --- a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java @@ -47,27 +47,40 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P // /////////////////////////////////////////////////// @IdentityMapper(entityTableName = "user_ip_address") - @Parameter(name = ApiConstants.IP_ADDRESS_ID, type = CommandType.LONG, required = true, description = "the IP address id of the port forwarding rule") + @Parameter(name = ApiConstants.IP_ADDRESS_ID, type = CommandType.LONG, required = true, + description = "the IP address id of the port forwarding rule") private Long ipAddressId; - @Parameter(name = ApiConstants.PRIVATE_START_PORT, type = CommandType.INTEGER, required = true, description = "the starting port of port forwarding rule's private port range") + @Parameter(name = ApiConstants.PRIVATE_START_PORT, type = CommandType.INTEGER, required = true, + description = "the starting port of port forwarding rule's private port range") private Integer privateStartPort; - @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description = "the protocol for the port fowarding rule. Valid values are TCP or UDP.") + @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, + description = "the protocol for the port fowarding rule. Valid values are TCP or UDP.") private String protocol; - @Parameter(name = ApiConstants.PUBLIC_START_PORT, type = CommandType.INTEGER, required = true, description = "the starting port of port forwarding rule's public port range") + @Parameter(name = ApiConstants.PUBLIC_START_PORT, type = CommandType.INTEGER, required = true, + description = "the starting port of port forwarding rule's public port range") private Integer publicStartPort; @IdentityMapper(entityTableName = "vm_instance") - @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.LONG, required = true, description = "the ID of the virtual machine for the port forwarding rule") + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.LONG, required = true, + description = "the ID of the virtual machine for the port forwarding rule") private Long virtualMachineId; - @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from") + @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, + description = "the cidr list to forward traffic from") private List cidrlist; - @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default") + @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, + description = "if true, firewall rule for source/end pubic port is automatically created; " + + "if false - firewall rule has to be created explicitely. Has value true by default") private Boolean openFirewall; + + @IdentityMapper(entityTableName="networks") + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, + description="The network of the vm the Port Forwarding rule will be created for") + private Long networkId; // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// @@ -93,7 +106,8 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P public List getSourceCidrList() { if (cidrlist != null) { - throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command"); + throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall " + + "rule for the specific cidr, please refer to createFirewallRule command"); } return null; } @@ -189,7 +203,19 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P @Override public long getNetworkId() { - throw new UnsupportedOperationException("Not yet implemented"); + IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId()); + Long ntwkId = null; + + if (ip.getAssociatedWithNetworkId() != null) { + ntwkId = ip.getAssociatedWithNetworkId(); + } else { + ntwkId = networkId; + } + if (ntwkId == null) { + throw new InvalidParameterValueException("Unable to create port forwarding rule for the ipAddress id=" + ipAddressId + + " as ip is not associated with any network and no networkId is passed in"); + } + return ntwkId; } @Override @@ -201,7 +227,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are -// tracked + // tracked } @Override @@ -232,7 +258,6 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P @Override public void create() { - // cidr list parameter is deprecated if (cidrlist != null) { throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command"); diff --git a/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java b/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java index b6e13878f46..b783adf781a 100644 --- a/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java +++ b/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java @@ -58,6 +58,11 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default") private Boolean openFirewall; + @IdentityMapper(entityTableName="networks") + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, + description="The network of the ip the VPN be created for") + private Long networkId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -125,10 +130,26 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { return EventTypes.EVENT_REMOTE_ACCESS_VPN_CREATE; } + public long getNetworkId() { + IpAddress ip = _entityMgr.findById(IpAddress.class, getPublicIpId()); + Long ntwkId = null; + + if (ip.getAssociatedWithNetworkId() != null) { + ntwkId = ip.getAssociatedWithNetworkId(); + } else { + ntwkId = networkId; + } + if (ntwkId == null) { + throw new InvalidParameterValueException("Unable to create remote access vpn for the ipAddress id=" + getPublicIpId() + + " as ip is not associated with any network and no networkId is passed in"); + } + return ntwkId; + } + @Override public void create() { try { - RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall()); + RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall(), getNetworkId()); if (vpn != null) { this.setEntityId(vpn.getServerAddressId()); } else { diff --git a/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java b/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java index afdc7d7ff47..ea19ea319c6 100644 --- a/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java @@ -41,7 +41,8 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd { ///////////////////////////////////////////////////// @IdentityMapper(entityTableName="user_ip_address") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the id of the public ip address to disassociate") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the id of the public ip address" + + " to disassociate") private Long id; // unexposed parameter needed for events logging @@ -67,8 +68,8 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd { @Override public void execute() throws InsufficientAddressCapacityException{ - UserContext.current().setEventDetails("Ip Id: "+getIpAddressId()); - boolean result = _networkService.disassociateIpAddress(id); + UserContext.current().setEventDetails("Ip Id: " + getIpAddressId()); + boolean result = _networkService.releaseIpAddress(getIpAddressId()); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); diff --git a/api/src/com/cloud/api/commands/EnableStaticNatCmd.java b/api/src/com/cloud/api/commands/EnableStaticNatCmd.java index e62d963c097..b0106ad975c 100644 --- a/api/src/com/cloud/api/commands/EnableStaticNatCmd.java +++ b/api/src/com/cloud/api/commands/EnableStaticNatCmd.java @@ -21,8 +21,10 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.IpAddress; import com.cloud.user.Account; import com.cloud.uservm.UserVm; @@ -37,12 +39,19 @@ public class EnableStaticNatCmd extends BaseCmd{ ///////////////////////////////////////////////////// @IdentityMapper(entityTableName="user_ip_address") - @Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP address id for which static nat feature is being enabled") + @Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP " + + "address id for which static nat feature is being enabled") private Long ipAddressId; @IdentityMapper(entityTableName="vm_instance") - @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of the virtual machine for enabling static nat feature") + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of " + + "the virtual machine for enabling static nat feature") private Long virtualMachineId; + + @IdentityMapper(entityTableName="networks") + @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, + description="The network of the vm the static nat will be enabled for.") + private Long networkId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -55,6 +64,22 @@ public class EnableStaticNatCmd extends BaseCmd{ public Long getVirtualMachineId() { return virtualMachineId; } + + public long getNetworkId() { + IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId()); + Long ntwkId = null; + + if (ip.getAssociatedWithNetworkId() != null) { + ntwkId = ip.getAssociatedWithNetworkId(); + } else { + ntwkId = networkId; + } + if (ntwkId == null) { + throw new InvalidParameterValueException("Unable to enable static nat for the ipAddress id=" + ipAddressId + + " as ip is not associated with any network and no networkId is passed in"); + } + return ntwkId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// @@ -78,7 +103,7 @@ public class EnableStaticNatCmd extends BaseCmd{ @Override public void execute() throws ResourceUnavailableException{ try { - boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId); + boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId, getNetworkId()); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 200aebfea69..5eb57130869 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -37,22 +37,10 @@ public interface NetworkService { List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner); - IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, - InsufficientAddressCapacityException, ConcurrentOperationException; + IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, + InsufficientAddressCapacityException, ConcurrentOperationException; - /** - * Associates a public IP address for a router. - * - * @param ipId - * - the command specifying ipAddress - * @return ip address object - * @throws ResourceAllocationException - * , InsufficientCapacityException - */ - IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, - ConcurrentOperationException, ResourceUnavailableException; - - boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; + boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException; @@ -144,4 +132,18 @@ public interface NetworkService { List listNetworksByVpc(long vpcId); boolean isVmPartOfNetwork(long vmId, long ntwkId); + + /** + * @param entityId + * @param networkId + * @param vpcId + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws ResourceAllocationException + * @throws InsufficientAddressCapacityException + */ + IpAddress associateIP(long ipId, Long networkId, Long vpcId) throws InsufficientAddressCapacityException, + ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException; + } diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java index 137c10c35fc..60cc7b37fcf 100644 --- a/api/src/com/cloud/network/rules/RulesService.java +++ b/api/src/com/cloud/network/rules/RulesService.java @@ -60,7 +60,7 @@ public interface RulesService { boolean applyPortForwardingRules(long ipAdddressId, Account caller) throws ResourceUnavailableException; - boolean enableStaticNat(long ipAddressId, long vmId) throws NetworkRuleConflictException, ResourceUnavailableException; + boolean enableStaticNat(long ipAddressId, long vmId, long networkId) throws NetworkRuleConflictException, ResourceUnavailableException; PortForwardingRule getPortForwardigRule(long ruleId); diff --git a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java index 3a50d7466d1..ba9540480f8 100644 --- a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java +++ b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java @@ -23,7 +23,7 @@ import com.cloud.network.VpnUser; public interface RemoteAccessVpnService { - RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall) throws NetworkRuleConflictException; + RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, long networkId) throws NetworkRuleConflictException; void destroyRemoteAccessVpn(long vpnServerAddressId) throws ResourceUnavailableException; RemoteAccessVpn startRemoteAccessVpn(long vpnServerAddressId, boolean openFirewall) throws ResourceUnavailableException; diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 1e7d09017cd..16c8e514756 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2487,7 +2487,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura " as ip " + ip + " belonging to the range has firewall rules applied. Cleanup the rules first"); } //release public ip address here - success = success && _networkMgr.releasePublicIpAddress(ip.getId(), userId, caller); + success = success && _networkMgr.disassociatePublicIpAddress(ip.getId(), userId, caller); } if (!success) { s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + " removal"); diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java index 3ad8c339350..1acba8ba7b6 100644 --- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java @@ -512,7 +512,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase // release the public & private IP back to dc pool, as the load balancer // appliance is now destroyed _dcDao.releasePrivateIpAddress(lbIP, guestConfig.getDataCenterId(), null); - _networkMgr.releasePublicIpAddress(publicIp.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount()); + _networkMgr.disassociatePublicIpAddress(publicIp.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount()); } } catch (Exception e) { s_logger.warn("Failed to destroy load balancer appliance created for the network" + guestConfig.getId() + " due to " + e.getMessage()); @@ -664,7 +664,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase // release the public IP allocated for this LB appliance DetailVO publicIpDetail = _hostDetailDao.findDetail(lbHost.getId(), "publicip"); IPAddressVO ipVo = _ipAddressDao.findByIpAndDcId(guestConfig.getDataCenterId(), publicIpDetail.toString()); - _networkMgr.releasePublicIpAddress(ipVo.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount()); + _networkMgr.disassociatePublicIpAddress(ipVo.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount()); } else { deviceMapLock.unlock(); } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index cdfa9aaeca1..c6c877051ba 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -77,7 +77,8 @@ public interface NetworkManager extends NetworkService { * @throws InsufficientAddressCapacityException */ - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; + PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, + boolean isSystem) throws InsufficientAddressCapacityException; /** @@ -89,7 +90,7 @@ public interface NetworkManager extends NetworkService { * @param ipAddress * @return true if it did; false if it didn't */ - public boolean releasePublicIpAddress(long id, long userId, Account caller); + public boolean disassociatePublicIpAddress(long id, long userId, Account caller); /** * Lists IP addresses that belong to VirtualNetwork VLANs @@ -369,7 +370,8 @@ public interface NetworkManager extends NetworkService { * @throws InsufficientCapacityException * @throws ResourceUnavailableException */ - NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, + NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, + ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; @@ -380,7 +382,8 @@ public interface NetworkManager extends NetworkService { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException; + NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) + throws ConcurrentOperationException, ResourceUnavailableException; /** @@ -398,4 +401,18 @@ public interface NetworkManager extends NetworkService { */ List listPublicIpsAssignedToAccount(long accountId, long dcId, Boolean sourceNat); + + /** + * @param ipAddrId + * @param networkId + */ + IpAddress associateIPToGuestNetwork(long ipAddrId, long networkId) throws ResourceAllocationException, ResourceUnavailableException, + InsufficientAddressCapacityException, ConcurrentOperationException; + + + /** + * @param ipId + */ + void unassignIPFromVpcNetwork(long ipId); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index d7486f0e33d..13ba9721037 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -232,10 +232,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Inject UserVmDao _userVmDao = null; @Inject - ResourceLimitDao _limitDao = null; - @Inject - CapacityDao _capacityDao = null; - @Inject AlertManager _alertMgr; @Inject AccountManager _accountMgr; @@ -404,13 +400,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (addrs.size() == 0) { if (podId != null) { - InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId); + InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException + ("Insufficient address capacity", Pod.class, podId); // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object. ex.addProxyObject("Pod", podId, "podId"); throw ex; } s_logger.warn(errorMessage.toString()); - InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId); + InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException + ("Insufficient address capacity", DataCenter.class, dcId); ex.addProxyObject("data_center", dcId, "dcId"); throw ex; } @@ -432,9 +430,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setState(assign ? IpAddress.State.Allocated : IpAddress.State.Allocating); if (vlanUse != VlanType.DirectAttached || zone.getNetworkType() == NetworkType.Basic) { - Network guestNtwk = getNetwork(guestNetworkId); addr.setAssociatedWithNetworkId(guestNetworkId); - addr.setVpcId(guestNtwk.getVpcId()); addr.setVpcId(vpcId); } @@ -454,7 +450,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @DB protected void markPublicIpAsAllocated(IPAddressVO addr) { - assert (addr.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) : "Unable to transition from state " + addr.getState() + " to " + IpAddress.State.Allocated; + assert (addr.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) : + "Unable to transition from state " + addr.getState() + " to " + IpAddress.State.Allocated; Transaction txn = Transaction.currentTxn(); @@ -470,7 +467,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String guestType = vlan.getVlanType().toString(); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), + addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, + addr.getSystem()); _usageEventDao.persist(usageEvent); // don't increment resource count for direct ip addresses if (addr.getAssociatedWithNetworkId() != null) { @@ -627,7 +626,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List publicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); publicIps.add(publicIp); } } @@ -636,17 +636,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (success) { for (IPAddressVO addr : userIps) { - if (addr.getState() == IpAddress.State.Allocating) { - - addr.setAssociatedWithNetworkId(network.getId()); markPublicIpAsAllocated(addr); - } else if (addr.getState() == IpAddress.State.Releasing) { // Cleanup all the resources for ip address if there are any, and only then un-assign ip in the // system if (cleanupIpResources(addr.getId(), Account.ACCOUNT_ID_SYSTEM, _accountMgr.getSystemAccount())) { - _ipAddressDao.unassignIpAddress(addr.getId()); + s_logger.debug("Unassiging ip address " + addr); + _ipAddressDao.unassignIpAddress(addr.getId()); } else { success = false; s_logger.warn("Failed to release resources for ip address id=" + addr.getId()); @@ -906,7 +903,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return providerToIpList; } - protected boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, List publicIps) throws ResourceUnavailableException { + protected boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, + List publicIps) throws ResourceUnavailableException { boolean success = true; Map> ipToServices = getIpToServices(publicIps, rulesRevoked, false); @@ -1002,51 +1000,32 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { + public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) + throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); - long userId = UserContext.current().getCallerUserId(); - - long ownerId = ipOwner.getId(); - Network network = _networksDao.findById(networkId); - if (network == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Network id is invalid"); - ex.addProxyObject("networks", networkId, "networkId"); - throw ex; - } + long callerUserId = UserContext.current().getCallerUserId(); // check permissions _accountMgr.checkAccess(caller, null, false, ipOwner); - _accountMgr.checkAccess(ipOwner, AccessType.UseNetwork, false, network); - - DataCenter zone = _configMgr.getZone(network.getDataCenterId()); - - // allow associating IP addresses to guest network only - if (network.getTrafficType() != TrafficType.Guest) { - throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + TrafficType.Guest); - } - - // In Advance zone only allow to do IP assoc for Isolated networks with source nat service enabled - if (zone.getNetworkType() == NetworkType.Advanced && - !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + - " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " - + Service.SourceNat.getName() + " enabled"); - } - - // Check that network belongs to IP owner - skip this check for Basic zone as there is just one guest network, - // and it belongs to the system - if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != ipOwner.getId()) { - throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); - } + + DataCenter zone = _configMgr.getZone(zoneId); + + return allocateIp(ipOwner, isSystem, caller, callerUserId, zone); + } + @DB + public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerUserId, DataCenter zone) + throws ConcurrentOperationException, ResourceAllocationException, + InsufficientAddressCapacityException { + VlanType vlanType = VlanType.VirtualNetwork; boolean assign = false; if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { // zone is of type DataCenter. See DataCenterVO.java. - PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled"); + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, " + + "Zone is currently disabled"); ex.addProxyObject("data_center", zone.getId(), "zoneId"); throw ex; } @@ -1057,11 +1036,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Account accountToLock = null; try { if (s_logger.isDebugEnabled()) { - s_logger.debug("Associate IP address called for user " + userId + " account " + ownerId); + s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId()); } - accountToLock = _accountDao.acquireInLockTable(ownerId); + accountToLock = _accountDao.acquireInLockTable(ipOwner.getId()); if (accountToLock == null) { - s_logger.warn("Unable to lock account: " + ownerId); + s_logger.warn("Unable to lock account: " + ipOwner.getId()); throw new ConcurrentOperationException("Unable to acquire account lock"); } @@ -1073,42 +1052,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // accountId will not be exceeded _resourceLimitMgr.checkResourceLimit(accountToLock, ResourceType.public_ip); - boolean isSourceNat = false; - txn.start(); - NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); - boolean sharedSourceNat = offering.getSharedSourceNat(); - - if (!sharedSourceNat) { - if (getExistingSourceNat(ownerId, network.getId(), network.getVpcId()) == null) { - if (network.getGuestType() == GuestType.Isolated) { - isSourceNat = true; - } - } - } - - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), - isSourceNat, assign, null, isSystem, network.getVpcId()); + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, + false, assign, null, isSystem, null); if (ip == null) { - InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId()); + InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException + ("Unable to find available public IP addresses", DataCenter.class, zone.getId()); ex.addProxyObject("data_center", zone.getId(), "zoneId"); throw ex; } UserContext.current().setEventDetails("Ip Id: " + ip.getId()); Ip ipAddress = ip.getAddress(); - s_logger.debug("Got " + ipAddress + " to assign for account " + ipOwner.getId() + " in zone " + network.getDataCenterId()); + s_logger.debug("Got " + ipAddress + " to assign for account " + ipOwner.getId() + " in zone " + zone.getId()); txn.commit(); } finally { if (accountToLock != null) { - _accountDao.releaseFromLockTable(ownerId); + _accountDao.releaseFromLockTable(ipOwner.getId()); s_logger.debug("Associate IP address lock released"); } } - return ip; } @@ -1140,10 +1106,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return sourceNatIp; } - @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) - public IpAddress associateIP(long ipId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { + @Override + public IpAddress associateIPToGuestNetwork(long ipId, long networkId) throws ResourceAllocationException, ResourceUnavailableException, + InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); Account owner = null; @@ -1155,17 +1121,69 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.debug("Unable to find ip address by id: " + ipId); return null; } + + if (ipToAssoc.getAssociatedWithNetworkId() != null) { + s_logger.debug("IP " + ipToAssoc + " is already assocaited with network id" + networkId); + return ipToAssoc; + } + + Network network = _networksDao.findById(networkId); + if (network != null) { + _accountMgr.checkAccess(caller, AccessType.UseNetwork, false, network); + } else { + s_logger.debug("Unable to find ip address by id: " + ipId); + return null; + } + + DataCenter zone = _configMgr.getZone(network.getDataCenterId()); - Network network = _networksDao.findById(ipToAssoc.getAssociatedWithNetworkId()); + // allow associating IP addresses to guest network only + if (network.getTrafficType() != TrafficType.Guest) { + throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + + TrafficType.Guest); + } + // Check that network belongs to IP owner - skip this check for Basic zone as there is just one guest network, + // and it belongs to the system + if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != owner.getId()) { + throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); + } + + // In Advance zone only allow to do IP assoc for Isolated networks with source nat service enabled + if (zone.getNetworkType() == NetworkType.Advanced && + !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), + Service.SourceNat))) { + throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + + Service.SourceNat.getName() + " enabled"); + } + + NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); + boolean sharedSourceNat = offering.getSharedSourceNat(); + boolean isSourceNat = false; + if (!sharedSourceNat) { + if (getExistingSourceNat(owner.getId(), networkId, null) == null) { + if (network.getGuestType() == GuestType.Isolated) { + isSourceNat = true; + } + } + } + + s_logger.debug("Associating ip " + ipToAssoc + " to network " + network); + IPAddressVO ip = _ipAddressDao.findById(ipId); + //update ip address with networkId + ip.setAssociatedWithNetworkId(networkId); + ip.setSourceNat(isSourceNat); + _ipAddressDao.update(ipId, ip); + boolean success = false; try { success = applyIpAssociations(network, false); if (success) { - s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " for account " + owner.getId() + " in zone " + network.getDataCenterId()); + s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network); } else { - s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " for account " + owner.getId() + " in zone " + network.getDataCenterId()); + s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network); } return ip; } catch (ResourceUnavailableException e) { @@ -1189,10 +1207,56 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } + + + @DB + protected IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, + InsufficientAddressCapacityException, ConcurrentOperationException { + Account caller = UserContext.current().getCaller(); + Account owner = null; + + IpAddress ipToAssoc = getIp(ipId); + if (ipToAssoc != null) { + _accountMgr.checkAccess(caller, null, true, ipToAssoc); + owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId()); + } else { + s_logger.debug("Unable to find ip address by id: " + ipId); + return null; + } + + Vpc vpc = _vpcMgr.getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Invalid VPC id " + vpcId); + } + + // check permissions + _accountMgr.checkAccess(caller, null, true, owner, vpc); + + boolean isSourceNat = false; + if (getExistingSourceNat(owner.getId(), null, vpcId) == null) { + isSourceNat = true; + } + + s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc); + + Transaction txn = Transaction.currentTxn(); + txn.start(); + IPAddressVO ip = _ipAddressDao.findById(ipId); + //update ip address with networkId + ip.setVpcId(vpcId); + ip.setSourceNat(isSourceNat); + _ipAddressDao.update(ipId, ip); + txn.commit(); + + s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc); + + return _ipAddressDao.findById(ipId); + } + @Override @DB - public boolean releasePublicIpAddress(long addrId, long userId, Account caller) { + public boolean disassociatePublicIpAddress(long addrId, long userId, Account caller) { boolean success = true; // Cleanup all ip address resources - PF/LB/Static nat rules @@ -2199,7 +2263,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_RELEASE, eventDescription = "disassociating Ip", async = true) - public boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException { + public boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException { Long userId = UserContext.current().getCallerUserId(); Account caller = UserContext.current().getCaller(); @@ -2220,16 +2284,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ipVO.getAllocatedToAccountId() != null) { _accountMgr.checkAccess(caller, null, true, ipVO); } - - //if ip address is a source nat ip in vpc, fail to disassociate - if (ipVO.getVpcId() != null && ipVO.isSourceNat()) { - throw new InvalidParameterValueException("IP address id=" + ipAddressId + " is a source nat for VPC id=" + - ipVO.getVpcId() + " and can't be released"); - } - Network associatedNetwork = getNetwork(ipVO.getAssociatedWithNetworkId()); - - if (ipVO.isSourceNat() && areServicesSupportedInNetwork(associatedNetwork.getId(), Service.SourceNat)) { + if (ipVO.isSourceNat()) { throw new IllegalArgumentException("ip address is used for source nat purposes and can not be disassociated."); } @@ -2241,7 +2297,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Check for account wide pool. It will have an entry for account_vlan_map. if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) { //see IPaddressVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to Account wide IP pool and cannot be disassociated"); + InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to" + + " Account wide IP pool and cannot be disassociated"); ex.addProxyObject("user_ip_address", ipAddressId, "ipAddressId"); throw ex; } @@ -2251,9 +2308,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new InvalidParameterValueException("Can't release system IP address " + ipVO); } - boolean success = releasePublicIpAddress(ipAddressId, userId, caller); - if (success) { - Network guestNetwork = getNetwork(ipVO.getAssociatedWithNetworkId()); + boolean success = disassociatePublicIpAddress(ipAddressId, userId, caller); + + Long networkId = ipVO.getAssociatedWithNetworkId(); + if (success && networkId != null) { + Network guestNetwork = getNetwork(networkId); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); Long vmId = ipVO.getAssociatedWithVmId(); if (offering.getElasticIp() && vmId != null) { @@ -4255,7 +4314,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String guestType = vlan.getVlanType().toString(); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getSystem()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, + ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), + ip.isSourceNat(), guestType, ip.getSystem()); _usageEventDao.persist(usageEvent); } @@ -4665,8 +4726,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // static NAT rules can not programmed unless IP is associated with network service provider, so run IP -// association for - // the network so as to ensure IP is associated before applying rules (in add state) + // association for the network so as to ensure IP is associated before applying rules (in add state) applyIpAssociations(network, false, continueOnError, publicIps); // get provider @@ -5697,8 +5757,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // release all ip addresses List ipsToRelease = _ipAddressDao.listByAssociatedNetwork(networkId, null); for (IPAddressVO ipToRelease : ipsToRelease) { - IPAddressVO ip = markIpAsUnavailable(ipToRelease.getId()); - assert (ip != null) : "Unable to mark the ip address id=" + ipToRelease.getId() + " as unavailable."; + if (ipToRelease.getVpcId() != null) { + IPAddressVO ip = markIpAsUnavailable(ipToRelease.getId()); + assert (ip != null) : "Unable to mark the ip address id=" + ipToRelease.getId() + " as unavailable."; + } } try { @@ -6354,7 +6416,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { - PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.SecurityGroupProvider.getName(), null, null); + PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, + Network.Provider.SecurityGroupProvider.getName(), null, null); return nsp; } @@ -6628,7 +6691,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException { + public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) + throws InsufficientAddressCapacityException { Network guestNetwork = getNetwork(networkId); NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); IpAddress ip = null; @@ -6637,9 +6701,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag try { s_logger.debug("Allocating system IP address for load balancer rule..."); // allocate ip - ip = allocateIP(networkId, owner, true); + ip = allocateIP(owner, true, guestNetwork.getDataCenterId()); // apply ip associations - ip = associateIP(ip.getId()); + ip = associateIP(ip.getId(), networkId, null); } catch (ResourceAllocationException ex) { throw new CloudRuntimeException("Failed to allocate system ip due to ", ex); } catch (ConcurrentOperationException ex) { @@ -6663,7 +6727,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networkId != null) { if (ip.getSystem()) { UserContext ctx = UserContext.current(); - if (!releasePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) { + if (!disassociatePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) { s_logger.warn("Unable to release system ip address id=" + ip.getId()); success = false; } else { @@ -6793,5 +6857,35 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return false; } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) + public IpAddress associateIP(long ipId, Long networkId, Long vpcId) throws InsufficientAddressCapacityException, + ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException { + if (vpcId != null) { + return associateIPToVpc(ipId, vpcId); + } + + if (networkId != null) { + return associateIPToGuestNetwork(ipId, networkId); + } + + return null; + } + + @Override + public void unassignIPFromVpcNetwork(long ipId) { + IPAddressVO ip = _ipAddressDao.findById(ipId); + Long vpcId = ip.getVpcId(); + + if (vpcId == null) { + return; + } + + ip.setAssociatedWithNetworkId(null); + _ipAddressDao.update(ipId, ip); + s_logger.debug("IP address " + ip + " is no longer associated with the network inside vpc id=" + vpcId); + } + } diff --git a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java index aef6d7ca77e..506b615bd9d 100644 --- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java +++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java @@ -33,6 +33,7 @@ import com.cloud.event.EventTypes; import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; import com.cloud.event.dao.UsageEventDao; +import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; @@ -131,21 +132,38 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma public FirewallRule createFirewallRule(FirewallRule rule) throws NetworkRuleConflictException { Account caller = UserContext.current().getCaller(); - return createFirewallRule(rule.getSourceIpAddressId(), caller, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(), - rule.getIcmpType(), null, rule.getType()); + return createFirewallRule(rule.getSourceIpAddressId(), caller, rule.getXid(), rule.getSourcePortStart(), + rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(), + rule.getIcmpType(), null, rule.getType(), rule.getNetworkId()); } @DB @Override @ActionEvent(eventType = EventTypes.EVENT_FIREWALL_OPEN, eventDescription = "creating firewall rule", create = true) - public FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, Integer portEnd, String protocol, List sourceCidrList, Integer icmpCode, Integer icmpType, - Long relatedRuleId, FirewallRule.FirewallRuleType type) throws NetworkRuleConflictException { + public FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, + Integer portEnd, String protocol, List sourceCidrList, Integer icmpCode, Integer icmpType, + Long relatedRuleId, FirewallRule.FirewallRuleType type, long networkId) throws NetworkRuleConflictException { + IPAddressVO ipAddress = _ipAddressDao.findById(ipAddrId); - // Validate ip address if (ipAddress == null && type == FirewallRule.FirewallRuleType.User) { - throw new InvalidParameterValueException("Unable to create port forwarding rule; ip id=" + ipAddrId + " doesn't exist in the system"); + throw new InvalidParameterValueException("Unable to create port forwarding rule; ip id=" + ipAddrId + + " doesn't exist in the system"); } + + //associate ip address to network (if needed) + if (ipAddress.getAssociatedWithNetworkId() == null) { + s_logger.debug("The ip is not associated with the network id="+ networkId + " so assigning"); + try { + _networkMgr.associateIPToGuestNetwork(ipAddrId, networkId); + } catch (Exception ex) { + s_logger.warn("Failed to associate ip id=" + ipAddrId + " to network id=" + networkId + " as " + + "a part of firewall rule creation"); + return null; + } + } + + _networkMgr.checkIpForService(ipAddress, Service.Firewall); validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type); @@ -158,17 +176,14 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP"); } - Long networkId = null; Long accountId = null; Long domainId = null; if (ipAddress != null) { - networkId = ipAddress.getAssociatedWithNetworkId(); accountId = ipAddress.getAllocatedToAccountId(); domainId = ipAddress.getAllocatedInDomainId(); } - _networkMgr.checkIpForService(ipAddress, Service.Firewall); Transaction txn = Transaction.currentTxn(); txn.start(); @@ -369,7 +384,8 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma } @Override - public boolean applyRules(List rules, boolean continueOnError, boolean updateRulesInDB) throws ResourceUnavailableException { + public boolean applyRules(List rules, boolean continueOnError, boolean updateRulesInDB) + throws ResourceUnavailableException { boolean success = true; if (!_networkMgr.applyRules(rules, continueOnError)) { s_logger.warn("Rules are not completely applied"); @@ -380,10 +396,11 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma if (rule.getState() == FirewallRule.State.Revoke) { FirewallRuleVO relatedRule = _firewallDao.findByRelatedId(rule.getId()); if (relatedRule != null) { - s_logger.warn("Can't remove the firewall rule id=" + rule.getId() + " as it has related firewall rule id=" + relatedRule.getId() + "; leaving it in Revoke state"); + s_logger.warn("Can't remove the firewall rule id=" + rule.getId() + + " as it has related firewall rule id=" + relatedRule.getId() + "; leaving it in Revoke state"); success = false; } else { - _firewallDao.remove(rule.getId()); + removeRule(rule); } } else if (rule.getState() == FirewallRule.State.Add) { FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId()); @@ -397,6 +414,23 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma return success; } + @DB + protected void removeRule(FirewallRule rule) { + //Lock ip address + IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId()); + + Transaction txn = Transaction.currentTxn(); + txn.start(); + //remove the rule + _firewallDao.remove(rule.getId()); + if (ip.getVpcId() != null && _firewallDao.listByIp(ip.getId()).isEmpty()) { + //if the rule is the last one for the ip address assigned to VPC, unassign it from the network + _networkMgr.unassignIPFromVpcNetwork(ip.getId()); + } + + txn.commit(); + } + @Override public boolean applyFirewallRules(long ipId, Account caller) throws ResourceUnavailableException { List rules = _firewallDao.listByIpAndPurpose(ipId, Purpose.Firewall); @@ -535,18 +569,21 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma } @Override - public FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId) + public FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, + Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId, long networkId) throws NetworkRuleConflictException { // If firwallRule for this port range already exists, return it - List rules = _firewallDao.listByIpPurposeAndProtocolAndNotRevoked(ipAddrId, startPort, endPort, protocol, Purpose.Firewall); + List rules = _firewallDao.listByIpPurposeAndProtocolAndNotRevoked(ipAddrId, startPort, endPort, + protocol, Purpose.Firewall); if (!rules.isEmpty()) { return rules.get(0); } List oneCidr = new ArrayList(); oneCidr.add(NetUtils.ALL_CIDRS); - return createFirewallRule(ipAddrId, caller, null, startPort, endPort, protocol, oneCidr, icmpCode, icmpType, relatedRuleId, FirewallRule.FirewallRuleType.User); + return createFirewallRule(ipAddrId, caller, null, startPort, endPort, protocol, oneCidr, icmpCode, icmpType, + relatedRuleId, FirewallRule.FirewallRuleType.User, networkId); } @Override @@ -654,7 +691,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma for (FirewallRuleVO rule : systemRules) { try { this.createFirewallRule(ip.getId(), acct, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), - rule.getSourceCidrList(), rule.getIcmpCode(), rule.getIcmpType(), rule.getRelated(), FirewallRuleType.System); + rule.getSourceCidrList(), rule.getIcmpCode(), rule.getIcmpType(), rule.getRelated(), FirewallRuleType.System, rule.getNetworkId()); } catch (Exception e) { s_logger.debug("Failed to add system wide firewall rule, due to:" + e.toString()); } diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 8c15d807b44..d479f76e012 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -611,7 +611,7 @@ public class ElasticLoadBalancerManagerImpl implements IPAddressVO ipvo = _ipAddressDao.findById(ipId); ipvo.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipvo.getId(), ipvo); - _networkMgr.releasePublicIpAddress(ipId, userId, caller); + _networkMgr.disassociatePublicIpAddress(ipId, userId, caller); _ipAddressDao.unassignIpAddress(ipId); } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index f3f72884fc1..e4ddfffda0b 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -702,7 +702,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa // Validate ip address if (ipAddressVo == null) { - throw new InvalidParameterValueException("Unable to create load balance rule; ip id=" + ipAddrId + " doesn't exist in the system"); + throw new InvalidParameterValueException("Unable to create load balance rule; ip id=" + ipAddrId + "" + + " doesn't exist in the system"); } else if (ipAddressVo.isOneToOneNat()) { throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipAddressVo.getAddress()); } @@ -719,7 +720,14 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa ip = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false); lb.setSourceIpAddressId(ip.getId()); } + + + try { + if (ip.getAssociatedWithNetworkId() == null) { + s_logger.debug("The ip is not associated with the network id="+ lb.getNetworkId() + " so assigning"); + _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId()); + } result = createLoadBalancer(lb, openFirewall); } catch (Exception ex) { s_logger.warn("Failed to create load balancer due to ", ex); @@ -755,10 +763,12 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa if (ipAddr == null || !ipAddr.readyToUse()) { throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id" + sourceIpId); } else if (ipAddr.isOneToOneNat()) { - throw new InvalidParameterValueException("Unable to create load balancer rule; ip id=" + sourceIpId + " has static nat enabled"); + throw new InvalidParameterValueException("Unable to create load balancer rule; ip id=" + sourceIpId + + " has static nat enabled"); } - _firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPortStart, srcPortEnd, lb.getProtocol(), Purpose.LoadBalancing, FirewallRuleType.User); + _firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPortStart, srcPortEnd, lb.getProtocol(), + Purpose.LoadBalancing, FirewallRuleType.User); networkId = ipAddr.getAssociatedWithNetworkId(); if (networkId == null) { @@ -784,7 +794,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa newRule = _lbDao.persist(newRule); if (openFirewall) { - _firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCaller(), lb.getSourcePortStart(), lb.getSourcePortEnd(), lb.getProtocol(), null, null, newRule.getId()); + _firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCaller(), lb.getSourcePortStart(), + lb.getSourcePortEnd(), lb.getProtocol(), null, null, newRule.getId(), networkId); } boolean success = true; @@ -931,7 +942,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa boolean success = true; if (ip.getSystem()) { s_logger.debug("Releasing system ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule"); - if (!_networkMgr.releasePublicIpAddress(lb.getSourceIpAddressId(), UserContext.current().getCallerUserId(), UserContext.current().getCaller())) { + if (!_networkMgr.disassociatePublicIpAddress(lb.getSourceIpAddressId(), UserContext.current().getCallerUserId(), UserContext.current().getCaller())) { s_logger.warn("Unable to release system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); success = false; } else { diff --git a/server/src/com/cloud/network/rules/FirewallManager.java b/server/src/com/cloud/network/rules/FirewallManager.java index 2de4d062087..58e8750500b 100644 --- a/server/src/com/cloud/network/rules/FirewallManager.java +++ b/server/src/com/cloud/network/rules/FirewallManager.java @@ -67,10 +67,10 @@ public interface FirewallManager extends FirewallService { boolean revokeFirewallRule(long ruleId, boolean apply, Account caller, long userId); FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, Integer portEnd, String protocol, List sourceCidrList, Integer icmpCode, Integer icmpType, Long relatedRuleId, - FirewallRule.FirewallRuleType type) + FirewallRule.FirewallRuleType type, long networkId) throws NetworkRuleConflictException; - FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId) throws NetworkRuleConflictException; + FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId, long networkId) throws NetworkRuleConflictException; boolean revokeAllFirewallRulesForNetwork(long networkId, long userId, Account caller) throws ResourceUnavailableException; diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 05f1d3c4af5..d3207cb91fe 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -153,7 +153,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating forwarding rule", create = true) - public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, boolean openFirewall) throws NetworkRuleConflictException { + public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, boolean openFirewall) + throws NetworkRuleConflictException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); @@ -167,10 +168,25 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } else if (ipAddress.isOneToOneNat()) { throw new InvalidParameterValueException("Unable to create port forwarding rule; ip id=" + ipAddrId + " has static nat enabled"); } + + Long networkId = rule.getNetworkId(); + //associate ip address to network (if needed) + if (ipAddress.getAssociatedWithNetworkId() == null) { + s_logger.debug("The ip is not associated with the network id="+ networkId + " so assigning"); + try { + _networkMgr.associateIPToGuestNetwork(ipAddrId, networkId); + } catch (Exception ex) { + s_logger.warn("Failed to associate ip id=" + ipAddrId + " to network id=" + networkId + " as " + + "a part of port forwarding rule creation"); + return null; + } + } + + _networkMgr.checkIpForService(ipAddress, Service.PortForwarding); - _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), Purpose.PortForwarding, FirewallRuleType.User); - - Long networkId = ipAddress.getAssociatedWithNetworkId(); + _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(), + rule.getProtocol(), Purpose.PortForwarding, FirewallRuleType.User); + Long accountId = ipAddress.getAllocatedToAccountId(); Long domainId = ipAddress.getAllocatedInDomainId(); @@ -187,12 +203,12 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { // validate user VM exists UserVm vm = _vmDao.findById(vmId); if (vm == null) { - throw new InvalidParameterValueException("Unable to create port forwarding rule on address " + ipAddress + ", invalid virtual machine id specified (" + vmId + ")."); + throw new InvalidParameterValueException("Unable to create port forwarding rule on address " + ipAddress + + ", invalid virtual machine id specified (" + vmId + ")."); } else { checkRuleAndUserVm(rule, vm, caller); } - _networkMgr.checkIpForService(ipAddress, Service.PortForwarding); // Verify that vm has nic in the network Ip dstIp = rule.getDestinationIpAddress(); @@ -206,13 +222,15 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { Transaction txn = Transaction.currentTxn(); txn.start(); - PortForwardingRuleVO newRule = new PortForwardingRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), dstIp, rule.getDestinationPortStart(), + PortForwardingRuleVO newRule = new PortForwardingRuleVO(rule.getXid(), rule.getSourceIpAddressId(), + rule.getSourcePortStart(), rule.getSourcePortEnd(), dstIp, rule.getDestinationPortStart(), rule.getDestinationPortEnd(), rule.getProtocol().toLowerCase(), networkId, accountId, domainId, vmId); newRule = _portForwardingDao.persist(newRule); // create firewallRule for 0.0.0.0/0 cidr if (openFirewall) { - _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null, newRule.getId()); + _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), + rule.getProtocol(), null, null, newRule.getId(), networkId); } try { @@ -221,19 +239,17 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { throw new CloudRuntimeException("Unable to update the state to add for " + newRule); } UserContext.current().setEventDetails("Rule Id: " + newRule.getId()); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), ipAddress.getDataCenterId(), newRule.getId(), null); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), + ipAddress.getDataCenterId(), newRule.getId(), null); _usageEventDao.persist(usageEvent); txn.commit(); return newRule; } catch (Exception e) { - if (newRule != null) { - txn.start(); // no need to apply the rule as it wasn't programmed on the backend yet _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); _portForwardingDao.remove(newRule.getId()); - txn.commit(); } @@ -287,7 +303,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { // create firewallRule for 0.0.0.0/0 cidr if (openFirewall) { - _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null, newRule.getId()); + _firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null, newRule.getId(), networkId); } try { @@ -321,30 +337,41 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public boolean enableStaticNat(long ipId, long vmId) throws NetworkRuleConflictException, ResourceUnavailableException { + public boolean enableStaticNat(long ipId, long vmId, long networkId) throws NetworkRuleConflictException, ResourceUnavailableException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); // Verify input parameters UserVmVO vm = _vmDao.findById(vmId); if (vm == null) { - throw new InvalidParameterValueException("Can't enable static nat for the address id=" + ipId + ", invalid virtual machine id specified (" + vmId + ")."); + throw new InvalidParameterValueException("Can't enable static nat for the address id=" + ipId + + ", invalid virtual machine id specified (" + vmId + ")."); } IPAddressVO ipAddress = _ipAddressDao.findById(ipId); if (ipAddress == null) { throw new InvalidParameterValueException("Unable to find ip address by id " + ipId); } + + boolean setNetworkId = false; + //associate ip address to network (if needed) + if (ipAddress.getAssociatedWithNetworkId() == null) { + s_logger.debug("The ip is not associated with the network id="+ networkId + " so assigning"); + try { + _networkMgr.associateIPToGuestNetwork(ipId, networkId); + } catch (Exception ex) { + s_logger.warn("Failed to associate ip id=" + ipId + " to network id=" + networkId + " as " + + "a part of enable static nat"); + return false; + } + setNetworkId = true; + } + + _networkMgr.checkIpForService(ipAddress, Service.StaticNat); // Check permissions checkIpAndUserVm(ipAddress, vm, caller); - // Verify that the ip is associated with the network and static nat service is supported for the network - Long networkId = ipAddress.getAssociatedWithNetworkId(); - if (networkId == null) { - throw new InvalidParameterValueException("Unable to enable static nat for the ipAddress id=" + ipId + " as ip is not associated with any network"); - } - // Check that vm has a nic in the network Nic guestNic = _networkMgr.getNicInNetwork(vmId, networkId); if (guestNic == null) { @@ -353,14 +380,12 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { Network network = _networkMgr.getNetwork(networkId); if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) { - throw new InvalidParameterValueException("Unable to create static nat rule; StaticNat service is not supported in network id=" + networkId); + throw new InvalidParameterValueException("Unable to create static nat rule; StaticNat service is not " + + "supported in network id=" + networkId); } // Verify ip address parameter isIpReadyForStaticNat(vmId, ipAddress, caller, ctx.getCallerUserId()); - - _networkMgr.checkIpForService(ipAddress, Service.StaticNat); - ipAddress.setOneToOneNat(true); ipAddress.setAssociatedWithVmId(vmId); @@ -372,6 +397,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } else { ipAddress.setOneToOneNat(false); ipAddress.setAssociatedWithVmId(null); + if (setNetworkId) { + ipAddress.setAssociatedWithNetworkId(null); + } _ipAddressDao.update(ipAddress.getId(), ipAddress); s_logger.warn("Failed to enable static nat rule for ip address " + ipId + " on the backend"); return false; @@ -382,7 +410,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } } - protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress, Account caller, long callerUserId) throws NetworkRuleConflictException, ResourceUnavailableException { + protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress, Account caller, long callerUserId) + throws NetworkRuleConflictException, ResourceUnavailableException { if (ipAddress.isSourceNat()) { throw new InvalidParameterValueException("Can't enable static, ip address " + ipAddress + " is a sourceNat ip address"); } @@ -955,7 +984,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { @Override @DB - public FirewallRuleVO[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose purpose, boolean openFirewall, Account caller, int... ports) throws NetworkRuleConflictException { + public FirewallRuleVO[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose purpose, + boolean openFirewall, Account caller, int... ports) throws NetworkRuleConflictException { FirewallRuleVO[] rules = new FirewallRuleVO[ports.length]; Transaction txn = Transaction.currentTxn(); @@ -966,7 +996,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { rules[i] = _firewallDao.persist(rules[i]); if (openFirewall) { - _firewallMgr.createRuleForAllCidrs(ip.getId(), caller, ports[i], ports[i], protocol, null, null, rules[i].getId()); + _firewallMgr.createRuleForAllCidrs(ip.getId(), caller, ports[i], ports[i], protocol, null, null, + rules[i].getId(), ip.getAssociatedWithNetworkId()); } } txn.commit(); @@ -1033,8 +1064,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } // if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to -// re-enable it on the new one - // enable static nat takes care of that + // re-enable it on the new one enable static nat takes care of that Network guestNetwork = _networkMgr.getNetwork(ipAddress.getAssociatedWithNetworkId()); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); if (offering.getElasticIp()) { @@ -1075,14 +1105,17 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } if (success) { + Transaction txn = Transaction.currentTxn(); + txn.start(); boolean isIpSystem = ipAddress.getSystem(); - ipAddress.setOneToOneNat(false); ipAddress.setAssociatedWithVmId(null); if (isIpSystem && !releaseIpIfElastic) { ipAddress.setSystem(false); } _ipAddressDao.update(ipAddress.getId(), ipAddress); + _networkMgr.unassignIPFromVpcNetwork(ipAddress.getId()); + txn.commit(); if (isIpSystem && releaseIpIfElastic && !_networkMgr.handleSystemIpRelease(ipAddress)) { s_logger.warn("Failed to release system ip address " + ipAddress); @@ -1161,7 +1194,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { dstIp = _networkMgr.getIpInNetwork(sourceIp.getAssociatedWithVmId(), networkId); } - StaticNatImpl staticNat = new StaticNatImpl(sourceIp.getAllocatedToAccountId(), sourceIp.getAllocatedInDomainId(), networkId, sourceIpId, dstIp, forRevoke); + StaticNatImpl staticNat = new StaticNatImpl(sourceIp.getAllocatedToAccountId(), sourceIp.getAllocatedInDomainId(), + networkId, sourceIpId, dstIp, forRevoke); staticNats.add(staticNat); try { @@ -1202,12 +1236,14 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { s_logger.debug("Allocated system ip " + ip + ", now enabling static nat on it for vm " + vm); try { - success = enableStaticNat(ip.getId(), vm.getId()); + success = enableStaticNat(ip.getId(), vm.getId(), guestNetwork.getId()); } catch (NetworkRuleConflictException ex) { - s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + vm + " in guest network " + guestNetwork + " due to exception ", ex); + s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + + vm + " in guest network " + guestNetwork + " due to exception ", ex); success = false; } catch (ResourceUnavailableException ex) { - s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + vm + " in guest network " + guestNetwork + " due to exception ", ex); + s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + + vm + " in guest network " + guestNetwork + " due to exception ", ex); success = false; } @@ -1221,5 +1257,4 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } } } - } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 1d57e28be38..c2b85dc3488 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -859,7 +859,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ List ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null); s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup"); for (IPAddressVO ipToRelease : ipsToRelease) { - success = success && _ntwkMgr.releasePublicIpAddress(ipToRelease.getId(), callerUserId, caller); + success = success && _ntwkMgr.disassociatePublicIpAddress(ipToRelease.getId(), callerUserId, caller); if (!success) { s_logger.warn("Failed to cleanup ip " + ipToRelease + " as a part of vpc id=" + vpcId + " cleanup"); } diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index 035629ceb85..b1ee175b0e7 100755 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -102,7 +102,8 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag SearchBuilder VpnSearch; @Override - public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall) throws NetworkRuleConflictException { + public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall, long networkId) + throws NetworkRuleConflictException { UserContext ctx = UserContext.current(); Account caller = ctx.getCaller(); @@ -114,11 +115,23 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag _accountMgr.checkAccess(caller, null, true, ipAddr); - if (!ipAddr.readyToUse() || ipAddr.getAssociatedWithNetworkId() == null) { + if (!ipAddr.readyToUse()) { throw new InvalidParameterValueException("The Ip address is not ready to be used yet: " + ipAddr.getAddress()); } IPAddressVO ipAddress = _ipAddressDao.findById(publicIpId); + + //associate ip address to network (if needed) + if (ipAddress.getAssociatedWithNetworkId() == null) { + s_logger.debug("The ip is not associated with the network id="+ networkId + " so assigning"); + try { + _networkMgr.associateIPToGuestNetwork(publicIpId, networkId); + } catch (Exception ex) { + s_logger.warn("Failed to associate ip id=" + publicIpId + " to network id=" + networkId + " as " + + "a part of remote access vpn creation"); + return null; + } + } _networkMgr.checkIpForService(ipAddress, Service.Vpn); RemoteAccessVpnVO vpnVO = _remoteAccessVpnDao.findByPublicIpAddress(publicIpId); @@ -132,7 +145,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag } // TODO: assumes one virtual network / domr per account per zone - vpnVO = _remoteAccessVpnDao.findByAccountAndNetwork(ipAddr.getAccountId(), ipAddr.getAssociatedWithNetworkId()); + vpnVO = _remoteAccessVpnDao.findByAccountAndNetwork(ipAddr.getAccountId(), networkId); if (vpnVO != null) { //if vpn is in Added state, return it to the api if (vpnVO.getState() == RemoteAccessVpn.State.Added) { @@ -142,7 +155,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag } //Verify that vpn service is enabled for the network - Network network = _networkMgr.getNetwork(ipAddr.getAssociatedWithNetworkId()); + Network network = _networkMgr.getNetwork(networkId); if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.Vpn)) { throw new InvalidParameterValueException("Vpn service is not supported in network id=" + ipAddr.getAssociatedWithNetworkId()); } diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 3503d3f475d..8ce4ea7c31e 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -597,7 +597,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag List ipsToRelease = _ipAddressDao.listByAccount(accountId); for (IpAddress ip : ipsToRelease) { s_logger.debug("Releasing ip " + ip + " as a part of account id=" + accountId + " cleanup"); - if (!_networkMgr.releasePublicIpAddress(ip.getId(), callerUserId, caller)) { + if (!_networkMgr.disassociatePublicIpAddress(ip.getId(), callerUserId, caller)) { s_logger.warn("Failed to release ip address " + ip + " as a part of account id=" + accountId + " clenaup"); accountCleanupNeeded = true; } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index b0fccf0bbab..12583f885f9 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -74,13 +74,13 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException { + public IpAddress associateIPToGuestNetwork(long ipId, long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub return null; } @Override - public boolean disassociateIpAddress(long ipAddressId) { + public boolean releaseIpAddress(long ipAddressId) { // TODO Auto-generated method stub return false; } @@ -181,7 +181,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override - public boolean releasePublicIpAddress(long id, long userId, Account caller) { + public boolean disassociatePublicIpAddress(long id, long userId, Account caller) { // TODO Auto-generated method stub return false; } @@ -764,8 +764,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public IpAddress allocateIP(long networkId, Account ipOwner, - boolean isSystem) throws ResourceAllocationException, + public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub return null; diff --git a/wscript b/wscript index edf3a13850c..5b3e8e74340 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-29T18:21:13Z' +VERSION = '3.0.3.2012-05-31T02:45:25Z' APPNAME = 'cloud' import shutil,os From 0d89f34a48241363c3e3e40d7e666e38280c00e9 Mon Sep 17 00:00:00 2001 From: anthony Date: Fri, 25 May 2012 14:07:26 -0700 Subject: [PATCH 18/64] 1. move control network to eth0 on domr 2. if it is basic mode, use guest NIC as Control NIC --- .../systemvm/debian/config/etc/dnsmasq.conf | 9 ++-- .../config/etc/init.d/cloud-early-config | 39 +++----------- .../config/etc/iptables/iptables-router | 11 +--- .../network/guru/ControlNetworkGuru.java | 19 +------ .../lb/ElasticLoadBalancerManagerImpl.java | 8 +-- .../VirtualNetworkApplianceManagerImpl.java | 51 ++++++++++--------- ...VpcVirtualNetworkApplianceManagerImpl.java | 2 +- wscript | 2 +- 8 files changed, 45 insertions(+), 96 deletions(-) diff --git a/patches/systemvm/debian/config/etc/dnsmasq.conf b/patches/systemvm/debian/config/etc/dnsmasq.conf index 8f999a75cb1..f997004ef78 100644 --- a/patches/systemvm/debian/config/etc/dnsmasq.conf +++ b/patches/systemvm/debian/config/etc/dnsmasq.conf @@ -70,19 +70,18 @@ local=/2.vmops-test.vmops.com/ # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. # Repeat the line for more than one interface. -interface=eth0 +#interface=eth0 + # Or you can specify which interface _not_ to listen on -except-interface=eth1 -except-interface=eth2 except-interface=lo + # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) #listen-address= # If you want dnsmasq to provide only DNS service on an interface, # configure it as shown above, and then use the following line to # disable DHCP on it. -no-dhcp-interface=eth1 -no-dhcp-interface=eth2 +#no-dhcp-interface=eth1 # On systems which support it, dnsmasq binds the wildcard address, # even when it is listening on only some interfaces. It then discards diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 9c0d189046f..52f7fb919aa 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -376,6 +376,7 @@ setup_dnsmasq() { sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\""$DNS_SEARCH_ORDER"\"/ /etc/dnsmasq.conf fi + sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf @@ -523,8 +524,6 @@ setup_router() { - setup_dnsmasq - NS=$NS1 [ -n "$NS2" ] && NS=$NS1,$NS2 if [ "$USE_EXTERNAL_DNS" == "true" ] @@ -533,12 +532,9 @@ setup_router() { echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf fi - setup_apache2 $ETH0_IP - sed -i /gateway/d /etc/hosts - echo "$ETH0_IP $NAME" >> /etc/hosts - setup_sshd $ETH1_IP + setup_sshd $ETH0_IP enable_svc dnsmasq 1 enable_svc haproxy 1 @@ -552,7 +548,7 @@ setup_router() { setup_dhcpsrvr() { log_it "Setting up dhcp server system vm" - setup_common eth0 eth1 + setup_common eth0 setup_dnsmasq setup_apache2 $ETH0_IP @@ -580,12 +576,7 @@ setup_dhcpsrvr() { sed -i /gateway/d /etc/hosts echo "$ETH0_IP $NAME" >> /etc/hosts - if [ "$SSHONGUEST" == "true" ] - then - setup_sshd $ETH0_IP - else - setup_sshd $ETH1_IP - fi + setup_sshd $ETH0_IP enable_svc dnsmasq 1 enable_svc haproxy 0 @@ -593,12 +584,7 @@ setup_dhcpsrvr() { enable_svc cloud 0 enable_fwding 0 chkconfig nfs-common off - if [ "$SSHONGUEST" == "true" ] - then - sed '/3922/i -A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT' /etc/iptables/iptables-router > /etc/iptables/rules - else - cp /etc/iptables/iptables-router /etc/iptables/rules - fi + cp /etc/iptables/iptables-router /etc/iptables/rules } setup_storage_network() { @@ -673,17 +659,11 @@ setup_elbvm() { setup_common eth0 eth1 sed -i /gateway/d /etc/hosts public_ip=$ETH2_IP - [ "$ETH2_IP" == "0.0.0.0" ] || [ "$ETH2_IP" == "" ] && public_ip=$ETH0_IP + [ "$ETH2_IP" == "0.0.0.0" ] || [ "$ETH2_IP" == "" ] && public_ip=$ETH1_IP echo "$public_ip $NAME" >> /etc/hosts - if [ "$SSHONGUEST" == "true" ] - then - sed '/3922/s/eth1/eth0/' - setup_sshd $ETH0_IP - else - cp /etc/iptables/iptables-elbvm /etc/iptables/rules - setup_sshd $ETH1_IP - fi + cp /etc/iptables/iptables-elbvm /etc/iptables/rules + setup_sshd $ETH0_IP enable_fwding 0 enable_svc haproxy 0 @@ -823,9 +803,6 @@ for i in $CMDLINE template) TEMPLATE=$VALUE ;; - sshonguest) - SSHONGUEST=$VALUE - ;; name) NAME=$VALUE ;; diff --git a/patches/systemvm/debian/config/etc/iptables/iptables-router b/patches/systemvm/debian/config/etc/iptables/iptables-router index e1972e3a12d..ac40ed41056 100644 --- a/patches/systemvm/debian/config/etc/iptables/iptables-router +++ b/patches/systemvm/debian/config/etc/iptables/iptables-router @@ -14,16 +14,7 @@ COMMIT -A INPUT -i eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT --A INPUT -i eth0 -p udp -m udp --dport 67 -j ACCEPT --A INPUT -i eth0 -p udp -m udp --dport 53 -j ACCEPT --A INPUT -i eth1 -p tcp -m state --state NEW --dport 3922 -j ACCEPT --A INPUT -i eth0 -p tcp -m state --state NEW --dport 8080 -j ACCEPT --A INPUT -i eth0 -p tcp -m state --state NEW --dport 80 -j ACCEPT --A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT --A FORWARD -i eth0 -o eth2 -j ACCEPT --A FORWARD -i eth2 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT --A FORWARD -i eth0 -o eth0 -m state --state NEW -j ACCEPT --A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT COMMIT *mangle :PREROUTING ACCEPT [0:0] diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java index 4427be7a064..807bf312eff 100755 --- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java @@ -106,14 +106,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu @Override public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - - if(vm.getHypervisorType() == HypervisorType.VMware && vm.getType() != VirtualMachine.Type.DomainRouter) { - NicProfile nicProf = new NicProfile(Nic.ReservationStrategy.Create, null, null, null, null); - String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); - nicProf.setMacAddress(mac); - return nicProf; - } - + if (nic != null) { throw new CloudRuntimeException("Does not support nic specification at this time: " + nic); } @@ -137,15 +130,6 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); nic.setMacAddress(mac); return; - } else { - // in basic mode and in VMware case, control network will be shared with guest network - String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); - nic.setMacAddress(mac); - nic.setIp4Address("0.0.0.0"); - nic.setNetmask("0.0.0.0"); - nic.setFormat(AddressFormat.Ip4); - nic.setGateway("0.0.0.0"); - return; } } @@ -158,6 +142,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu nic.setNetmask("255.255.0.0"); nic.setFormat(AddressFormat.Ip4); nic.setGateway(NetUtils.getLinkLocalGateway()); + nic.setDeviceId(0); } @Override diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index d479f76e012..cf88fcd5b80 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -498,8 +498,9 @@ public class ElasticLoadBalancerManagerImpl implements List> networks = new ArrayList>(2); NicProfile guestNic = new NicProfile(); guestNic.setDefaultNic(true); - networks.add(new Pair((NetworkVO) guestNetwork, guestNic)); networks.add(new Pair(controlConfig, null)); + networks.add(new Pair((NetworkVO) guestNetwork, guestNic)); + VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId); @@ -851,11 +852,6 @@ public class ElasticLoadBalancerManagerImpl implements // always add management explicit route, for basic networking setup buf.append(" mgmtcidr=").append(_mgmtCidr); buf.append(" localgw=").append(dest.getPod().getGateway()); - - if (dc.getNetworkType() == NetworkType.Basic) { - // ask elb vm to setup SSH on guest network - buf.append(" sshonguest=true"); - } } controlNic = nic; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index edf29d19f9d..116f0df5168 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1202,7 +1202,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); } - //Check if public network has to be sest on VR + //Check if public network has to be set on VR boolean publicNetwork = false; if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { publicNetwork = true; @@ -1211,7 +1211,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.error("Didn't support redundant virtual router without public network!"); return null; } - + //Check if control network has to be set on VR + boolean controlNetwork = true; + if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { + // in basic mode, use private network as control network + controlNetwork = false; + } //1) Get deployment plan and find out the list of routers boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || @@ -1253,7 +1258,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian int count = routerCount - routers.size(); PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { - DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant, + DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, controlNetwork, guestNetwork, isRedundant, vrProvider, offeringId, sourceNatIp, null); routers.add(router); } @@ -1266,7 +1271,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, - boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant, + boolean setupPublicNetwork, boolean setupControlNetwork, Network guestNetwork, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp, Long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1275,9 +1280,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (s_logger.isDebugEnabled()) { s_logger.debug("Creating the router " + id + " in datacenter " + dest.getDataCenter()); } - - //1) Create router networks - List> networks = createRouterNetworks(owner, setupPublicNetwork, guestNetwork, + + List> networks = createRouterNetworks(owner, setupPublicNetwork, setupControlNetwork, guestNetwork, isRedundant, plan, sourceNatIp); @@ -1367,13 +1371,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return router; } - protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, + protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, boolean setupControlNetwork, Network guestNetwork, boolean isRedundant, DeploymentPlan plan, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException { //Form networks List> networks = new ArrayList>(3); - //1) Guest network + + //1) Control network + if (setupControlNetwork) { + s_logger.debug("Adding nic for Virtual Router in Control network "); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + networks.add(new Pair(controlConfig, null)); + } + + //2) Guest network boolean hasGuestNetwork = false; if (guestNetwork != null) { s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); @@ -1408,7 +1422,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian hasGuestNetwork = true; } - //2) Public network + //3) Public network if (setupPublicNetwork) { s_logger.debug("Adding nic for Virtual Router in Public network "); //if source nat service is supported by the network, get the source nat ip address @@ -1428,13 +1442,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); networks.add(new Pair(publicNetworks.get(0), defaultNic)); } - - //3) Control network - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - s_logger.debug("Adding nic for Virtual Router in Control network "); - networks.add(new Pair(controlConfig, null)); + return networks; } @@ -1632,12 +1640,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" mgmtcidr=").append(_mgmt_cidr); buf.append(" localgw=").append(dest.getPod().getGateway()); } - - - if (dc.getNetworkType() == NetworkType.Basic) { - // ask domR to setup SSH on guest network - buf.append(" sshonguest=true"); - } } } else if (nic.getTrafficType() == TrafficType.Guest) { dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); @@ -1798,8 +1800,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile controlNic = null; - if(profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) { - // TODO this is a ugly to test hypervisor type here + if( dcVo.getNetworkType() == NetworkType.Basic) { // for basic network mode, we will use the guest NIC for control NIC for (NicProfile nic : profile.getNics()) { if (nic.getTrafficType() == TrafficType.Guest && nic.getIp4Address() != null) { diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index df1177d86a8..dc753d10839 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -110,7 +110,7 @@ VpcVirtualNetworkApplianceManager{ VirtualRouterProviderType.VirtualRouter); PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); - DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false, + DomainRouterVO router = deployRouter(owner, dest, plan, params, true, true, null, false, vrProvider, offeringId, sourceNatIp, vpc.getId()); routers.add(router); diff --git a/wscript b/wscript index 5b3e8e74340..661b34996c7 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-31T02:45:25Z' +VERSION = '3.0.3.2012-05-25T20:59:05Z' APPNAME = 'cloud' import shutil,os From 0be4382bf179cc1a77c1b8d28a42107a8eeb1e35 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 4 Jun 2012 16:29:31 -0700 Subject: [PATCH 19/64] add guestnw.sh add acl.sh merge setup_dhcpsvr and setup_route --- .../config/etc/init.d/cloud-early-config | 119 +++-------- patches/systemvm/debian/config/root/acl.sh | 199 ++++++++++++++++++ .../systemvm/debian/config/root/guestnw.sh | 163 ++++++++++++++ 3 files changed, 395 insertions(+), 86 deletions(-) create mode 100755 patches/systemvm/debian/config/root/acl.sh create mode 100755 patches/systemvm/debian/config/root/guestnw.sh diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 52f7fb919aa..3785340dc20 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -171,8 +171,7 @@ setup_interface() { local intfnum=$1 local ip=$2 local mask=$3 - local gw=$4 - local force=$5 + local force=$4 local intf=eth${intfnum} local bootproto="static" @@ -286,11 +285,11 @@ disable_hvc() { setup_common() { init_interfaces $1 $2 $3 - setup_interface "0" $ETH0_IP $ETH0_MASK $GW - setup_interface "1" $ETH1_IP $ETH1_MASK $GW + setup_interface "0" $ETH0_IP $ETH0_MASK + setup_interface "1" $ETH1_IP $ETH1_MASK if [ -n "$ETH2_IP" ] then - setup_interface "2" $ETH2_IP $ETH2_MASK $GW + setup_interface "2" $ETH2_IP $ETH2_MASK fi echo $NAME > /etc/hostname @@ -472,38 +471,20 @@ setup_redundant_router() { fi } -setup_router() { - log_it "Setting up virtual router system vm" - + +setup_vmware_extra_nics() { + local oldmd5 oldmd5= [ -f "/etc/udev/rules.d/70-persistent-net.rules" ] && oldmd5=$(md5sum "/etc/udev/rules.d/70-persistent-net.rules" | awk '{print $1}') - - if [ -n "$ETH2_IP" ] + + if [ -n "$EXTRA_NICS" ] then - setup_common eth0 eth1 eth2 - - if [ -n "$EXTRA_PUBNICS" ] - then - for((i = 3; i < 3 + $EXTRA_PUBNICS; i++)) - do - setup_interface "$i" "0.0.0.0" "255.255.255.255" $GW "force" - done - fi - else - setup_common eth0 eth1 - if [ -n "$EXTRA_PUBNICS" ] - then - for((i = 2; i < 2 + $EXTRA_PUBNICS; i++)) - do - setup_interface "$i" "0.0.0.0" "255.255.255.255" $GW "force" - done - fi - fi - - if [ -n "$ETH2_IP" -a "$RROUTER" == "1" ] - then - setup_redundant_router + for((i = 1; i < 1 + $EXTRA_NICS; i++)) + do + setup_interface "$i" "0.0.0.0" "255.255.255.255" "force" + done fi + log_it "Checking udev NIC assignment order changes" if [ "$NIC_MACS" != "" ] @@ -522,18 +503,29 @@ setup_router() { fi fi - - - NS=$NS1 - [ -n "$NS2" ] && NS=$NS1,$NS2 - if [ "$USE_EXTERNAL_DNS" == "true" ] - then - sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf + +} + + +setup_router() { + log_it "Setting up virtual router system vm" + if [ "$hyp" == "vmware" ]; then + setup_vmware_extra_nics fi + + setup_common eth0 + + if [ "$RROUTER" == "1" ] + then + setup_redundant_router + fi + + setup_dnsmasq + setup_apache2 $ETH0_IP sed -i /gateway/d /etc/hosts + echo "$ETH0_IP $NAME" >> /etc/hosts setup_sshd $ETH0_IP enable_svc dnsmasq 1 @@ -546,47 +538,6 @@ setup_router() { cp /etc/iptables/iptables-router /etc/iptables/rules } -setup_dhcpsrvr() { - log_it "Setting up dhcp server system vm" - setup_common eth0 - setup_dnsmasq - setup_apache2 $ETH0_IP - - NS=$NS1 - [ -n "$NS2" ] && NS=$NS1,$NS2 - if [ "$DEFAULTROUTE" != "false" ] - then - sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf - #for now set up ourself as the dns server as well - sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf - if [ "$USE_EXTERNAL_DNS" == "true" ] - then - echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf - else - echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf - fi - else - sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=option:router" >> /etc/dnsmasq.conf - sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf - fi - - sed -i /gateway/d /etc/hosts - echo "$ETH0_IP $NAME" >> /etc/hosts - - setup_sshd $ETH0_IP - - enable_svc dnsmasq 1 - enable_svc haproxy 0 - enable_svc cloud-passwd-srvr 1 - enable_svc cloud 0 - enable_fwding 0 - chkconfig nfs-common off - cp /etc/iptables/iptables-router /etc/iptables/rules -} - setup_storage_network() { if [ x"$STORAGE_IP" == "x" -o x"$STORAGE_NETMASK" == "x" ] then @@ -704,10 +655,6 @@ start() { [ "$NAME" == "" ] && NAME=router setup_router ;; - dhcpsrvr) - [ "$NAME" == "" ] && NAME=dhcpsrvr - setup_dhcpsrvr - ;; secstorage) [ "$NAME" == "" ] && NAME=secstorage setup_secstorage $hyp; diff --git a/patches/systemvm/debian/config/root/acl.sh b/patches/systemvm/debian/config/root/acl.sh new file mode 100755 index 00000000000..6a3449aabee --- /dev/null +++ b/patches/systemvm/debian/config/root/acl.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env bash +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 +# firewall_rule.sh -- allow some ports / protocols to vm instances +# @VERSION@ + +source /root/func.sh + +lock="biglock" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +usage() { + printf "Usage: %s: -a \n" $(basename $0) >&2 + printf "sourcecidrs format: cidr1-cidr2-cidr3-...\n" +} +#set -x +#FIXME: eating up the error code during execution of iptables +acl_remove_backup() { + sudo iptables -F _ACL_INBOND_$gGW 2>/dev/null + sudo iptables -D FORWARD -o $dev -d $gcidr -j _ACL_INBOND_$gGW 2>/dev/null + sudo iptables -X _ACL_INBOND_$gGW 2>/dev/null + sudo iptables -F _ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j _ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -X _ACL_OUTBOND_$gGW 2>/dev/null +} + +acl_remove() { + sudo iptables -F ACL_INBOND_$gGW 2>/dev/null + sudo iptables -D FORWARD -o $dev -d $gcidr -j ACL_INBOND_$gGW 2>/dev/null + sudo iptables -X ACL_INBOND_$gGW 2>/dev/null + sudo iptables -F ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -X ACL_OUTBOND_$gGW 2>/dev/null +} + +acl_restore() { + acl_remove + sudo iptables -E _ACL_INBOND_$gGW ACL_INBOND_$gGW 2>/dev/null + sudo iptables -E _ACL_OUTBOND_$gGW ACL_OUTBOND_$gGW 2>/dev/null +} + +acl_save() { + acl_remove_backup + sudo iptables -E ACL_INBOND_$gGW _ACL_INBOND_$gGW 2>/dev/null + sudo iptables -E ACL_OUTBOND_$gGW _ACL_OUTBOND_$gGW 2>/dev/null +} + +acl_chain_for_guest_network () { + acl_save + # inbond + sudo iptables -E ACL_INBOND_$gGW _ACL_INBOND_$gGW 2>/dev/null + sudo iptables -N ACL_INBOND_$gGW 2>/dev/null + # drop if no rules match (this will be the last rule in the chain) + sudo iptables -A ACL_INBOND_$gGW -j DROP 2>/dev/null + sudo iptables -A FORWARD -o $dev -d $gcidr -j ACL_INBOND_$gGW 2>/dev/null + # outbond + sudo iptables -E ACL_OUTBOND_$gGW _ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -N ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -A ACL_OUTBOND_$gGW -j DROP 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOND_$gGW 2>/dev/null +} + + + +acl_entry_for_guest_network() { + local rule=$1 + + local inbond=$(echo $rule | cut -d: -f1) + local prot=$(echo $rules | cut -d: -f2) + local sport=$(echo $rules | cut -d: -f3) + local eport=$(echo $rules | cut -d: -f4) + local cidrs=$(echo $rules | cut -d: -f5 | sed 's/-/ /g') + + logger -t cloud "$(basename $0): enter apply firewall rules for guest network: $gcidr inbond:$inbond:$prot:$sport:$eport:$cidrs" + + # note that rules are inserted after the RELATED,ESTABLISHED rule + # but before the DROP rule + for lcidr in $scidrs + do + [ "$prot" == "reverted" ] && continue; + if [ "$prot" == "icmp" ] + then + typecode="$sport/$eport" + [ "$eport" == "-1" ] && typecode="$sport" + [ "$sport" == "-1" ] && typecode="any" + if [ "$inbond" == "1" ] + then + sudo iptables -I ACL_INBOND_$gGW -p $prot -s $lcidr \ + --icmp-type $typecode -j ACCEPT + else + sudo iptables -I ACL_OUTBOND_$gGW -p $prot -d $lcidr \ + --icmp-type $typecode -j ACCEPT + fi + else + if [ "$inbond" == "1" ] + then + sudo iptables -I ACL_INBOND_$gGW -p $prot -s $lcidr \ + --dport $sport:$eport -j ACCEPT + else + sudo iptables -I ACL_OUTBOND_$gGW -p $prot -d $lcidr \ + --dport $sport:$eport -j ACCEP`T + fi + result=$? + [ $result -gt 0 ] && + logger -t cloud "Error adding iptables entry for $pubIp:$prot:$sport:$eport:$src" && + break + done + + logger -t cloud "$(basename $0): exit apply firewall rules for public ip $pubIp" + return $result +} + + +shift +dflag=0 +gflag=0 +aflag=0 +rules="" +rules_list="" +gcidr="" +gGW="" +dev="" +while getopts ':d:g:a:' OPTION +do + case $OPTION in + d) dflag=1 + dev="$OPTAGR" + g) gflag=1 + gcidr="$OPTAGR" + a) aflag=1 + rules="$OPTARG" + ;; + ?) usage + unlock_exit 2 $lock $locked + ;; + esac +done + +VIF_LIST=$(get_vif_list) + +if [ "$gflag$aflag" != "11" ] +then + usage() +fi + + +if [ -n "$rules" == "" ] +then + rules_list=$(echo $rules | cut -d, -f1- --output-delimiter=" ") +fi + +# rule format +# protocal:sport:eport:cidr +#-a tcp:80:80:0.0.0.0/0::tcp:220:220:0.0.0.0/0:,172.16.92.44:tcp:222:222:192.168.10.0/24-75.57.23.0/22-88.100.33.1/32 +# if any entry is reverted , entry will be in the format :reverted:0:0:0 +# example : 172.16.92.44:tcp:80:80:0.0.0.0/0:,172.16.92.44:tcp:220:220:0.0.0.0/0:,200.1.1.2:reverted:0:0:0 + +success=0 +gGW=$(echo $gcidr | awk -F'/' '{print $1}') + +acl_chain_for_guest_network + +for r in $rules_list +do + acl_entry_for_guest_network $r + success=$? + if [ $success -gt 0 ] + then + logger -t cloud "$(basename $0): failure to apply fw rules for guest network: $gcidr" + break + else + logger -t cloud "$(basename $0): successful in applying fw rules for guest network: $gcidr" + fi +done + +if [ $success -gt 0 ] +then + logger -t cloud "$(basename $0): restoring from backup for guest network: $gcidr" + acl_restore +else + logger -t cloud "$(basename $0): deleting backup for guest network: $gcidr" + acl_remove_backup +fi +unlock_exit $success $lock $locked + diff --git a/patches/systemvm/debian/config/root/guestnw.sh b/patches/systemvm/debian/config/root/guestnw.sh new file mode 100755 index 00000000000..e958dd07bd5 --- /dev/null +++ b/patches/systemvm/debian/config/root/guestnw.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 + +# guestnw.sh -- create/destroy guest network +# @VERSION@ + +source /root/func.sh + +lock="biglock" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +usage() { + printf "Usage:\n %s -A -c -g -m -d -r [-f] \n" $(basename $0) >&2 + printf " %s -D -c \n" $(basename $0) >&2 +} + + +setup_dnsmasq() { + loger -t cloud "Setting up dnsmasq for network $gwIP " + + sed -i -e "/^[#]*dhcp-range=interface:$ethDev/d" /etc/dnsmasq.d/cloud.conf + + echo "dhcp-range=interface:$ethDev,$gwIP,static/" >> /etc/dnsmasq.d/cloud.conf + + service dnsmasq restart + sleep 1 +} + +desetup_dnsmasq() { + loger -t cloud "Setting up dnsmasq for network $gwIP " + + sed -i -e "/^[#]*dhcp-range=interface:$ethDev/d" /etc/dnsmasq.d/cloud.conf + + service dnsmasq restart + sleep 1 +} + + +create_network() { + logger -t cloud " $(basename $0): Create network on interface $ethDev, gateway $gwIP, network $network, cidr $cidr " + + sudo ip addr add $ethDev $gwIP/$cidr + + # create inbond acl chain + if sudo iptables -N ACL_INBOND_$gwIP 2>/dev/null + then + logger -t cloud "$(basename $0): create VPC inbond acl chain for network $gwIP" + # policy drop + sudo iptables -A ACL_INBOND_$gwIP DROP >/dev/null + sudo iptables -A FORWARD -o $dev -d $gwIP/$cidr -j ACL_INBOND_$gwIP + fi + # create outbond acl chain + if sudo iptables -N ACL_OUTBOND_$gwIP 2>/dev/null + then + logger -t cloud "$(basename $0): create VPC outbond acl chain for network $gwIP" + sudo iptables -A ACL_OUTBOND_$gwIP DROP >/dev/null + sudo iptables -A FORWARD -i $dev -s $gwIP/$cidr -j ACL_OUTBOND_$gwIP + fi + + setup_dnsmasq +} + +destroy_network() { + logger -t cloud " $(basename $0): Create network on interface $ethDev, gateway $gwIP, network $network, cidr $cidr " + + + # destroy egress firewall chain + sudo iptables -t mangle -D PREROUTING -s $gwIP/$cidr -j FIREWALL_EGRESS_$gwIP + sudo iptables -t mangle -F FIREWALL_EGRESS_$gwIP + sudo iptables -t mangle -X FIREWALL_EGRESS_$gwIP + + # destroy ingress firewall chain + + sudo iptables -t mangle -D POSTROUTING -o $devDev-d $gwIP/$cidr -j FIREWALL_IEGRESS_$gwIP + sudo iptables -t mangle -F FIREWALL_INGRESS_$gwIP + sudo iptables -t mangle -X FIREWALL_INGRESS_$gwIP + + desetup_dnsmasq +} + +#set -x +nflag=0 +dflag= +cflag= +gflag= +Cflag= +Dflag= + +op="" + + +while getopts 'CDg:n:m:c:v' OPTION +do + case $OPTION in + C) Cflag=1 + op="-C" + ;; + D) Dflag=1 + op="-D" + ;; + n) nflag=1 + network="$OPTAGR" + ;; + c) cflag=1 + cidr="$OPTARG" + ;; + d) dflag=1 + ethDev="$OPTARG" + ;; + v) vflag=1 + vcidr="$OPTARG" + ;; + + g) gflag=1 + gwIP="$OPTARG" + ;; + ?) usage + unlock_exit 2 $lock $locked + ;; + esac +done + + +if [ "$Cflag$Dflag$cflag" != "11" ] +then + usage + unlock_exit 2 $lock $locked +fi + +if [ "$Cflag" == "1" ] && ["$nflag$mflag$gflag$vflag" != "1111" ] +then + usage + unlock_exit 2 $lock $locked +fi + + +if [ "$Cflag" == "1" ] +then + create_guest_network +fi + + +if [ "$Dflag" == "1" ] +then + destroy_guest_network +fi + +unlock_exit 0 $lock $locked From e682f10fc81fab23d81c1c2513f177f0e3e63e28 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 4 Jun 2012 18:00:14 -0700 Subject: [PATCH 20/64] typo fix --- patches/systemvm/debian/config/root/acl.sh | 80 ++++++++-------- .../systemvm/debian/config/root/guestnw.sh | 91 ++++++++++--------- wscript | 2 +- 3 files changed, 90 insertions(+), 83 deletions(-) diff --git a/patches/systemvm/debian/config/root/acl.sh b/patches/systemvm/debian/config/root/acl.sh index 6a3449aabee..525dfe47b0c 100755 --- a/patches/systemvm/debian/config/root/acl.sh +++ b/patches/systemvm/debian/config/root/acl.sh @@ -30,48 +30,48 @@ usage() { #set -x #FIXME: eating up the error code during execution of iptables acl_remove_backup() { - sudo iptables -F _ACL_INBOND_$gGW 2>/dev/null - sudo iptables -D FORWARD -o $dev -d $gcidr -j _ACL_INBOND_$gGW 2>/dev/null - sudo iptables -X _ACL_INBOND_$gGW 2>/dev/null - sudo iptables -F _ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -D FORWARD -i $dev -s $gcidr -j _ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -X _ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -F _ACL_INBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -o $dev -d $gcidr -j _ACL_INBOUND_$ip 2>/dev/null + sudo iptables -X _ACL_INBOUND_$ip 2>/dev/null + sudo iptables -F _ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j _ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -X _ACL_OUTBOUND_$ip 2>/dev/null } acl_remove() { - sudo iptables -F ACL_INBOND_$gGW 2>/dev/null - sudo iptables -D FORWARD -o $dev -d $gcidr -j ACL_INBOND_$gGW 2>/dev/null - sudo iptables -X ACL_INBOND_$gGW 2>/dev/null - sudo iptables -F ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -X ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -F ACL_INBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -o $dev -d $gcidr -j ACL_INBOUND_$ip 2>/dev/null + sudo iptables -X ACL_INBOUND_$ip 2>/dev/null + sudo iptables -F ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -X ACL_OUTBOUND_$ip 2>/dev/null } acl_restore() { acl_remove - sudo iptables -E _ACL_INBOND_$gGW ACL_INBOND_$gGW 2>/dev/null - sudo iptables -E _ACL_OUTBOND_$gGW ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -E _ACL_INBOUND_$ip ACL_INBOUND_$ip 2>/dev/null + sudo iptables -E _ACL_OUTBOUND_$ip ACL_OUTBOUND_$ip 2>/dev/null } acl_save() { acl_remove_backup - sudo iptables -E ACL_INBOND_$gGW _ACL_INBOND_$gGW 2>/dev/null - sudo iptables -E ACL_OUTBOND_$gGW _ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -E ACL_INBOUND_$ip _ACL_INBOUND_$ip 2>/dev/null + sudo iptables -E ACL_OUTBOUND_$ip _ACL_OUTBOUND_$gGW 2>/dev/null } acl_chain_for_guest_network () { acl_save - # inbond - sudo iptables -E ACL_INBOND_$gGW _ACL_INBOND_$gGW 2>/dev/null - sudo iptables -N ACL_INBOND_$gGW 2>/dev/null + # inbound + sudo iptables -E ACL_INBOUND_$ip _ACL_INBOUND_$ip 2>/dev/null + sudo iptables -N ACL_INBOUND_$ip 2>/dev/null # drop if no rules match (this will be the last rule in the chain) - sudo iptables -A ACL_INBOND_$gGW -j DROP 2>/dev/null - sudo iptables -A FORWARD -o $dev -d $gcidr -j ACL_INBOND_$gGW 2>/dev/null - # outbond - sudo iptables -E ACL_OUTBOND_$gGW _ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -N ACL_OUTBOND_$gGW 2>/dev/null - sudo iptables -A ACL_OUTBOND_$gGW -j DROP 2>/dev/null - sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOND_$gGW 2>/dev/null + sudo iptables -A ACL_INBOUND_$ip -j DROP 2>/dev/null + sudo iptables -A FORWARD -o $dev -d $gcidr -j ACL_INBOUND_$ip 2>/dev/null + # outbound + sudo iptables -E ACL_OUTBOUND_$ip _ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -N ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -A ACL_OUTBOUND_$ip -j DROP 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $gcidr -j ACL_OUTBOUND_$ip 2>/dev/null } @@ -79,13 +79,13 @@ acl_chain_for_guest_network () { acl_entry_for_guest_network() { local rule=$1 - local inbond=$(echo $rule | cut -d: -f1) + local inbound=$(echo $rule | cut -d: -f1) local prot=$(echo $rules | cut -d: -f2) local sport=$(echo $rules | cut -d: -f3) local eport=$(echo $rules | cut -d: -f4) local cidrs=$(echo $rules | cut -d: -f5 | sed 's/-/ /g') - logger -t cloud "$(basename $0): enter apply firewall rules for guest network: $gcidr inbond:$inbond:$prot:$sport:$eport:$cidrs" + logger -t cloud "$(basename $0): enter apply acl rules for guest network: $gcidr, inbound:$inbound:$prot:$sport:$eport:$cidrs" # note that rules are inserted after the RELATED,ESTABLISHED rule # but before the DROP rule @@ -97,30 +97,30 @@ acl_entry_for_guest_network() { typecode="$sport/$eport" [ "$eport" == "-1" ] && typecode="$sport" [ "$sport" == "-1" ] && typecode="any" - if [ "$inbond" == "1" ] + if [ "$inbound" == "1" ] then - sudo iptables -I ACL_INBOND_$gGW -p $prot -s $lcidr \ + sudo iptables -I ACL_INBOUND_$gGW -p $prot -s $lcidr \ --icmp-type $typecode -j ACCEPT else - sudo iptables -I ACL_OUTBOND_$gGW -p $prot -d $lcidr \ + sudo iptables -I ACL_OUTBOUND_$gGW -p $prot -d $lcidr \ --icmp-type $typecode -j ACCEPT fi else - if [ "$inbond" == "1" ] + if [ "$inbound" == "1" ] then - sudo iptables -I ACL_INBOND_$gGW -p $prot -s $lcidr \ + sudo iptables -I ACL_INBOUND_$gGW -p $prot -s $lcidr \ --dport $sport:$eport -j ACCEPT else - sudo iptables -I ACL_OUTBOND_$gGW -p $prot -d $lcidr \ + sudo iptables -I ACL_OUTBOUND_$gGW -p $prot -d $lcidr \ --dport $sport:$eport -j ACCEP`T fi result=$? [ $result -gt 0 ] && - logger -t cloud "Error adding iptables entry for $pubIp:$prot:$sport:$eport:$src" && + logger -t cloud "Error adding iptables entry for guest network : $gcidr,inbound:$inbound:$prot:$sport:$eport:$cidrs" && break done - logger -t cloud "$(basename $0): exit apply firewall rules for public ip $pubIp" + logger -t cloud "$(basename $0): exit apply acl rules for guest network : $gcidr" return $result } @@ -132,7 +132,7 @@ aflag=0 rules="" rules_list="" gcidr="" -gGW="" +ip="" dev="" while getopts ':d:g:a:' OPTION do @@ -150,9 +150,7 @@ do esac done -VIF_LIST=$(get_vif_list) - -if [ "$gflag$aflag" != "11" ] +if [ "$dflag$gflag$aflag" != "!11" ] then usage() fi @@ -170,7 +168,7 @@ fi # example : 172.16.92.44:tcp:80:80:0.0.0.0/0:,172.16.92.44:tcp:220:220:0.0.0.0/0:,200.1.1.2:reverted:0:0:0 success=0 -gGW=$(echo $gcidr | awk -F'/' '{print $1}') +ip=$(echo $gcidr | awk -F'/' '{print $1}') acl_chain_for_guest_network diff --git a/patches/systemvm/debian/config/root/guestnw.sh b/patches/systemvm/debian/config/root/guestnw.sh index e958dd07bd5..d15f8a45c3c 100755 --- a/patches/systemvm/debian/config/root/guestnw.sh +++ b/patches/systemvm/debian/config/root/guestnw.sh @@ -31,64 +31,71 @@ usage() { setup_dnsmasq() { - loger -t cloud "Setting up dnsmasq for network $gwIP " + loger -t cloud "Setting up dnsmasq for network $ip/$mask " - sed -i -e "/^[#]*dhcp-range=interface:$ethDev/d" /etc/dnsmasq.d/cloud.conf + sed -i -e "/^[#]*dhcp-range=interface:$dev/d" /etc/dnsmasq.d/cloud.conf - echo "dhcp-range=interface:$ethDev,$gwIP,static/" >> /etc/dnsmasq.d/cloud.conf + echo "dhcp-range=interface:$dev,set:interface-$dev,$ip,static/" >> /etc/dnsmasq.d/cloud.conf + sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,option:router.*$/d" /etc/dnsmasq.d/cloud.conf + if [ -n "$gw" ] + then + echo "dhcp-option=tag:interface-$dev,option:router,$gw" >> /etc/dnsmasq.d/cloud.conf + fi + sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,6.*$/d" /etc/dnsmasq.d/cloud.conf + if [ -n "$NS" ] + then + echo "dhcp-option=tag:interface-$dev,6,$NS" >> /etc/dnsmasq.d/cloud.conf + fi service dnsmasq restart sleep 1 } desetup_dnsmasq() { - loger -t cloud "Setting up dnsmasq for network $gwIP " + loger -t cloud "Setting up dnsmasq for network $ip/$mask " - sed -i -e "/^[#]*dhcp-range=interface:$ethDev/d" /etc/dnsmasq.d/cloud.conf - + sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,option:router.*$/d" /etc/dnsmasq.d/cloud.conf + sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,6.*$/d" /etc/dnsmasq.d/cloud.conf + sed -i -e "/^[#]*dhcp-range=interface:$dev/d" /etc/dnsmasq.d/cloud.conf service dnsmasq restart sleep 1 } -create_network() { - logger -t cloud " $(basename $0): Create network on interface $ethDev, gateway $gwIP, network $network, cidr $cidr " +create_guest_network() { + logger -t cloud " $(basename $0): Create network on interface $dev, gateway $gw, network $ip/$mask " - sudo ip addr add $ethDev $gwIP/$cidr + sudo ip addr add $dev $ip/$mask - # create inbond acl chain - if sudo iptables -N ACL_INBOND_$gwIP 2>/dev/null + # create inbound acl chain + if sudo iptables -N ACL_INBOUND_$ip 2>/dev/null then - logger -t cloud "$(basename $0): create VPC inbond acl chain for network $gwIP" + logger -t cloud "$(basename $0): create VPC inbound acl chain for network $ip/$mask" # policy drop - sudo iptables -A ACL_INBOND_$gwIP DROP >/dev/null - sudo iptables -A FORWARD -o $dev -d $gwIP/$cidr -j ACL_INBOND_$gwIP + sudo iptables -A ACL_INBOUND_$ip DROP >/dev/null + sudo iptables -A FORWARD -o $dev -d $ip/$mask -j ACL_INBOUND_$ip fi - # create outbond acl chain - if sudo iptables -N ACL_OUTBOND_$gwIP 2>/dev/null + # create outbound acl chain + if sudo iptables -N ACL_OUTBOUND_$ip 2>/dev/null then - logger -t cloud "$(basename $0): create VPC outbond acl chain for network $gwIP" - sudo iptables -A ACL_OUTBOND_$gwIP DROP >/dev/null - sudo iptables -A FORWARD -i $dev -s $gwIP/$cidr -j ACL_OUTBOND_$gwIP + logger -t cloud "$(basename $0): create VPC outbound acl chain for network $ip/$mask" + sudo iptables -A ACL_OUTBOUND_$ip DROP >/dev/null + sudo iptables -A FORWARD -i $dev -s $ip/$mask -j ACL_OUTBOUND_$ip fi setup_dnsmasq } -destroy_network() { - logger -t cloud " $(basename $0): Create network on interface $ethDev, gateway $gwIP, network $network, cidr $cidr " - - - # destroy egress firewall chain - sudo iptables -t mangle -D PREROUTING -s $gwIP/$cidr -j FIREWALL_EGRESS_$gwIP - sudo iptables -t mangle -F FIREWALL_EGRESS_$gwIP - sudo iptables -t mangle -X FIREWALL_EGRESS_$gwIP - - # destroy ingress firewall chain - - sudo iptables -t mangle -D POSTROUTING -o $devDev-d $gwIP/$cidr -j FIREWALL_IEGRESS_$gwIP - sudo iptables -t mangle -F FIREWALL_INGRESS_$gwIP - sudo iptables -t mangle -X FIREWALL_INGRESS_$gwIP +destroy_guest_network() { + logger -t cloud " $(basename $0): Create network on interface $dev, gateway $gw, network $ip/$mask " + # destroy inbound acl chain + sudo iptables -F ACL_INBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -o $dev -d $ip/$mask -j ACL_INBOUND_$ip 2>/dev/null + sudo iptables -X ACL_INBOUND_$ip 2>/dev/null + # destroy outbound acl chain + sudo iptables -F ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -D FORWARD -i $dev -s $ip/$mask -j ACL_OUTBOUND_$ip 2>/dev/null + sudo iptables -X ACL_OUTBOUND_$ip 2>/dev/null desetup_dnsmasq } @@ -116,18 +123,20 @@ do n) nflag=1 network="$OPTAGR" ;; - c) cflag=1 - cidr="$OPTARG" + c) mflag=1 + mask="$OPTARG" ;; d) dflag=1 - ethDev="$OPTARG" + dev="$OPTARG" ;; - v) vflag=1 - vcidr="$OPTARG" + v) iflag=1 + ip="$OPTARG" ;; - g) gflag=1 - gwIP="$OPTARG" + gw="$OPTARG" + ;; + s) sflag=1 + DNS="$OPTARG" ;; ?) usage unlock_exit 2 $lock $locked @@ -142,7 +151,7 @@ then unlock_exit 2 $lock $locked fi -if [ "$Cflag" == "1" ] && ["$nflag$mflag$gflag$vflag" != "1111" ] +if [ "$Cflag" == "1" ] && ["$dflag$iflag$gflag$mflag" != "1111" ] then usage unlock_exit 2 $lock $locked diff --git a/wscript b/wscript index 661b34996c7..1589fecf1ba 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-25T20:59:05Z' +VERSION = '3.0.3.2012-06-04T23:35:51Z' APPNAME = 'cloud' import shutil,os From 460bab4a7d2ebb1a88420689b68a505575d1891a Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 4 Jun 2012 11:32:04 -0700 Subject: [PATCH 21/64] Support for adding private network --- .../com/cloud/agent/api/PlugNicCommand.java | 10 +- .../agent/api/SetupGuestNetworkAnswer.java | 24 + .../agent/api/SetupGuestNetworkCommand.java | 48 ++ .../api/routing/NetworkElementCommand.java | 1 + .../commands/CreatePhysicalNetworkCmd.java | 6 +- .../api/commands/CreatePrivateNetworkCmd.java | 195 +++++++ api/src/com/cloud/network/NetworkService.java | 19 + .../VirtualNetworkApplianceService.java | 21 + .../cloud/network/VirtualRouterProvider.java | 3 +- .../cloud/network/element/VpcProvider.java | 8 +- .../cloud/network/router/VirtualRouter.java | 1 - api/src/com/cloud/network/vpc/Vpc.java | 2 +- .../VpcVirtualNetworkApplianceService.java | 45 -- .../network/vpn/RemoteAccessVpnService.java | 3 +- .../com/cloud/offering/NetworkOffering.java | 3 +- awsapi.log.2012-05-30.gz | Bin 0 -> 14294 bytes client/tomcatconf/commands.properties.in | 4 + client/tomcatconf/components.xml.in | 1 + core/src/com/cloud/vm/DomainRouterVO.java | 12 - .../ConfigurationManagerImpl.java | 2 + .../DefaultComponentLibrary.java | 2 + .../src/com/cloud/network/NetworkManager.java | 8 + .../com/cloud/network/NetworkManagerImpl.java | 120 ++++- .../network/element/VirtualRouterElement.java | 37 +- .../element/VpcVirtualRouterElement.java | 85 +-- .../cloud/network/guru/GuestNetworkGuru.java | 5 +- .../network/guru/PrivateNetworkGuru.java | 215 ++++++++ .../cloud/network/guru/PublicNetworkGuru.java | 6 +- .../lb/ElasticLoadBalancerManagerImpl.java | 22 +- .../VirtualNetworkApplianceManagerImpl.java | 502 ++++++++++-------- .../VpcVirtualNetworkApplianceManager.java | 3 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 116 +--- .../cloud/network/vpc/Dao/PrivateIpDao.java | 62 +++ .../network/vpc/Dao/PrivateIpDaoImpl.java | 129 +++++ .../cloud/network/vpc/Dao/VpcGatewayDao.java | 23 + .../com/cloud/network/vpc/PrivateIpVO.java | 76 +++ .../com/cloud/network/vpc/VpcGatewayVO.java | 22 + .../cloud/offerings/NetworkOfferingVO.java | 6 + .../cloud/server/ConfigurationServerImpl.java | 18 +- server/src/com/cloud/test/PodZoneConfig.java | 3 +- .../cloud/upgrade/dao/Upgrade2214to30.java | 6 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 3 +- .../com/cloud/vm/VirtualMachineManager.java | 2 +- .../cloud/vm/VirtualMachineManagerImpl.java | 14 +- .../src/com/cloud/vm/dao/DomainRouterDao.java | 3 +- .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 6 +- server/src/com/cloud/vm/dao/NicDao.java | 9 + server/src/com/cloud/vm/dao/NicDaoImpl.java | 27 + .../vm/MockVirtualMachineManagerImpl.java | 2 +- setup/db/create-schema.sql | 29 + wscript | 4 + 51 files changed, 1484 insertions(+), 489 deletions(-) create mode 100644 api/src/com/cloud/agent/api/SetupGuestNetworkAnswer.java create mode 100644 api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java create mode 100644 api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java delete mode 100644 api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java create mode 100644 awsapi.log.2012-05-30.gz create mode 100644 server/src/com/cloud/network/guru/PrivateNetworkGuru.java create mode 100644 server/src/com/cloud/network/vpc/Dao/PrivateIpDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/PrivateIpDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcGatewayDao.java create mode 100644 server/src/com/cloud/network/vpc/PrivateIpVO.java create mode 100644 server/src/com/cloud/network/vpc/VpcGatewayVO.java diff --git a/api/src/com/cloud/agent/api/PlugNicCommand.java b/api/src/com/cloud/agent/api/PlugNicCommand.java index f2f36cb56ef..4222e4c4369 100644 --- a/api/src/com/cloud/agent/api/PlugNicCommand.java +++ b/api/src/com/cloud/agent/api/PlugNicCommand.java @@ -12,8 +12,6 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.agent.api; -import java.util.Map; - import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; @@ -21,14 +19,9 @@ import com.cloud.agent.api.to.VirtualMachineTO; * @author Alena Prokharchyk */ public class PlugNicCommand extends Command { - public enum Param { - DhcpRange, - NetworkDomain - } VirtualMachineTO vm; NicTO nic; - Map params; public VirtualMachineTO getVirtualMachine() { return vm; @@ -46,9 +39,8 @@ public class PlugNicCommand extends Command { protected PlugNicCommand() { } - public PlugNicCommand(VirtualMachineTO vm, NicTO nic, Map params) { + public PlugNicCommand(VirtualMachineTO vm, NicTO nic) { this.vm = vm; this.nic = nic; - this.params = params; } } diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkAnswer.java b/api/src/com/cloud/agent/api/SetupGuestNetworkAnswer.java new file mode 100644 index 00000000000..e20a9c5ccc8 --- /dev/null +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkAnswer.java @@ -0,0 +1,24 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +/** + * @author Alena Prokharchyk + */ +public class SetupGuestNetworkAnswer extends Answer{ + public SetupGuestNetworkAnswer() {} + + public SetupGuestNetworkAnswer(SetupGuestNetworkCommand cmd, boolean success, String result) { + super(cmd, success, result); + } +} diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java new file mode 100644 index 00000000000..a1507c28ab4 --- /dev/null +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -0,0 +1,48 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +import com.cloud.agent.api.routing.NetworkElementCommand; + +/** + * @author Alena Prokharchyk + */ +public class SetupGuestNetworkCommand extends NetworkElementCommand{ + String dhcpRange; + String networkDomain; + String defaultDns1 = null; + String defaultDns2 = null; + boolean isRedundant = false; + Integer priority; + boolean add = true; + + @Override + public boolean executeInSequence() { + return true; + } + + protected SetupGuestNetworkCommand() { + } + + + public SetupGuestNetworkCommand(String dhcpRange, String networkDomain, boolean isRedundant, Integer priority, + String defaultDns1, String defaultDns2, boolean add) { + this.dhcpRange = dhcpRange; + this.networkDomain = networkDomain; + this.defaultDns1 = defaultDns1; + this.defaultDns2 = defaultDns2; + this.isRedundant = isRedundant; + this.priority = priority; + this.add = add; + } +} diff --git a/api/src/com/cloud/agent/api/routing/NetworkElementCommand.java b/api/src/com/cloud/agent/api/routing/NetworkElementCommand.java index b2d882baee6..db86bb48eb9 100644 --- a/api/src/com/cloud/agent/api/routing/NetworkElementCommand.java +++ b/api/src/com/cloud/agent/api/routing/NetworkElementCommand.java @@ -27,6 +27,7 @@ public abstract class NetworkElementCommand extends Command { public static final String ROUTER_IP = "router.ip"; public static final String ROUTER_GUEST_IP = "router.guest.ip"; public static final String ZONE_NETWORK_TYPE = "zone.network.type"; + public static final String GUEST_BRIDGE = "guest.bridge"; protected NetworkElementCommand() { super(); diff --git a/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java b/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java index 220b4155de7..d2d43ce6a49 100644 --- a/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java @@ -55,13 +55,15 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a physical network") private Long domainId; - @Parameter(name=ApiConstants.BROADCAST_DOMAIN_RANGE, type=CommandType.STRING, description="the broadcast domain range for the physical network[Pod or Zone]. In Acton release it can be Zone only in Advance zone, and Pod in Basic") + @Parameter(name=ApiConstants.BROADCAST_DOMAIN_RANGE, type=CommandType.STRING, description="the broadcast domain " + + "range for the physical network[Pod or Zone]. In Acton release it can be Zone only in Advance zone, and Pod in Basic") private String broadcastDomainRange; @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="Tag the physical network") private List tags; - @Parameter(name=ApiConstants.ISOLATION_METHODS, type=CommandType.LIST, collectionType=CommandType.STRING, description="the isolation method for the physical network[VLAN/L3/GRE]") + @Parameter(name=ApiConstants.ISOLATION_METHODS, type=CommandType.LIST, collectionType=CommandType.STRING, + description="the isolation method for the physical network[VLAN/L3/GRE]") private List isolationMethods; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the physical network") diff --git a/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java new file mode 100644 index 00000000000..276c1fb8e24 --- /dev/null +++ b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java @@ -0,0 +1,195 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.NetworkResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.Network; +import com.cloud.user.UserContext; + +@Implementation(description="Creates a private network", responseObject=NetworkResponse.class) +public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd { + public static final Logger s_logger = Logger.getLogger(CreatePrivateNetworkCmd.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; + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID the network belongs to") + private Long physicalNetworkId; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the network") + private String gateway; + + @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the network") + private String netmask; + + @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the beginning IP address in the network IP range") + private String startIp; + + @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" + + " range. If not specified, will be defaulted to startIP") + private String endIp; + + @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the ID or VID of the network") + private String vlan; + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network") + private String accountName; + + @IdentityMapper(entityTableName="projects") + @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key") + private Long projectId; + + @IdentityMapper(entityTableName="domain") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network") + private Long domainId; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getGateway() { + return gateway; + } + + 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 getNetworkName() { + return name; + } + + public String getDisplayText() { + return displayText; + } + + public Long getProjectId() { + return projectId; + } + + public long getPhysicalNetworkId() { + return physicalNetworkId; + } + + public String getEndIp() { + return endIp; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return s_name; + } + + + @Override + public void create() throws ResourceAllocationException { + Network result = null; + try { + result = _networkService.createPrivateNetwork(getNetworkName(), getDisplayText(), getPhysicalNetworkId(), getVlan(), + getStartIp(), getEndIp(), getGateway(), getNetmask(), getEntityOwnerId()); + } catch (InsufficientCapacityException ex){ + s_logger.info(ex); + s_logger.trace(ex); + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } + + if (result != null) { + this.setEntityId(result.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a Private network"); + } + } + + @Override + public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{ + Network result = _networkService.getNetwork(getEntityId()); + if (result != null) { + NetworkResponse response = _responseGenerator.createNetworkResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private network"); + } + } + + @Override + public long getEntityOwnerId() { + Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); + if (accountId == null) { + return UserContext.current().getCaller().getId(); + } + return accountId; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_NETWORK_CREATE; + } + + @Override + public String getEventDescription() { + return "creating private network"; + + } + + @Override + public String getEntityTable() { + return "networks"; + } +} diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 5eb57130869..386da85276d 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -146,4 +146,23 @@ public interface NetworkService { IpAddress associateIP(long ipId, Long networkId, Long vpcId) throws InsufficientAddressCapacityException, ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException; + /** + * @param networkName + * @param displayText + * @param physicalNetworkId + * @param vlan + * @param startIp + * @param endIP TODO + * @param gateway + * @param netmask + * @param networkOwnerId + * @return + * @throws InsufficientCapacityException + * @throws ConcurrentOperationException + * @throws ResourceAllocationException + */ + Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan, + String startIp, String endIP, String gateway, String netmask, long networkOwnerId) + throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException; + } diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index e68d6d91f1e..f7bc817af7e 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -57,4 +57,25 @@ public interface VirtualNetworkApplianceService { VirtualRouter startRouter(long id) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException; VirtualRouter destroyRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException; + + /** + * @param router + * @param network + * @param isRedundant TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + + /** + * @param router + * @param network + * @param isRedundant TODO + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/VirtualRouterProvider.java b/api/src/com/cloud/network/VirtualRouterProvider.java index 81eaf1e3c68..f6d416faa6b 100644 --- a/api/src/com/cloud/network/VirtualRouterProvider.java +++ b/api/src/com/cloud/network/VirtualRouterProvider.java @@ -15,7 +15,8 @@ package com.cloud.network; public interface VirtualRouterProvider { public enum VirtualRouterProviderType { VirtualRouter, - ElasticLoadBalancerVm + ElasticLoadBalancerVm, + VPCVirtualRouter } public VirtualRouterProviderType getType(); diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 63d0ce5af2b..bd55ff47c77 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -40,5 +40,11 @@ public interface VpcProvider extends NetworkElement{ */ boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; - + boolean createPrivateGateway(); + + boolean createVpnGateway(); + + boolean deletePrivateGateway(); + + boolean deleteVpnGateway(); } diff --git a/api/src/com/cloud/network/router/VirtualRouter.java b/api/src/com/cloud/network/router/VirtualRouter.java index 02aafefeca9..2ab2a5deafb 100755 --- a/api/src/com/cloud/network/router/VirtualRouter.java +++ b/api/src/com/cloud/network/router/VirtualRouter.java @@ -30,7 +30,6 @@ public interface VirtualRouter extends VirtualMachine { FAULT } RedundantState getRedundantState(); - String getGuestIpAddress(); String getPublicIpAddress(); boolean isStopPending(); void setStopPending(boolean stopPending); diff --git a/api/src/com/cloud/network/vpc/Vpc.java b/api/src/com/cloud/network/vpc/Vpc.java index da50066fa76..5e15bab1732 100644 --- a/api/src/com/cloud/network/vpc/Vpc.java +++ b/api/src/com/cloud/network/vpc/Vpc.java @@ -25,7 +25,7 @@ public interface Vpc extends ControlledEntity{ Disabled } - public static final String _supportedProviders = Network.Provider.VirtualRouter.getName(); + public static final String _supportedProviders = Network.Provider.VPCVirtualRouter.getName(); boolean readyToUse(); diff --git a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java deleted file mode 100644 index 08c3b21d087..00000000000 --- a/api/src/com/cloud/network/vpc/VpcVirtualNetworkApplianceService.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2012 Citrix Systems, Inc. Licensed under the -// Apache License, Version 2.0 (the "License"); you may not use this -// file except in compliance with the License. Citrix Systems, Inc. -// reserves all rights not expressly granted by the License. -// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.network.vpc; - -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; -import com.cloud.network.router.VirtualRouter; - -/** - * @author Alena Prokharchyk - */ -public interface VpcVirtualNetworkApplianceService { - - /** - * @param router - * @param network - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientCapacityException - */ - public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; - - /** - * @param router - * @param network - * @return - * @throws ResourceUnavailableException - * @throws ConcurrentOperationException - */ - boolean removeVmFromNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, ResourceUnavailableException; -} diff --git a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java index ba9540480f8..091626cdc26 100644 --- a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java +++ b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java @@ -23,7 +23,8 @@ import com.cloud.network.VpnUser; public interface RemoteAccessVpnService { - RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, long networkId) throws NetworkRuleConflictException; + RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, long networkId) + throws NetworkRuleConflictException; void destroyRemoteAccessVpn(long vpnServerAddressId) throws ResourceUnavailableException; RemoteAccessVpn startRemoteAccessVpn(long vpnServerAddressId, boolean openFirewall) throws ResourceUnavailableException; diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 8e8939d563a..7415e1a44bc 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -35,7 +35,8 @@ public interface NetworkOffering { public final static String SystemControlNetwork = "System-Control-Network"; public final static String SystemManagementNetwork = "System-Management-Network"; public final static String SystemStorageNetwork = "System-Storage-Network"; - + public final static String SystemPrivateGatewayNetworkOffering = "System-Private-Gateway-Network-Offering"; + public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService"; public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService"; public final static String OvsIsolatedNetworkOfferingWithSourceNatService = "OvsIsolatedNetworkOfferingWithSourceNatService"; diff --git a/awsapi.log.2012-05-30.gz b/awsapi.log.2012-05-30.gz new file mode 100644 index 0000000000000000000000000000000000000000..2f45884fddf0a648283159025233f2c0b0aa2414 GIT binary patch literal 14294 zcmbt)X&}_=-+rglsk8}UY)OSM46+oVvW6MiGGom!7;9w7-a$#$!ice)V#wZ%-B?c9 zVyNsP9LYMCvK!m~9>4SaUp+6(@9|>3-#6~L=d)a&>$>inKl1pY|NPAln?1ZFkNfA> zRGQxF@H7Yb5$Jfzp{0(BgX2E}B%r)IKO&qsgAzTrOAKFCwUawd5_41W1)>E#nHw*CddZIDBsRfh_@FFNTK@*3hh)cjMKY#9nJI8ho8At8#EF>kF z*as)W_8ta#Z3Q`7)g))^1$3Octzvn3V*9)8?$GA8x3BNR z;gyG8?jC_9y0IOf7n7Fbtrn&tefGRd9tEyVF6C@~_bX4$I9;r=wd*#zjg|7>@-E+S zTt)8KUfQ!Mzp;5!brjaEYW2;0FGYFd+@9~cRZeWiW_^j3y;slPulGmy`jaw(r5bwz z#Z=>m(w%q;^IW1WhugbyeAeLW!JP7=<|E>ITlIq#SiYT>(MO3RYpYZ$zG>U7qve-+ ziGZ@R#%AFiCD+N?3S<7+oer3Zy-PTLaWvpBm&U<&h0&88C1gzh-@)Q`{XQlo6CK~F z6%{5tr)$^MhW^TJ?}JU#Rwq`s3x+Rz+Ff=VEnVDObMy|x)rFbJM^?;-Z~YTdex1D{ zNHz%`Jerdx68M7pmmL4}Na1kb%3wu>Qf*Rav)M%7Vpiaky~?mSXUXyeO?Ct)y4qzOGV7AT`jdw#K|}%fq`n5HXyQL)9en-3-i1 zj9h73+*_V>9jKWAd4xYaL{kpDQ_{aYIo3Vax^S{YuhgfXPyLhfBj-EC+TkM|5{S`Y z_5R2J(K+{Fb4x1;n7v8T-j3SVpizDP&dT+`z%<0={wY1rvl+CdA_=RG&!cHp9VRY8 zy{@yPrw1y+ts!Ai{@cZljt+f4%*IcWzQn!jUcM3FEnmL@ReB*&V`))WXC*VW9?o}T zGfyJ)XHUxrZ^%@=_~*XGJN8sq^|8HIh*upx{^>zCOF08$E!}CaE4*5!b7IsfleZ_< z?1(q~OUy^oW!>dl%{!9jBM459dOIddhKYtMCBrT70dfC8+O3xe=l+tFU(l{Qm(xNe z>>?xiIZK9yq8kDnzpv~}RWGi-?;W3(tB~gy|5{Gd%Xgs`_mBFhya)L&*Dt^=ofTP`-yN=35l!2uk*g?Q?cBKM zE8A~P%|3sF_T#C1Y0uuQl9T0#%ilXO+Y=M$k%es)IM& zqE&3yrgGK?O_c_%jt1Xne$<0pHXPG8%U30sERFLFax$O4#A}`OGktT2Qa;KO|p<1~GrBk{W{tzA(^A6gZiT~___Ye5?J!v_A zle$tw?boZIz3=xl`D5p3=e9d8Xr%u9;Nl3;F?TP2>+$zv-f_K}+nXI7q|MsEq2Oj} z{Z{@9=2ZXl6`kL%_}4S#cX4bq%_&>_O5I*5at%IQ7wEID(>C`#XL+?YhrH(Izc%I5 zQJe3BE#8>VZ~AVx%rU^+uVOX2onJNT?X|Z?`@!tv*7Zqv&v#9gmPm7<&94>Xo0|9$ z65UseC8kU`g*(zBRBrs@%h{3m!*`T7g+Jh1|8j6)P+QD5Q;kwj+L%eq*GJ8sOTSEf zMstH5%?2M0g+7(%Ut~UFx8ol)PT78aJ*)nX|5oodjAzk}e*tEfmor-F%W1vC!Pe7P zkyV&AtW0wnnf%;~^H8|a ~od#E{P+Cxt-`iZZB3lX1Q|r^x_EII}O!PcOu1y4e z9x7br57-*sRa*+7J7P~QGB{s{606$jz&@-*6k869IlG$V z=uuZ{!?(t9C1yh#ayu8woD;j?QkhQa;*m7fB(pGyc@xx~)4ats~GaF)m`^bs8r zGO4(zk|EwL-!n2f>uL}LqLyQ>G%)&Qz^`RxtakcXhw}*Hp7rt)b;fMQLIc0J;;2@? z!=pk*a4zR>{TW)DnI$t(AJlsJ3VHtz<8LHix^jA?-RCMoc9rDD!8@}J? zxJo3;GjnD8%ka%0f>QT9yGFBgr*QW&C#Pu6a%QOkUAOvLc&S#)8C`CbWIg-6YW%Qe z5N+HfBlsnnR_eC0(0wf0Rqs+|0d{-vTV!3;u3B2v)x@ibny2eCVhSLvQctBnlA<+qPNHt(;skA(4)U11MEP`IH}x9I8=J)&8wxd4KsYE4vSw)F z?)A1Y5i}^%zkT#zw}FO0w;b|Lkiwt>Iv-gN@@Uth6f~IGM=iujIb^&B%D)-v9$HDC#`fm zPtN7RgmJ6v%~4)XghH4RIDF^E@q>im-(XE%pqvivq*mP$*2Lkl(=|(e$4PTtzh=V2 z;<^@+p*Dlj>Vg)nwgXL-BR83Ka27Hnw+2&|?a7vJwG-nf)cZ#Un`ADEp4a%a^$VxoWV>tq2FL_JP97>k?{-XUPHE*SZX;Cva zC?Fk4)A+rcdGTcvDYi370OulOdhDQ!g0Gj(KzbiFga-(M9k>7VyGD#E>-{k87>mwz zOjhvtK)qXlJR_CD%0c3N!^Cm0t?vJ*_RBc2P$s`F8)&$Uv*jbDIAoq@Rsn%SVZlp) z(gUZNFpX=|Yp;#t7D%An&Tov=$3@D>{cl;EB;Kx{no{Bgd4>6jY<*Fd=p|Gr)Ww+R zk|+B~4vMmd)l;N*C#3M~frHFKaYhgDMB!IT->Gs_6ZwTDa70v6w?oP3EgT}7-~Qq` zrH`aoVjO+T`V7{bJcPR6fyN^;XEbn#e(B>gYd2s8SIgu+7-zP4oDYGLA+@5R&>;s= z_6rB>Y=8lj0NVksC_^@3ibVAI1sw~qc!_~0BQR99Yu=zE%l5P@kOSe6P>IJ-lTNjq zgF*&B&f@su8BF;LHg*BGtm@s7qOlFp^`tu^l? zcCKFhXfgF<7!FN?lhYp9l}4Vw3EhIYaCLw1?ldwGz&#U0M<6dAmM9;^TBj8!vJ57_Y$Zh!4KQ&So@o732SMh4F}z(10Q5CQcK~u9Z`@mX zU^~-|)q-3H*nbE2+PkAVs>qf!hmLvz7KXq3jgf^l!NO`v?j+~#XKj2;sOCY(vF}B; zRg{`{**MW1wzgb!lLucW>?SA-W^ocq8I;6dH>Iq-hgE2^>G$GT8@5zdF1}Id(qRhLlQ1MMng;vt7W zZ3kN3QZ7)Gx!oAqxU((RmL~ke@5ZQ1D@jk4zv+t3=%ti$ zK*Q{VDNa>}g^_rx)2V?#bh0$+43@X0@tuo;#0kNM7+Wx~D0%lZDkc4(Qv!{oSScKR zvLr?yyjh-Ml!=04HqW4i>UoI5QdpC8ti#eWc1#)>N)WgofqVV9GHHEK}%j>+$59x z9|wRA@BXPtN+3L(IWF$Wt7Jnh!I3|d^+H21 zM-P|pnZQ0cSQ}61yM4?`4kah0VQ~VL?GPo)2p>g|oKM*)El%3DN)xOJH@HbMh->WY zvM}eN$UA%@W2+7jrN_uMDQ;94a;@{xQPhF(em@wKY#K-G(PzK~&sARSF2B_i!O+f@6T3D3GVzlF+e&7Csex2)al$D z0_UGZkv5L&{_IhYUWFB80dZ870CfZsGPGO#o|OADpt~ za-8WpFD5$WbD2^ZihSxhVM#%*7~oW+Iyo=k@*Sd78K}005fk?%1@_Zc)TNbEIeu1$ z;54JIptblg4l|pbM_?6*dfKTPhvBq=TE|U@rZ}M54kR!CGXpQtXW&X>E1+GId}4l* zq@L`18d^$z(XCT22<0>1)wE0&=sQmY`jzaEfKE7|DyEA~P|v5EtFZC=VpAWdK6$3+WW7l6x>y)1DAx#+*SVR`?ospCx3 zt|Z2Um*s_>z`UGjfH1>>h;?8{&R?J$J37An=`Ae;0A=(wUy^f|)Qnd0nF^7#+Lweo z{&%V+*x!evTRomh@%o8VIvn0aGqQCd67MOYA8GolPe9BYm_(K(T75y(MfnDw;M_Gy zQRE0h5#iimYzoBhLpp;s`=?BN%Snj-Fj3{y^RCW$nWxc@{{-jWle@O_*IXFKF9D! zKV*c@$PwpG3$=kwCutb@c3+D_4w|;CL`SxLRCx(AfS_*AUQ{U^F40r?rub4sc5LM&n$ZUrMeMUBnAUdDQ_K4@C z2u0tIQH8n`7z?g!unYMEuS%HYNs_Zv+s`3zl`_Rbpm>LnxPv!5E2&)*SNp#5j^0Vd ztTAA9SU4Xk@A3w|RiHSg`id6+paUe(oydzeH(U9w$%8#wTK8n+fyYd;4)j=Pt8O3+ zic{s5T10mK9zoF4Y_k)f3?D-+2;p)$$JJ=Q_ukP*x-osEA7O~!&_}vQ@uAJ{=z$#T z?=PMaiY(3|qJe+li^k$x?E|m)-23VkCD?v~{9FhUd*EG1Aos~a-_=lr5%6iy*Uk`S z6n5B*AxgAgC^S~L8aix#iFA`VXXA-!KQW{>9+tq)2-kx{{X>atoWQ9Ob>lw9ro-dJ z^`z517R{BC>*;mweXOPUa#NGXGk2vkE057t&xN=TsB8a2`dBIN0jWNDvyML3!!nUA z(gZ`<_-{vZ*Trx%8LV~xNCEgR3iE=7J6tUJaBuvq*Rxi zR^DF|#L?86Jtz7C93=9jo0e`xjeS8^vA`z|GZGV3sQhW6+1BS18r(BzyCrn4UV?6w zOuqcAqX|*hjSr54%U63N-j*%nG;mZ%n$iu_nN9}|#w3zcC=u8oUffROcxlwE#{I(K zsoS6g&8VVjb76)P&nM1i7M-BC{98ugN*7%v{YqQUM}X2HQ=oK|=-f>-RfDaI;xuxc z*v87lk$}AScXRL?0lzooKpx@0Zeq#4RX9PY;{>I0`r&0zdE$k~T}uU(^`L>Ys*54w zrhr&l2%rbl*-#%3=s(h}!c1iOQ8u_NT^Bs?4S#-K7h34trSDo_^1;-CN4%@ZfZmUy zhV*`9j8fA3F$%X&vGMZJ4H1Mpqm`15^mXw;_=vWo8_jg%TNM!D8d*jFkgh6 znCSru^i!5N@`%~IF*Gfoz=FsN0kC9qBYd}`z)nnv9@#XqqPyRvOCXc?00q>q+IdcpEz4IE z)Jf;?X14)`-dg814${F}rCk_Iu*RC6bub4AW3lScv^(|z0`qij$Est}D|ftD6PDzA z2;j909j`UnAT|d_RG`d(mT5zn0eKg7os}3xm;9do=XBDPiKf`G7FZG(KUFcrFe$*~ zLu~jMGT#7lToD!rfT{on0jrLoPEwuwSg&%E^s0fZMBeQx;JQO>m~7~_9;M*j!HcA- z(L?f8oX>;rCnG0BPsejvG7I5EvrcNTq>khx^Il1es3{b2LUH+!Ko)==Hqnd-5CBVV zl0o|i0`!q9b^7n>)d~_PQKsBm<7*yZPW@8%)SqEEqYa}NVNUcMRyq!XNj^3%^^5=~ z10r_Z4uG91)DWh?*Yji@0JK8$-N&F8v2~n`u+&)OnWKhPB9Xw;n{0Ifq0k^$!7p;x zn-FC>LXu}x#ZW+Y;3NS!!DSd?dqQB(M)B$F-df|x#;$wVSa$uzhkQCFl%5xy8r8s) zeWss$xDnWp^Wq23-80O2qB&PoqF)>Ode&>;+Ys^-i^|xWW6B%tBM6Qr6q$SM|C2gR zHahxo#K>YXWKiI->+6y;vxp<_QcujQEOE6|10^3(K7lA05B z=BQ0WLaT>XrUy91XzOod%3ssPiONWGM~S=w8EmEt$EUv52R|IS`Vt(*xeqRXID@st z^*6l0yoC$qt^ULY?wT{gM-g=ZX$Dv*V;uM){d`$T1@Uv#EK1Qevov{~84W|kLf5FK2SmgOA zXmpXWpeM}+oLwtM5R9=ZEQwsFGmo7GW~4D_aZNUc$QZp&emU{rvyp39WFRjZ>!oly z;-7UWPH0Dt4Qm5Kf$5UDKgUaNF)$RbJ_q4eUJS^C!NA0og4F=#k%nzXYAgb_^hu5q ztZlJW@GdYaI|^kDxDtb)WG|@=4-f#PdiBR^Lk^upxxY=ZEQJG^$h-x1wN!$`h?(m_ynn<@0^XPw-?wBDVG0Ge)w<-)JTIl3xX$=2|A@!%XBw!-Vff*MgO|Mk#Tgtn>Lz#$+79Hr{_Y+}SnhcF84;6y&maPLzbP0EZ7eM@3ezP~Y|GBkS`4TVq3+;&+)WR=`nG^X;R+-iLsr-veVJJ&Qb187sE| zf6(Xu9d&Q!XR7z{F;Q~yE!=`y^Wf7#T93}_lPK5b$`NH|K^#w~k=@GSOdkE(y|e=H z`&;V9SkIt%f5Y}iZ^OF@^rM4*^;zw}}95Q58TCd{blM;a+oKVRCrO(Mmfui5*n z2-y-X`zwtESIwQtxH25^a^CYNLQU2$=UZjR!`)@7`rsRhy7{+MyIK8sub^EpE}uy$A-Rg^@tX9x7v^_s%*EA< zm0pZdqc%23bd%>U{c7MNcXc9}Fp;&}Bfw(Y)vb>aic%h249e#B>-1|&8l}p#OPL4d zc&5Cug|*YnxcoO=ycK+T49Qm#crBm-kJCu8`s_dPkNBefKQZHeDPl$`e*GDfhylWD z%!n1su^|y~@4)X9qN>3SO>j(H3lz`0M)Up}xtNd-sfAkS@V>cIA0bkhQ<~o8r%h$> zLy-hE`1sH7($zNX-xN{h(to=I! z?|@h~=H@90MdVxbX!UAEV= ztbM@!(EB7AWxm(yl9@?Tf#*>vcNN9H(G11nK(nQZ(@kbkK1Q}qZwg)ZZ2BdsG2}<- zzC6~!TyUOPHk0({Gtv)zz)i4DgzmLWmi;G!@ zg5g!|IWYo##nsF_5kQB`X#knVGWx`q2fpm^3?o70J=J{Akb@!+-NpyD>ZvOp`XGC7 zs`OovyJe30@l4M48%I#yQX0lbQRSU#PK*o^`mGh+k4}LwJ)8)*UXrSeYGxDc?zhkp z@qC9d{caaUWqQJliQwsk@Vq;?pljsCRbnM?!TVT&#NBm(c51wyn|6;-WDcIIW-2>* z@#|e_u;1#?VkzJ=C9pG+$yhoC1}9Sz``+6noy@NH8q<{(vO;9bl(Oqjyq+MwR&&{S z{bVwef8#EFaCht?j()4;6%*J}vPPnObZ7*jw=Cvjw#u3at}ko(@w@6D;Jyis!!;h*J(q{Oe@@d$c?)V!&A&$$_S&98~4o#DzvuvdIQ|ZE;PB z=xLUzKlp=_LZOy=L8;lT>#iN(e)=n`w4JKWKbK>LMM}srTD9VPpC>wu{oSzn*qAvX zn73uMY_FwWt;53>Is38w3&m}dVtHHDfx|Q1#nfuzQ1#3U(I#m(l+$#f zVUb&S4vgP>X}4R6HeG0suSq*nvidu|Oc*~hS64UfH>;fTxjKhdvOaUnvMYn8d?9=I zWH)v(NLi+G6Uk{)w)*3`o2zn`>Sq4f?;AmDPCh#5%9(G$IUQ`l76C~ylSxw@9g8`m zUo5`N%u6lyjkWl7dQjzLvXjUwA7hg!^1+U~+HTbwwC^^xA|tl9>w5c4 zpYqY_s)95s+?|LYGG{|3aU-F9{KniyK~CGTrqx>y#CrS22R;=#Z{OR}dVQG)j1J#rx+!?*e}B1=&-&N(p&H99{;&LX-P;p^ z!He^k`Gh$Z5xZZ^wR$qVxxXYZ_1ro-(D0ETVL1#%1f}OB)w-l_P3^$;oOd%!e{=lf z2b+;z;op1AWrug*?}Z1uyIl7iGX~P1_r`Dq7u3$L{+`5XFQzi%Rx}FToywS`j3Ku6 z((B1Q+qsLgCDh2`Ag9HR3}wHE^{?GlpUj<`46wR$H#a=-2(xn!+`D}881~WCRqYTV zzOzAu*x;}>)0O|~ zC8j*#J|^?i57`Y)2|-BLgZPYuzw}!Ax=wOx=yCpxy2E4ulW47iFy6kM4FGp?<`1w8Yh-#E2``tVL;HxfXoijN4Uq$r) z=OHAs@G``?XI8|7^%T}<5`^|P%?p*Ujdb%VxU9wBuwf8#R}tkT{${BO$9hW2(d?$k z`?GM&|Gkp_D$&1`)$a5YX09!n^*R>q8=4SPL}1e}@lQ>-AanKlTkUJP+C`VAZ3^1n uUY>qKjQKBX=iguY&nq!{3HdVZPKYs8%e={O6nww;JKsnr>CfiVhyEY#&3YXG literal 0 HcmV?d00001 diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 6601d712d23..ad7fcda55c9 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -352,3 +352,7 @@ createVPCGateway=com.cloud.api.commands.CreateVPCGatewayCmd;15 listVPCGateways=com.cloud.api.commands.ListVPCGatewaysCmd;15 deleteVPCGateway=com.cloud.api.commands.DeleteVPCGatewayCmd;15 +#### Private network command +createPrivateNetwork=com.cloud.api.commands.CreatePrivateNetworkCmd;1 +deletePrivateNetwork=com.cloud.api.commands.CreatePrivateNetworkCmd;1 + diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 5a5bcac3e6e..8202d70e4bf 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -78,6 +78,7 @@ + diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 7b03dd15144..463d68ebb07 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -41,9 +41,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { @Column(name="public_netmask") private String publicNetmask; - - @Column(name="guest_ip_address") - private String guestIpAddress; @Column(name="is_redundant_router") boolean isRedundantRouter; @@ -140,10 +137,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { public void setPublicNetmask(String publicNetmask) { this.publicNetmask = publicNetmask; } - - public void setGuestIpAddress(String routerIpAddress) { - this.guestIpAddress = routerIpAddress; - } @Override public long getDataCenterIdToDeployIn() { @@ -158,11 +151,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { return publicMacAddress; } - @Override - public String getGuestIpAddress() { - return guestIpAddress; - } - protected DomainRouterVO() { super(); } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 16c8e514756..473c6fd9337 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1608,6 +1608,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } else { continue; } + } else if (offering.getTrafficType() == TrafficType.Guest) { + continue; } userNetwork.setBroadcastDomainType(broadcastDomainType); diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 7a2c5b2c5b3..b3048730716 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -123,6 +123,7 @@ import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl; import com.cloud.network.security.dao.SecurityGroupWorkDaoImpl; import com.cloud.network.security.dao.VmRulesetLogDaoImpl; import com.cloud.network.vpc.VpcManagerImpl; +import com.cloud.network.vpc.Dao.PrivateIpDaoImpl; import com.cloud.network.vpc.Dao.VpcDaoImpl; import com.cloud.network.vpc.Dao.VpcOfferingDaoImpl; import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDaoImpl; @@ -335,6 +336,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("VpcDao", VpcDaoImpl.class); addDao("VpcOfferingDao", VpcOfferingDaoImpl.class); addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class); + addDao("PrivateIpDao", PrivateIpDaoImpl.class); } @Override diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index c6c877051ba..265f7f9388f 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -415,4 +415,12 @@ public interface NetworkManager extends NetworkService { */ void unassignIPFromVpcNetwork(long ipId); + + /** + * @param vm + * @param networkId + * @return + */ + NicProfile getNicProfile(VirtualMachine vm, long networkId); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 13ba9721037..104d35c6cac 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -55,12 +55,10 @@ import com.cloud.api.commands.CreateNetworkCmd; import com.cloud.api.commands.ListNetworksCmd; import com.cloud.api.commands.ListTrafficTypeImplementorsCmd; import com.cloud.api.commands.RestartNetworkCmd; -import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.configuration.dao.ResourceLimitDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; @@ -133,6 +131,7 @@ import com.cloud.network.element.SourceNatServiceProvider; import com.cloud.network.element.StaticNatServiceProvider; import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.element.VirtualRouterElement; +import com.cloud.network.element.VpcVirtualRouterElement; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.lb.LoadBalancingRule.LbDestination; @@ -149,8 +148,10 @@ import com.cloud.network.rules.StaticNat; import com.cloud.network.rules.StaticNatRule; import com.cloud.network.rules.StaticNatRuleImpl; import com.cloud.network.rules.dao.PortForwardingRulesDao; +import com.cloud.network.vpc.PrivateIpVO; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcManager; +import com.cloud.network.vpc.Dao.PrivateIpDao; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; @@ -301,6 +302,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag StorageNetworkManager _stnwMgr; @Inject VpcManager _vpcMgr; + @Inject + PrivateIpDao _privateIpDao; private final HashMap _systemNetworks = new HashMap(5); @@ -1326,6 +1329,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, true); storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemStorageNetwork, storageNetworkOffering); + NetworkOfferingVO privateGatewayNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPrivateGatewayNetworkOffering, + GuestType.Isolated); + privateGatewayNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(privateGatewayNetworkOffering); + _systemNetworks.put(NetworkOfferingVO.SystemPrivateGatewayNetworkOffering, privateGatewayNetworkOffering); + // populate providers Map> defaultSharedNetworkOfferingProviders = new HashMap>(); @@ -1346,7 +1354,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sgProviders.add(Provider.SecurityGroupProvider); defaultSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, sgProviders); - Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap>(); + Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = + new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders); @@ -1627,7 +1636,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (errorIfAlreadySetup) { throw new InvalidParameterValueException("Found existing network configuration for offering " - + offering + ": " + configs.get(0)); + + offering + ": " + configs.get(0)); } else { return configs; } @@ -2259,6 +2268,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return profiles; } + + @Override + public NicProfile getNicProfile(VirtualMachine vm, long networkId) { + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId()); + NetworkVO network = _networksDao.findById(networkId); + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); + + NetworkGuru guru = _networkGurus.get(network.getGuruName()); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); + guru.updateNicProfile(profile, network); + + return profile; + } @Override @DB @@ -3268,7 +3291,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // don't allow to delete system network - if (isNetworkSystem(network)) { + if (isNetworkSystem(network) && network.getTrafficType() != TrafficType.Guest) { throw new InvalidParameterValueException("Network " + network + " is system and can't be removed"); } @@ -3479,14 +3502,26 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return success; } - private boolean deleteVlansInNetwork(long networkId, long userId, Account callerAccount) { - List vlans = _vlanDao.listVlansByNetworkId(networkId); + protected boolean deleteVlansInNetwork(long networkId, long userId, Account callerAccount) { + + //cleanup Public vlans + List publicVlans = _vlanDao.listVlansByNetworkId(networkId); boolean result = true; - for (VlanVO vlan : vlans) { + for (VlanVO vlan : publicVlans) { if (!_configMgr.deleteVlanAndPublicIpRange(_accountMgr.getSystemUser().getId(), vlan.getId(), callerAccount)) { s_logger.warn("Failed to delete vlan " + vlan.getId() + ");"); result = false; } + } + + //cleanup private vlans + int privateIpAllocCount = _privateIpDao.countAllocatedByNetworkId(networkId); + if (privateIpAllocCount > 0) { + s_logger.warn("Can't delete Private ip range for network " + networkId + " as it has allocated ip addresses"); + result = false; + } else { + _privateIpDao.deleteByNetworkId(networkId); + s_logger.debug("Deleted ip range for private network id=" + networkId); } return result; } @@ -4942,7 +4977,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_CREATE, eventDescription = "Creating Physical Network", create = true) - public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List isolationMethods, String broadcastDomainRangeStr, Long domainId, List tags, String name) { + public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List + isolationMethods, String broadcastDomainRangeStr, Long domainId, List tags, String name) { // Check if zone exists if (zoneId == null) { @@ -6410,6 +6446,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.VPCVirtualRouter.getName(), null, null); + // add instance of the provider + VpcVirtualRouterElement element = (VpcVirtualRouterElement) getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName()); + if (element == null) { + throw new CloudRuntimeException("Unable to find the Network Element implementing the VPCVirtualRouter Provider"); + } + element.addElement(nsp.getId()); return nsp; } @@ -6852,7 +6894,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public boolean isVmPartOfNetwork(long vmId, long ntwkId) { - if (_nicDao.findByInstanceIdAndNetworkId(ntwkId, vmId) != null) { + if (_nicDao.findNonReleasedByInstanceIdAndNetworkId(ntwkId, vmId) != null) { return true; } return false; @@ -6887,5 +6929,63 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _ipAddressDao.update(ipId, ip); s_logger.debug("IP address " + ip + " is no longer associated with the network inside vpc id=" + vpcId); } + + @Override @DB + public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, + String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId) + throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { + + Account owner = _accountMgr.getAccount(networkOwnerId); + + // Get system network offeirng + NetworkOfferingVO ntwkOff = _systemNetworks.get(NetworkOffering.SystemPrivateGatewayNetworkOffering); + + + // Validate physical network + PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId); + if (pNtwk == null) { + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network" + + " having the given id"); + ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId"); + throw ex; + } + + // VALIDATE IP INFO + // if end ip is not specified, default it to startIp + if (!NetUtils.isValidIp(startIp)) { + throw new InvalidParameterValueException("Invalid format for the startIp parameter"); + } + if (endIp == null) { + endIp = startIp; + } else if (!NetUtils.isValidIp(endIp)) { + throw new InvalidParameterValueException("Invalid format for the endIp parameter"); + } + + String cidr = null; + if (!NetUtils.isValidIp(gateway)) { + throw new InvalidParameterValueException("Invalid gateway"); + } + if (!NetUtils.isValidNetmask(netmask)) { + throw new InvalidParameterValueException("Invalid netmask"); + } + + cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); + + + Transaction txn = Transaction.currentTxn(); + txn.start(); + //create Guest network + Network privateNetwork = createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan, + null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null); + + //add entry to private_ip_address table + PrivateIpVO privateIp = new PrivateIpVO(startIp, privateNetwork.getId()); + _privateIpDao.persist(privateIp); + + txn.commit(); + s_logger.debug("Private network " + privateNetwork + " is created"); + + return privateNetwork; + } } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index f5a18fdecf5..a642cd6bfef 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -54,6 +54,7 @@ import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; +import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.LbStickinessMethod; @@ -161,10 +162,26 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), params, + List routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, + _accountMgr.getAccount(network.getAccountId()), params, offering.getRedundantRouter()); - - return true; + if ((routers == null) || (routers.size() == 0)) { + throw new ResourceUnavailableException("Can't find at least one running router!", + DataCenter.class, network.getDataCenterId()); + } + + boolean success = true; + for (VirtualRouter router : routers) { + //Add router to guest network + success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router router " + router); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); + } + } + + return success; } @Override @@ -196,7 +213,19 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); } - return true; + + boolean success = true; + for (VirtualRouter router : routers) { + //Add router to guest network + success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); + } + } + + return success; } @Override diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 4f352c86cd7..738b663aaf0 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -35,7 +35,6 @@ import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcService; -import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Inject; import com.cloud.vm.DomainRouterVO; @@ -53,8 +52,6 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc @Inject NetworkService _ntwkService; @Inject - VpcVirtualNetworkApplianceService _vpcElementService; - @Inject VpcService _vpcService; @@ -116,13 +113,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc boolean success = true; for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; - } - //2) Call plugNics in the network service - success = success && _vpcElementService.addVmToNetwork(router, network); + //Add router to guest network + success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); } if (!success) { @@ -131,7 +123,6 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); } - return success; } @@ -155,7 +146,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); + List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, + _accountMgr.getAccount(vpc.getAccountId()), params); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); @@ -163,21 +155,14 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc boolean success = true; for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); - continue; + //2) Add router to guest network + success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); + if (!success) { + s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router); + } else { + s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); } - //2) Call plugNics in the network service - success = success && _vpcElementService.addVmToNetwork(router, network); } - - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - return success; } @@ -200,13 +185,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc continue; } //2) Call unplugNics in the network service - success = success && _vpcElementService.removeVmFromNetwork(router, network); - } - - if (!success) { - s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId); + success = success && _vpcRouterMgr.removeRouterFromGuestNetwork(router, network, false); + if (!success) { + s_logger.warn("Failed to unplug nic in network " + network + " for virtual router " + router); + } else { + s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router " + router); + } } return success; @@ -229,13 +213,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc continue; } //2) Call unplugNics in the network service - success = success && _vpcElementService.removeVmFromNetwork(router, config); - } - - if (!success) { - s_logger.warn("Failed to unplug nic in network " + config + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router in vpc id=" + vpcId); + success = success && _vpcRouterMgr.removeRouterFromGuestNetwork(router, config, false); + if (!success) { + s_logger.warn("Failed to unplug nic in network " + config + " for virtual router " + router); + } else { + s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router " + router); + } } return success; @@ -260,5 +243,29 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc public Map> getCapabilities() { return capabilities; } + + @Override + public boolean createPrivateGateway() { + //TODO - add implementation here + return true; + } + + @Override + public boolean createVpnGateway() { + //TODO - add implementation here + return true; + } + + @Override + public boolean deletePrivateGateway() { + //TODO - add implementation here + return true; + } + + @Override + public boolean deleteVpnGateway() { + //TODO - add implementation here + return true; + } } diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index 3407e329dec..cb6f045bc68 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -115,10 +115,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { protected boolean canHandle(NetworkOffering offering, DataCenter dc) { // This guru handles only Guest Isolated network that supports Source nat service if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) - && offering.getGuestType() == Network.GuestType.Isolated) { + && offering.getGuestType() == Network.GuestType.Isolated && !offering.isSystemOnly()) { return true; } else { - s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); + s_logger.trace("We only take care of non-system Guest networks of type " + GuestType.Isolated + " in zone of type " + + NetworkType.Advanced); return false; } } diff --git a/server/src/com/cloud/network/guru/PrivateNetworkGuru.java b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java new file mode 100644 index 00000000000..27c05981a6d --- /dev/null +++ b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java @@ -0,0 +1,215 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.guru; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.configuration.ConfigurationManager; +import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.Network; +import com.cloud.network.Network.GuestType; +import com.cloud.network.Network.State; +import com.cloud.network.NetworkProfile; +import com.cloud.network.NetworkVO; +import com.cloud.network.Networks.BroadcastDomainType; +import com.cloud.network.Networks.Mode; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.vpc.PrivateIpVO; +import com.cloud.network.vpc.Dao.PrivateIpDao; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.NetUtils; +import com.cloud.vm.Nic.ReservationStrategy; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; + +@Local(value = NetworkGuru.class) +public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru { + private static final Logger s_logger = Logger.getLogger(PrivateNetworkGuru.class); + @Inject + protected ConfigurationManager _configMgr; + @Inject + protected PrivateIpDao _privateIpDao; + + private static final TrafficType[] _trafficTypes = {TrafficType.Guest}; + + protected PrivateNetworkGuru() { + super(); + } + + @Override + public boolean isMyTrafficType(TrafficType type) { + for (TrafficType t : _trafficTypes) { + if (t == type) { + return true; + } + } + return false; + } + + @Override + public TrafficType[] getSupportedTrafficType() { + return _trafficTypes; + } + + protected boolean canHandle(NetworkOffering offering, DataCenter dc) { + // This guru handles only system Guest network + if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) + && offering.getGuestType() == Network.GuestType.Isolated && offering.isSystemOnly()) { + return true; + } else { + s_logger.trace("We only take care of system Guest networks of type " + GuestType.Isolated + " in zone of type " + + NetworkType.Advanced); + return false; + } + } + + @Override + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + DataCenter dc = _configMgr.getZone(plan.getDataCenterId()); + if (!canHandle(offering, dc)) { + return null; + } + + NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), + State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId()); + if (userSpecified != null) { + if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || + (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) { + throw new InvalidParameterValueException("cidr and gateway must be specified together."); + } + + if (userSpecified.getCidr() != null) { + network.setCidr(userSpecified.getCidr()); + network.setGateway(userSpecified.getGateway()); + } else { + String guestNetworkCidr = dc.getGuestNetworkCidr(); + if (guestNetworkCidr != null) { + String[] cidrTuple = guestNetworkCidr.split("\\/"); + network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]))); + network.setCidr(guestNetworkCidr); + } else if (dc.getNetworkType() == NetworkType.Advanced) { + throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc); + } + } + + if (offering.getSpecifyVlan()) { + network.setBroadcastUri(userSpecified.getBroadcastUri()); + network.setState(State.Setup); + } + } else { + throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway must be passed in"); + + } + + return network; + } + + @Override + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); + } + + PrivateIpVO ip = _privateIpDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address()); + if (ip != null) { + _privateIpDao.releaseIpAddress(nic.getIp4Address(), nic.getNetworkId()); + } + nic.deallocate(); + } + + + @Override + public Network implement(Network network, NetworkOffering offering, DeployDestination dest, + ReservationContext context) throws InsufficientVirtualNetworkCapcityException { + + return network; + } + + @Override + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); + if (!canHandle(offering, dc)) { + return null; + } + + if (nic == null) { + nic = new NicProfile(ReservationStrategy.Create, null, null, null, null); + } else if (nic.getIp4Address() == null) { + nic.setStrategy(ReservationStrategy.Start); + } else { + nic.setStrategy(ReservationStrategy.Create); + } + + _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId()); + nic.setStrategy(ReservationStrategy.Create); + + return nic; + } + + @Override + public void updateNicProfile(NicProfile profile, Network network) { + DataCenter dc = _configMgr.getZone(network.getDataCenterId()); + if (profile != null) { + profile.setDns1(dc.getDns1()); + profile.setDns2(dc.getDns2()); + } + } + + @Override + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { + if (nic.getIp4Address() == null) { + _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId()); + nic.setStrategy(ReservationStrategy.Create); + } + } + + @Override + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + return true; + } + + @Override + public void shutdown(NetworkProfile profile, NetworkOffering offering) { + + } + + @Override + public boolean trash(Network network, NetworkOffering offering, Account owner) { + return true; + } + + @Override + public void updateNetworkProfile(NetworkProfile networkProfile) { + DataCenter dc = _configMgr.getZone(networkProfile.getDataCenterId()); + networkProfile.setDns1(dc.getDns1()); + networkProfile.setDns2(dc.getDns2()); + } +} diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java index d26493872cd..d094445c2f8 100755 --- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java @@ -132,7 +132,8 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(network.getDataCenterId()); @@ -172,7 +173,8 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException { + public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) + throws InsufficientVirtualNetworkCapcityException { return network; } diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index cf88fcd5b80..17b4050c006 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -130,6 +130,7 @@ import com.cloud.vm.VirtualMachineName; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile.Param; import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.NicDao; @Local(value = { ElasticLoadBalancerManager.class }) public class ElasticLoadBalancerManagerImpl implements @@ -187,6 +188,8 @@ public class ElasticLoadBalancerManagerImpl implements PhysicalNetworkServiceProviderDao _physicalProviderDao; @Inject VirtualRouterProviderDao _vrProviderDao; + @Inject + NicDao _nicDao; String _name; @@ -276,7 +279,7 @@ public class ElasticLoadBalancerManagerImpl implements } private void createApplyLoadBalancingRulesCommands( - List rules, DomainRouterVO elbVm, Commands cmds) { + List rules, DomainRouterVO elbVm, Commands cmds, long guestNetworkId) { LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()]; @@ -295,7 +298,8 @@ public class ElasticLoadBalancerManagerImpl implements lbs[i++] = lb; } - LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,elbVm.getPublicIpAddress(),elbVm.getGuestIpAddress(),elbVm.getPrivateIpAddress()); + LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,elbVm.getPublicIpAddress(), + _nicDao.getIpAddress(guestNetworkId, elbVm.getId()),elbVm.getPrivateIpAddress()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, elbVm.getPrivateIpAddress()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, @@ -312,9 +316,9 @@ public class ElasticLoadBalancerManagerImpl implements } protected boolean applyLBRules(DomainRouterVO elbVm, - List rules) throws ResourceUnavailableException { + List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createApplyLoadBalancingRulesCommands(rules, elbVm, cmds); + createApplyLoadBalancingRulesCommands(rules, elbVm, cmds, guestNetworkId); // Send commands to elbVm return sendCommandsToRouter(elbVm, cmds); } @@ -359,7 +363,7 @@ public class ElasticLoadBalancerManagerImpl implements lb, dstList, policyList); lbRules.add(loadBalancing); } - return applyLBRules(elbVm, lbRules); + return applyLBRules(elbVm, lbRules, network.getId()); } else if (elbVm.getState() == State.Stopped || elbVm.getState() == State.Stopping) { s_logger.debug("ELB VM is in " @@ -889,8 +893,6 @@ public class ElasticLoadBalancerManagerImpl implements elbVm.setPublicIpAddress(nic.getIp4Address()); elbVm.setPublicNetmask(nic.getNetmask()); elbVm.setPublicMacAddress(nic.getMacAddress()); - } else if (nic.getTrafficType() == TrafficType.Guest) { - elbVm.setGuestIpAddress(nic.getIp4Address()); } else if (nic.getTrafficType() == TrafficType.Control) { elbVm.setPrivateIpAddress(nic.getIp4Address()); elbVm.setPrivateMacAddress(nic.getMacAddress()); @@ -921,6 +923,7 @@ public class ElasticLoadBalancerManagerImpl implements DataCenterVO dcVo = _dcDao.findById(elbVm.getDataCenterIdToDeployIn()); NicProfile controlNic = null; + Long guestNetworkId = null; if(profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) { // TODO this is a ugly to test hypervisor type here @@ -928,12 +931,15 @@ public class ElasticLoadBalancerManagerImpl implements for (NicProfile nic : profile.getNics()) { if (nic.getTrafficType() == TrafficType.Guest && nic.getIp4Address() != null) { controlNic = nic; + guestNetworkId = nic.getNetworkId(); } } } else { for (NicProfile nic : profile.getNics()) { if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { controlNic = nic; + } else if (nic.getTrafficType() == TrafficType.Guest) { + guestNetworkId = nic.getNetworkId(); } } } @@ -957,7 +963,7 @@ public class ElasticLoadBalancerManagerImpl implements s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of ELB vm " + elbVm + " start."); if (!lbRules.isEmpty()) { - createApplyLoadBalancingRulesCommands(lbRules, elbVm, cmds); + createApplyLoadBalancingRulesCommands(lbRules, elbVm, cmds, guestNetworkId); } return true; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 116f0df5168..a51d6c39747 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -48,9 +48,15 @@ import com.cloud.agent.api.GetDomRVersionCmd; import com.cloud.agent.api.ModifySshKeysCommand; import com.cloud.agent.api.NetworkUsageAnswer; import com.cloud.agent.api.NetworkUsageCommand; +import com.cloud.agent.api.PlugNicAnswer; +import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.RebootAnswer; +import com.cloud.agent.api.SetupGuestNetworkAnswer; +import com.cloud.agent.api.SetupGuestNetworkCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StopAnswer; +import com.cloud.agent.api.UnPlugNicAnswer; +import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; @@ -121,8 +127,6 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; -import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PublicIpAddress; @@ -196,6 +200,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; @@ -709,11 +714,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, - String vmInstanceName, long vmId, String publicKey) { + String vmInstanceName, long vmId, String publicKey, long guestNetworkId) { VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); @@ -1256,10 +1261,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //3) Deploy Virtual Router(s) try { int count = routerCount - routers.size(); - PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); for (int i = 0; i < count; i++) { - DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, controlNetwork, guestNetwork, isRedundant, - vrProvider, offeringId, sourceNatIp, null); + DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, + null); routers.add(router); } } finally { @@ -1271,8 +1275,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, - boolean setupPublicNetwork, boolean setupControlNetwork, Network guestNetwork, boolean isRedundant, - VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp, Long vpcId) throws ConcurrentOperationException, + boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, + Long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1280,9 +1284,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (s_logger.isDebugEnabled()) { s_logger.debug("Creating the router " + id + " in datacenter " + dest.getDataCenter()); } - - List> networks = createRouterNetworks(owner, setupPublicNetwork, setupControlNetwork, guestNetwork, - isRedundant, plan, sourceNatIp); + + //1) Create router control network + List> networks = createRouterControlNetwork(owner, isRedundant, plan); ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); @@ -1357,7 +1361,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian break; } catch (InsufficientCapacityException ex) { if (startRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", destroying it and recreating one more time"); + s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", " + + "destroying it and recreating one more time"); //destroy the router destroyRouter(router.getId()); continue; @@ -1367,82 +1372,24 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } finally { startRetry++; } - } + } + + //3) Plug public nic + return router; } - protected List> createRouterNetworks(Account owner, boolean setupPublicNetwork, boolean setupControlNetwork, - Network guestNetwork, boolean isRedundant, DeploymentPlan plan, PublicIp sourceNatIp) throws ConcurrentOperationException, + protected List> createRouterControlNetwork(Account owner, boolean isRedundant, + DeploymentPlan plan) throws ConcurrentOperationException, InsufficientAddressCapacityException { - //Form networks - List> networks = new ArrayList>(3); + //Form control network + List> networks = new ArrayList>(1); - - //1) Control network - if (setupControlNetwork) { - s_logger.debug("Adding nic for Virtual Router in Control network "); - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - networks.add(new Pair(controlConfig, null)); - } - - //2) Guest network - boolean hasGuestNetwork = false; - if (guestNetwork != null) { - s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); - String defaultNetworkStartIp = null; - if (guestNetwork.getCidr() != null && !setupPublicNetwork) { - String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); - if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { - defaultNetworkStartIp = startIp; - } else if (s_logger.isDebugEnabled()){ - s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + - " is already allocated, can't use it for domain router; will get random ip address from the range"); - } - } - - NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); - if (setupPublicNetwork) { - if (isRedundant) { - gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null)); - } else { - gatewayNic.setIp4Address(guestNetwork.getGateway()); - } - gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri()); - gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); - gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri()); - gatewayNic.setMode(guestNetwork.getMode()); - String gatewayCidr = guestNetwork.getCidr(); - gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); - } else { - gatewayNic.setDefaultNic(true); - } - networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); - hasGuestNetwork = true; - } - - //3) Public network - if (setupPublicNetwork) { - s_logger.debug("Adding nic for Virtual Router in Public network "); - //if source nat service is supported by the network, get the source nat ip address - NicProfile defaultNic = new NicProfile(); - defaultNic.setDefaultNic(true); - defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); - defaultNic.setGateway(sourceNatIp.getGateway()); - defaultNic.setNetmask(sourceNatIp.getNetmask()); - defaultNic.setMacAddress(sourceNatIp.getMacAddress()); - defaultNic.setBroadcastType(BroadcastDomainType.Vlan); - defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - if (hasGuestNetwork) { - defaultNic.setDeviceId(2); - } - NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); - networks.add(new Pair(publicNetworks.get(0), defaultNic)); - } - + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + s_logger.debug("Adding nic for Virtual Router in Control network "); + networks.add(new Pair(controlConfig, null)); return networks; } @@ -1543,7 +1490,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian Map params, boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - List routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params); + List routers = findOrDeployVirtualRouterInGuestNetwork + (guestNetwork, dest, owner, isRedundant, params); return startRouters(params, routers); } @@ -1581,8 +1529,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - boolean dnsProvided = true; - boolean dhcpProvided = true; DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); _dcDao.loadDetails(dc); @@ -1591,7 +1537,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian Map details = _vmDetailsDao.findDetails(router.getId()); router.setDetails(details); - //2) Prepare boot loader elements related with Public/Control networks + //2) Prepare boot loader elements related with Control network StringBuilder buf = profile.getBootArgsBuilder(); buf.append(" template=domP"); @@ -1604,7 +1550,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile controlNic = null; String defaultDns1 = null; String defaultDns2 = null; - boolean publicNetwork = false; for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); @@ -1641,13 +1586,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" localgw=").append(dest.getPod().getGateway()); } } - } else if (nic.getTrafficType() == TrafficType.Guest) { - dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); - //build bootloader parameter for the guest - buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router)); - } else if (nic.getTrafficType() == TrafficType.Public) { - publicNetwork = true; } } @@ -1663,14 +1601,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } String rpFilter = " "; - String type = null; - if (!publicNetwork) { - type = "dhcpsrvr"; - } else { - type = "router"; - if (_disable_rp_filter) { - rpFilter=" disable_rp_filter=true"; - } + String type = "router"; + if (_disable_rp_filter) { + rpFilter=" disable_rp_filter=true"; } buf.append(" type=" + type + rpFilter); @@ -1684,26 +1617,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" extra_pubnics=" + _routerExtraPublicNics); } - - /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response - * to return DNS server rather than - * virtual router itself. */ - if (dnsProvided || dhcpProvided) { + if (defaultDns1 != null) { buf.append(" dns1=").append(defaultDns1); - if (defaultDns2 != null) { - buf.append(" dns2=").append(defaultDns2); - } + } + + if (defaultDns2 != null) { + buf.append(" dns2=").append(defaultDns2); + } - boolean useExtDns = !dnsProvided; - /* For backward compatibility */ - String use_external_dns = _configDao.getValue(Config.UseExternalDnsServers.key()); - if (use_external_dns != null && use_external_dns.equals("true")) { - useExtDns = true; - } + boolean useExtDns = false; + /* For backward compatibility */ + String use_external_dns = _configDao.getValue(Config.UseExternalDnsServers.key()); + if (use_external_dns != null && use_external_dns.equals("true")) { + useExtDns = true; + } - if (useExtDns) { - buf.append(" useextdns=true"); - } + if (useExtDns) { + buf.append(" useextdns=true"); } if (s_logger.isDebugEnabled()) { @@ -1712,66 +1642,28 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } - - protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, - String defaultDns2, DomainRouterVO router) { - long guestNetworkId = guestNic.getNetworkId(); - NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + + protected String getGuestDhcpRange(NicProfile guestNic, Network guestNetwork, DataCenter dc) { String dhcpRange = null; - DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); - - StringBuilder buf = new StringBuilder(); - - boolean isRedundant = router.getIsRedundantRouter(); - if (isRedundant) { - buf.append(" redundant_router=1"); - List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); - try { - int priority = getUpdatedPriority(guestNetwork, routers, router); - router.setPriority(priority); - } catch (InsufficientVirtualNetworkCapcityException e) { - s_logger.error("Failed to get update priority!", e); - throw new CloudRuntimeException("Failed to get update priority!"); - } - Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); - buf.append(" guestgw=").append(net.getGateway()); - String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); - buf.append(" guestbrd=").append(brd); - buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); - buf.append(" router_pr=").append(router.getPriority()); - } - - //setup network domain - String domain = guestNetwork.getNetworkDomain(); - if (domain != null) { - buf.append(" domain=" + domain); - } - //setup dhcp range if (dc.getNetworkType() == NetworkType.Basic) { - if (guestNic.isDefaultNic()) { - long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); - String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); - if (cidr != null) { - dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); - } - } + long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); + if (cidr != null) { + dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); + } } else if (dc.getNetworkType() == NetworkType.Advanced) { String cidr = guestNetwork.getCidr(); if (cidr != null) { dhcpRange = NetUtils.getDhcpRange(cidr); } } - - if (dhcpRange != null) { - buf.append(" dhcprange=" + dhcpRange); - } - - return buf; + return dhcpRange; } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, + DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { DomainRouterVO router = profile.getVirtualMachine(); List nics = profile.getNics(); @@ -1780,8 +1672,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router.setPublicIpAddress(nic.getIp4Address()); router.setPublicNetmask(nic.getNetmask()); router.setPublicMacAddress(nic.getMacAddress()); - } else if (nic.getTrafficType() == TrafficType.Guest) { - router.setGuestIpAddress(nic.getIp4Address()); } else if (nic.getTrafficType() == TrafficType.Control) { router.setPrivateIpAddress(nic.getIp4Address()); router.setPrivateMacAddress(nic.getMacAddress()); @@ -1915,19 +1805,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Re-apply static nats s_logger.debug("Found " + staticNats.size() + " static nat(s) to apply as a part of domR " + router + " start."); if (!staticNats.isEmpty()) { - createApplyStaticNatCommands(staticNats, router, cmds); + createApplyStaticNatCommands(staticNats, router, cmds, guestNetworkId); } //Re-apply firewall rules s_logger.debug("Found " + staticNats.size() + " firewall rule(s) to apply as a part of domR " + router + " start."); if (!firewallRules.isEmpty()) { - createFirewallRulesCommands(firewallRules, router, cmds); + createFirewallRulesCommands(firewallRules, router, cmds, guestNetworkId); } // Re-apply port forwarding rules s_logger.debug("Found " + pfRules.size() + " port forwarding rule(s) to apply as a part of domR " + router + " start."); if (!pfRules.isEmpty()) { - createApplyPortForwardingRulesCommands(pfRules, router, cmds); + createApplyPortForwardingRulesCommands(pfRules, router, cmds, guestNetworkId); } // Re-apply static nat rules @@ -1937,7 +1827,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (FirewallRule rule : staticNatFirewallRules) { staticNatRules.add(_rulesMgr.buildStaticNatRule(rule, false)); } - createApplyStaticNatRulesCommands(staticNatRules, router, cmds); + createApplyStaticNatRulesCommands(staticNatRules, router, cmds, guestNetworkId); } // Re-apply vpn rules @@ -1962,7 +1852,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of domR " + router + " start."); if (!lbRules.isEmpty()) { - createApplyLoadBalancingRulesCommands(lbRules, router, cmds); + createApplyLoadBalancingRulesCommands(lbRules, router, cmds, guestNetworkId); } } @@ -2110,7 +2000,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); @@ -2283,7 +2173,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian cmd.setAccessDetail(NetworkElementCommand.ACCOUNT_ID, String.valueOf(router.getAccountId())); cmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR, network.getCidr()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2442,7 +2332,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } IpAssocCommand cmd = new IpAssocCommand(ipsToSend); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(), router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2451,7 +2341,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - private void createApplyPortForwardingRulesCommands(List rules, VirtualRouter router, Commands cmds) { + private void createApplyPortForwardingRulesCommands(List rules, VirtualRouter router, Commands cmds, long guestNetworkId) { List rulesTO = null; if (rules != null) { rulesTO = new ArrayList(); @@ -2464,7 +2354,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rulesTO); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2472,7 +2362,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian cmds.addCommand(cmd); } - private void createApplyStaticNatRulesCommands(List rules, VirtualRouter router, Commands cmds) { + private void createApplyStaticNatRulesCommands(List rules, VirtualRouter router, Commands cmds, long guestNetworkId) { List rulesTO = null; if (rules != null) { rulesTO = new ArrayList(); @@ -2485,14 +2375,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand(cmd); } - private void createApplyLoadBalancingRulesCommands(List rules, VirtualRouter router, Commands cmds) { + private void createApplyLoadBalancingRulesCommands(List rules, VirtualRouter router, Commands cmds, long guestNetworkId) { LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()]; int i = 0; @@ -2515,7 +2405,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian RouterPublicIp = domr.getPublicIpAddress(); } - LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,RouterPublicIp, router.getGuestIpAddress(),router.getPrivateIpAddress()); + LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,RouterPublicIp, getRouterIpInNetwork(guestNetworkId, router.getId()),router.getPrivateIpAddress()); cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key()); cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key()); @@ -2524,7 +2414,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2546,7 +2436,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian VpnUsersCfgCommand addUsersCmd = new VpnUsersCfgCommand(addUsers, removeUsers); addUsersCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - addUsersCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + addUsersCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(vpn.getNetworkId(), router.getId())); addUsersCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); IpAddress ip = _networkMgr.getIp(vpn.getServerAddressId()); @@ -2554,7 +2444,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(true, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey()); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(vpn.getNetworkId(), router.getId())); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); startVpnCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2572,7 +2462,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian final String encodedPassword = PasswordGenerator.rot13(password); SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2586,7 +2476,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String zoneName = _dcDao.findById(router.getDataCenterIdToDeployIn()).getName(); cmds.addCommand("vmdata", generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), - vm.getHostName(), vm.getInstanceName(), vm.getId(), publicKey)); + vm.getHostName(), vm.getInstanceName(), vm.getId(), publicKey, nic.getNetworkId())); } @@ -2626,7 +2516,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); - dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId())); dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("dhcp", dhcpCommand); @@ -2651,7 +2541,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - private boolean sendCommandsToRouter(final VirtualRouter router, Commands cmds) throws AgentUnavailableException { + protected boolean sendCommandsToRouter(final VirtualRouter router, Commands cmds) throws AgentUnavailableException { Answer[] answers = null; try { answers = _agentMgr.send(router.getHostId(), cmds); @@ -2767,13 +2657,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList,policyList); lbRules.add(loadBalancing); } - return sendLBRules(router, lbRules); + return sendLBRules(router, lbRules, network.getId()); } else if (rules.get(0).getPurpose() == Purpose.PortForwarding) { - return sendPortForwardingRules(router, (List) rules); + return sendPortForwardingRules(router, (List) rules, network.getId()); } else if (rules.get(0).getPurpose() == Purpose.StaticNat) { - return sendStaticNatRules(router, (List) rules); + return sendStaticNatRules(router, (List) rules, network.getId()); } else if (rules.get(0).getPurpose() == Purpose.Firewall) { - return sendFirewallRules(router, (List) rules); + return sendFirewallRules(router, (List) rules, network.getId()); } else { s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose()); return false; @@ -2782,21 +2672,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian }); } - protected boolean sendLBRules(VirtualRouter router, List rules) throws ResourceUnavailableException { + protected boolean sendLBRules(VirtualRouter router, List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createApplyLoadBalancingRulesCommands(rules, router, cmds); + createApplyLoadBalancingRulesCommands(rules, router, cmds, guestNetworkId); return sendCommandsToRouter(router, cmds); } - protected boolean sendPortForwardingRules(VirtualRouter router, List rules) throws ResourceUnavailableException { + protected boolean sendPortForwardingRules(VirtualRouter router, List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createApplyPortForwardingRulesCommands(rules, router, cmds); + createApplyPortForwardingRulesCommands(rules, router, cmds, guestNetworkId); return sendCommandsToRouter(router, cmds); } - protected boolean sendStaticNatRules(VirtualRouter router, List rules) throws ResourceUnavailableException { + protected boolean sendStaticNatRules(VirtualRouter router, List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createApplyStaticNatRulesCommands(rules, router, cmds); + createApplyStaticNatRulesCommands(rules, router, cmds, guestNetworkId); return sendCommandsToRouter(router, cmds); } @@ -2810,7 +2700,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return vrs; } - private void createFirewallRulesCommands(List rules, VirtualRouter router, Commands cmds) { + private void createFirewallRulesCommands(List rules, VirtualRouter router, Commands cmds, long guestNetworkId) { List rulesTO = null; if (rules != null) { rulesTO = new ArrayList(); @@ -2823,7 +2713,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian SetFirewallRulesCommand cmd = new SetFirewallRulesCommand(rulesTO); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -2831,9 +2721,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } - protected boolean sendFirewallRules(VirtualRouter router, List rules) throws ResourceUnavailableException { + protected boolean sendFirewallRules(VirtualRouter router, List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createFirewallRulesCommands(rules, router, cmds); + createFirewallRulesCommands(rules, router, cmds, guestNetworkId); return sendCommandsToRouter(router, cmds); } @@ -2941,19 +2831,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return applyRules(network, routers, "static nat rules", false, null, false, new RuleApplier() { @Override public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException { - return applyStaticNat(router, rules); + return applyStaticNat(router, rules, network.getId()); } }); } - protected boolean applyStaticNat(VirtualRouter router, List rules) throws ResourceUnavailableException { + protected boolean applyStaticNat(VirtualRouter router, List rules, long guestNetworkId) throws ResourceUnavailableException { Commands cmds = new Commands(OnError.Continue); - createApplyStaticNatCommands(rules, router, cmds); + createApplyStaticNatCommands(rules, router, cmds, guestNetworkId); return sendCommandsToRouter(router, cmds); } - private void createApplyStaticNatCommands(List rules, VirtualRouter router, Commands cmds) { + private void createApplyStaticNatCommands(List rules, VirtualRouter router, Commands cmds, long guestNetworkId) { List rulesTO = null; if (rules != null) { rulesTO = new ArrayList(); @@ -2967,7 +2857,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -3025,6 +2915,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override + public boolean processDisconnect(long agentId, Status state) { return false; } @@ -3034,7 +2925,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - private String getRouterControlIp(long routerId) { + protected String getRouterControlIp(long routerId) { String routerControlIpAddress = null; List nics = _nicDao.listByVmId(routerId); for (NicVO n : nics) { @@ -3053,19 +2944,190 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return routerControlIpAddress; } - @Override - public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - //not supported - throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); + + protected String getRouterIpInNetwork(long networkId, long instanceId) { + return _nicDao.getIpAddress(networkId, instanceId); } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + boolean result = true; + + //FIXME - Anthony, here I send plug nic command on xen side + try { + + PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("plugnic", plugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); + if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { + s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); + result = false; + } + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network, + dest.getHost().getId(), e); + } + + return result; + } @Override public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - //not supported - throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); + + //FIXME - Anthony, add unplug nic agent command on xen side + boolean result = true; + DomainRouterVO router = _routerDao.findById(vm.getId()); + try { + UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic); + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("unplugnic", unplugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); + if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { + s_logger.warn("Unable to unplug nic from router " + router); + result = false; + } + + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, + dest.getHost().getId(), e); + } + + return result; + } + + protected boolean setupGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant, + NicProfile guestNic) + throws ConcurrentOperationException, ResourceUnavailableException{ + + String networkDomain = network.getNetworkDomain(); + String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); + + //FIXME - Anthony, add setup guest network command logic on Xen side + boolean result = true; + long guestVlanTag = Long.parseLong(network.getBroadcastUri().getHost()); + + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); + Integer priority = null; + if (isRedundant) { + List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); + try { + getUpdatedPriority(network, routers, _routerDao.findById(router.getId())); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + } + + String defaultDns1 = null; + String defaultDns2 = null; + + boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); + + if (guestNic.isDefaultNic() && (dnsProvided || dhcpProvided)) { + defaultDns1 = guestNic.getDns1(); + defaultDns2 = guestNic.getDns2(); + } + + SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, + defaultDns1, defaultDns2, add); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway()); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("setupguestnetwork", setupCmd); + sendCommandsToRouter(router, cmds); + + SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class); + String setup = add ? "set" : "unset"; + if (!(setupAnswer != null && setupAnswer.getResult())) { + s_logger.warn("Unable to " + setup + " guest network on router " + router); + result = false; + } + + return result; + } + + + @Override + public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + + //Check if router is already a part of the network + if (_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is already part of the network " + network); + return true; + } + + //Add router to network + boolean result = false; + try { + DomainRouterVO routerVO = _routerDao.findById(router.getId()); + s_logger.debug("Plugging nic for vpc virtual router " + router + " in network " + network); + _routerDao.addRouterToGuestNetwork(routerVO, network); + + NicProfile guestNic = _itMgr.addVmToNetwork(router, network); + //setup guest network + if (guestNic != null) { + result = setupGuestNetwork(network, router, true, isRedundant, guestNic); + } else { + s_logger.warn("Failed to add router " + router + " to guest network " + network); + } + } catch (Exception ex) { + s_logger.warn("Failed to add router " + router + " to network " + network); + } finally { + if (!result) { + s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup"); + if (removeRouterFromGuestNetwork(router, network, isRedundant)) { + s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup"); + } else { + s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup"); + } + } + } + + return result; + } + + + @Override + public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException { + + //Check if router is a part of the network + if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part of the network " + network); + return true; + } + + boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId())); + if (!result) { + s_logger.warn("Failed to reset guest network config " + network + " on router " + router); + return false; + } + + result = result && _itMgr.removeVmFromNetwork(router, network); + + if (result) { + if (result) { + s_logger.debug("Removing router " + router + " from network " + network); + _routerDao.removeRouterFromNetwork(router.getId(), network.getId()); + } + } + return result; } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java index 32da887f311..ef2feda9537 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -20,7 +20,6 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.Vpc; -import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.user.Account; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.VirtualMachineProfile.Param; @@ -28,7 +27,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{ +public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{ /** * @param vpc diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index dc753d10839..513ee5cb56d 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -19,15 +19,12 @@ import javax.ejb.Local; import org.apache.log4j.Logger; -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network; import com.cloud.network.NetworkService; import com.cloud.network.PhysicalNetwork; import com.cloud.network.VirtualRouterProvider; @@ -35,25 +32,21 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.vpc.Vpc; -import com.cloud.network.vpc.VpcVirtualNetworkApplianceService; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; -import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; -import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -@Local(value = { VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class,}) -public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements -VpcVirtualNetworkApplianceManager{ +@Local(value = {VpcVirtualNetworkApplianceManager.class}) +public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); @Inject @@ -103,15 +96,19 @@ VpcVirtualNetworkApplianceManager{ //3) Deploy Virtual Router try { - //FIXME - remove hardcoded provider type when decide if we want cross physical networks vpcs List pNtwks = _pNtwkDao.listByZone(vpc.getZoneId()); - VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(pNtwks.get(0).getId(), - VirtualRouterProviderType.VirtualRouter); + VirtualRouterProvider vpcVrProvider = null; + for (PhysicalNetwork pNtwk : pNtwks) { + vpcVrProvider = _vrProviderDao.findByNspIdAndType(pNtwk.getId(), + VirtualRouterProviderType.VPCVirtualRouter); + if (vpcVrProvider != null) { + break; + } + } - PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); - DomainRouterVO router = deployRouter(owner, dest, plan, params, true, true, null, false, - vrProvider, offeringId, sourceNatIp, vpc.getId()); + DomainRouterVO router = deployRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId, + vpc.getId()); routers.add(router); } finally { @@ -131,93 +128,4 @@ VpcVirtualNetworkApplianceManager{ return new Pair>(plan, routers); } - @Override - public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - - String networkDomain = network.getNetworkDomain(); - String cidr = network.getCidr(); - String dhcpRange = null; - if (cidr != null) { - dhcpRange = NetUtils.getDhcpRange(cidr); - } - - boolean result = true; - - //add router to network - DomainRouterVO router = _routerDao.findById(vm.getId()); - s_logger.debug("Adding router " + router + " to network " + network); - _routerDao.addRouterToNetwork(router, network); - - - //FIXME - Anthony, here I send plug nic command -// try { -// Map params = new HashMap(); -// params.put(PlugNicCommand.Param.NetworkDomain, networkDomain); -// params.put(PlugNicCommand.Param.DhcpRange, dhcpRange); -// -// PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params); -// -// Commands cmds = new Commands(OnError.Stop); -// cmds.addCommand("plugnic", plugNicCmd); -// _agentMgr.send(dest.getHost().getId(), cmds); -// -// PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); -// if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { -// s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); -// result = false; -// } -// -// } catch (OperationTimedoutException e) { -// throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName() + " in network " + network, -// dest.getHost().getId(), e); -// } - - return result; - } - - @Override - public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - - //FIXME - Anthony, add unplug nic agent command - boolean result = true; -// try { -// UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic); -// Commands cmds = new Commands(OnError.Stop); -// cmds.addCommand("unplugnic", unplugNicCmd); -// _agentMgr.send(dest.getHost().getId(), cmds); -// -// UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); -// if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { -// s_logger.warn("Unable to unplug nic from vm " + vm.getHostName()); -// result = false; -// } -// -// } catch (OperationTimedoutException e) { -// throw new AgentUnavailableException("Unable to unplug nic from vm " + vm.getHostName() + " from network " + network, -// dest.getHost().getId(), e); -// } -// - if (result) { - s_logger.debug("Removing router " + vm.getHostName() + " from network " + network); - _routerDao.removeRouterFromNetwork(vm.getId(), network.getId()); - } - - return result; - } - - @Override - public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { - return _itMgr.addVmToNetwork(router, network); - } - - - @Override - public boolean removeVmFromNetwork(VirtualRouter router, Network network) - throws ConcurrentOperationException, ResourceUnavailableException { - return _itMgr.removeVmFromNetwork(router, network); - } } diff --git a/server/src/com/cloud/network/vpc/Dao/PrivateIpDao.java b/server/src/com/cloud/network/vpc/Dao/PrivateIpDao.java new file mode 100644 index 00000000000..226b8b1269d --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/PrivateIpDao.java @@ -0,0 +1,62 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import java.util.List; + +import com.cloud.network.vpc.PrivateIpVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface PrivateIpDao extends GenericDao{ + + /** + * @param dcId + * @param networkId + * @return + */ + PrivateIpVO allocateIpAddress(long dcId, long networkId); + + /** + * @param ipAddress + * @param networkId + */ + void releaseIpAddress(String ipAddress, long networkId); + + /** + * @param networkId + * @param ip4Address + * @return + */ + PrivateIpVO findByIpAndSourceNetworkId(long networkId, String ip4Address); + + /** + * @param networkId + * @return + */ + List listByNetworkId(long networkId); + + /** + * @param ntwkId + * @return + */ + int countAllocatedByNetworkId(long ntwkId); + + /** + * @param networkId + */ + void deleteByNetworkId(long networkId); + +} diff --git a/server/src/com/cloud/network/vpc/Dao/PrivateIpDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/PrivateIpDaoImpl.java new file mode 100644 index 00000000000..a9d945663e4 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/PrivateIpDaoImpl.java @@ -0,0 +1,129 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import java.util.Date; +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.network.vpc.PrivateIpVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = PrivateIpDao.class) +@DB(txn = false) +public class PrivateIpDaoImpl extends GenericDaoBase implements PrivateIpDao { + private static final Logger s_logger = Logger.getLogger(PrivateIpDaoImpl.class); + + private final SearchBuilder AllFieldsSearch; + private final GenericSearchBuilder CountAllocatedByNetworkId; + + + protected PrivateIpDaoImpl() { + super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ); + AllFieldsSearch.done(); + + CountAllocatedByNetworkId = createSearchBuilder(Integer.class); + CountAllocatedByNetworkId.select(null, Func.COUNT, CountAllocatedByNetworkId.entity().getId()); + CountAllocatedByNetworkId.and("networkId", CountAllocatedByNetworkId.entity().getNetworkId(), Op.EQ); + CountAllocatedByNetworkId.and("taken", CountAllocatedByNetworkId.entity().getTakenAt(), Op.NNULL); + CountAllocatedByNetworkId.done(); + } + + @Override + public PrivateIpVO allocateIpAddress(long dcId, long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("networkId", networkId); + sc.setParameters("taken", (Date)null); + + Transaction txn = Transaction.currentTxn(); + txn.start(); + PrivateIpVO vo = lockOneRandomRow(sc, true); + if (vo == null) { + txn.rollback(); + return null; + } + vo.setTakenAt(new Date()); + update(vo.getId(), vo); + txn.commit(); + return vo; + } + + @Override + public void releaseIpAddress(String ipAddress, long networkId) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId); + } + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("ip", ipAddress); + sc.setParameters("networkId", networkId); + + PrivateIpVO vo = createForUpdate(); + + vo.setTakenAt(null); + update(vo, sc); + } + + /* (non-Javadoc) + * @see com.cloud.network.vpc.Dao.PrivateIpDao#findByIpAndSourceNetworkId(long, java.lang.String) + */ + @Override + public PrivateIpVO findByIpAndSourceNetworkId(long networkId, String ip4Address) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("ip", ip4Address); + sc.setParameters("networkId", networkId); + return findOneBy(sc); + } + + @Override + public List listByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("networkId", networkId); + return listBy(sc); + } + + @Override + public int countAllocatedByNetworkId(long ntwkId) { + SearchCriteria sc = CountAllocatedByNetworkId.create(); + sc.setParameters("networkId", ntwkId); + List results = customSearch(sc, null); + return results.get(0); + } + + + @Override + public void deleteByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("networkId", networkId); + remove(sc); + } +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcGatewayDao.java b/server/src/com/cloud/network/vpc/Dao/VpcGatewayDao.java new file mode 100644 index 00000000000..8e9a72b214a --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcGatewayDao.java @@ -0,0 +1,23 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import com.cloud.network.vpc.VpcGatewayVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcGatewayDao extends GenericDao{ + +} diff --git a/server/src/com/cloud/network/vpc/PrivateIpVO.java b/server/src/com/cloud/network/vpc/PrivateIpVO.java new file mode 100644 index 00000000000..42df20ce923 --- /dev/null +++ b/server/src/com/cloud/network/vpc/PrivateIpVO.java @@ -0,0 +1,76 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="private_ip_address") +public class PrivateIpVO { + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + long id; + + @Column(name="ip_address", updatable=false, nullable=false) + String ipAddress; + + @Column(name="taken") + @Temporal(value=TemporalType.TIMESTAMP) + private Date takenAt; + + @Column(name="network_id", updatable=false, nullable=false) + private long networkId; + + public PrivateIpVO() { + } + + public PrivateIpVO(String ipAddress, long networkId) { + this.ipAddress = ipAddress; + this.networkId = networkId; + } + + public void setTakenAt(Date takenDate) { + this.takenAt = takenDate; + } + + public String getIpAddress() { + return ipAddress; + } + + public long getNetworkId() { + return networkId; + } + + public Date getTakenAt() { + return takenAt; + } + + public long getId() { + return id; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcGatewayVO.java b/server/src/com/cloud/network/vpc/VpcGatewayVO.java new file mode 100644 index 00000000000..277c440da53 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcGatewayVO.java @@ -0,0 +1,22 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc; + +/** + * @author Alena Prokharchyk + */ +public class VpcGatewayVO { + + public VpcGatewayVO() { + } +} diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index cf0e6702437..d1adeac96a8 100755 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -307,6 +307,12 @@ public class NetworkOfferingVO implements NetworkOffering, Identity { this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges); this.state = State.Enabled; } + + public NetworkOfferingVO(String name, Network.GuestType guestType) { + this(name, "System Offering for " + name, TrafficType.Guest, true, true, 0, 0, true, Availability.Optional, + null, Network.GuestType.Isolated, true, false); + this.state = State.Enabled; + } @Override public String toString() { diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 88379e3528b..0727776ebca 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -61,6 +61,7 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; +import com.cloud.network.Network.GuestType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.Network.State; @@ -94,7 +95,6 @@ import com.cloud.utils.PropertiesUtil; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.db.DB; -import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; @@ -858,16 +858,22 @@ public class ConfigurationServerImpl implements ConfigurationServer { @DB protected void createDefaultNetworkOfferings() { - NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, true); + NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, + TrafficType.Public, true); publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering); - NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, false); + NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, + TrafficType.Management, false); managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering); - NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, false); + NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, + TrafficType.Control, false); controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering); - NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, true); + NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, + TrafficType.Storage, true); storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); + NetworkOfferingVO privateGatewayNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPrivateGatewayNetworkOffering, GuestType.Isolated); + privateGatewayNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(privateGatewayNetworkOffering); - // populate providers + //populate providers Map defaultSharedNetworkOfferingProviders = new HashMap(); defaultSharedNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter); defaultSharedNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter); diff --git a/server/src/com/cloud/test/PodZoneConfig.java b/server/src/com/cloud/test/PodZoneConfig.java index 2669e66d774..0daa9167493 100644 --- a/server/src/com/cloud/test/PodZoneConfig.java +++ b/server/src/com/cloud/test/PodZoneConfig.java @@ -381,7 +381,8 @@ public class PodZoneConfig { String defaultXenStorageNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Storage); String defaultXenGuestNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Guest); - String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)"; + String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` " + + "(physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)"; try { PreparedStatement stmt = txn.prepareAutoCloseStatement(insertTraficType); diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java index 14fab7dd83b..67ad160325b 100755 --- a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java @@ -859,7 +859,8 @@ public class Upgrade2214to30 implements DbUpgrade { ResultSet rs = null; try { pstmt = conn - .prepareStatement("select id, dns_service, gateway_service, firewall_service, lb_service, userdata_service, vpn_service, dhcp_service, unique_name from `cloud`.`network_offerings` where traffic_type='Guest'"); + .prepareStatement("select id, dns_service, gateway_service, firewall_service, " + + "lb_service, userdata_service, vpn_service, dhcp_service, unique_name from `cloud`.`network_offerings` where traffic_type='Guest'"); rs = pstmt.executeQuery(); while (rs.next()) { long id = rs.getLong(1); @@ -905,7 +906,8 @@ public class Upgrade2214to30 implements DbUpgrade { } for (String service : services) { - pstmt = conn.prepareStatement("INSERT INTO `cloud`.`ntwk_offering_service_map` (`network_offering_id`, `service`, `provider`, `created`) values (?,?,?, now())"); + pstmt = conn.prepareStatement("INSERT INTO `cloud`.`ntwk_offering_service_map` " + + "(`network_offering_id`, `service`, `provider`, `created`) values (?,?,?, now())"); pstmt.setLong(1, id); pstmt.setString(2, service); if (service.equalsIgnoreCase("SecurityGroup")) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index de0a237085f..21e3e648e32 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -425,7 +425,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); - NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork)); + NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, + _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index f43de6e1a8b..485edb4a77d 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -142,7 +142,7 @@ public interface VirtualMachineManager extends Manager { * @throws ResourceUnavailableException * @throws InsufficientCapacityException */ - boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 798a977fabc..0d1d8a3c42f 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2432,7 +2432,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene @Override @DB - public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { VMInstanceVO vmVO = _vmDao.findById(vm.getId()); @@ -2476,10 +2476,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) { s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); - return true; + return nic; } else { s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); - return false; + return null; } } @@ -2501,18 +2501,16 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene //1) Release the nic NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO); - //2) TODO - unplug the nic + //2) Convert vmProfile to vmTO VirtualMachineGuru vmGuru = getVmGuru(vmVO); - - //3) Convert vmProfile to vmTO HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - //4) Convert nicProfile to NicTO + //3) Convert nicProfile to NicTO NicTO nicTO = hvGuru.toNicTO(nic); boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest); - //5) Unplug the nic + //4) Unplug the nic if (result) { s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network ); } else { diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 3dd615b1906..cfc73a00e55 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -116,11 +116,12 @@ public interface DomainRouterDao extends GenericDao { * @param routerId * @param guestNetwork */ - void addRouterToNetwork(DomainRouterVO router, Network guestNetwork); + void addRouterToGuestNetwork(DomainRouterVO router, Network guestNetwork); /** * @param routerId * @param guestNetworkId */ void removeRouterFromNetwork(long routerId, long guestNetworkId); + } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index a3285f03fcc..b40cb8c2fcf 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -264,7 +264,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im if (guestNetworks != null && !guestNetworks.isEmpty()) { // 2) add router to the network for (Network guestNetwork : guestNetworks) { - addRouterToNetwork(router, guestNetwork); + addRouterToGuestNetwork(router, guestNetwork); } } @@ -274,7 +274,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override @DB - public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) { + public void addRouterToGuestNetwork(DomainRouterVO router, Network guestNetwork) { Transaction txn = Transaction.currentTxn(); txn.start(); //1) add router to network @@ -309,5 +309,5 @@ public class DomainRouterDaoImpl extends GenericDaoBase im sc.setParameters("role", Role.VIRTUAL_ROUTER); return listBy(sc); } - + } diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java index 2748ba22231..deb302f4e3e 100644 --- a/server/src/com/cloud/vm/dao/NicDao.java +++ b/server/src/com/cloud/vm/dao/NicDao.java @@ -37,4 +37,13 @@ public interface NicDao extends GenericDao { NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId); NicVO findDefaultNicForVM(long instanceId); + + /** + * @param networkId + * @param instanceId + * @return + */ + NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId); + + String getIpAddress(long networkId, long instanceId); } diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index 1e3d6e06363..09786ca10d6 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -22,6 +22,8 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.vm.Nic.State; +import com.cloud.vm.Nic; import com.cloud.vm.NicVO; import com.cloud.vm.VirtualMachine; @@ -29,6 +31,7 @@ import com.cloud.vm.VirtualMachine; public class NicDaoImpl extends GenericDaoBase implements NicDao { private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder IpSearch; + private final SearchBuilder NonReleasedSearch; protected NicDaoImpl() { super(); @@ -46,6 +49,12 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ); IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL); IpSearch.done(); + + NonReleasedSearch = createSearchBuilder(); + NonReleasedSearch.and("instance", NonReleasedSearch.entity().getInstanceId(), Op.EQ); + NonReleasedSearch.and("network", NonReleasedSearch.entity().getNetworkId(), Op.EQ); + NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN); + NonReleasedSearch.done(); } @Override @@ -123,4 +132,22 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { sc.setParameters("isDefault", 1); return findOneBy(sc); } + + @Override + public NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId) { + SearchCriteria sc = NonReleasedSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + sc.setParameters("state", State.Releasing, Nic.State.Deallocating); + return findOneBy(sc); + } + + @Override + public String getIpAddress(long networkId, long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + return findOneBy(sc).getIp4Address(); + } + } diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java index f72e7e85cfc..f2e69bc76f3 100755 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java @@ -240,7 +240,7 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager { * @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) */ @Override - public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // TODO Auto-generated method stub return false; } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index be56b2ab35c..7645455bd8b 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2193,5 +2193,34 @@ CREATE TABLE `cloud`.`router_network_ref` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`vpc_gateways` ( + `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40), + `ip4_address` char(40) COMMENT 'ip4 address of the gateway', + `type` varchar(32) COMMENT 'type of gateway; can be Public/Private/Vpn', + `network_id` bigint unsigned NOT NULL COMMENT 'network id vpc gateway belongs to', + `vpc_id` bigint unsigned NOT NULL COMMENT 'id of the vpc the gateway belongs to', + `zone_id` bigint unsigned NOT NULL COMMENT 'id of the zone the gateway belongs to', + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime COMMENT 'date removed if not null', + PRIMARY KEY (`id`), + CONSTRAINT `fk_vpc_gateways__network_id` FOREIGN KEY `fk_vpc_gateways__network_id`(`network_id`) REFERENCES `networks`(`id`), + CONSTRAINT `fk_vpc_gateways__vpc_id` FOREIGN KEY `fk_vpc_gateways__vpc_id`(`vpc_id`) REFERENCES `vpc`(`id`), + CONSTRAINT `fk_vpc_gateways__zone_id` FOREIGN KEY `fk_vpc_gateways__zone_id`(`zone_id`) REFERENCES `data_center`(`id`), + CONSTRAINT `uc_vpc_gateways__uuid` UNIQUE (`uuid`), + INDEX `i_vpc_gateways__removed`(`removed`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`private_ip_address` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key', + `ip_address` char(40) NOT NULL COMMENT 'ip address', + `network_id` bigint unsigned NOT NULL COMMENT 'id of the network ip belongs to', + `reservation_id` char(40) COMMENT 'reservation id', + `taken` datetime COMMENT 'Date taken', + PRIMARY KEY (`id`), + CONSTRAINT `fk_private_ip_address__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + SET foreign_key_checks = 1; diff --git a/wscript b/wscript index 1589fecf1ba..357ef6d4c7d 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,11 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog +<<<<<<< HEAD VERSION = '3.0.3.2012-06-04T23:35:51Z' +======= +VERSION = '3.0.3.2012-06-04T21:10:12Z' +>>>>>>> Support for adding private network APPNAME = 'cloud' import shutil,os From 3ae5b0b5c87b0bd092dd639b8237ee818de4a1d1 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 5 Jun 2012 10:55:20 -0700 Subject: [PATCH 22/64] Modified virtual router startup procedure - initial start happens with control nic only; then we plug Public and then Guest nic to it --- .../CreateVirtualRouterElementCmd.java | 3 +- .../VirtualNetworkApplianceService.java | 6 +- .../element/VirtualRouterElementService.java | 3 +- .../xen/resource/CitrixResourceBase.java | 40 ++++- .../src/com/cloud/network/NetworkManager.java | 1 - .../com/cloud/network/NetworkManagerImpl.java | 5 +- .../network/element/VirtualRouterElement.java | 6 +- .../VirtualNetworkApplianceManagerImpl.java | 159 ++++++++++++++++-- ...VpcVirtualNetworkApplianceManagerImpl.java | 15 +- wscript | 7 +- 10 files changed, 209 insertions(+), 36 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java index 48c6c4e19a3..ef5f8e8e4c7 100644 --- a/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java +++ b/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.response.VirtualRouterProviderResponse; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; import com.cloud.network.VirtualRouterProvider; +import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.element.VirtualRouterElementService; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -92,7 +93,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException { - VirtualRouterProvider result = _service.addElement(getNspId()); + VirtualRouterProvider result = _service.addElement(getNspId(), VirtualRouterProviderType.VirtualRouter); if (result != null) { setEntityId(result.getId()); } else { diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index f7bc817af7e..7f719c22c29 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -67,7 +67,8 @@ public interface VirtualNetworkApplianceService { * @throws ResourceUnavailableException * @throws InsufficientCapacityException */ - boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * @param router @@ -77,5 +78,6 @@ public interface VirtualNetworkApplianceService { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException; + boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/element/VirtualRouterElementService.java b/api/src/com/cloud/network/element/VirtualRouterElementService.java index dc4e510259a..32139be141e 100644 --- a/api/src/com/cloud/network/element/VirtualRouterElementService.java +++ b/api/src/com/cloud/network/element/VirtualRouterElementService.java @@ -17,11 +17,12 @@ import java.util.List; import com.cloud.api.commands.ConfigureVirtualRouterElementCmd; import com.cloud.api.commands.ListVirtualRouterElementsCmd; import com.cloud.network.VirtualRouterProvider; +import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.utils.component.PluggableService; public interface VirtualRouterElementService extends PluggableService{ VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd); - VirtualRouterProvider addElement(Long nspId); + VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType); VirtualRouterProvider getCreatedElement(long id); List searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd); } diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index ba1094d2c0d..bfbde2b7c33 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -103,6 +103,8 @@ import com.cloud.agent.api.PingCommand; import com.cloud.agent.api.PingRoutingWithNwGroupsCommand; import com.cloud.agent.api.PingRoutingWithOvsCommand; import com.cloud.agent.api.PingTestCommand; +import com.cloud.agent.api.PlugNicAnswer; +import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.PoolEjectCommand; import com.cloud.agent.api.PrepareForMigrationAnswer; import com.cloud.agent.api.PrepareForMigrationCommand; @@ -115,6 +117,8 @@ import com.cloud.agent.api.SecurityGroupRuleAnswer; import com.cloud.agent.api.SecurityGroupRulesCmd; import com.cloud.agent.api.SetupAnswer; import com.cloud.agent.api.SetupCommand; +import com.cloud.agent.api.SetupGuestNetworkAnswer; +import com.cloud.agent.api.SetupGuestNetworkCommand; import com.cloud.agent.api.StartAnswer; import com.cloud.agent.api.StartCommand; import com.cloud.agent.api.StartupCommand; @@ -123,6 +127,8 @@ import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.StoragePoolInfo; +import com.cloud.agent.api.UnPlugNicAnswer; +import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.api.UpgradeSnapshotCommand; import com.cloud.agent.api.VmStatsEntry; @@ -512,12 +518,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return execute((GetDomRVersionCmd)cmd); } else if (clazz == CheckNetworkCommand.class) { return execute((CheckNetworkCommand) cmd); - } else { + } else if (clazz == SetupGuestNetworkCommand.class) { + return execute((SetupGuestNetworkCommand) cmd); + } else if (clazz == PlugNicCommand.class) { + return execute((PlugNicCommand) cmd); + } else if (clazz == UnPlugNicCommand.class) { + return execute((UnPlugNicCommand) cmd); + }else { return Answer.createUnsupportedCommandAnswer(cmd); } } - protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type, String name) throws XenAPIException, XmlRpcException { if (name != null) { if (s_logger.isDebugEnabled()) { @@ -6944,7 +6955,32 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return changes; } + /** + * @param cmd + * @return + */ + private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { + // TODO Auto-generated method stub + return null; + } + /** + * @param cmd + * @return + */ + private PlugNicAnswer execute(PlugNicCommand cmd) { + // TODO Auto-generated method stub + return null; + } + + /** + * @param cmd + * @return + */ + private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) { + // TODO Auto-generated method stub + return null; + } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 265f7f9388f..6ab1200792c 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -49,7 +49,6 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; -import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 104d35c6cac..3ca50687972 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -108,6 +108,7 @@ import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetwork.BroadcastDomainRange; +import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; @@ -6437,7 +6438,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (element == null) { throw new CloudRuntimeException("Unable to find the Network Element implementing the VirtualRouter Provider"); } - element.addElement(nsp.getId()); + element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter); return nsp; } @@ -6451,7 +6452,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (element == null) { throw new CloudRuntimeException("Unable to find the Network Element implementing the VPCVirtualRouter Provider"); } - element.addElement(nsp.getId()); + element.addElement(nsp.getId(), VirtualRouterProviderType.VPCVirtualRouter); return nsp; } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index a642cd6bfef..b2f139ee9de 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -696,13 +696,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public VirtualRouterProvider addElement(Long nspId) { - VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.VirtualRouter); + public VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType) { + VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType); if (element != null) { s_logger.debug("There is already a virtual router element with service provider id " + nspId); return null; } - element = new VirtualRouterProviderVO(nspId, VirtualRouterProviderType.VirtualRouter); + element = new VirtualRouterProviderVO(nspId, providerType); _vrProviderDao.persist(element); return element; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a51d6c39747..d5357202a8f 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -60,6 +60,7 @@ import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; +import com.cloud.agent.api.routing.IpAssocAnswer; import com.cloud.agent.api.routing.IpAssocCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; @@ -200,7 +201,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; -import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; @@ -1259,11 +1259,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } //3) Deploy Virtual Router(s) + PublicIp sourceNatIp = null; + if (publicNetwork) { + sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); + } try { int count = routerCount - routers.size(); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, - null); + null, sourceNatIp); routers.add(router); } } finally { @@ -1276,7 +1280,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, - Long vpcId) throws ConcurrentOperationException, + Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1374,7 +1378,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - //3) Plug public nic + //3) Plug public nic + boolean addToPublicNtwk = true; + if (sourceNatIp != null) { + Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0); + addToPublicNtwk = addRouterToPublicNetwork(router, publicNetwork, sourceNatIp); + } + + if (!addToPublicNtwk) { + s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up"); + destroyRouter(router.getId()); + } return router; } @@ -2955,9 +2969,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian InsufficientCapacityException { boolean result = true; - //FIXME - Anthony, here I send plug nic command on xen side try { - PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic); Commands cmds = new Commands(OnError.Stop); @@ -2982,7 +2994,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - //FIXME - Anthony, add unplug nic agent command on xen side boolean result = true; DomainRouterVO router = _routerDao.findById(vm.getId()); try { @@ -3012,7 +3023,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String networkDomain = network.getNetworkDomain(); String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); - //FIXME - Anthony, add setup guest network command logic on Xen side boolean result = true; long guestVlanTag = Long.parseLong(network.getBroadcastUri().getHost()); @@ -3053,7 +3063,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian sendCommandsToRouter(router, cmds); SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class); - String setup = add ? "set" : "unset"; + String setup = add ? "set" : "destroy"; if (!(setupAnswer != null && setupAnswer.getResult())) { s_logger.warn("Unable to " + setup + " guest network on router " + router); result = false; @@ -3061,20 +3071,24 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - @Override public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - //Check if router is already a part of the network + if (network.getTrafficType() != TrafficType.Guest) { + s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); + return false; + } + + //Check if router is already a part of the Guest network if (_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the network " + network); + s_logger.debug("Router " + router + " is already part of the Guest network " + network); return true; } - //Add router to network - boolean result = false; + //Add router to the Guest network + boolean result = true; try { DomainRouterVO routerVO = _routerDao.findById(router.getId()); s_logger.debug("Plugging nic for vpc virtual router " + router + " in network " + network); @@ -3089,6 +3103,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } catch (Exception ex) { s_logger.warn("Failed to add router " + router + " to network " + network); + result = false; } finally { if (!result) { s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup"); @@ -3107,16 +3122,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException { + if (network.getTrafficType() != TrafficType.Guest) { + s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); + return false; + } - //Check if router is a part of the network + //Check if router is a part of the Guest network if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part of the network " + network); + s_logger.debug("Router " + router + " is not a part of the Guest network " + network); return true; } boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId())); if (!result) { - s_logger.warn("Failed to reset guest network config " + network + " on router " + router); + s_logger.warn("Failed to destroy guest network config " + network + " on router " + router); return false; } @@ -3130,4 +3149,110 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } return result; } + + protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress sourceNatIp) + throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException { + + if (publicNetwork.getTrafficType() != TrafficType.Public) { + s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); + return false; + } + + //Check if router is already a part of the Public network + if (_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) { + s_logger.debug("Router " + router + " is already part of the Public network " + publicNetwork); + return true; + } + + //Add router to the Public network + boolean result = true; + try { + + NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork); + //setup public network + if (publicNic != null) { + if (sourceNatIp != null) { + IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); + PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), + NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); + result = setupPublicNetwork(publicNetwork, router, false, publicIp); + } + } else { + result = false; + s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork); + } + } catch (Exception ex) { + s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork); + } finally { + if (!result) { + s_logger.debug("Removing the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); + if (removeRouterFromPublicNetwork(router, publicNetwork)) { + s_logger.debug("Removed the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); + } else { + s_logger.warn("Failed to remove the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); + } + } + } + + return result; + } + + + protected boolean removeRouterFromPublicNetwork(VirtualRouter router, Network publicNetwork) + throws ConcurrentOperationException, ResourceUnavailableException { + + if (publicNetwork.getTrafficType() != TrafficType.Public) { + s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); + return false; + } + + //Check if router is a part of the Guest network + if (!_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) { + s_logger.debug("Router " + router + " is not a part of the Public network " + publicNetwork); + return true; + } + + String routerIpStr = router.getPublicIpAddress(); + + IPAddressVO sourceNatIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNetwork.getId(), routerIpStr); + + assert sourceNatIp.isSourceNat() : "Ip " + sourceNatIp + " is not source nat"; + + boolean result = true; + if (sourceNatIp != null) { + IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); + _networkMgr.markIpAsUnavailable(ipVO.getId()); + PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), + NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); + result = setupPublicNetwork(publicNetwork, router, false, publicIp); + } + + if (!result) { + s_logger.warn("Failed to destroy public network config " + publicNetwork + " on router " + router); + return false; + } + + result = result && _itMgr.removeVmFromNetwork(router, publicNetwork); + + return result; + } + + protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp sourceNatIp) + throws ConcurrentOperationException, ResourceUnavailableException{ + + List publicIps = new ArrayList(1); + Commands cmds = new Commands(OnError.Stop); + createAssociateIPCommands(router, publicIps, cmds, 0); + sendCommandsToRouter(router, cmds); + + boolean result = true; + IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class); + String setup = add ? "set" : "destroy"; + if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) { + s_logger.warn("Unable to " + setup + " guest network on router " + router); + result = false; + } + + return result; + } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 513ee5cb56d..b967e8048c5 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -27,6 +27,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.NetworkService; import com.cloud.network.PhysicalNetwork; +import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.addr.PublicIp; @@ -38,6 +39,7 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.VirtualMachineProfile.Param; @@ -99,16 +101,25 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian List pNtwks = _pNtwkDao.listByZone(vpc.getZoneId()); VirtualRouterProvider vpcVrProvider = null; + for (PhysicalNetwork pNtwk : pNtwks) { - vpcVrProvider = _vrProviderDao.findByNspIdAndType(pNtwk.getId(), + PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(pNtwk.getId(), + VirtualRouterProviderType.VPCVirtualRouter.toString()); + if (provider == null) { + throw new CloudRuntimeException("Cannot find service provider " + + VirtualRouterProviderType.VPCVirtualRouter.toString() + " in physical network " + pNtwk.getId()); + } + vpcVrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderType.VPCVirtualRouter); if (vpcVrProvider != null) { break; } } + PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); + DomainRouterVO router = deployRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId, - vpc.getId()); + vpc.getId(), sourceNatIp); routers.add(router); } finally { diff --git a/wscript b/wscript index 357ef6d4c7d..a95dd0fb094 100644 --- a/wscript +++ b/wscript @@ -3,11 +3,8 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -<<<<<<< HEAD -VERSION = '3.0.3.2012-06-04T23:35:51Z' -======= -VERSION = '3.0.3.2012-06-04T21:10:12Z' ->>>>>>> Support for adding private network + +VERSION = '3.0.3.2012-06-05T18:30:03Z' APPNAME = 'cloud' import shutil,os From 5700510c26adbbbb79a757b86170dcc604186ba0 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 5 Jun 2012 15:38:25 -0700 Subject: [PATCH 23/64] VPC, implement plug/unplug nic --- .../xen/resource/CitrixResourceBase.java | 47 +++++++++++++++++-- .../config/etc/iptables/iptables-router | 2 - wscript | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index bfbde2b7c33..16e4d578f87 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -6960,8 +6960,31 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * @return */ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { - // TODO Auto-generated method stub - return null; + Connection conn = getConnection(); + VirtualMachineTO vmto = cmd.getVirtualMachine(); + String vmName = vmto.getName(); + try { + Set vms = VM.getByNameLabel(conn, vmName); + if ( vms == null || vms.isEmpty() ) { + return new UnPlugNicAnswer(cmd, false, "Can not find VM " + vmName); + } + VM vm = vms.iterator().next(); + NicTO nic = cmd.getNic(); + String mac = nic.getMac(); + for ( VIF vif : vm.getVIFs(conn)) { + String lmac = vif.getMAC(conn); + if ( lmac.equals(mac) ) { + vif.unplug(conn); + vif.destroy(conn); + break; + } + } + return new UnPlugNicAnswer(cmd, true, "success"); + } catch (Exception e) { + String msg = " UnPlug Nic failed due to " + e.toString(); + s_logger.warn(msg, e); + return new UnPlugNicAnswer(cmd, false, msg); + } } /** @@ -6969,8 +6992,24 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * @return */ private PlugNicAnswer execute(PlugNicCommand cmd) { - // TODO Auto-generated method stub - return null; + Connection conn = getConnection(); + VirtualMachineTO vmto = cmd.getVirtualMachine(); + String vmName = vmto.getName(); + try { + Set vms = VM.getByNameLabel(conn, vmName); + if ( vms == null || vms.isEmpty() ) { + return new PlugNicAnswer(cmd, false, "Can not find VM " + vmName); + } + VM vm = vms.iterator().next(); + NicTO nic = cmd.getNic(); + VIF vif = createVif(conn, vmName, vm, nic); + vif.plug(conn); + return new PlugNicAnswer(cmd, true, "success"); + } catch (Exception e) { + String msg = " Plug Nic failed due to " + e.toString(); + s_logger.warn(msg, e); + return new PlugNicAnswer(cmd, false, msg); + } } /** diff --git a/patches/systemvm/debian/config/etc/iptables/iptables-router b/patches/systemvm/debian/config/etc/iptables/iptables-router index ac40ed41056..193d54fa33e 100644 --- a/patches/systemvm/debian/config/etc/iptables/iptables-router +++ b/patches/systemvm/debian/config/etc/iptables/iptables-router @@ -10,8 +10,6 @@ COMMIT -A INPUT -d 224.0.0.18/32 -j ACCEPT -A INPUT -d 225.0.0.50/32 -j ACCEPT -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT diff --git a/wscript b/wscript index a95dd0fb094..4fd09f1bf04 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-05T18:30:03Z' +VERSION = '3.0.3.2012-06-05T22:35:08Z' APPNAME = 'cloud' import shutil,os From d9758045d9ed8344a6579064d19ac394f1ddc2e5 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 5 Jun 2012 16:10:20 -0700 Subject: [PATCH 24/64] Added NicTO to setupGuestNetworkCommand constructor - we need this info for guest network configuraiton --- .../agent/api/SetupGuestNetworkCommand.java | 5 ++++- api/src/com/cloud/vm/NicProfile.java | 3 ++- server/src/com/cloud/network/NetworkManager.java | 3 +++ .../VirtualNetworkApplianceManagerImpl.java | 6 +++++- server/src/com/cloud/vm/UserVmManagerImpl.java | 3 ++- .../src/com/cloud/vm/VirtualMachineManager.java | 8 ++++++++ .../com/cloud/vm/VirtualMachineManagerImpl.java | 16 ++++++++++++---- wscript | 2 +- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java index a1507c28ab4..c2ca11b741b 100644 --- a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -13,6 +13,7 @@ package com.cloud.agent.api; import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.to.NicTO; /** * @author Alena Prokharchyk @@ -25,6 +26,7 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ boolean isRedundant = false; Integer priority; boolean add = true; + NicTO nic; @Override public boolean executeInSequence() { @@ -36,7 +38,7 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ public SetupGuestNetworkCommand(String dhcpRange, String networkDomain, boolean isRedundant, Integer priority, - String defaultDns1, String defaultDns2, boolean add) { + String defaultDns1, String defaultDns2, boolean add, NicTO nic) { this.dhcpRange = dhcpRange; this.networkDomain = networkDomain; this.defaultDns1 = defaultDns1; @@ -44,5 +46,6 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ this.isRedundant = isRedundant; this.priority = priority; this.add = add; + this.nic = nic; } } diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index ee6481d96f4..a21748f3db2 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -203,7 +203,8 @@ public class NicProfile { return strategy; } - public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name) { + public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, + boolean isSecurityGroupEnabled, String name) { this.id = nic.getId(); this.networkId = network.getId(); this.gateway = nic.getGateway(); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6ab1200792c..5873115f1c5 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -18,6 +18,7 @@ import java.util.Map; import java.util.Set; import com.cloud.acl.ControlledEntity.ACLType; +import com.cloud.agent.api.to.NicTO; import com.cloud.dc.DataCenter; import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; @@ -49,6 +50,7 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; +import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; @@ -421,5 +423,6 @@ public interface NetworkManager extends NetworkService { * @return */ NicProfile getNicProfile(VirtualMachine vm, long networkId); + } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index d5357202a8f..73269b72a00 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -3048,9 +3048,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian defaultDns1 = guestNic.getDns1(); defaultDns2 = guestNic.getDns2(); } + + NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, - defaultDns1, defaultDns2, add); + defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 21e3e648e32..55c61d0c4ef 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -426,7 +426,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, - _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork)); + _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), + _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 485edb4a77d..0cde9fb2364 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -15,6 +15,7 @@ package com.cloud.vm; import java.util.List; import java.util.Map; +import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; @@ -154,4 +155,11 @@ public interface VirtualMachineManager extends Manager { */ boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException; + /** + * @param nic + * @param hypervisorType + * @return + */ + NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType); + } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 0d1d8a3c42f..5dee3d1e9ee 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2131,7 +2131,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene List nics = _nicsDao.listByVmId(profile.getId()); for (NicVO nic : nics) { Network network = _networkMgr.getNetwork(nic.getNetworkId()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(profile.getHypervisorType(), network)); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(profile.getHypervisorType(), network)); profile.addNic(nicProfile); } @@ -2469,7 +2470,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene VirtualMachineTO vmTO = hvGuru.implement(vmProfile); //4) Convert nicProfile to NicTO - NicTO nicTO = hvGuru.toNicTO(nic); + NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); //5) plug the nic to the vm VirtualMachineGuru vmGuru = getVmGuru(vmVO); @@ -2483,6 +2484,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } } + + @Override + public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) { + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(hypervisorType); + + NicTO nicTO = hvGuru.toNicTO(nic); + return nicTO; + } @Override public boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException { @@ -2506,8 +2515,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - //3) Convert nicProfile to NicTO - NicTO nicTO = hvGuru.toNicTO(nic); + NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest); //4) Unplug the nic diff --git a/wscript b/wscript index 4fd09f1bf04..858577443cb 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-05T22:35:08Z' +VERSION = '3.0.3.2012-06-05T23:07:27Z' APPNAME = 'cloud' import shutil,os From 076a876f8090cbea84fe4f5c72031089f836ae01 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 5 Jun 2012 17:26:19 -0700 Subject: [PATCH 25/64] VPC : introduce router_proxy.sh, resource should use this as a proxy to call scripts inside domr already did this for ipassoc and getDomRVersion --- .../xen/resource/CitrixResourceBase.java | 8 +-- scripts/network/domr/ipassoc.sh | 52 ------------------ .../{getDomRVersion.sh => router_proxy.sh} | 40 +++++++++----- scripts/vm/hypervisor/xenserver/vmops | 53 ++++++++----------- .../vm/hypervisor/xenserver/xenserver56/patch | 3 +- .../hypervisor/xenserver/xenserver56fp1/patch | 3 +- .../vm/hypervisor/xenserver/xenserver60/patch | 3 +- wscript | 2 +- 8 files changed, 56 insertions(+), 108 deletions(-) delete mode 100755 scripts/network/domr/ipassoc.sh rename scripts/network/domr/{getDomRVersion.sh => router_proxy.sh} (81%) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 16e4d578f87..ac39b61956b 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1340,8 +1340,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe private GetDomRVersionAnswer execute(GetDomRVersionCmd cmd) { Connection conn = getConnection(); - String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - String result = callHostPlugin(conn, "vmops", "getDomRVersion", "args", args); + String args = "get_template_version.sh " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); if (result == null || result.isEmpty()) { return new GetDomRVersionAnswer(cmd, "getDomRVersionCmd failed"); } @@ -1717,7 +1717,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with."); } - String args = privateIpAddress; + String args = "ipassoc.sh " + privateIpAddress; if (add) { args += " -A "; @@ -1744,7 +1744,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe args += vlanGateway; - String result = callHostPlugin(conn, "vmops", "ipassoc", "args", args); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); if (result == null || result.isEmpty()) { throw new InternalErrorException("Xen plugin \"ipassoc\" failed."); } diff --git a/scripts/network/domr/ipassoc.sh b/scripts/network/domr/ipassoc.sh deleted file mode 100755 index 592b56c97f7..00000000000 --- a/scripts/network/domr/ipassoc.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2012 Citrix Systems, Inc. Licensed under the -# Apache License, Version 2.0 (the "License"); you may not use this -# file except in compliance with the License. Citrix Systems, Inc. -# reserves all rights not expressly granted by the License. -# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Automatically generated by addcopyright.py at 04/03/2012 - - - - - -# $Id: ipassoc.sh 9804 2010-06-22 18:36:49Z alex $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/network/domr/ipassoc.sh $ -# ipassoc.sh -- associate/disassociate a public ip with an instance -# 2.1.4 -usage() { - printf "Usage:\n %s -A -i -l -r [-f] \n" $(basename $0) >&2 - printf " %s -D -i -l -r [-f] \n" $(basename $0) >&2 -} - -cert="/root/.ssh/id_rsa.cloud" -domRIp=$1 -shift - - -check_gw() { - ping -c 1 -n -q $1 > /dev/null - if [ $? -gt 0 ] - then - sleep 1 - ping -c 1 -n -q $1 > /dev/null - fi - return $?; -} - - -check_gw "$domRIp" -if [ $? -gt 0 ] -then - exit 1 -fi - - -ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/root/ipassoc.sh $*" -exit $? - diff --git a/scripts/network/domr/getDomRVersion.sh b/scripts/network/domr/router_proxy.sh similarity index 81% rename from scripts/network/domr/getDomRVersion.sh rename to scripts/network/domr/router_proxy.sh index e11e052f7a1..175cb6ba58a 100755 --- a/scripts/network/domr/getDomRVersion.sh +++ b/scripts/network/domr/router_proxy.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2012 Citrix Systems, Inc. Licensed under the # Apache License, Version 2.0 (the "License"); you may not use this # file except in compliance with the License. Citrix Systems, Inc. @@ -12,14 +12,11 @@ # # Automatically generated by addcopyright.py at 04/03/2012 -usage() { - printf "Usage:\n %s \n" $(basename $0) >&2 - printf " %s \n" $(basename $0) >&2 -} -cert="/root/.ssh/id_rsa.cloud" -domRIp=$1 -shift + +# used as a proxy to call script inside virtual router + +#set -x check_gw() { ping -c 1 -n -q $1 > /dev/null @@ -28,15 +25,30 @@ check_gw() { sleep 1 ping -c 1 -n -q $1 > /dev/null fi - return $?; + if [ $? -gt 0 ] + then + exit 1 + fi } +cert="/root/.ssh/id_rsa.cloud" + +script=$1 +shift + +domRIp=$1 +shift check_gw "$domRIp" -if [ $? -gt 0 ] -then - exit 1 -fi -ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/opt/cloud/bin/get_template_version.sh" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/root/$script $*" exit $? + + + + + + + + + diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index 248108bbd85..d06d89023be 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -139,21 +139,6 @@ def pingxenserver(session, args): txt = 'success' return txt -@echo -def ipassoc(session, args): - sargs = args['args'] - cmd = sargs.split(' ') - cmd.insert(0, "/opt/xensource/bin/ipassoc.sh") - cmd.insert(0, "/bin/bash") - try: - txt = util.pread2(cmd) - txt = 'success' - except: - util.SMlog(" ip associate failed " ) - txt = '' - - return txt - @echo def vm_data(session, args): router_ip = args.pop('routerIP') @@ -298,6 +283,8 @@ def setLinkLocalIP(session, args): txt = '' txt = 'success' return txt + + @echo def setFirewallRule(session, args): @@ -313,6 +300,23 @@ def setFirewallRule(session, args): txt = '' return txt + +@echo +def routerProxy(session, args): + sargs = args['args'] + cmd = sargs.split(' ') + cmd.insert(0, "/opt/xensource/bin/router_proxy.sh") + cmd.insert(0, "/bin/bash") + try: + txt = util.pread2(cmd) + txt = 'success' + except: + util.SMlog("routerProxy command " + sargs + " failed " ) + txt = '' + + return txt + + @echo def setLoadBalancerRule(session, args): @@ -1436,26 +1440,13 @@ def bumpUpPriority(session, args): return txt -@echo -def getDomRVersion(session, args): - sargs = args['args'] - cmd = sargs.split(' ') - cmd.insert(0, "/opt/xensource/bin/getDomRVersion.sh") - cmd.insert(0, "/bin/bash") - try: - txt = util.pread2(cmd) - except: - util.SMlog(" get domR version fail! ") - txt = '' - - return txt if __name__ == "__main__": XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats, "getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration, "setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver, - "ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword, - "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, + "vm_data": vm_data, "savePassword": savePassword, + "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "routerProxy": routerProxy, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, "networkUsage": networkUsage, "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, @@ -1464,5 +1455,5 @@ if __name__ == "__main__": "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn, "cleanup_rules":cleanup_rules, "checkRouter":checkRouter, - "bumpUpPriority":bumpUpPriority, "getDomRVersion":getDomRVersion, + "bumpUpPriority":bumpUpPriority, "kill_copy_process":kill_copy_process}) diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index b06f0ea3d3b..a7dac08e9f4 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -22,12 +22,12 @@ setup_iscsi.sh=..,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin -ipassoc.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin +router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin @@ -46,6 +46,5 @@ cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin -getDomRVersion.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index 88d33c8b2df..3482fb752df 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -27,12 +27,12 @@ make_migratable.sh=..,0755,/opt/xensource/bin setup_iscsi.sh=..,0755,/opt/xensource/bin pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin -ipassoc.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin +router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin @@ -51,6 +51,5 @@ cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin -getDomRVersion.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index 88d33c8b2df..f087c3ab80c 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -27,12 +27,12 @@ make_migratable.sh=..,0755,/opt/xensource/bin setup_iscsi.sh=..,0755,/opt/xensource/bin pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin -ipassoc.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin +router_proxy=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin @@ -51,6 +51,5 @@ cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin -getDomRVersion.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/wscript b/wscript index 858577443cb..2f5219c2363 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-05T23:07:27Z' +VERSION = '3.0.3.2012-06-06T00:22:14Z' APPNAME = 'cloud' import shutil,os From 6310b051d8de0f9e38a50a54f469cc0aa4f8cabc Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 5 Jun 2012 18:49:00 -0700 Subject: [PATCH 26/64] VPC : implement SetupGuestNetworkCommand --- .../agent/api/SetupGuestNetworkCommand.java | 4 ++ .../xen/resource/CitrixResourceBase.java | 43 ++++++++++++++++++- wscript | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java index c2ca11b741b..e36ca28d0e3 100644 --- a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -28,6 +28,10 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ boolean add = true; NicTO nic; + public NicTO getNic() { + return nic; + } + @Override public boolean executeInSequence() { return true; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index ac39b61956b..ce709963af0 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -7017,8 +7017,47 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * @return */ private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) { - // TODO Auto-generated method stub - return null; + Connection conn = getConnection(); + NicTO nic = cmd.getNic(); + String domrIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); + String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); + try { + Set vms = VM.getByNameLabel(conn, domrName); + if ( vms == null || vms.isEmpty() ) { + return new SetupGuestNetworkAnswer(cmd, false, "Can not find VM " + domrName); + } + VM vm = vms.iterator().next(); + String mac = nic.getMac(); + VIF domrVif = null; + for ( VIF vif : vm.getVIFs(conn)) { + String lmac = vif.getMAC(conn); + if ( lmac.equals(mac) ) { + domrVif = vif; + break; + } + } + if ( domrVif == null ) { + return new SetupGuestNetworkAnswer(cmd, false, "Can not find vif with mac " + mac + " for VM " + domrName); + } + + String args = "guestnw.sh " + domrIP + " -C"; + String dev = "eth" + domrVif.getDevice(conn); + args += " -d " + dev; + args += " -i " + domrGIP; + args += " -g " + nic.getGateway(); + args += " -m " + Long.toString(NetUtils.getCidrSize(nic.getNetmask())); + args += " -s " + nic.getDns1(); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); + if (result == null || result.isEmpty()) { + return new SetupGuestNetworkAnswer(cmd, false, "creating guest network failed due to " + ((result == null)? "null":result)); + } + return new SetupGuestNetworkAnswer(cmd, true, "success"); + } catch (Exception e) { + String msg = " UnPlug Nic failed due to " + e.toString(); + s_logger.warn(msg, e); + return new SetupGuestNetworkAnswer(cmd, false, msg); + } } diff --git a/wscript b/wscript index 2f5219c2363..55a487809a6 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T00:22:14Z' +VERSION = '3.0.3.2012-06-06T01:46:43Z' APPNAME = 'cloud' import shutil,os From 98127b0b9288f24093cea629924d0b6883ee36ce Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 12:13:43 -0700 Subject: [PATCH 27/64] VPC: typo fix --- scripts/vm/hypervisor/xenserver/xcpserver/patch | 4 ++-- scripts/vm/hypervisor/xenserver/xenserver56fp1/patch | 1 - scripts/vm/hypervisor/xenserver/xenserver60/patch | 3 +-- wscript | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch index 74338f76835..6e9603baa0d 100644 --- a/scripts/vm/hypervisor/xenserver/xcpserver/patch +++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch @@ -1,4 +1,5 @@ # This file specifies the files that need +# # to be transferred over to the XenServer. # The format of this file is as follows: # [Name of file]=[source path],[file permission],[destination path] @@ -11,7 +12,6 @@ # If [source path] does not start with '/' or '~', then it is relative path to the location of the patch file. NFSSR.py=/opt/xensource/sm vmops=..,0755,/etc/xapi.d/plugins -ovsgre=..,0755,/etc/xapi.d/plugins ovstunnel=..,0755,/etc/xapi.d/plugins vmopsSnapshot=..,0755,/etc/xapi.d/plugins hostvmstats.py=..,0755,/opt/xensource/sm @@ -23,7 +23,7 @@ make_migratable.sh=..,0755,/opt/xensource/bin setup_iscsi.sh=..,0755,/opt/xensource/bin pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin -ipassoc.sh=../../../../network/domr/,0755,/opt/xensource/bin +router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index 3482fb752df..f373900a5a6 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -15,7 +15,6 @@ xen-ovs-vif-flows.rules=..,0644,/etc/udev/rules.d ovs-vif-flows.py=..,0755,/etc/xapi.d/plugins cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins -ovsgre=..,0755,/etc/xapi.d/plugins ovstunnel=..,0755,/etc/xapi.d/plugins vmopsSnapshot=..,0755,/etc/xapi.d/plugins hostvmstats.py=..,0755,/opt/xensource/sm diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index f087c3ab80c..f373900a5a6 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -15,7 +15,6 @@ xen-ovs-vif-flows.rules=..,0644,/etc/udev/rules.d ovs-vif-flows.py=..,0755,/etc/xapi.d/plugins cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins -ovsgre=..,0755,/etc/xapi.d/plugins ovstunnel=..,0755,/etc/xapi.d/plugins vmopsSnapshot=..,0755,/etc/xapi.d/plugins hostvmstats.py=..,0755,/opt/xensource/sm @@ -32,7 +31,7 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin -router_proxy=../../../../network/domr/,0755,/opt/xensource/bin +router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin diff --git a/wscript b/wscript index 55a487809a6..ebd8ab74fd4 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T01:46:43Z' +VERSION = '3.0.3.2012-06-06T18:22:16Z' APPNAME = 'cloud' import shutil,os From 78f1aab58427269e3ee6675d1ea9404c88a9508c Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 12:20:25 -0700 Subject: [PATCH 28/64] VPC : pass netmask once for secondary storage VM --- .../com/cloud/storage/secondary/SecondaryStorageManagerImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 470f363d39b..c424795edeb 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -1083,7 +1083,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); } - buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getGateway()); } From 1fa6ba5eccecd6fec0113d22ce566632b2875c78 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 14:22:06 -0700 Subject: [PATCH 29/64] VPC : move acl.sh ipassoc.sh to /opt/cloud/bin/ --- patches/systemvm/debian/config/{root => opt/cloud/bin}/acl.sh | 0 .../systemvm/debian/config/{root => opt/cloud/bin}/ipassoc.sh | 0 scripts/network/domr/router_proxy.sh | 2 +- wscript | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename patches/systemvm/debian/config/{root => opt/cloud/bin}/acl.sh (100%) rename patches/systemvm/debian/config/{root => opt/cloud/bin}/ipassoc.sh (100%) diff --git a/patches/systemvm/debian/config/root/acl.sh b/patches/systemvm/debian/config/opt/cloud/bin/acl.sh similarity index 100% rename from patches/systemvm/debian/config/root/acl.sh rename to patches/systemvm/debian/config/opt/cloud/bin/acl.sh diff --git a/patches/systemvm/debian/config/root/ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh similarity index 100% rename from patches/systemvm/debian/config/root/ipassoc.sh rename to patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh diff --git a/scripts/network/domr/router_proxy.sh b/scripts/network/domr/router_proxy.sh index 175cb6ba58a..ac0c9cb8df3 100755 --- a/scripts/network/domr/router_proxy.sh +++ b/scripts/network/domr/router_proxy.sh @@ -41,7 +41,7 @@ shift check_gw "$domRIp" -ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/root/$script $*" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/opt/cloud/bin/$script $*" exit $? diff --git a/wscript b/wscript index ebd8ab74fd4..73f363448de 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T18:22:16Z' +VERSION = '3.0.3.2012-06-06T19:22:49Z' APPNAME = 'cloud' import shutil,os From a015a9203eb4b651f9f18a967aee0abfc6f6b11c Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 16:08:14 -0700 Subject: [PATCH 30/64] VCP : use routerProxy to call checkrouter script --- .../xen/resource/CitrixResourceBase.java | 4 +- scripts/network/domr/getRouterStatus.sh | 42 ------------------- scripts/vm/hypervisor/xenserver/vmops | 16 +------ .../vm/hypervisor/xenserver/xenserver56/patch | 1 - .../hypervisor/xenserver/xenserver56fp1/patch | 1 - .../vm/hypervisor/xenserver/xenserver60/patch | 1 - wscript | 2 +- 7 files changed, 4 insertions(+), 63 deletions(-) delete mode 100755 scripts/network/domr/getRouterStatus.sh diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index ce709963af0..5d30664ebab 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1330,8 +1330,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe private CheckRouterAnswer execute(CheckRouterCommand cmd) { Connection conn = getConnection(); - String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - String result = callHostPlugin(conn, "vmops", "checkRouter", "args", args); + String args = "checkrouter.sh " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); if (result == null || result.isEmpty()) { return new CheckRouterAnswer(cmd, "CheckRouterCommand failed"); } diff --git a/scripts/network/domr/getRouterStatus.sh b/scripts/network/domr/getRouterStatus.sh deleted file mode 100755 index 04511b6a6f3..00000000000 --- a/scripts/network/domr/getRouterStatus.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# Copyright 2012 Citrix Systems, Inc. Licensed under the -# Apache License, Version 2.0 (the "License"); you may not use this -# file except in compliance with the License. Citrix Systems, Inc. -# reserves all rights not expressly granted by the License. -# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Automatically generated by addcopyright.py at 04/03/2012 - -usage() { - printf "Usage:\n %s \n" $(basename $0) >&2 - printf " %s \n" $(basename $0) >&2 -} - -cert="/root/.ssh/id_rsa.cloud" -domRIp=$1 -shift - -check_gw() { - ping -c 1 -n -q $1 > /dev/null - if [ $? -gt 0 ] - then - sleep 1 - ping -c 1 -n -q $1 > /dev/null - fi - return $?; -} - - -check_gw "$domRIp" -if [ $? -gt 0 ] -then - exit 1 -fi - -ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/root/checkrouter.sh" -exit $? diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index d06d89023be..afe3f5e671e 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -1411,20 +1411,6 @@ def network_rules(session, args): except: util.SMlog("Failed to network rule !") -@echo -def checkRouter(session, args): - sargs = args['args'] - cmd = sargs.split(' ') - cmd.insert(0, "/opt/xensource/bin/getRouterStatus.sh") - cmd.insert(0, "/bin/bash") - try: - txt = util.pread2(cmd) - except: - util.SMlog(" check router status fail! ") - txt = '' - - return txt - @echo def bumpUpPriority(session, args): sargs = args['args'] @@ -1454,6 +1440,6 @@ if __name__ == "__main__": "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn, - "cleanup_rules":cleanup_rules, "checkRouter":checkRouter, + "cleanup_rules":cleanup_rules, "bumpUpPriority":bumpUpPriority, "kill_copy_process":kill_copy_process}) diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index a7dac08e9f4..82f16a93834 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -44,7 +44,6 @@ create_privatetemplate_from_snapshot.sh=..,0755,/opt/xensource/bin upgrade_snapshot.sh=..,0755,/opt/xensource/bin cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin -getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index f373900a5a6..4d6e97131f8 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -48,7 +48,6 @@ create_privatetemplate_from_snapshot.sh=..,0755,/opt/xensource/bin upgrade_snapshot.sh=..,0755,/opt/xensource/bin cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin -getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index f373900a5a6..4d6e97131f8 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -48,7 +48,6 @@ create_privatetemplate_from_snapshot.sh=..,0755,/opt/xensource/bin upgrade_snapshot.sh=..,0755,/opt/xensource/bin cloud-clean-vlan.sh=..,0755,/opt/xensource/bin cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin -getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin swift=..,0755,/opt/xensource/bin swiftxen=..,0755,/etc/xapi.d/plugins diff --git a/wscript b/wscript index 73f363448de..76fca74cb23 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T19:22:49Z' +VERSION = '3.0.3.2012-06-06T21:28:42Z' APPNAME = 'cloud' import shutil,os From 1b813423548b2cab94da4fbfaf2e0ff17b100b51 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 16:36:47 -0700 Subject: [PATCH 31/64] VPC : use routerProxy to call networkUsage.sh --- .../computing/LibvirtComputingResource.java | 16 +++--- .../vmware/resource/VmwareResource.java | 6 +-- .../xen/resource/XenServer56Resource.java | 6 +-- .../config/{root => opt/cloud/bin}/guestnw.sh | 0 .../debian/config/opt/cloud/bin/ipassoc.sh | 0 .../{root => opt/cloud/bin}/netusage.sh | 0 scripts/network/domr/networkUsage.sh | 53 ------------------- scripts/vm/hypervisor/xenserver/vmops | 15 +----- .../vm/hypervisor/xenserver/xcpserver/patch | 1 - .../vm/hypervisor/xenserver/xenserver56/patch | 1 - .../hypervisor/xenserver/xenserver56fp1/patch | 1 - .../vm/hypervisor/xenserver/xenserver60/patch | 1 - wscript | 2 +- 13 files changed, 16 insertions(+), 86 deletions(-) rename patches/systemvm/debian/config/{root => opt/cloud/bin}/guestnw.sh (100%) mode change 100644 => 100755 patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh rename patches/systemvm/debian/config/{root => opt/cloud/bin}/netusage.sh (100%) mode change 100644 => 100755 delete mode 100755 scripts/network/domr/networkUsage.sh diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index 0f6aa78d9d6..3fee46ccd6c 100755 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -235,7 +235,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements private String _createTmplPath; private String _heartBeatPath; private String _securityGroupPath; - private String _networkUsagePath; + private String _routerProxyPath; private String _host; private String _dcId; private String _pod; @@ -539,11 +539,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements "Unable to find the security_group.py"); } - _networkUsagePath = Script.findScript("scripts/network/domr/", - "networkUsage.sh"); - if (_networkUsagePath == null) { + _routerProxyPath = Script.findScript("scripts/network/domr/", + "routerProxy.sh"); + if (_routerProxyPath == null) { throw new ConfigurationException( - "Unable to find the networkUsage.sh"); + "Unable to find the routerProxy.sh"); } String value = (String) params.get("developer"); @@ -2168,7 +2168,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements protected String networkUsage(final String privateIpAddress, final String option, final String vif) { - Script getUsage = new Script(_networkUsagePath, s_logger); + Script getUsage = new Script(_routerProxyPath, s_logger); + getUsage.add("netusage.sh"); + getUsage.add(privateIpAddress); if (option.equals("get")) { getUsage.add("-g"); } else if (option.equals("create")) { @@ -2181,7 +2183,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements getUsage.add("-d", vif); } - getUsage.add("-i", privateIpAddress); + final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser(); String result = getUsage.execute(usageParser); if (result != null) { diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index d31a7386ee6..eeb8002d569 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1021,7 +1021,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa protected Answer execute(CheckRouterCommand cmd) { if (s_logger.isDebugEnabled()) { s_logger.debug("Executing resource CheckRouterCommand: " + _gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/checkrouter.sh "); + s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /opt/cloud/bin/checkrouter.sh "); } Pair result; @@ -3858,12 +3858,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa try { if (s_logger.isTraceEnabled()) { - s_logger.trace("Executing /root/netusage.sh " + args + " on DomR " + privateIpAddress); + s_logger.trace("Executing /opt/cloud/bin/netusage.sh " + args + " on DomR " + privateIpAddress); } VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - Pair result = SshHelper.sshExecute(privateIpAddress, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/root/netusage.sh " + args); + Pair result = SshHelper.sshExecute(privateIpAddress, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/opt/cloud/bin/netusage.sh " + args); if (!result.first()) { return null; diff --git a/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java b/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java index ff0c5d7b87c..264cee52c15 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java +++ b/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java @@ -142,7 +142,7 @@ public class XenServer56Resource extends CitrixResourceBase { @Override protected String networkUsage(Connection conn, final String privateIpAddress, final String option, final String vif) { - String args = null; + String args = "netusage.sh " + privateIpAddress + " "; if (option.equals("get")) { args = "-g"; } else if (option.equals("create")) { @@ -157,9 +157,7 @@ public class XenServer56Resource extends CitrixResourceBase { args += vif; } - args += " -i "; - args += privateIpAddress; - return callHostPlugin(conn, "vmops", "networkUsage", "args", args); + return callHostPlugin(conn, "vmops", "routerProxy", "args", args); } protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) { diff --git a/patches/systemvm/debian/config/root/guestnw.sh b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh similarity index 100% rename from patches/systemvm/debian/config/root/guestnw.sh rename to patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh diff --git a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh old mode 100644 new mode 100755 diff --git a/patches/systemvm/debian/config/root/netusage.sh b/patches/systemvm/debian/config/opt/cloud/bin/netusage.sh old mode 100644 new mode 100755 similarity index 100% rename from patches/systemvm/debian/config/root/netusage.sh rename to patches/systemvm/debian/config/opt/cloud/bin/netusage.sh diff --git a/scripts/network/domr/networkUsage.sh b/scripts/network/domr/networkUsage.sh deleted file mode 100755 index 3b1450ad902..00000000000 --- a/scripts/network/domr/networkUsage.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2012 Citrix Systems, Inc. Licensed under the -# Apache License, Version 2.0 (the "License"); you may not use this -# file except in compliance with the License. Citrix Systems, Inc. -# reserves all rights not expressly granted by the License. -# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Automatically generated by addcopyright.py at 04/03/2012 - - - - - -# $Id: networkUsage.sh 9879 2010-06-24 02:41:46Z anthony $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/hypervisor/xenserver/networkUsage.sh $ -# networkUsage.sh -- create iptable rules to gather network stats -usage() { - printf "Usage: %s -[c|g|r] -i [-[a|d] ]\n" $(basename $0) >&2 -} - -check_gw() { - ping -c 1 -n -q $1 > /dev/null - if [ $? -gt 0 ] - then - sleep 1 - ping -c 1 -n -q $1 > /dev/null - fi - return $?; -} - -cert="/root/.ssh/id_rsa.cloud" - -while getopts 'cgri:a:d:' OPTION -do - case $OPTION in - i) iflag=1 - domRIp="$OPTARG" - ;; - esac -done - -if ! check_gw "$domRIp" -then - printf "Unable to ping the routing domain, exiting\n" >&2 - exit 3 -fi - -ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/root/netusage.sh $*" -exit $? diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index afe3f5e671e..be41ee86b29 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -364,19 +364,6 @@ def deleteFile(session, args): return txt -@echo -def networkUsage(session, args): - sargs = args['args'] - cmd = sargs.split(' ') - cmd.insert(0, "/opt/xensource/bin/networkUsage.sh") - cmd.insert(0, "/bin/bash") - try: - txt = util.pread2(cmd) - except: - util.SMlog(" network usage error " ) - txt = '' - - return txt def get_private_nic(session, args): vms = session.xenapi.VM.get_all() @@ -1434,7 +1421,7 @@ if __name__ == "__main__": "vm_data": vm_data, "savePassword": savePassword, "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "routerProxy": routerProxy, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, - "networkUsage": networkUsage, "network_rules":network_rules, + "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch index 6e9603baa0d..b26bd31d633 100644 --- a/scripts/vm/hypervisor/xenserver/xcpserver/patch +++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch @@ -26,7 +26,6 @@ dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin -networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index 82f16a93834..23c87611591 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -24,7 +24,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin -networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index 4d6e97131f8..a7212e8ec1a 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -28,7 +28,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin -networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index 4d6e97131f8..a7212e8ec1a 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -28,7 +28,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin -networkUsage.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin diff --git a/wscript b/wscript index 76fca74cb23..16da43f83be 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T21:28:42Z' +VERSION = '3.0.3.2012-06-06T23:35:14Z' APPNAME = 'cloud' import shutil,os From 7bdcb244a25a81dbaa1ff2319795efc21bb5e1cc Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 6 Jun 2012 16:49:16 -0700 Subject: [PATCH 32/64] StartRouter: set only control nic during the initial router start; plug exising public and guest nics after the router is started with control nic --- .../VirtualNetworkApplianceManagerImpl.java | 85 +++++++++++++------ .../cloud/vm/VirtualMachineManagerImpl.java | 46 +++++----- server/src/com/cloud/vm/dao/NicDao.java | 2 + server/src/com/cloud/vm/dao/NicDaoImpl.java | 16 ++++ wscript | 2 +- 5 files changed, 103 insertions(+), 48 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 73269b72a00..ab5da7d9db8 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -201,6 +201,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; @@ -1565,7 +1566,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String defaultDns1 = null; String defaultDns2 = null; - for (NicProfile nic : profile.getNics()) { + + Iterator it = profile.getNics().iterator(); + while (it.hasNext()) { + NicProfile nic = it.next(); int deviceId = nic.getDeviceId(); buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); @@ -1600,6 +1604,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" localgw=").append(dest.getPod().getGateway()); } } + } else { + //Remove public and guest nics from the profile + s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from virtual machine profile " + profile.getVirtualMachine()); + it.remove(); } } @@ -1893,15 +1901,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian ReservationContext context) { DomainRouterVO router = profile.getVirtualMachine(); - //Get guest nic info - List routerNics = profile.getNics(); - List guestNetworks = new ArrayList(); - for (NicProfile routerNic : routerNics) { - if (routerNic.getTrafficType() == TrafficType.Guest) { - guestNetworks.add(_networkMgr.getNetwork(routerNic.getNetworkId())); - } - } - boolean result = true; Answer answer = cmds.getAnswer("checkSsh"); @@ -1917,6 +1916,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (result == false) { return false; } + + //Get guest nic info + Map guestNics = new HashMap(); + Map publicNics = new HashMap(); + List guestNetworks = new ArrayList(); + + List routerNics = _nicDao.listByVmId(profile.getId()); + for (Nic routerNic : routerNics) { + Network network = _networkMgr.getNetwork(routerNic.getNetworkId()); + if (network.getTrafficType() == TrafficType.Guest) { + guestNics.put(routerNic, network); + guestNetworks.add(network); + } else if (network.getTrafficType() == TrafficType.Public) { + publicNics.put(routerNic, network); + } + } + answer = cmds.getAnswer("getDomRVersion"); if (answer != null && answer instanceof GetDomRVersionAnswer) { GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer; @@ -1930,6 +1946,30 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router = _routerDao.persist(router, guestNetworks); } } + + try { + //add router to public and guest networks + for (Nic publicNic : publicNics.keySet()) { + Network publicNtwk = publicNics.get(publicNic); + if (!addRouterToPublicNetwork(router, publicNtwk, _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), + publicNic.getIp4Address()))) { + s_logger.warn("Failed to plug nic " + publicNic + " to router " + router); + return false; + } + } + + for (Nic guestNic : guestNics.keySet()) { + Network guestNtwk = guestNics.get(guestNic); + if (!addRouterToGuestNetwork(router, guestNtwk, false)) { + s_logger.warn("Failed to plug nic " + guestNic + " to router " + router); + return false; + } + } + } catch (Exception ex) { + s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex); + return false; + } + return result; } @@ -3050,7 +3090,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), router.getId()), _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, @@ -3085,12 +3125,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - //Check if router is already a part of the Guest network - if (_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is already part of the Guest network " + network); - return true; - } - //Add router to the Guest network boolean result = true; try { @@ -3154,7 +3188,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress sourceNatIp) + protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress publicIpAddr) throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException { if (publicNetwork.getTrafficType() != TrafficType.Public) { @@ -3162,12 +3196,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - //Check if router is already a part of the Public network - if (_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) { - s_logger.debug("Router " + router + " is already part of the Public network " + publicNetwork); - return true; - } - //Add router to the Public network boolean result = true; try { @@ -3175,8 +3203,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork); //setup public network if (publicNic != null) { - if (sourceNatIp != null) { - IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); + if (publicIpAddr != null) { + IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId()); PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); result = setupPublicNetwork(publicNetwork, router, false, publicIp); @@ -3241,10 +3269,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp sourceNatIp) + protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) throws ConcurrentOperationException, ResourceUnavailableException{ List publicIps = new ArrayList(1); + publicIps.add(ipAddress); Commands cmds = new Commands(OnError.Stop); createAssociateIPCommands(router, publicIps, cmds, 0); sendCommandsToRouter(router, cmds); @@ -3253,7 +3282,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class); String setup = add ? "set" : "destroy"; if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) { - s_logger.warn("Unable to " + setup + " guest network on router " + router); + s_logger.warn("Unable to " + setup + " public network on router " + router); result = false; } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 5dee3d1e9ee..11cb7337dd3 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2448,31 +2448,40 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Host host = _hostDao.findById(vm.getHostId()); DeployDestination dest = new DeployDestination(dc, null, null, host); - s_logger.debug("Adding vm " + vm + " to network " + network); + NicProfile nic = null; + NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId()); + if (nicVO != null) { + nic = new NicProfile(nicVO, network, nicVO.getBroadcastUri(), nicVO.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), vm.getId()), + _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(vm.getHypervisorType(), network)); + } - Transaction txn = Transaction.currentTxn(); - txn.start(); - //1) allocate nic - NicProfile nic = _networkMgr.allocateNic(null, network, false, - 100, vmProfile).first(); + if (nic == null) { + s_logger.debug("Allocating nic for the " + vm + " in network " + network); + Transaction txn = Transaction.currentTxn(); + txn.start(); + //1) allocate nic and prepare nic if needed + int deviceId = _nicsDao.countNics(vm.getId()); + + nic = _networkMgr.allocateNic(null, network, false, + deviceId, vmProfile).first(); + + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + + nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); + + s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); + + txn.commit(); + } - s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); - - //2) Prepare nic - nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); - - s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); - - txn.commit(); - - //3) Convert vmProfile to vmTO + //2) Convert vmProfile to vmTO HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - //4) Convert nicProfile to NicTO + //3) Convert nicProfile to NicTO NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); - //5) plug the nic to the vm + //4) plug the nic to the vm VirtualMachineGuru vmGuru = getVmGuru(vmVO); if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) { @@ -2482,7 +2491,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); return null; } - } @Override diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java index deb302f4e3e..9a62467cfa6 100644 --- a/server/src/com/cloud/vm/dao/NicDao.java +++ b/server/src/com/cloud/vm/dao/NicDao.java @@ -46,4 +46,6 @@ public interface NicDao extends GenericDao { NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId); String getIpAddress(long networkId, long instanceId); + + int countNics(long instanceId); } diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index 09786ca10d6..baa75cd5d2b 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -32,6 +32,8 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder IpSearch; private final SearchBuilder NonReleasedSearch; + final GenericSearchBuilder CountBy; + protected NicDaoImpl() { super(); @@ -55,6 +57,12 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { NonReleasedSearch.and("network", NonReleasedSearch.entity().getNetworkId(), Op.EQ); NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN); NonReleasedSearch.done(); + + CountBy = createSearchBuilder(Integer.class); + CountBy.select(null, Func.COUNT, CountBy.entity().getId()); + CountBy.and("vmId", CountBy.entity().getInstanceId(), Op.EQ); + CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); + CountBy.done(); } @Override @@ -150,4 +158,12 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { return findOneBy(sc).getIp4Address(); } + @Override + public int countNics(long instanceId) { + SearchCriteria sc = CountBy.create(); + sc.setParameters("vmId", instanceId); + List results = customSearch(sc, null); + return results.get(0); + } + } diff --git a/wscript b/wscript index 16da43f83be..a92504bc25e 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T23:35:14Z' +VERSION = '3.0.3.2012-06-06T23:43:59Z' APPNAME = 'cloud' import shutil,os From 2619492b6e0a0f66b6bf8339a9be08625b7bf022 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 17:18:36 -0700 Subject: [PATCH 33/64] VPC : use routerProxy to call l2tpVpn --- .../VirtualRoutingResource.java | 135 ++++++++---------- .../xen/resource/CitrixResourceBase.java | 4 +- scripts/network/domr/l2tp_vpn.sh | 26 ---- scripts/vm/hypervisor/xenserver/vmops | 17 +-- .../vm/hypervisor/xenserver/xcpserver/patch | 1 - .../vm/hypervisor/xenserver/xenserver56/patch | 1 - .../hypervisor/xenserver/xenserver56fp1/patch | 1 - .../vm/hypervisor/xenserver/xenserver60/patch | 1 - wscript | 2 +- 9 files changed, 64 insertions(+), 124 deletions(-) delete mode 100755 scripts/network/domr/l2tp_vpn.sh diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 4527404e7aa..15cfdade21e 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -82,7 +82,6 @@ import com.cloud.utils.script.Script; public class VirtualRoutingResource implements Manager { private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class); private String _savepasswordPath; // This script saves a random password to the DomR file system - private String _ipassocPath; private String _publicIpAddress; private String _firewallPath; private String _loadbPath; @@ -90,11 +89,8 @@ public class VirtualRoutingResource implements Manager { private String _vmDataPath; private String _publicEthIf; private String _privateEthIf; - private String _getRouterStatusPath; private String _bumpUpPriorityPath; - private String _l2tpVpnPath; - private String _getDomRVersionPath; - + private String _routerProxyPath; private int _timeout; private int _startTimeout; @@ -146,37 +142,41 @@ public class VirtualRoutingResource implements Manager { } private Answer execute(VpnUsersCfgCommand cmd) { - for (VpnUsersCfgCommand.UsernamePassword userpwd: cmd.getUserpwds()) { - Script command = new Script(_l2tpVpnPath, _timeout, s_logger); - command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP)); + for (VpnUsersCfgCommand.UsernamePassword userpwd: cmd.getUserpwds()) { + String args = ""; if (!userpwd.isAdd()) { - command.add("-U ", userpwd.getUsername()); + args +="-U "; + args +=userpwd.getUsername(); } else { - command.add("-u ", userpwd.getUsernamePassword()); + args +="-u "; + args += userpwd.getUsernamePassword(); } - String result = command.execute(); + String result = routerProxy("vpn_l2tp.sh", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), args); if (result != null) { return new Answer(cmd, false, "Configure VPN user failed for user " + userpwd.getUsername()); } - } - + } return new Answer(cmd); } private Answer execute(RemoteAccessVpnCfgCommand cmd) { - Script command = new Script(_l2tpVpnPath, _timeout, s_logger); - command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP)); + String args = ""; if (cmd.isCreate()) { - command.add("-r ", cmd.getIpRange()); - command.add("-p ", cmd.getPresharedKey()); - command.add("-s ", cmd.getVpnServerIp()); - command.add("-l ", cmd.getLocalIp()); - command.add("-c "); + args += "-r "; + args += cmd.getIpRange(); + args += " -p "; + args += cmd.getPresharedKey(); + args += " -s "; + args += cmd.getVpnServerIp(); + args += " -l "; + args += cmd.getLocalIp(); + args += " -c "; } else { - command.add("-d "); - command.add("-s ", cmd.getVpnServerIp()); + args +="-d "; + args += " -s "; + args += cmd.getVpnServerIp(); } - String result = command.execute(); + String result = routerProxy("vpn_l2tp.sh", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), args); if (result != null) { return new Answer(cmd, false, "Configure VPN failed"); } @@ -474,9 +474,18 @@ public class VirtualRoutingResource implements Manager { } public String getRouterStatus(String routerIP) { - final Script command = new Script(_getRouterStatusPath, _timeout, s_logger); + return routerProxy("checkrouter.sh", routerIP, null); + } + + + public String routerProxy(String script, String routerIP, String args) { + final Script command = new Script(_routerProxyPath, _timeout, s_logger); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); + command.add(script); command.add(routerIP); + if ( args != null ) { + command.add(args); + } String result = command.execute(parser); if (result == null) { return parser.getLine(); @@ -507,14 +516,7 @@ public class VirtualRoutingResource implements Manager { } protected String getDomRVersion(String routerIP) { - final Script command = new Script(_getDomRVersionPath, _timeout, s_logger); - final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); - command.add(routerIP); - String result = command.execute(parser); - if (result == null) { - return parser.getLine(); - } - return null; + return routerProxy("netusage.sh", routerIP, null); } protected Answer execute(GetDomRVersionCmd cmd) { @@ -592,16 +594,17 @@ public class VirtualRoutingResource implements Manager { public String assignPublicIpAddress(final String vmName, final long id, final String vnet, final String privateIpAddress, final String macAddress, final String publicIpAddress) { - - final Script command = new Script(_ipassocPath, _timeout, s_logger); - command.add("-A"); - command.add("-f"); //first ip is source nat ip - command.add("-r", vmName); - command.add("-i", privateIpAddress); - command.add("-a", macAddress); - command.add("-l", publicIpAddress); - - return command.execute(); + String args ="-A"; + args += " -f"; //first ip is source nat ip + args += " -r "; + args += vmName; + args += " -i "; + args += privateIpAddress; + args += " -a "; + args += macAddress; + args += " -l "; + args += publicIpAddress; + return routerProxy("ipassoc.sh", privateIpAddress, args); } public String assignPublicIpAddress(final String vmName, @@ -610,31 +613,29 @@ public class VirtualRoutingResource implements Manager { final String vlanId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress, String guestIp, int nicNum){ - final Script command = new Script(_ipassocPath, _timeout, s_logger); - command.add( privateIpAddress); + String args = ""; if (add) { - command.add("-A"); + args += "-A"; } else { - command.add("-D"); + args += "-D"; } String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); if (sourceNat) { - command.add("-s"); + args +=" -s"; } if (firstIP) { - command.add( "-f"); - command.add( "-l", publicIpAddress + "/" + cidrSize); - } else { - command.add("-l", publicIpAddress); + args += " -f"; } + args += " -l "; + args += publicIpAddress + "/" + cidrSize; String publicNic = "eth" + nicNum; - command.add("-c", publicNic); + args += " -c "; + args += publicNic; - command.add("-g", vlanGateway); - - - return command.execute(); + args +=" -g "; + args += vlanGateway; + return routerProxy("ipassoc.sh", privateIpAddress, args); } private void deletExitingLinkLocalRoutTable(String linkLocalBr) { @@ -802,12 +803,6 @@ public class VirtualRoutingResource implements Manager { value = (String)params.get("ssh.port"); _port = NumbersUtil.parseInt(value, 3922); - _ipassocPath = findScript("ipassoc.sh"); - if (_ipassocPath == null) { - throw new ConfigurationException("Unable to find the ipassoc.sh"); - } - s_logger.info("ipassoc.sh found in " + _ipassocPath); - _publicIpAddress = (String)params.get("public.ip.address"); if (_publicIpAddress != null) { s_logger.warn("Incoming public ip address is overriden. Will always be using the same ip address: " + _publicIpAddress); @@ -838,11 +833,6 @@ public class VirtualRoutingResource implements Manager { throw new ConfigurationException("Unable to find user_data.sh"); } - _getRouterStatusPath = findScript("getRouterStatus.sh"); - if(_getRouterStatusPath == null) { - throw new ConfigurationException("Unable to find getRouterStatus.sh"); - } - _publicEthIf = (String)params.get("public.network.device"); if (_publicEthIf == null) { _publicEthIf = "xenbr1"; @@ -860,14 +850,9 @@ public class VirtualRoutingResource implements Manager { throw new ConfigurationException("Unable to find bumpUpPriority.sh"); } - _l2tpVpnPath = findScript("l2tp_vpn.sh"); - if (_l2tpVpnPath == null) { - throw new ConfigurationException("Unable to find l2tp_vpn.sh"); - } - - _getDomRVersionPath = findScript("getDomRVersion.sh"); - if(_getDomRVersionPath == null) { - throw new ConfigurationException("Unable to find getDomRVersion.sh"); + _routerProxyPath = findScript("routerProxy.sh"); + if (_routerProxyPath == null) { + throw new ConfigurationException("Unable to find routerProxy.sh"); } return true; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 5d30664ebab..31a44888d5b 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1569,7 +1569,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected synchronized Answer execute(final RemoteAccessVpnCfgCommand cmd) { Connection conn = getConnection(); - String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + String args = "vpn_l2tp.sh " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); if (cmd.isCreate()) { args += " -r " + cmd.getIpRange(); args += " -p " + cmd.getPresharedKey(); @@ -1581,7 +1581,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe args += " -d "; args += " -s " + cmd.getVpnServerIp(); } - String result = callHostPlugin(conn, "vmops", "lt2p_vpn", "args", args); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); if (result == null || result.isEmpty()) { return new Answer(cmd, false, "Configure VPN failed"); } diff --git a/scripts/network/domr/l2tp_vpn.sh b/scripts/network/domr/l2tp_vpn.sh deleted file mode 100755 index 87d9a033c0e..00000000000 --- a/scripts/network/domr/l2tp_vpn.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Copyright 2012 Citrix Systems, Inc. Licensed under the -# Apache License, Version 2.0 (the "License"); you may not use this -# file except in compliance with the License. Citrix Systems, Inc. -# reserves all rights not expressly granted by the License. -# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Automatically generated by addcopyright.py at 04/03/2012 - - - - - -# @VERSION@ - -cert="/root/.ssh/id_rsa.cloud" -domr=$1 -shift -ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/opt/cloud/bin/vpn_l2tp.sh $*" >/dev/null - -exit $? diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index be41ee86b29..4b918c70913 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -232,21 +232,6 @@ def saveDhcpEntry(session, args): return txt -@echo -def lt2p_vpn(session, args): - sargs = args['args'] - cmd = sargs.split(' ') - cmd.insert(0, "/opt/xensource/bin/l2tp_vpn.sh") - cmd.insert(0, "/bin/bash") - try: - txt = util.pread2(cmd) - txt = 'success' - except: - util.SMlog("l2tp vpn failed " ) - txt = '' - - return txt - @echo def setLinkLocalIP(session, args): brName = args['brName'] @@ -1426,7 +1411,7 @@ if __name__ == "__main__": "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, - "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn, + "setLinkLocalIP":setLinkLocalIP, "cleanup_rules":cleanup_rules, "bumpUpPriority":bumpUpPriority, "kill_copy_process":kill_copy_process}) diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch index b26bd31d633..7171635be16 100644 --- a/scripts/vm/hypervisor/xenserver/xcpserver/patch +++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch @@ -28,7 +28,6 @@ vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin -l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index 23c87611591..37d4290f1c3 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -27,7 +27,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin -l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin kill_copy_process.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index a7212e8ec1a..fdbfbbef050 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -31,7 +31,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin -l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index a7212e8ec1a..fdbfbbef050 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -31,7 +31,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin -l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin diff --git a/wscript b/wscript index a92504bc25e..e578b8d6469 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-06T23:43:59Z' +VERSION = '3.0.3.2012-06-07T00:17:43Z' APPNAME = 'cloud' import shutil,os From 657a40ad30e29ea695d4feb65e2097ddc59cb7cc Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 6 Jun 2012 18:22:09 -0700 Subject: [PATCH 34/64] VPC : get correct guest gateway --- .../com/cloud/hypervisor/xen/resource/CitrixResourceBase.java | 3 ++- wscript | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 31a44888d5b..75b02664e30 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -7022,6 +7022,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String domrIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); + String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); try { Set vms = VM.getByNameLabel(conn, domrName); if ( vms == null || vms.isEmpty() ) { @@ -7045,7 +7046,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String dev = "eth" + domrVif.getDevice(conn); args += " -d " + dev; args += " -i " + domrGIP; - args += " -g " + nic.getGateway(); + args += " -g " + gw; args += " -m " + Long.toString(NetUtils.getCidrSize(nic.getNetmask())); args += " -s " + nic.getDns1(); String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); diff --git a/wscript b/wscript index e578b8d6469..54f1386bcff 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-07T00:17:43Z' +VERSION = '3.0.3.2012-06-07T00:21:40Z' APPNAME = 'cloud' import shutil,os From a159255e36c71989655c4a82cb5d191f6f952302 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 7 Jun 2012 17:53:12 -0700 Subject: [PATCH 35/64] VPC : many debug fix --- .../agent/api/SetupGuestNetworkCommand.java | 4 ++ .../xen/resource/CitrixResourceBase.java | 12 ++++- .../systemvm/debian/config/etc/dnsmasq.conf | 4 +- .../config/etc/init.d/cloud-early-config | 50 ++----------------- .../debian/config/opt/cloud/bin/guestnw.sh | 35 ++++++++----- wscript | 2 +- 6 files changed, 44 insertions(+), 63 deletions(-) diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java index e36ca28d0e3..f5f57c8d316 100644 --- a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -32,6 +32,10 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ return nic; } + public String getNetworkDomain() { + return networkDomain; + } + @Override public boolean executeInSequence() { return true; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 75b02664e30..4c02f71941b 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -7023,6 +7023,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); + String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));; + String domainName = cmd.getNetworkDomain(); + String dns = nic.getDns1(); try { Set vms = VM.getByNameLabel(conn, domrName); if ( vms == null || vms.isEmpty() ) { @@ -7047,8 +7050,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe args += " -d " + dev; args += " -i " + domrGIP; args += " -g " + gw; - args += " -m " + Long.toString(NetUtils.getCidrSize(nic.getNetmask())); - args += " -s " + nic.getDns1(); + args += " -m " + cidr; + if ( dns != null && !dns.isEmpty() ) { + args += " -s " + dns; + } + if ( domainName != null && !domainName.isEmpty() ) { + args += " -e " + domainName; + } String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args); if (result == null || result.isEmpty()) { return new SetupGuestNetworkAnswer(cmd, false, "creating guest network failed due to " + ((result == null)? "null":result)); diff --git a/patches/systemvm/debian/config/etc/dnsmasq.conf b/patches/systemvm/debian/config/etc/dnsmasq.conf index f997004ef78..ca328694ca7 100644 --- a/patches/systemvm/debian/config/etc/dnsmasq.conf +++ b/patches/systemvm/debian/config/etc/dnsmasq.conf @@ -110,14 +110,14 @@ expand-hosts # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3) Provides the domain part for "expand-hosts" -domain=2.vmops-test.vmops.com +#domain=2.vmops-test.vmops.com # Uncomment this to enable the integrated DHCP server, you need # to supply the range of addresses available for lease and optionally # a lease time. If you have more than one network, you will need to # repeat this for each network on which you want to supply DHCP # service. -dhcp-range=10.1.1.1,static +#dhcp-range=10.1.1.1,static #dhcp-range=10.0.0.1,10.255.255.255 dhcp-hostsfile=/etc/dhcphosts.txt diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 3785340dc20..463d6408c46 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -286,10 +286,13 @@ disable_hvc() { setup_common() { init_interfaces $1 $2 $3 setup_interface "0" $ETH0_IP $ETH0_MASK - setup_interface "1" $ETH1_IP $ETH1_MASK + if [ -n "$ETH1_IP" ] + then + setup_interface "1" $ETH1_IP $ETH1_MASK + fi if [ -n "$ETH2_IP" ] then - setup_interface "2" $ETH2_IP $ETH2_MASK + setup_interface "2" $ETH2_IP $ETH2_MASK fi echo $NAME > /etc/hostname @@ -349,46 +352,6 @@ setup_common() { fi } -setup_dnsmasq() { - log_it "Setting up dnsmasq" - [ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP - [ -z $DOMAIN ] && DOMAIN="cloudnine.internal" - - if [ -n "$DOMAIN" ] - then - #send domain name to dhcp clients - sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\"$DOMAIN\"/ /etc/dnsmasq.conf - #DNS server will append $DOMAIN to local queries - sed -r -i s/^[#]?domain=.*$/domain=$DOMAIN/ /etc/dnsmasq.conf - #answer all local domain queries - sed -i -e "s/^[#]*local=.*$/local=\/$DOMAIN\//" /etc/dnsmasq.conf - - fi - - if [ -n "$DNS_SEARCH_ORDER" ] - then - sed -i -e "/^[#]*dhcp-option.*=119.*$/d" /etc/dnsmasq.conf - echo "dhcp-option-force=119,$DNS_SEARCH_ORDER" >> /etc/dnsmasq.conf - # set the domain search order as a space seprated list for option 15 - DNS_SEARCH_ORDER=$(echo $DNS_SEARCH_ORDER | sed 's/,/ /g') - #send domain name to dhcp clients - sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\""$DNS_SEARCH_ORDER"\"/ /etc/dnsmasq.conf - fi - - - sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf - sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf - - if [ "$RROUTER" == "1" ] - then - sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=option:router,$GUEST_GW" >> /etc/dnsmasq.conf - sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf - echo "dhcp-option=6,$GUEST_GW" >> /etc/dnsmasq.conf - fi - -} - setup_sshd(){ local ip=$1 [ -f /etc/ssh/sshd_config ] && sed -i -e "s/^[#]*ListenAddress.*$/ListenAddress $ip/" /etc/ssh/sshd_config @@ -520,9 +483,6 @@ setup_router() { setup_redundant_router fi - setup_dnsmasq - setup_apache2 $ETH0_IP - sed -i /gateway/d /etc/hosts echo "$ETH0_IP $NAME" >> /etc/hosts diff --git a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh index d15f8a45c3c..c90ef7649fb 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh @@ -32,20 +32,26 @@ usage() { setup_dnsmasq() { loger -t cloud "Setting up dnsmasq for network $ip/$mask " - + # setup static sed -i -e "/^[#]*dhcp-range=interface:$dev/d" /etc/dnsmasq.d/cloud.conf - - echo "dhcp-range=interface:$dev,set:interface-$dev,$ip,static/" >> /etc/dnsmasq.d/cloud.conf - + echo "dhcp-range=interface:$dev,set:interface-$dev,$ip,static" >> /etc/dnsmasq.d/cloud.conf + # setup gateway sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,option:router.*$/d" /etc/dnsmasq.d/cloud.conf if [ -n "$gw" ] then echo "dhcp-option=tag:interface-$dev,option:router,$gw" >> /etc/dnsmasq.d/cloud.conf fi + # setup DNS sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,6.*$/d" /etc/dnsmasq.d/cloud.conf - if [ -n "$NS" ] + if [ -n "$DNS" ] then - echo "dhcp-option=tag:interface-$dev,6,$NS" >> /etc/dnsmasq.d/cloud.conf + echo "dhcp-option=tag:interface-$dev,6,$DNS" >> /etc/dnsmasq.d/cloud.conf + fi + # setup DOMAIN + sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,15.*$/d" /etc/dnsmasq.d/cloud.conf + if [ -n "$DOMAIN" ] + then + echo "dhcp-option=tag:interface-$dev,15,$DOMAIN" >> /etc/dnsmasq.d/cloud.conf fi service dnsmasq restart sleep 1 @@ -72,14 +78,14 @@ create_guest_network() { then logger -t cloud "$(basename $0): create VPC inbound acl chain for network $ip/$mask" # policy drop - sudo iptables -A ACL_INBOUND_$ip DROP >/dev/null + sudo iptables -A ACL_INBOUND_$ip -j DROP >/dev/null sudo iptables -A FORWARD -o $dev -d $ip/$mask -j ACL_INBOUND_$ip fi # create outbound acl chain if sudo iptables -N ACL_OUTBOUND_$ip 2>/dev/null then logger -t cloud "$(basename $0): create VPC outbound acl chain for network $ip/$mask" - sudo iptables -A ACL_OUTBOUND_$ip DROP >/dev/null + sudo iptables -A ACL_OUTBOUND_$ip -j DROP >/dev/null sudo iptables -A FORWARD -i $dev -s $ip/$mask -j ACL_OUTBOUND_$ip fi @@ -111,7 +117,7 @@ Dflag= op="" -while getopts 'CDg:n:m:c:v' OPTION +while getopts 'CDn:m:d:i:g:s:e:' OPTION do case $OPTION in C) Cflag=1 @@ -123,13 +129,13 @@ do n) nflag=1 network="$OPTAGR" ;; - c) mflag=1 + m) mflag=1 mask="$OPTARG" ;; d) dflag=1 dev="$OPTARG" ;; - v) iflag=1 + i) iflag=1 ip="$OPTARG" ;; g) gflag=1 @@ -137,6 +143,9 @@ do ;; s) sflag=1 DNS="$OPTARG" + ;; + e) eflag=1 + DOMAIN="$OPTARG" ;; ?) usage unlock_exit 2 $lock $locked @@ -145,13 +154,13 @@ do done -if [ "$Cflag$Dflag$cflag" != "11" ] +if [ "$Cflag$Dflag$dflag" != "11" ] then usage unlock_exit 2 $lock $locked fi -if [ "$Cflag" == "1" ] && ["$dflag$iflag$gflag$mflag" != "1111" ] +if [ "$Cflag" == "1" ] && ["$iflag$gflag$mflag" != "111" ] then usage unlock_exit 2 $lock $locked diff --git a/wscript b/wscript index 54f1386bcff..c5a522ec0bd 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-07T00:21:40Z' +VERSION = '3.0.3.2012-06-08T00:42:03Z' APPNAME = 'cloud' import shutil,os From 52d93071c8a22c170ea094df08c2e7750ff3d2d2 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 7 Jun 2012 19:10:20 -0700 Subject: [PATCH 36/64] VPC : bug fix --- patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh | 8 +++++--- wscript | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh index c90ef7649fb..a97e28a8078 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh @@ -31,7 +31,7 @@ usage() { setup_dnsmasq() { - loger -t cloud "Setting up dnsmasq for network $ip/$mask " + logger -t cloud "Setting up dnsmasq for network $ip/$mask " # setup static sed -i -e "/^[#]*dhcp-range=interface:$dev/d" /etc/dnsmasq.d/cloud.conf echo "dhcp-range=interface:$dev,set:interface-$dev,$ip,static" >> /etc/dnsmasq.d/cloud.conf @@ -58,7 +58,7 @@ setup_dnsmasq() { } desetup_dnsmasq() { - loger -t cloud "Setting up dnsmasq for network $ip/$mask " + logger -t cloud "Setting up dnsmasq for network $ip/$mask " sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,option:router.*$/d" /etc/dnsmasq.d/cloud.conf sed -i -e "/^[#]*dhcp-option=tag:interface-$dev,6.*$/d" /etc/dnsmasq.d/cloud.conf @@ -71,7 +71,9 @@ desetup_dnsmasq() { create_guest_network() { logger -t cloud " $(basename $0): Create network on interface $dev, gateway $gw, network $ip/$mask " - sudo ip addr add $dev $ip/$mask + sudo ip addr add dev $dev $ip/$mask + sudo ip link set $dev up + sudo arping -c 3 -I $dev -A -U -s $ip $ip; # create inbound acl chain if sudo iptables -N ACL_INBOUND_$ip 2>/dev/null diff --git a/wscript b/wscript index c5a522ec0bd..d7a5ef16033 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-08T00:42:03Z' +VERSION = '3.0.3.2012-06-08T01:50:26Z' APPNAME = 'cloud' import shutil,os From cf1882a2c818fe2bf8468b1bc06e35bb48ff0e82 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Sun, 10 Jun 2012 12:24:43 -0700 Subject: [PATCH 37/64] 1) Added VpcVirtualNetworkApplianceService interface 2) Pass dns1/dns2 to setupGuestNetworkCommand 3) Network implement - don't get source nat ip address for Vpc if it already has one --- .../VirtualNetworkApplianceService.java | 1 + .../VpcVirtualNetworkApplianceService.java | 36 ++++++++++ awsapi.log.2012-05-30.gz | Bin 14294 -> 0 bytes .../src/com/cloud/network/NetworkManager.java | 8 +++ .../com/cloud/network/NetworkManagerImpl.java | 44 +++++++++--- .../network/element/VirtualRouterElement.java | 26 +++---- .../element/VpcVirtualRouterElement.java | 66 +++++++++++++----- .../VirtualNetworkApplianceManager.java | 1 + .../VirtualNetworkApplianceManagerImpl.java | 65 +++++++++++------ .../VpcVirtualNetworkApplianceManager.java | 3 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 20 +++++- .../cloud/vm/VirtualMachineManagerImpl.java | 13 ++-- .../src/com/cloud/vm/dao/DomainRouterDao.java | 7 ++ .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 6 ++ setup/db/create-schema.sql | 3 +- wscript | 3 +- 16 files changed, 229 insertions(+), 73 deletions(-) create mode 100644 api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java delete mode 100644 awsapi.log.2012-05-30.gz diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index 7f719c22c29..8a22cf8cd96 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -62,6 +62,7 @@ public interface VirtualNetworkApplianceService { * @param router * @param network * @param isRedundant TODO + * @param setupDns TODO * @return * @throws ConcurrentOperationException * @throws ResourceUnavailableException diff --git a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java new file mode 100644 index 00000000000..139de989459 --- /dev/null +++ b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java @@ -0,0 +1,36 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.router.VirtualRouter; + +/** + * @author Alena Prokharchyk + */ +public interface VpcVirtualNetworkApplianceService { + + /** + * @param router + * @param network + * @param isRedundant + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + +} diff --git a/awsapi.log.2012-05-30.gz b/awsapi.log.2012-05-30.gz deleted file mode 100644 index 2f45884fddf0a648283159025233f2c0b0aa2414..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14294 zcmbt)X&}_=-+rglsk8}UY)OSM46+oVvW6MiGGom!7;9w7-a$#$!ice)V#wZ%-B?c9 zVyNsP9LYMCvK!m~9>4SaUp+6(@9|>3-#6~L=d)a&>$>inKl1pY|NPAln?1ZFkNfA> zRGQxF@H7Yb5$Jfzp{0(BgX2E}B%r)IKO&qsgAzTrOAKFCwUawd5_41W1)>E#nHw*CddZIDBsRfh_@FFNTK@*3hh)cjMKY#9nJI8ho8At8#EF>kF z*as)W_8ta#Z3Q`7)g))^1$3Octzvn3V*9)8?$GA8x3BNR z;gyG8?jC_9y0IOf7n7Fbtrn&tefGRd9tEyVF6C@~_bX4$I9;r=wd*#zjg|7>@-E+S zTt)8KUfQ!Mzp;5!brjaEYW2;0FGYFd+@9~cRZeWiW_^j3y;slPulGmy`jaw(r5bwz z#Z=>m(w%q;^IW1WhugbyeAeLW!JP7=<|E>ITlIq#SiYT>(MO3RYpYZ$zG>U7qve-+ ziGZ@R#%AFiCD+N?3S<7+oer3Zy-PTLaWvpBm&U<&h0&88C1gzh-@)Q`{XQlo6CK~F z6%{5tr)$^MhW^TJ?}JU#Rwq`s3x+Rz+Ff=VEnVDObMy|x)rFbJM^?;-Z~YTdex1D{ zNHz%`Jerdx68M7pmmL4}Na1kb%3wu>Qf*Rav)M%7Vpiaky~?mSXUXyeO?Ct)y4qzOGV7AT`jdw#K|}%fq`n5HXyQL)9en-3-i1 zj9h73+*_V>9jKWAd4xYaL{kpDQ_{aYIo3Vax^S{YuhgfXPyLhfBj-EC+TkM|5{S`Y z_5R2J(K+{Fb4x1;n7v8T-j3SVpizDP&dT+`z%<0={wY1rvl+CdA_=RG&!cHp9VRY8 zy{@yPrw1y+ts!Ai{@cZljt+f4%*IcWzQn!jUcM3FEnmL@ReB*&V`))WXC*VW9?o}T zGfyJ)XHUxrZ^%@=_~*XGJN8sq^|8HIh*upx{^>zCOF08$E!}CaE4*5!b7IsfleZ_< z?1(q~OUy^oW!>dl%{!9jBM459dOIddhKYtMCBrT70dfC8+O3xe=l+tFU(l{Qm(xNe z>>?xiIZK9yq8kDnzpv~}RWGi-?;W3(tB~gy|5{Gd%Xgs`_mBFhya)L&*Dt^=ofTP`-yN=35l!2uk*g?Q?cBKM zE8A~P%|3sF_T#C1Y0uuQl9T0#%ilXO+Y=M$k%es)IM& zqE&3yrgGK?O_c_%jt1Xne$<0pHXPG8%U30sERFLFax$O4#A}`OGktT2Qa;KO|p<1~GrBk{W{tzA(^A6gZiT~___Ye5?J!v_A zle$tw?boZIz3=xl`D5p3=e9d8Xr%u9;Nl3;F?TP2>+$zv-f_K}+nXI7q|MsEq2Oj} z{Z{@9=2ZXl6`kL%_}4S#cX4bq%_&>_O5I*5at%IQ7wEID(>C`#XL+?YhrH(Izc%I5 zQJe3BE#8>VZ~AVx%rU^+uVOX2onJNT?X|Z?`@!tv*7Zqv&v#9gmPm7<&94>Xo0|9$ z65UseC8kU`g*(zBRBrs@%h{3m!*`T7g+Jh1|8j6)P+QD5Q;kwj+L%eq*GJ8sOTSEf zMstH5%?2M0g+7(%Ut~UFx8ol)PT78aJ*)nX|5oodjAzk}e*tEfmor-F%W1vC!Pe7P zkyV&AtW0wnnf%;~^H8|a ~od#E{P+Cxt-`iZZB3lX1Q|r^x_EII}O!PcOu1y4e z9x7br57-*sRa*+7J7P~QGB{s{606$jz&@-*6k869IlG$V z=uuZ{!?(t9C1yh#ayu8woD;j?QkhQa;*m7fB(pGyc@xx~)4ats~GaF)m`^bs8r zGO4(zk|EwL-!n2f>uL}LqLyQ>G%)&Qz^`RxtakcXhw}*Hp7rt)b;fMQLIc0J;;2@? z!=pk*a4zR>{TW)DnI$t(AJlsJ3VHtz<8LHix^jA?-RCMoc9rDD!8@}J? zxJo3;GjnD8%ka%0f>QT9yGFBgr*QW&C#Pu6a%QOkUAOvLc&S#)8C`CbWIg-6YW%Qe z5N+HfBlsnnR_eC0(0wf0Rqs+|0d{-vTV!3;u3B2v)x@ibny2eCVhSLvQctBnlA<+qPNHt(;skA(4)U11MEP`IH}x9I8=J)&8wxd4KsYE4vSw)F z?)A1Y5i}^%zkT#zw}FO0w;b|Lkiwt>Iv-gN@@Uth6f~IGM=iujIb^&B%D)-v9$HDC#`fm zPtN7RgmJ6v%~4)XghH4RIDF^E@q>im-(XE%pqvivq*mP$*2Lkl(=|(e$4PTtzh=V2 z;<^@+p*Dlj>Vg)nwgXL-BR83Ka27Hnw+2&|?a7vJwG-nf)cZ#Un`ADEp4a%a^$VxoWV>tq2FL_JP97>k?{-XUPHE*SZX;Cva zC?Fk4)A+rcdGTcvDYi370OulOdhDQ!g0Gj(KzbiFga-(M9k>7VyGD#E>-{k87>mwz zOjhvtK)qXlJR_CD%0c3N!^Cm0t?vJ*_RBc2P$s`F8)&$Uv*jbDIAoq@Rsn%SVZlp) z(gUZNFpX=|Yp;#t7D%An&Tov=$3@D>{cl;EB;Kx{no{Bgd4>6jY<*Fd=p|Gr)Ww+R zk|+B~4vMmd)l;N*C#3M~frHFKaYhgDMB!IT->Gs_6ZwTDa70v6w?oP3EgT}7-~Qq` zrH`aoVjO+T`V7{bJcPR6fyN^;XEbn#e(B>gYd2s8SIgu+7-zP4oDYGLA+@5R&>;s= z_6rB>Y=8lj0NVksC_^@3ibVAI1sw~qc!_~0BQR99Yu=zE%l5P@kOSe6P>IJ-lTNjq zgF*&B&f@su8BF;LHg*BGtm@s7qOlFp^`tu^l? zcCKFhXfgF<7!FN?lhYp9l}4Vw3EhIYaCLw1?ldwGz&#U0M<6dAmM9;^TBj8!vJ57_Y$Zh!4KQ&So@o732SMh4F}z(10Q5CQcK~u9Z`@mX zU^~-|)q-3H*nbE2+PkAVs>qf!hmLvz7KXq3jgf^l!NO`v?j+~#XKj2;sOCY(vF}B; zRg{`{**MW1wzgb!lLucW>?SA-W^ocq8I;6dH>Iq-hgE2^>G$GT8@5zdF1}Id(qRhLlQ1MMng;vt7W zZ3kN3QZ7)Gx!oAqxU((RmL~ke@5ZQ1D@jk4zv+t3=%ti$ zK*Q{VDNa>}g^_rx)2V?#bh0$+43@X0@tuo;#0kNM7+Wx~D0%lZDkc4(Qv!{oSScKR zvLr?yyjh-Ml!=04HqW4i>UoI5QdpC8ti#eWc1#)>N)WgofqVV9GHHEK}%j>+$59x z9|wRA@BXPtN+3L(IWF$Wt7Jnh!I3|d^+H21 zM-P|pnZQ0cSQ}61yM4?`4kah0VQ~VL?GPo)2p>g|oKM*)El%3DN)xOJH@HbMh->WY zvM}eN$UA%@W2+7jrN_uMDQ;94a;@{xQPhF(em@wKY#K-G(PzK~&sARSF2B_i!O+f@6T3D3GVzlF+e&7Csex2)al$D z0_UGZkv5L&{_IhYUWFB80dZ870CfZsGPGO#o|OADpt~ za-8WpFD5$WbD2^ZihSxhVM#%*7~oW+Iyo=k@*Sd78K}005fk?%1@_Zc)TNbEIeu1$ z;54JIptblg4l|pbM_?6*dfKTPhvBq=TE|U@rZ}M54kR!CGXpQtXW&X>E1+GId}4l* zq@L`18d^$z(XCT22<0>1)wE0&=sQmY`jzaEfKE7|DyEA~P|v5EtFZC=VpAWdK6$3+WW7l6x>y)1DAx#+*SVR`?ospCx3 zt|Z2Um*s_>z`UGjfH1>>h;?8{&R?J$J37An=`Ae;0A=(wUy^f|)Qnd0nF^7#+Lweo z{&%V+*x!evTRomh@%o8VIvn0aGqQCd67MOYA8GolPe9BYm_(K(T75y(MfnDw;M_Gy zQRE0h5#iimYzoBhLpp;s`=?BN%Snj-Fj3{y^RCW$nWxc@{{-jWle@O_*IXFKF9D! zKV*c@$PwpG3$=kwCutb@c3+D_4w|;CL`SxLRCx(AfS_*AUQ{U^F40r?rub4sc5LM&n$ZUrMeMUBnAUdDQ_K4@C z2u0tIQH8n`7z?g!unYMEuS%HYNs_Zv+s`3zl`_Rbpm>LnxPv!5E2&)*SNp#5j^0Vd ztTAA9SU4Xk@A3w|RiHSg`id6+paUe(oydzeH(U9w$%8#wTK8n+fyYd;4)j=Pt8O3+ zic{s5T10mK9zoF4Y_k)f3?D-+2;p)$$JJ=Q_ukP*x-osEA7O~!&_}vQ@uAJ{=z$#T z?=PMaiY(3|qJe+li^k$x?E|m)-23VkCD?v~{9FhUd*EG1Aos~a-_=lr5%6iy*Uk`S z6n5B*AxgAgC^S~L8aix#iFA`VXXA-!KQW{>9+tq)2-kx{{X>atoWQ9Ob>lw9ro-dJ z^`z517R{BC>*;mweXOPUa#NGXGk2vkE057t&xN=TsB8a2`dBIN0jWNDvyML3!!nUA z(gZ`<_-{vZ*Trx%8LV~xNCEgR3iE=7J6tUJaBuvq*Rxi zR^DF|#L?86Jtz7C93=9jo0e`xjeS8^vA`z|GZGV3sQhW6+1BS18r(BzyCrn4UV?6w zOuqcAqX|*hjSr54%U63N-j*%nG;mZ%n$iu_nN9}|#w3zcC=u8oUffROcxlwE#{I(K zsoS6g&8VVjb76)P&nM1i7M-BC{98ugN*7%v{YqQUM}X2HQ=oK|=-f>-RfDaI;xuxc z*v87lk$}AScXRL?0lzooKpx@0Zeq#4RX9PY;{>I0`r&0zdE$k~T}uU(^`L>Ys*54w zrhr&l2%rbl*-#%3=s(h}!c1iOQ8u_NT^Bs?4S#-K7h34trSDo_^1;-CN4%@ZfZmUy zhV*`9j8fA3F$%X&vGMZJ4H1Mpqm`15^mXw;_=vWo8_jg%TNM!D8d*jFkgh6 znCSru^i!5N@`%~IF*Gfoz=FsN0kC9qBYd}`z)nnv9@#XqqPyRvOCXc?00q>q+IdcpEz4IE z)Jf;?X14)`-dg814${F}rCk_Iu*RC6bub4AW3lScv^(|z0`qij$Est}D|ftD6PDzA z2;j909j`UnAT|d_RG`d(mT5zn0eKg7os}3xm;9do=XBDPiKf`G7FZG(KUFcrFe$*~ zLu~jMGT#7lToD!rfT{on0jrLoPEwuwSg&%E^s0fZMBeQx;JQO>m~7~_9;M*j!HcA- z(L?f8oX>;rCnG0BPsejvG7I5EvrcNTq>khx^Il1es3{b2LUH+!Ko)==Hqnd-5CBVV zl0o|i0`!q9b^7n>)d~_PQKsBm<7*yZPW@8%)SqEEqYa}NVNUcMRyq!XNj^3%^^5=~ z10r_Z4uG91)DWh?*Yji@0JK8$-N&F8v2~n`u+&)OnWKhPB9Xw;n{0Ifq0k^$!7p;x zn-FC>LXu}x#ZW+Y;3NS!!DSd?dqQB(M)B$F-df|x#;$wVSa$uzhkQCFl%5xy8r8s) zeWss$xDnWp^Wq23-80O2qB&PoqF)>Ode&>;+Ys^-i^|xWW6B%tBM6Qr6q$SM|C2gR zHahxo#K>YXWKiI->+6y;vxp<_QcujQEOE6|10^3(K7lA05B z=BQ0WLaT>XrUy91XzOod%3ssPiONWGM~S=w8EmEt$EUv52R|IS`Vt(*xeqRXID@st z^*6l0yoC$qt^ULY?wT{gM-g=ZX$Dv*V;uM){d`$T1@Uv#EK1Qevov{~84W|kLf5FK2SmgOA zXmpXWpeM}+oLwtM5R9=ZEQwsFGmo7GW~4D_aZNUc$QZp&emU{rvyp39WFRjZ>!oly z;-7UWPH0Dt4Qm5Kf$5UDKgUaNF)$RbJ_q4eUJS^C!NA0og4F=#k%nzXYAgb_^hu5q ztZlJW@GdYaI|^kDxDtb)WG|@=4-f#PdiBR^Lk^upxxY=ZEQJG^$h-x1wN!$`h?(m_ynn<@0^XPw-?wBDVG0Ge)w<-)JTIl3xX$=2|A@!%XBw!-Vff*MgO|Mk#Tgtn>Lz#$+79Hr{_Y+}SnhcF84;6y&maPLzbP0EZ7eM@3ezP~Y|GBkS`4TVq3+;&+)WR=`nG^X;R+-iLsr-veVJJ&Qb187sE| zf6(Xu9d&Q!XR7z{F;Q~yE!=`y^Wf7#T93}_lPK5b$`NH|K^#w~k=@GSOdkE(y|e=H z`&;V9SkIt%f5Y}iZ^OF@^rM4*^;zw}}95Q58TCd{blM;a+oKVRCrO(Mmfui5*n z2-y-X`zwtESIwQtxH25^a^CYNLQU2$=UZjR!`)@7`rsRhy7{+MyIK8sub^EpE}uy$A-Rg^@tX9x7v^_s%*EA< zm0pZdqc%23bd%>U{c7MNcXc9}Fp;&}Bfw(Y)vb>aic%h249e#B>-1|&8l}p#OPL4d zc&5Cug|*YnxcoO=ycK+T49Qm#crBm-kJCu8`s_dPkNBefKQZHeDPl$`e*GDfhylWD z%!n1su^|y~@4)X9qN>3SO>j(H3lz`0M)Up}xtNd-sfAkS@V>cIA0bkhQ<~o8r%h$> zLy-hE`1sH7($zNX-xN{h(to=I! z?|@h~=H@90MdVxbX!UAEV= ztbM@!(EB7AWxm(yl9@?Tf#*>vcNN9H(G11nK(nQZ(@kbkK1Q}qZwg)ZZ2BdsG2}<- zzC6~!TyUOPHk0({Gtv)zz)i4DgzmLWmi;G!@ zg5g!|IWYo##nsF_5kQB`X#knVGWx`q2fpm^3?o70J=J{Akb@!+-NpyD>ZvOp`XGC7 zs`OovyJe30@l4M48%I#yQX0lbQRSU#PK*o^`mGh+k4}LwJ)8)*UXrSeYGxDc?zhkp z@qC9d{caaUWqQJliQwsk@Vq;?pljsCRbnM?!TVT&#NBm(c51wyn|6;-WDcIIW-2>* z@#|e_u;1#?VkzJ=C9pG+$yhoC1}9Sz``+6noy@NH8q<{(vO;9bl(Oqjyq+MwR&&{S z{bVwef8#EFaCht?j()4;6%*J}vPPnObZ7*jw=Cvjw#u3at}ko(@w@6D;Jyis!!;h*J(q{Oe@@d$c?)V!&A&$$_S&98~4o#DzvuvdIQ|ZE;PB z=xLUzKlp=_LZOy=L8;lT>#iN(e)=n`w4JKWKbK>LMM}srTD9VPpC>wu{oSzn*qAvX zn73uMY_FwWt;53>Is38w3&m}dVtHHDfx|Q1#nfuzQ1#3U(I#m(l+$#f zVUb&S4vgP>X}4R6HeG0suSq*nvidu|Oc*~hS64UfH>;fTxjKhdvOaUnvMYn8d?9=I zWH)v(NLi+G6Uk{)w)*3`o2zn`>Sq4f?;AmDPCh#5%9(G$IUQ`l76C~ylSxw@9g8`m zUo5`N%u6lyjkWl7dQjzLvXjUwA7hg!^1+U~+HTbwwC^^xA|tl9>w5c4 zpYqY_s)95s+?|LYGG{|3aU-F9{KniyK~CGTrqx>y#CrS22R;=#Z{OR}dVQG)j1J#rx+!?*e}B1=&-&N(p&H99{;&LX-P;p^ z!He^k`Gh$Z5xZZ^wR$qVxxXYZ_1ro-(D0ETVL1#%1f}OB)w-l_P3^$;oOd%!e{=lf z2b+;z;op1AWrug*?}Z1uyIl7iGX~P1_r`Dq7u3$L{+`5XFQzi%Rx}FToywS`j3Ku6 z((B1Q+qsLgCDh2`Ag9HR3}wHE^{?GlpUj<`46wR$H#a=-2(xn!+`D}881~WCRqYTV zzOzAu*x;}>)0O|~ zC8j*#J|^?i57`Y)2|-BLgZPYuzw}!Ax=wOx=yCpxy2E4ulW47iFy6kM4FGp?<`1w8Yh-#E2``tVL;HxfXoijN4Uq$r) z=OHAs@G``?XI8|7^%T}<5`^|P%?p*Ujdb%VxU9wBuwf8#R}tkT{${BO$9hW2(d?$k z`?GM&|Gkp_D$&1`)$a5YX09!n^*R>q8=4SPL}1e}@lQ>-AanKlTkUJP+C`VAZ3^1n uUY>qKjQKBX=iguY&nq!{3HdVZPKYs8%e={O6nww;JKsnr>CfiVhyEY#&3YXG diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 5873115f1c5..18b1154305c 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -423,6 +423,14 @@ public interface NetworkManager extends NetworkService { * @return */ NicProfile getNicProfile(VirtualMachine vm, long networkId); + + + /** + * @param network + * @param provider + * @return + */ + boolean setupDns(Network network, Provider provider); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 3ca50687972..c037a49f4fa 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1932,7 +1932,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, + public Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Transaction.currentTxn(); Pair implemented = new Pair(null, null); @@ -1993,7 +1994,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, NetworkVO network, NetworkOfferingVO offering) + private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, + NetworkVO network, NetworkOfferingVO offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { // If this is a 1) guest virtual network 2) network has sourceNat service 3) network offering does not support a // Shared source NAT rule, @@ -2001,14 +2003,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean sharedSourceNat = offering.getSharedSourceNat(); - if (network.getGuestType() == Network.GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) + if (network.getGuestType() == Network.GuestType.Isolated + && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && !sharedSourceNat) { - List ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true); + + List ips = null; + Vpc vpc = null; + if (network.getVpcId() != null) { + vpc = _vpcMgr.getVpc(network.getVpcId()); + ips = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true); + } else { + ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true); + } + if (ips.isEmpty()) { - s_logger.debug("Creating a source nat ip for " + network); + String target = vpc != null ? vpc.toString() : network.toString(); + s_logger.debug("Creating a source nat ip for " + target); Account owner = _accountMgr.getAccount(network.getAccountId()); - assignSourceNatIpAddressToGuestNetwork(owner, network); + if (vpc != null) { + assignSourceNatIpAddressToVpc(owner, vpc); + } else { + assignSourceNatIpAddressToGuestNetwork(owner, network); + } } } @@ -2109,14 +2126,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - @DB public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - - Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicVO nic = _nicDao.findById(nicId); @@ -2164,7 +2178,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (s_logger.isDebugEnabled()) { s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); } - prepareElement(element, network, profile, vmProfile, dest, context); + prepareElement(element, network, profile, vmProfile, dest, context); } profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); @@ -6989,4 +7003,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return privateNetwork; } + @Override + public boolean setupDns(Network network, Provider provider) { + boolean dnsProvided = isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider ); + boolean dhcpProvided =isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, + provider); + + boolean setupDns = dnsProvided || dhcpProvided; + return setupDns; + } + } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index b2f139ee9de..f22b3484617 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -129,8 +129,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (physicalNetworkId == null) { return false; } + + if (network.getVpcId() != null) { + return false; + } - if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, "VirtualRouter")) { + if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, Network.Provider.VirtualRouter.getName())) { return false; } @@ -170,18 +174,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl DataCenter.class, network.getDataCenterId()); } - boolean success = true; for (VirtualRouter router : routers) { //Add router to guest network - success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router router " + router); + if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); + s_logger.debug("Successfully added router " + router + " to guest network " + network); } } - return success; + return true; } @Override @@ -214,18 +216,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl DataCenter.class, network.getDataCenterId()); } - boolean success = true; for (VirtualRouter router : routers) { //Add router to guest network - success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router); + if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); + s_logger.debug("Successfully added router " + router + " to guest network " + network); } } - return success; + return true; } @Override diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 738b663aaf0..cf4bd0b4479 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -31,12 +31,14 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; +import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcService; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; @@ -53,6 +55,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc NetworkService _ntwkService; @Inject VpcService _vpcService; + @Inject + VpcVirtualNetworkApplianceService _vpcMgr; private static final Map> capabilities = setCapabilities(); @@ -60,6 +64,39 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc @Inject VpcVirtualNetworkApplianceManager _vpcRouterMgr; + + @Override + protected boolean canHandle(Network network, Service service) { + Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); + if (physicalNetworkId == null) { + return false; + } + + if (network.getVpcId() == null) { + return false; + } + + if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, Network.Provider.VPCVirtualRouter.getName())) { + return false; + } + + if (service == null) { + if (!_networkMgr.isProviderForNetwork(getProvider(), network.getId())) { + s_logger.trace("Element " + getProvider().getName() + " is not a provider for the network " + network); + return false; + } + } else { + if (!_networkMgr.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) { + s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + + " in the network " + network); + return false; + } + } + + return true; + } + + @Override public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -111,19 +148,16 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DataCenter.class, network.getDataCenterId()); } - boolean success = true; for (VirtualRouter router : routers) { - //Add router to guest network - success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); + //Add router to guest network + if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network); + } else { + s_logger.debug("Successfully added VPC router " + router + " to guest network " + network); + } } - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId); - } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId); - } - - return success; + return true; } @Override @@ -153,18 +187,16 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DataCenter.class, network.getDataCenterId()); } - boolean success = true; for (VirtualRouter router : routers) { - //2) Add router to guest network - success = success && _routerMgr.addRouterToGuestNetwork(router, network, false); - if (!success) { - s_logger.warn("Failed to plug nic in network " + network + " for virtual router " + router); + //Add router to guest network + if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network); } else { - s_logger.debug("Successfully plugged nic in network " + network + " for virtual router " + router); + s_logger.debug("Successfully added VPC router " + router + " to guest network " + network); } } - return success; + return true; } @Override diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index f6d83c3f865..56ceac1309c 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -93,4 +93,5 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; + } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index ab5da7d9db8..b18e0c628e6 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1948,7 +1948,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } try { - //add router to public and guest networks + //add router to public and guest networks for (Nic publicNic : publicNics.keySet()) { Network publicNtwk = publicNics.get(publicNic); if (!addRouterToPublicNetwork(router, publicNtwk, _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), @@ -1958,9 +1958,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - for (Nic guestNic : guestNics.keySet()) { + for (Nic guestNic : guestNics.keySet()) { Network guestNtwk = guestNics.get(guestNic); - if (!addRouterToGuestNetwork(router, guestNtwk, false)) { + //FIXME - move vpc code to the vpc manager + boolean setupDnsRouter = _networkMgr.setupDns(guestNtwk, Provider.VirtualRouter); + boolean setupDnsVpc = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter); + + boolean setupDns = setupDnsRouter ? setupDnsRouter : setupDnsVpc; + + if (!addRouterToGuestNetwork(router, guestNtwk, false, setupDns)) { s_logger.warn("Failed to plug nic " + guestNic + " to router " + router); return false; } @@ -1968,8 +1974,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } catch (Exception ex) { s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex); return false; - } - + } return result; } @@ -3057,7 +3062,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } protected boolean setupGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant, - NicProfile guestNic) + NicProfile guestNic, boolean setupDns) throws ConcurrentOperationException, ResourceUnavailableException{ String networkDomain = network.getNetworkDomain(); @@ -3081,16 +3086,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String defaultDns1 = null; String defaultDns2 = null; - boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); - - if (guestNic.isDefaultNic() && (dnsProvided || dhcpProvided)) { + if (setupDns) { defaultDns1 = guestNic.getDns1(); defaultDns2 = guestNic.getDns2(); } NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), router.getId()), + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + _networkMgr.getNetworkRate(network.getId(), router.getId()), _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, @@ -3115,10 +3118,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - + @Override - public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { + public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + boolean setupDns = _networkMgr.setupDns(network, Provider.VirtualRouter); + + return addRouterToGuestNetwork(router, network, isRedundant, setupDns); + } + + + + protected boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (network.getTrafficType() != TrafficType.Guest) { s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); @@ -3128,19 +3140,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Add router to the Guest network boolean result = true; try { - DomainRouterVO routerVO = _routerDao.findById(router.getId()); - s_logger.debug("Plugging nic for vpc virtual router " + router + " in network " + network); - _routerDao.addRouterToGuestNetwork(routerVO, network); + if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + DomainRouterVO routerVO = _routerDao.findById(router.getId()); + s_logger.debug("Plugging nic for virtual router " + router + " in network " + network); + _routerDao.addRouterToGuestNetwork(routerVO, network); + } NicProfile guestNic = _itMgr.addVmToNetwork(router, network); //setup guest network if (guestNic != null) { - result = setupGuestNetwork(network, router, true, isRedundant, guestNic); + result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns); } else { s_logger.warn("Failed to add router " + router + " to guest network " + network); + result = false; } } catch (Exception ex) { - s_logger.warn("Failed to add router " + router + " to network " + network); + s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex); result = false; } finally { if (!result) { @@ -3156,7 +3171,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - @Override public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException { @@ -3165,13 +3179,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } + //check if router is already part of network + if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part of guest network " + network + "; no need to unplug guest nic"); + return true; + } + //Check if router is a part of the Guest network if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { s_logger.debug("Router " + router + " is not a part of the Guest network " + network); return true; } - boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId())); + boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false); if (!result) { s_logger.warn("Failed to destroy guest network config " + network + " on router " + router); return false; @@ -3203,6 +3223,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork); //setup public network if (publicNic != null) { + publicNic.setDefaultNic(true); if (publicIpAddr != null) { IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId()); PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), @@ -3214,7 +3235,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork); } } catch (Exception ex) { - s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork); + s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork + " due to ", ex); } finally { if (!result) { s_logger.debug("Removing the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java index ef2feda9537..68164138d11 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java @@ -19,6 +19,7 @@ import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.vm.DomainRouterVO; @@ -27,7 +28,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; /** * @author Alena Prokharchyk */ -public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{ +public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{ /** * @param vpc diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index b967e8048c5..c0632392bee 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -19,17 +19,23 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import sun.security.jca.ProviderList; + import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; +import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.vpc.Vpc; @@ -47,7 +53,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; * @author Alena Prokharchyk */ -@Local(value = {VpcVirtualNetworkApplianceManager.class}) +@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class}) public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); @@ -139,4 +145,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return new Pair>(plan, routers); } + @Override + public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + boolean dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VPCVirtualRouter); + boolean dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, + Provider.VPCVirtualRouter); + + boolean setupDns = dnsProvided || dhcpProvided; + + return super.addRouterToGuestNetwork(router, network, isRedundant, setupDns); + } + } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 11cb7337dd3..8522a034124 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2432,7 +2432,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override - @DB public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -2451,27 +2450,27 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene NicProfile nic = null; NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId()); if (nicVO != null) { - nic = new NicProfile(nicVO, network, nicVO.getBroadcastUri(), nicVO.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), vm.getId()), - _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(vm.getHypervisorType(), network)); + nic = _networkMgr.getNicProfile(vm, network.getId()); } if (nic == null) { s_logger.debug("Allocating nic for the " + vm + " in network " + network); - Transaction txn = Transaction.currentTxn(); - txn.start(); //1) allocate nic and prepare nic if needed int deviceId = _nicsDao.countNics(vm.getId()); nic = _networkMgr.allocateNic(null, network, false, deviceId, vmProfile).first(); + if (nic == null) { + throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); + } + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); - - txn.commit(); + } //2) Convert vmProfile to vmTO diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index cfc73a00e55..11f93bbb6ca 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -123,5 +123,12 @@ public interface DomainRouterDao extends GenericDao { * @param guestNetworkId */ void removeRouterFromNetwork(long routerId, long guestNetworkId); + + /** + * @param routerId + * @param guestNetworkId + * @return + */ + boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId); } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index b40cb8c2fcf..f0257ac12d7 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -309,5 +309,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase im sc.setParameters("role", Role.VIRTUAL_ROUTER); return listBy(sc); } + + @Override + public boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId) { + RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId); + return routerNtwkMap != null; + } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 7645455bd8b..d8a5437244f 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2189,7 +2189,8 @@ CREATE TABLE `cloud`.`router_network_ref` ( `guest_type` char(32) COMMENT 'type of guest network that can be shared or isolated', PRIMARY KEY (`id`), CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE + CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE, + UNIQUE `i_router_network_ref__router_id__network_id`(`router_id`, `network_id`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/wscript b/wscript index d7a5ef16033..a51f39df35e 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,8 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-08T01:50:26Z' + +VERSION = '3.0.3.2012-06-10T19:26:47Z' APPNAME = 'cloud' import shutil,os From ebbbb3b34332b26774a151d67ea2253f5f608459 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 09:41:40 -0700 Subject: [PATCH 38/64] Fixed create-schema.sql --- setup/db/create-schema.sql | 2 +- wscript | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index d8a5437244f..ea925db39f5 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2190,7 +2190,7 @@ CREATE TABLE `cloud`.`router_network_ref` ( PRIMARY KEY (`id`), CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_router_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE, - UNIQUE `i_router_network_ref__router_id__network_id`(`router_id`, `network_id`), + UNIQUE `i_router_network_ref__router_id__network_id`(`router_id`, `network_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/wscript b/wscript index a51f39df35e..ca91607b68a 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-10T19:26:47Z' +VERSION = '3.0.3.2012-06-11T16:40:18Z' APPNAME = 'cloud' import shutil,os From 3b943d84dd827af1f9553226a6af8689c331e280 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 13:37:38 -0700 Subject: [PATCH 39/64] Fixed addDhcpEntry/userdata/password in VPC setup --- .../com/cloud/network/NetworkManagerImpl.java | 2 +- .../network/element/VirtualRouterElement.java | 119 +++++++----------- .../element/VpcVirtualRouterElement.java | 76 ++++------- .../VirtualNetworkApplianceManagerImpl.java | 32 +++-- .../src/com/cloud/network/vpc/VpcManager.java | 7 ++ .../com/cloud/network/vpc/VpcManagerImpl.java | 9 ++ .../com/cloud/vm/VirtualMachineManager.java | 3 +- .../cloud/vm/VirtualMachineManagerImpl.java | 7 +- .../vm/MockVirtualMachineManagerImpl.java | 2 +- wscript | 2 +- 10 files changed, 122 insertions(+), 137 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c037a49f4fa..3f66257f032 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -3371,7 +3371,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag private boolean shutdownNetworkElementsAndResources(ReservationContext context, boolean cleanupElements, NetworkVO network) { // 1) Cleanup all the rules for the network. If it fails, just log the failure and proceed with shutting down -// the elements + // the elements boolean cleanupResult = true; try { cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId()); diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index f22b3484617..47fd9f8853d 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -80,6 +80,7 @@ import com.cloud.vm.ReservationContext; import com.cloud.vm.UserVmManager; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.UserVmDao; @@ -174,15 +175,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl DataCenter.class, network.getDataCenterId()); } - for (VirtualRouter router : routers) { - //Add router to guest network - if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { - throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); - } else { - s_logger.debug("Successfully added router " + router + " to guest network " + network); - } - } - return true; } @@ -216,12 +208,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl DataCenter.class, network.getDataCenterId()); } - for (VirtualRouter router : routers) { - //Add router to guest network - if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { - throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); - } else { - s_logger.debug("Successfully added router " + router + " to guest network " + network); + if (vm.getType() == Type.User) { + for (VirtualRouter router : routers) { + if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { + //Add router to guest network + if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); + } else { + s_logger.debug("Successfully added router " + router + " to guest network " + network); + } + } } } @@ -790,35 +786,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile) vm; - boolean publicNetwork = false; - if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { - publicNetwork = true; - } - boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic - || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && - network.getTrafficType() == TrafficType.Guest; - - List routers; - - if (publicNetwork) { - routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - } else { - Long podId = dest.getPod().getId(); - if (isPodBased) { - routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER); - } else { - routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - } - } - - // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when - // network.dns.basiczone.updates is set to "all" - Long podId = dest.getPod().getId(); - if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { - List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), - podId, State.Running, Role.VIRTUAL_ROUTER); - routers.addAll(allRunningRoutersOutsideThePod); - } + List routers = getRouters(network, dest); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId()); @@ -841,35 +809,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile) vm; - boolean publicNetwork = false; - if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { - publicNetwork = true; - } - boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic - || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && - network.getTrafficType() == TrafficType.Guest; - - List routers; - - if (publicNetwork) { - routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - } else { - Long podId = dest.getPod().getId(); - if (isPodBased) { - routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER); - } else { - routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - } - } - - // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when - // network.dns.basiczone.updates is set to "all" - Long podId = dest.getPod().getId(); - if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { - List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), - podId, State.Running, Role.VIRTUAL_ROUTER); - routers.addAll(allRunningRoutersOutsideThePod); - } + List routers = getRouters(network, dest); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId()); @@ -880,6 +820,39 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl return false; } + protected List getRouters(Network network, DeployDestination dest) { + boolean publicNetwork = false; + if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) { + publicNetwork = true; + } + boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic + || _networkMgr.isSecurityGroupSupportedInNetwork(network)) && + network.getTrafficType() == TrafficType.Guest; + + List routers; + + if (publicNetwork) { + routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); + } else { + Long podId = dest.getPod().getId(); + if (isPodBased) { + routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER); + } else { + routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); + } + } + + // for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when + // network.dns.basiczone.updates is set to "all" + Long podId = dest.getPod().getId(); + if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) { + List allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), + podId, State.Running, Role.VIRTUAL_ROUTER); + routers.addAll(allRunningRoutersOutsideThePod); + } + return routers; + } + @Override public List searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd) { Long id = cmd.getId(); diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index cf4bd0b4479..5534e0df707 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -31,18 +31,19 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; -import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; -import com.cloud.network.vpc.VpcService; +import com.cloud.network.vpc.VpcManager; import com.cloud.offering.NetworkOffering; +import com.cloud.uservm.UserVm; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; /** @@ -54,15 +55,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc @Inject NetworkService _ntwkService; @Inject - VpcService _vpcService; + VpcManager _vpcMgr; @Inject - VpcVirtualNetworkApplianceService _vpcMgr; + VpcVirtualNetworkApplianceManager _vpcRouterMgr; private static final Map> capabilities = setCapabilities(); - - @Inject - VpcVirtualNetworkApplianceManager _vpcRouterMgr; @Override @@ -133,7 +131,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - Vpc vpc = _vpcService.getActiveVpc(vpcId); + Vpc vpc = _vpcMgr.getActiveVpc(vpcId); if (vpc == null) { s_logger.warn("Unable to find Enabled VPC by id " + vpcId); return false; @@ -148,15 +146,6 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DataCenter.class, network.getDataCenterId()); } - for (VirtualRouter router : routers) { - //Add router to guest network - if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) { - throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network); - } else { - s_logger.debug("Successfully added VPC router " + router + " to guest network " + network); - } - } - return true; } @@ -171,7 +160,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return false; } - Vpc vpc = _vpcService.getActiveVpc(vpcId); + Vpc vpc = _vpcMgr.getActiveVpc(vpcId); if (vpc == null) { s_logger.warn("Unable to find Enabled VPC by id " + vpcId); return false; @@ -187,14 +176,18 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc DataCenter.class, network.getDataCenterId()); } - for (VirtualRouter router : routers) { - //Add router to guest network - if (!_vpcMgr.addVpcRouterToGuestNetwork(router, network, false)) { - throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network); - } else { - s_logger.debug("Successfully added VPC router " + router + " to guest network " + network); + if (vm.getType() == Type.User) { + for (VirtualRouter router : routers) { + //Add router to guest network + if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { + if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) { + throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network); + } else { + s_logger.debug("Successfully added VPC router " + router + " to guest network " + network); + } + } } - } + } return true; } @@ -202,30 +195,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - boolean success = true; - Long vpcId = network.getVpcId(); - if (vpcId == null) { - s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part"); - return success; - } - - List routers = _routerDao.listRoutersByVpcId(vpcId); - for (VirtualRouter router : routers) { - //1) Check if router is already a part of the network - if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part the network " + network); - continue; - } - //2) Call unplugNics in the network service - success = success && _vpcRouterMgr.removeRouterFromGuestNetwork(router, network, false); - if (!success) { - s_logger.warn("Failed to unplug nic in network " + network + " for virtual router " + router); - } else { - s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router " + router); - } - } - - return success; + return true; } @Override @@ -299,5 +269,13 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc //TODO - add implementation here return true; } + + + + @Override + protected List getRouters(Network network, DeployDestination dest) { + return _vpcMgr.getVpcRouters(network.getVpcId()); + } + } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index b18e0c628e6..d791f067617 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -128,6 +128,8 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.Networks.BroadcastDomainType; +import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PublicIpAddress; @@ -1951,8 +1953,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //add router to public and guest networks for (Nic publicNic : publicNics.keySet()) { Network publicNtwk = publicNics.get(publicNic); - if (!addRouterToPublicNetwork(router, publicNtwk, _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), - publicNic.getIp4Address()))) { + IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), + publicNic.getIp4Address()); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); + if (!addRouterToPublicNetwork(router, publicNtwk, publicIp)) { s_logger.warn("Failed to plug nic " + publicNic + " to router " + router); return false; } @@ -2108,7 +2113,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) + public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile profile, + DeployDestination dest, List routers) throws ResourceUnavailableException { _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); @@ -3146,7 +3152,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _routerDao.addRouterToGuestNetwork(routerVO, network); } - NicProfile guestNic = _itMgr.addVmToNetwork(router, network); + NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null); //setup guest network if (guestNic != null) { result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns); @@ -3208,7 +3214,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return result; } - protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress publicIpAddr) + protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, PublicIp sourceNatIp) throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException { if (publicNetwork.getTrafficType() != TrafficType.Public) { @@ -3219,13 +3225,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Add router to the Public network boolean result = true; try { + NicProfile defaultNic = new NicProfile(); + + defaultNic.setDefaultNic(true); + defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); + defaultNic.setGateway(sourceNatIp.getGateway()); + defaultNic.setNetmask(sourceNatIp.getNetmask()); + defaultNic.setMacAddress(sourceNatIp.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork); + NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic); //setup public network if (publicNic != null) { publicNic.setDefaultNic(true); - if (publicIpAddr != null) { - IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId()); + if (sourceNatIp != null) { + IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); result = setupPublicNetwork(publicNetwork, router, false, publicIp); diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index 9612690122d..55a607f2779 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -24,6 +24,7 @@ import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; +import com.cloud.vm.DomainRouterVO; /** @@ -89,4 +90,10 @@ public interface VpcManager extends VpcService{ * @throws ResourceUnavailableException */ boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; + + /** + * @param vpcId + * @return + */ + List getVpcRouters(long vpcId); } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index c2b85dc3488..55e95be2480 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -65,8 +65,10 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.net.NetUtils; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContextImpl; +import com.cloud.vm.dao.DomainRouterDao; /** * @author Alena Prokharchyk @@ -93,6 +95,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ NetworkManager _ntwkMgr; @Inject IPAddressDao _ipAddressDao; + @Inject + DomainRouterDao _routerDao; private VpcProvider vpcElement = null; @@ -907,4 +911,9 @@ public class VpcManagerImpl implements VpcManager, Manager{ _vpcDao.update(vpc.getId(), vpc); } } + + @Override + public List getVpcRouters(long vpcId) { + return _routerDao.listRoutersByVpcId(vpcId); + } } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 0cde9fb2364..049875b7817 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -138,12 +138,13 @@ public interface VirtualMachineManager extends Manager { /** * @param vm * @param network + * @param requested TODO * @return * @throws ConcurrentOperationException * @throws ResourceUnavailableException * @throws InsufficientCapacityException */ - NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 8522a034124..a30e112847d 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2432,9 +2432,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override - public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, + public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + s_logger.debug("Adding vm " + vm + " to network " + network); VMInstanceVO vmVO = _vmDao.findById(vm.getId()); NetworkVO networkVO = _networkDao.findById(network.getId()); ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), @@ -2458,7 +2459,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene //1) allocate nic and prepare nic if needed int deviceId = _nicsDao.countNics(vm.getId()); - nic = _networkMgr.allocateNic(null, network, false, + nic = _networkMgr.allocateNic(requested, network, false, deviceId, vmProfile).first(); if (nic == null) { @@ -2470,7 +2471,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO); s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); - + } //2) Convert vmProfile to vmTO diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java index f2e69bc76f3..465a4a45c66 100755 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java @@ -240,7 +240,7 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager { * @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) */ @Override - public NicProfile addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // TODO Auto-generated method stub return false; } diff --git a/wscript b/wscript index ca91607b68a..d00a1ddcdfe 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T16:40:18Z' +VERSION = '3.0.3.2012-06-11T20:32:53Z' APPNAME = 'cloud' import shutil,os From d1598e366ecd822f3d818641e4509880c56a7b44 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 14:31:39 -0700 Subject: [PATCH 40/64] Release acquired lock for VPC --- .../com/cloud/network/NetworkManagerImpl.java | 6 +++++ ...VpcVirtualNetworkApplianceManagerImpl.java | 26 ++++++++----------- wscript | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 3f66257f032..6d48726f6fa 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1075,6 +1075,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } finally { if (accountToLock != null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Releasing lock account " + ipOwner); + } _accountDao.releaseFromLockTable(ipOwner.getId()); s_logger.debug("Associate IP address lock released"); } @@ -1990,6 +1993,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag shutdownNetwork(networkId, context, false); } + if (s_logger.isDebugEnabled()) { + s_logger.debug("Releasing lock for network id " + networkId); + } _networksDao.releaseFromLockTable(networkId); } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index c0632392bee..67e37d59d16 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -19,8 +19,6 @@ import javax.ejb.Local; import org.apache.log4j.Logger; -import sun.security.jca.ProviderList; - import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; @@ -91,19 +89,17 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian Pair> planAndRouters = getDeploymentPlanAndRouters(vpc.getId(), dest); DeploymentPlan plan = planAndRouters.first(); List routers = planAndRouters.second(); - - //2) Return routers if exist - if (routers.size() >= 1) { - return routers; - } - - Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId(); - if (offeringId == null) { - offeringId = _offering.getId(); - } - - //3) Deploy Virtual Router - try { + try { + //2) Return routers if exist + if (routers.size() >= 1) { + return routers; + } + + Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId(); + if (offeringId == null) { + offeringId = _offering.getId(); + } + //3) Deploy Virtual Router List pNtwks = _pNtwkDao.listByZone(vpc.getZoneId()); VirtualRouterProvider vpcVrProvider = null; diff --git a/wscript b/wscript index d00a1ddcdfe..e77a50358ef 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T20:32:53Z' +VERSION = '3.0.3.2012-06-11T21:29:17Z' APPNAME = 'cloud' import shutil,os From 07be6918d8c861e1439ff9b5eab0d412a79714f7 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 15:01:51 -0700 Subject: [PATCH 41/64] VPC: fixed guest network shutdown --- .../VirtualNetworkApplianceManagerImpl.java | 18 ++++++++---------- wscript | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index d791f067617..9f10bc23d6c 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -3075,7 +3075,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); boolean result = true; - long guestVlanTag = Long.parseLong(network.getBroadcastUri().getHost()); + + Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); + long guestVlanTag = Long.parseLong(nic.getBroadcastUri().getHost()); String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); Integer priority = null; @@ -3097,7 +3099,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian defaultDns2 = guestNic.getDns2(); } - NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), router.getId()), _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); @@ -3185,12 +3186,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - //check if router is already part of network - if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part of guest network " + network + "; no need to unplug guest nic"); - return true; - } - //Check if router is a part of the Guest network if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { s_logger.debug("Router " + router + " is not a part of the Guest network " + network); @@ -3207,8 +3202,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (result) { if (result) { - s_logger.debug("Removing router " + router + " from network " + network); - _routerDao.removeRouterFromNetwork(router.getId(), network.getId()); + //check if router is already part of network + if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + s_logger.debug("Removing router " + router + " from network" + network); + _routerDao.removeRouterFromNetwork(router.getId(), network.getId()); + } } } return result; diff --git a/wscript b/wscript index e77a50358ef..f42d95e8f24 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T21:29:17Z' +VERSION = '3.0.3.2012-06-11T21:51:13Z' APPNAME = 'cloud' import shutil,os From 287ebd350dde4791be552823ff8b7b82fbb76852 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 15:58:26 -0700 Subject: [PATCH 42/64] More logging to plug nic code --- .../router/VirtualNetworkApplianceManagerImpl.java | 10 ++++++---- server/src/com/cloud/vm/VirtualMachineManagerImpl.java | 2 ++ wscript | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 9f10bc23d6c..1b43c158e96 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1271,6 +1271,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, null, sourceNatIp); + //add router to router network map + if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + DomainRouterVO routerVO = _routerDao.findById(router.getId()); + _routerDao.addRouterToGuestNetwork(routerVO, network); + } routers.add(router); } } finally { @@ -3134,8 +3139,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return addRouterToGuestNetwork(router, network, isRedundant, setupDns); } - - protected boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -3147,9 +3150,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Add router to the Guest network boolean result = true; try { - if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { DomainRouterVO routerVO = _routerDao.findById(router.getId()); - s_logger.debug("Plugging nic for virtual router " + router + " in network " + network); _routerDao.addRouterToGuestNetwork(routerVO, network); } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index a30e112847d..50990e629ff 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2484,6 +2484,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene //4) plug the nic to the vm VirtualMachineGuru vmGuru = getVmGuru(vmVO); + s_logger.debug("Plugging nic for vm " + vm + " in network " + network); if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) { s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); return nic; @@ -2525,6 +2526,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); + s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network); boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest); //4) Unplug the nic if (result) { diff --git a/wscript b/wscript index f42d95e8f24..98c6967b6ab 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T21:51:13Z' +VERSION = '3.0.3.2012-06-11T22:43:41Z' APPNAME = 'cloud' import shutil,os From eb2d05c6c6a461f2ebec7a1ed5be629777199bd5 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Mon, 11 Jun 2012 16:34:34 -0700 Subject: [PATCH 43/64] CS-15241: static NAT is not working when provider is set to Juniper SRX Description: Checking in fix for the exception seen due to the absence of the AsyncCommandQueued exception in the map of CSExceptionErrorCode which is used to look up the error code corresponding to a cloudstack exception. Also printing the stack trace in case an exception is not found in the map. --- utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java index 1e9939c2131..2789e62433c 100755 --- a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java +++ b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java @@ -94,13 +94,15 @@ public class CSExceptionErrorCode { ExceptionErrorCodeMap.put("com.cloud.exception.ResourceUnavailableException", 4520); ExceptionErrorCodeMap.put("com.cloud.exception.StorageUnavailableException", 4525); ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4530); - ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4535); + ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4535); + ExceptionErrorCodeMap.put("com.cloud.async.AsyncCommandQueued", 4540); // Have a special error code for ServerApiException when it is // thrown in a standalone manner when failing to detect any of the above // standard exceptions. ExceptionErrorCodeMap.put("com.cloud.api.ServerApiException", 9999); } catch (Exception e) { + e.printStackTrace(); throw new ExceptionInInitializerError(e); } } From 914b5fa981ad3c750d10b85ea3169f7e13299af6 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 11 Jun 2012 17:00:39 -0700 Subject: [PATCH 44/64] Fixed ip assoc --- api/src/com/cloud/api/commands/AssociateIPAddrCmd.java | 4 +--- wscript | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java index 15c596be8cd..9663ef2dca1 100644 --- a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java @@ -228,9 +228,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { IpAddress result = null; - if (getVpcId() != null) { - result = _networkService.associateIP(getEntityId(), getNetworkId(), getVpcId()); - } + result = _networkService.associateIP(getEntityId(), getNetworkId(), getVpcId()); if (result != null) { IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result); diff --git a/wscript b/wscript index 98c6967b6ab..1cde0e455d6 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T22:43:41Z' +VERSION = '3.0.3.2012-06-11T23:14:43Z' APPNAME = 'cloud' import shutil,os From 8712199cfd7878e8e1a2af539a7f577fb96bc935 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 17:05:51 -0700 Subject: [PATCH 45/64] VPC : bug fix --- .../com/cloud/agent/api/SetupGuestNetworkCommand.java | 8 ++++++++ .../hypervisor/xen/resource/CitrixResourceBase.java | 10 +++++++++- .../hypervisor/xen/resource/XenServer56Resource.java | 10 +++++----- .../debian/config/etc/init.d/cloud-early-config | 10 +++++----- .../systemvm/debian/config/opt/cloud/bin/guestnw.sh | 5 ++++- .../systemvm/debian/config/opt/cloud/bin/ipassoc.sh | 6 ++++++ wscript | 2 +- 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java index f5f57c8d316..1245e6eb4f8 100644 --- a/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -32,6 +32,14 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{ return nic; } + public String getDefaultDns1() { + return defaultDns1; + } + + public String getDefaultDns2() { + return defaultDns2; + } + public String getNetworkDomain() { return networkDomain; } diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 4c02f71941b..3d90bb4c868 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -7025,7 +7025,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));; String domainName = cmd.getNetworkDomain(); - String dns = nic.getDns1(); + String dns = cmd.getDefaultDns1(); + if (dns == null || dns.isEmpty()) { + dns = cmd.getDefaultDns2(); + } else { + String dns2= cmd.getDefaultDns2(); + if ( dns2 != null && !dns2.isEmpty()) { + dns += "," + dns2; + } + } try { Set vms = VM.getByNameLabel(conn, domrName); if ( vms == null || vms.isEmpty() ) { diff --git a/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java b/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java index 264cee52c15..4ad276f99a3 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java +++ b/core/src/com/cloud/hypervisor/xen/resource/XenServer56Resource.java @@ -144,16 +144,16 @@ public class XenServer56Resource extends CitrixResourceBase { protected String networkUsage(Connection conn, final String privateIpAddress, final String option, final String vif) { String args = "netusage.sh " + privateIpAddress + " "; if (option.equals("get")) { - args = "-g"; + args += "-g"; } else if (option.equals("create")) { - args = "-c"; + args += "-c"; } else if (option.equals("reset")) { - args = "-r"; + args += "-r"; } else if (option.equals("addVif")) { - args = "-a"; + args += "-a "; args += vif; } else if (option.equals("deleteVif")) { - args = "-d"; + args += "-d "; args += vif; } diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 463d6408c46..e812002de98 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -330,7 +330,7 @@ setup_common() { fi ip route delete default - if [ "$RROUTER" != "1" ] + if [ "$RROUTER" != "1" -a -n $GW ] then if [ -z "$3" ] then @@ -338,12 +338,12 @@ setup_common() { else ip route add default via $GW dev $3 fi + # a hacking way to activate vSwitch under VMware + ping -n -c 3 $GW & + sleep 3 + pkill ping fi - # a hacking way to activate vSwitch under VMware - ping -n -c 3 $GW & - sleep 3 - pkill ping if [ -n "$MGMTNET" -a -n "$LOCAL_GW" ] then ping -n -c 3 $LOCAL_GW & diff --git a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh index a97e28a8078..c2e3592e51a 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/guestnw.sh @@ -70,10 +70,13 @@ desetup_dnsmasq() { create_guest_network() { logger -t cloud " $(basename $0): Create network on interface $dev, gateway $gw, network $ip/$mask " - + # setup ip configuration sudo ip addr add dev $dev $ip/$mask sudo ip link set $dev up sudo arping -c 3 -I $dev -A -U -s $ip $ip; + # setup rules to allow dhcp/dns request + sudo iptables -A INPUT -i $dev -p udp -m udp --dport 67 -j ACCEPT + sudo iptables -A INPUT -i $dev -p udp -m udp --dport 53 -j ACCEPT # create inbound acl chain if sudo iptables -N ACL_INBOUND_$ip 2>/dev/null diff --git a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh index e9d75caa3d6..5a116220c60 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh @@ -216,6 +216,12 @@ add_snat() { sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; return 0; fi + # setup default gateway + sudo ip route | grep default + if [ $? -gt 0 ] + then + sudo ip route add default via $defaultGwIP dev $ethDev + fi logger -t cloud "$(basename $0):Added SourceNAT $pubIp on interface $ethDev" sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; diff --git a/wscript b/wscript index 1cde0e455d6..c8125352b67 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T23:14:43Z' +VERSION = '3.0.3.2012-06-11T22:40:12Z' APPNAME = 'cloud' import shutil,os From 00278191bb996a7c070c7d6e5121c924f002c4f5 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 17:35:37 -0700 Subject: [PATCH 46/64] VPC : revert changes in ipassoc.sh --- patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh index 5a116220c60..e9d75caa3d6 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/ipassoc.sh @@ -216,12 +216,6 @@ add_snat() { sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; return 0; fi - # setup default gateway - sudo ip route | grep default - if [ $? -gt 0 ] - then - sudo ip route add default via $defaultGwIP dev $ethDev - fi logger -t cloud "$(basename $0):Added SourceNAT $pubIp on interface $ethDev" sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; From 99385d7c38e63e04da8cf12e12e66501279c736d Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 17:37:37 -0700 Subject: [PATCH 47/64] VPC : add new ipassoc.sh for vpc --- .../config/opt/cloud/bin/vpc_ipassoc.sh | 461 ++++++++++++++++++ 1 file changed, 461 insertions(+) create mode 100755 patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh new file mode 100755 index 00000000000..5a116220c60 --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh @@ -0,0 +1,461 @@ +#!/usr/bin/env bash +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 + + + + + +# $Id: ipassoc.sh 9804 2010-06-22 18:36:49Z alex $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/network/domr/ipassoc.sh $ +# ipassoc.sh -- associate/disassociate a public ip with an instance +# @VERSION@ + +source /root/func.sh + +lock="biglock" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +usage() { + printf "Usage:\n %s -A -l -c [-f] \n" $(basename $0) >&2 + printf " %s -D -l -c [-f] \n" $(basename $0) >&2 +} + +add_fw_chain_for_ip () { + local pubIp=$(echo $1 | awk -F'/' '{print $1}') + if sudo iptables -t mangle -N FIREWALL_$pubIp &> /dev/null + then + logger -t cloud "$(basename $0): created firewall chain for $pubIp" + sudo iptables -t mangle -A FIREWALL_$pubIp -j DROP> /dev/null + #ensure outgoing connections are maintained (first rule in chain) + sudo iptables -t mangle -I FIREWALL_$pubIp -m state --state RELATED,ESTABLISHED -j ACCEPT> /dev/null + #ensure that this table is after VPN chain + sudo iptables -t mangle -I PREROUTING 2 -d $pubIp -j FIREWALL_$pubIp + return $? + fi + logger -t cloud "$(basename $0): firewall chain for $pubIp already exists" +} + +add_vpn_chain_for_ip () { + local pubIp=$(echo $1 | awk -F'/' '{print $1}') + if sudo iptables -t mangle -N VPN_$pubIp &> /dev/null + then + logger -t cloud "$(basename $0): created VPN chain for $pubIp" + #ensure outgoing connections are maintained (first rule in chain) + sudo iptables -t mangle -I VPN_$pubIp -m state --state RELATED,ESTABLISHED -j ACCEPT + sudo iptables -t mangle -A VPN_$pubIp -j RETURN + #ensure that this table is the first + sudo iptables -t mangle -I PREROUTING 1 -d $pubIp -j VPN_$pubIp + return $? + fi + logger -t cloud "$(basename $0): VPN chain for $pubIp already exists" +} + +del_fw_chain_for_ip () { + local pubIp=$(echo $1 | awk -F'/' '{print $1}') + if ! sudo iptables -t mangle -N FIREWALL_$pubIp &> /dev/null + then + logger -t cloud "$(basename $0): destroying firewall chain for $pubIp" + sudo iptables -t mangle -D PREROUTING -d $pubIp -j FIREWALL_$pubIp + sudo iptables -t mangle -F FIREWALL_$pubIp + sudo iptables -t mangle -X FIREWALL_$pubIp + return $? + fi + # firewall chain got created as a result of testing for the chain, cleanup + sudo iptables -t mangle -F FIREWALL_$pubIp + sudo iptables -t mangle -X FIREWALL_$pubIp + logger -t cloud "$(basename $0): firewall chain did not exist for $pubIp, cleaned up" +} + +del_vpn_chain_for_ip () { + local pubIp=$(echo $1 | awk -F'/' '{print $1}') + if ! sudo iptables -t mangle -N VPN_$pubIp &> /dev/null + then + logger -t cloud "$(basename $0): destroying vpn chain for $pubIp" + sudo iptables -t mangle -D PREROUTING -d $pubIp -j VPN_$pubIp + sudo iptables -t mangle -F VPN_$pubIp + sudo iptables -t mangle -X VPN_$pubIp + return $? + fi + # vpn chain got created as a result of testing for the chain, cleanup + sudo iptables -t mangle -F VPN_$pubIp + sudo iptables -t mangle -X VPN_$pubIp + logger -t cloud "$(basename $0): vpn chain did not exist for $pubIp, cleaned up" +} + +convert_primary_to_32() { + local existingIpMask=$(sudo ip addr show dev $ethDev | grep "inet " | awk '{print $2}') + local primary=$(echo $1 | awk -F'/' '{print $1}') +# add 32 mask to the existing primary + for ipMask in $existingIpMask + do + local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') + local mask=$(echo $ipMask | awk -F'/' '{print $2}') + if [ "$ipNoMask" == "$primary" ] + then + continue + fi + if [ "$mask" != "32" ] + then + ip_addr_add $ethDev $ipNoMask/32 + fi + done +#delete primaries + for ipMask in $existingIpMask + do + local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') + local mask=$(echo $ipMask | awk -F'/' '{print $2}') + if [ "$ipNoMask" == "$primary" ] + then + continue + fi + if [ "$mask" != "32" ] + then + # this would have erase all primaries and secondaries in the previous loop, so we need to eat up the error. + sudo ip addr del dev $ethDev $ipNoMask/$mask > /dev/null + fi + done +} + +remove_routing() { + local pubIp=$1 + logger -t cloud "$(basename $0):Remove routing $pubIp on interface $ethDev" + local ipNoMask=$(echo $pubIp | awk -F'/' '{print $1}') + local mask=$(echo $pubIp | awk -F'/' '{print $2}') + local tableNo=$(echo $ethDev | awk -F'eth' '{print $2}') + + local tableName="Table_$ethDev" + local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}') + if [ "$ethMask" == "" ] + then +# rules and routes will be deleted for the last ip of the interface. + sudo ip rule delete fwmark $tableNo table $tableName + sudo ip rule delete table $tableName + sudo ip route flush table $tableName + sudo ip route flush cache + logger -t cloud "$(basename $0):Remove routing $pubIp - routes and rules deleted" + fi +} + +# copy eth0,eth1 and the current public interface +copy_routes_from_main() { + local tableName=$1 + +#get the network masks from the main table + local eth0Mask=$(ip route list scope link dev eth0 | awk '{print $1}') + local eth1Mask=$(ip route list scope link dev eth1 | awk '{print $1}') + local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}') + +# eth0,eth1 and other know routes will be skipped, so as main routing table will decide the route. This will be useful if the interface is down and up. + sudo ip route add throw $eth0Mask table $tableName proto static + sudo ip route add throw $eth1Mask table $tableName proto static + sudo ip route add throw $ethMask table $tableName proto static + return 0; +} + +ip_addr_add() { + local dev="$1" + local ip="$2" + local brd=`TERM=linux ipcalc $ip|grep Broadcast|awk -F' ' '{print $2}'` + sudo ip addr add dev $dev $ip broadcast $brd +} + +add_routing() { + local pubIp=$1 + logger -t cloud "$(basename $0):Add routing $pubIp on interface $ethDev" + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + local mask=$(echo $1 | awk -F'/' '{print $2}') + + local tableName="Table_$ethDev" + local tablePresent=$(grep $tableName /etc/iproute2/rt_tables) + local tableNo=$(echo $ethDev | awk -F'eth' '{print $2}') + if [ "$tablePresent" == "" ] + then + if [ "$tableNo" == ""] + then + return 0; + fi + sudo echo "$tableNo $tableName" >> /etc/iproute2/rt_tables + fi + + copy_routes_from_main $tableName +# NOTE: this entry will be deleted if the interface is down without knowing to Management server, in that case all the outside traffic will be send through main routing table or it will be the first public NIC. + sudo ip route add default via $defaultGwIP table $tableName proto static + sudo ip route flush cache + + local ethMask=$(ip route list scope link dev $ethDev | awk '{print $1}') + local rulePresent=$(ip rule show | grep $ethMask) + if [ "$rulePresent" == "" ] + then +# rules will be added while adding the first ip of the interface + sudo ip rule add from $ethMask table $tableName + sudo ip rule add fwmark $tableNo table $tableName + logger -t cloud "$(basename $0):Add routing $pubIp rules added" + fi + return 0; +} +add_snat() { + local pubIp=$1 + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + if [ "$sflag" == "0" ] + then + logger -t cloud "$(basename $0):Remove SourceNAT $pubIp on interface $ethDev if it is present" + sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; + return 0; + fi + # setup default gateway + sudo ip route | grep default + if [ $? -gt 0 ] + then + sudo ip route add default via $defaultGwIP dev $ethDev + fi + + logger -t cloud "$(basename $0):Added SourceNAT $pubIp on interface $ethDev" + sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; + sudo iptables -t nat -A POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; + return $? +} +remove_snat() { + if [ "$sflag" == "0" ] + then + return 0; + fi + + local pubIp=$1 + logger -t cloud "$(basename $0):Removing SourceNAT $pubIp on interface $ethDev" + sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask; + return $? +} +add_first_ip() { + local pubIp=$1 + logger -t cloud "$(basename $0):Adding first ip $pubIp on interface $ethDev" + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + local mask=$(echo $1 | awk -F'/' '{print $2}') + sudo ip link show $ethDev | grep "state DOWN" > /dev/null + local old_state=$? + + convert_primary_to_32 $pubIp + ip_addr_add $ethDev $pubIp + if [ "$mask" != "32" ] && [ "$mask" != "" ] + then + # remove if duplicat ip with 32 mask, this happens when we are promting the ip to primary + sudo ip addr del dev $ethDev $ipNoMask/32 > /dev/null + fi + + sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT + sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT + sudo iptables -A FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT + sudo iptables -A FORWARD -i eth0 -o $ethDev -j ACCEPT + + add_snat $1 + if [ $? -gt 0 -a $? -ne 2 ] + then + logger -t cloud "$(basename $0):Failed adding source nat entry for ip $pubIp on interface $ethDev" + return 1 + fi + + logger -t cloud "$(basename $0):Added first ip $pubIp on interface $ethDev" + if [ $if_keep_state -ne 1 -o $old_state -ne 0 ] + then + sudo ip link set $ethDev up + sudo arping -c 3 -I $ethDev -A -U -s $ipNoMask $ipNoMask; + fi + add_routing $1 + + return 0 +} + +remove_first_ip() { + local pubIp=$1 + logger -t cloud "$(basename $0):Removing first ip $pubIp on interface $ethDev" + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + local mask=$(echo $1 | awk -F'/' '{print $2}') + + local existingIpMask=$(sudo ip addr show dev $ethDev | grep inet | awk '{print $2}' | grep -w $ipNoMask) + [ "$existingIpMask" == "" ] && return 0 + + [ "$mask" == "" ] && mask="32" + + sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT + sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT + remove_snat $1 + + sudo ip addr del dev $ethDev "$ipNoMask/$mask" + if [ $? -gt 0 -a $? -ne 2 ] + then + remove_routing $1 + return 1 + fi + remove_routing $1 + + return $? +} + + +add_an_ip () { + local pubIp=$1 + logger -t cloud "$(basename $0):Adding ip $pubIp on interface $ethDev" + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + sudo ip link show $ethDev | grep "state DOWN" > /dev/null + local old_state=$? + + ip_addr_add $ethDev $pubIp + add_snat $1 + if [ $if_keep_state -ne 1 -o $old_state -ne 0 ] + then + sudo ip link set $ethDev up + sudo arping -c 3 -I $ethDev -A -U -s $ipNoMask $ipNoMask; + fi + add_routing $1 + return $? + +} + +remove_an_ip () { + local pubIp=$1 + logger -t cloud "$(basename $0):Removing ip $pubIp on interface $ethDev" + local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + local mask=$(echo $1 | awk -F'/' '{print $2}') + local existingIpMask=$(sudo ip addr show dev $ethDev | grep inet | awk '{print $2}' | grep -w $ipNoMask) + [ "$existingIpMask" == "" ] && return 0 + remove_snat $1 + local existingMask=$(echo $existingIpMask | awk -F'/' '{print $2}') + if [ "$existingMask" == "32" ] + then + sudo ip addr del dev $ethDev $existingIpMask + result=$? + fi + + if [ "$existingMask" != "32" ] + then + replaceIpMask=`sudo ip addr show dev $ethDev | grep inet | grep -v $existingIpMask | awk '{print $2}' | sort -t/ -k2 -n|tail -1` + sudo ip addr del dev $ethDev $existingIpMask; + if [ -n "$replaceIpMask" ]; then + sudo ip addr del dev $ethDev $replaceIpMask; + replaceIp=`echo $replaceIpMask | awk -F/ '{print $1}'`; + ip_addr_add $ethDev $replaceIp/$existingMask + fi + result=$? + fi + + if [ $result -gt 0 -a $result -ne 2 ] + then + remove_routing $1 + return 1 + fi + remove_routing $1 + return 0 +} + +#set -x +sflag=0 +lflag= +fflag= +cflag= +op="" + +is_master=0 +is_redundant=0 +if_keep_state=0 +grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null +if [ $? -eq 0 ] +then + is_redundant=1 + sudo /root/checkrouter.sh --no-lock|grep "Status: MASTER" > /dev/null 2>&1 + if [ $? -eq 0 ] + then + is_master=1 + fi +fi +if [ $is_redundant -eq 1 -a $is_master -ne 1 ] +then + if_keep_state=1 +fi + +while getopts 'sfADa:l:c:g:' OPTION +do + case $OPTION in + A) Aflag=1 + op="-A" + ;; + D) Dflag=1 + op="-D" + ;; + f) fflag=1 + ;; + s) sflag=1 + ;; + l) lflag=1 + publicIp="$OPTARG" + ;; + c) cflag=1 + ethDev="$OPTARG" + ;; + g) gflag=1 + defaultGwIP="$OPTARG" + ;; + ?) usage + unlock_exit 2 $lock $locked + ;; + esac +done + + +if [ "$Aflag$Dflag" != "1" ] +then + usage + unlock_exit 2 $lock $locked +fi + +if [ "$lflag$cflag" != "11" ] +then + usage + unlock_exit 2 $lock $locked +fi + + +if [ "$fflag" == "1" ] && [ "$Aflag" == "1" ] +then + add_first_ip $publicIp && + add_vpn_chain_for_ip $publicIp && + add_fw_chain_for_ip $publicIp + unlock_exit $? $lock $locked +fi + +if [ "$Aflag" == "1" ] +then + add_an_ip $publicIp && + add_fw_chain_for_ip $publicIp + unlock_exit $? $lock $locked +fi + +if [ "$fflag" == "1" ] && [ "$Dflag" == "1" ] +then + remove_first_ip $publicIp && + del_fw_chain_for_ip $publicIp && + del_vpn_chain_for_ip $publicIp + unlock_exit $? $lock $locked +fi + +if [ "$Dflag" == "1" ] +then + remove_an_ip $publicIp && + del_fw_chain_for_ip $publicIp + unlock_exit $? $lock $locked +fi + +unlock_exit 0 $lock $locked + From 196be6f5fa3196716656fa06389670e13dca7951 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 17:41:26 -0700 Subject: [PATCH 48/64] VPC : revert change in cloud-early-config --- .../config/etc/init.d/cloud-early-config | 200 ++++++++++++++---- 1 file changed, 158 insertions(+), 42 deletions(-) diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index e812002de98..9c0d189046f 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -171,7 +171,8 @@ setup_interface() { local intfnum=$1 local ip=$2 local mask=$3 - local force=$4 + local gw=$4 + local force=$5 local intf=eth${intfnum} local bootproto="static" @@ -285,14 +286,11 @@ disable_hvc() { setup_common() { init_interfaces $1 $2 $3 - setup_interface "0" $ETH0_IP $ETH0_MASK - if [ -n "$ETH1_IP" ] - then - setup_interface "1" $ETH1_IP $ETH1_MASK - fi + setup_interface "0" $ETH0_IP $ETH0_MASK $GW + setup_interface "1" $ETH1_IP $ETH1_MASK $GW if [ -n "$ETH2_IP" ] then - setup_interface "2" $ETH2_IP $ETH2_MASK + setup_interface "2" $ETH2_IP $ETH2_MASK $GW fi echo $NAME > /etc/hostname @@ -330,7 +328,7 @@ setup_common() { fi ip route delete default - if [ "$RROUTER" != "1" -a -n $GW ] + if [ "$RROUTER" != "1" ] then if [ -z "$3" ] then @@ -338,12 +336,12 @@ setup_common() { else ip route add default via $GW dev $3 fi - # a hacking way to activate vSwitch under VMware - ping -n -c 3 $GW & - sleep 3 - pkill ping fi + # a hacking way to activate vSwitch under VMware + ping -n -c 3 $GW & + sleep 3 + pkill ping if [ -n "$MGMTNET" -a -n "$LOCAL_GW" ] then ping -n -c 3 $LOCAL_GW & @@ -352,6 +350,45 @@ setup_common() { fi } +setup_dnsmasq() { + log_it "Setting up dnsmasq" + [ -z $DHCP_RANGE ] && DHCP_RANGE=$ETH0_IP + [ -z $DOMAIN ] && DOMAIN="cloudnine.internal" + + if [ -n "$DOMAIN" ] + then + #send domain name to dhcp clients + sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\"$DOMAIN\"/ /etc/dnsmasq.conf + #DNS server will append $DOMAIN to local queries + sed -r -i s/^[#]?domain=.*$/domain=$DOMAIN/ /etc/dnsmasq.conf + #answer all local domain queries + sed -i -e "s/^[#]*local=.*$/local=\/$DOMAIN\//" /etc/dnsmasq.conf + + fi + + if [ -n "$DNS_SEARCH_ORDER" ] + then + sed -i -e "/^[#]*dhcp-option.*=119.*$/d" /etc/dnsmasq.conf + echo "dhcp-option-force=119,$DNS_SEARCH_ORDER" >> /etc/dnsmasq.conf + # set the domain search order as a space seprated list for option 15 + DNS_SEARCH_ORDER=$(echo $DNS_SEARCH_ORDER | sed 's/,/ /g') + #send domain name to dhcp clients + sed -i s/[#]*dhcp-option=15.*$/dhcp-option=15,\""$DNS_SEARCH_ORDER"\"/ /etc/dnsmasq.conf + fi + + sed -i -e "s/^dhcp-range=.*$/dhcp-range=$DHCP_RANGE,static/" /etc/dnsmasq.conf + sed -i -e "s/^[#]*listen-address=.*$/listen-address=$ETH0_IP/" /etc/dnsmasq.conf + + if [ "$RROUTER" == "1" ] + then + sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=option:router,$GUEST_GW" >> /etc/dnsmasq.conf + sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=6,$GUEST_GW" >> /etc/dnsmasq.conf + fi + +} + setup_sshd(){ local ip=$1 [ -f /etc/ssh/sshd_config ] && sed -i -e "s/^[#]*ListenAddress.*$/ListenAddress $ip/" /etc/ssh/sshd_config @@ -434,20 +471,38 @@ setup_redundant_router() { fi } - -setup_vmware_extra_nics() { - local oldmd5 +setup_router() { + log_it "Setting up virtual router system vm" + oldmd5= [ -f "/etc/udev/rules.d/70-persistent-net.rules" ] && oldmd5=$(md5sum "/etc/udev/rules.d/70-persistent-net.rules" | awk '{print $1}') - - if [ -n "$EXTRA_NICS" ] + + if [ -n "$ETH2_IP" ] then - for((i = 1; i < 1 + $EXTRA_NICS; i++)) - do - setup_interface "$i" "0.0.0.0" "255.255.255.255" "force" - done + setup_common eth0 eth1 eth2 + + if [ -n "$EXTRA_PUBNICS" ] + then + for((i = 3; i < 3 + $EXTRA_PUBNICS; i++)) + do + setup_interface "$i" "0.0.0.0" "255.255.255.255" $GW "force" + done + fi + else + setup_common eth0 eth1 + if [ -n "$EXTRA_PUBNICS" ] + then + for((i = 2; i < 2 + $EXTRA_PUBNICS; i++)) + do + setup_interface "$i" "0.0.0.0" "255.255.255.255" $GW "force" + done + fi + fi + + if [ -n "$ETH2_IP" -a "$RROUTER" == "1" ] + then + setup_redundant_router fi - log_it "Checking udev NIC assignment order changes" if [ "$NIC_MACS" != "" ] @@ -466,27 +521,24 @@ setup_vmware_extra_nics() { fi fi - -} - - -setup_router() { - log_it "Setting up virtual router system vm" - if [ "$hyp" == "vmware" ]; then - setup_vmware_extra_nics - fi - - setup_common eth0 - - if [ "$RROUTER" == "1" ] + + + setup_dnsmasq + + NS=$NS1 + [ -n "$NS2" ] && NS=$NS1,$NS2 + if [ "$USE_EXTERNAL_DNS" == "true" ] then - setup_redundant_router + sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf fi - - sed -i /gateway/d /etc/hosts + + setup_apache2 $ETH0_IP + sed -i /gateway/d /etc/hosts echo "$ETH0_IP $NAME" >> /etc/hosts - setup_sshd $ETH0_IP + + setup_sshd $ETH1_IP enable_svc dnsmasq 1 enable_svc haproxy 1 @@ -498,6 +550,57 @@ setup_router() { cp /etc/iptables/iptables-router /etc/iptables/rules } +setup_dhcpsrvr() { + log_it "Setting up dhcp server system vm" + setup_common eth0 eth1 + setup_dnsmasq + setup_apache2 $ETH0_IP + + NS=$NS1 + [ -n "$NS2" ] && NS=$NS1,$NS2 + if [ "$DEFAULTROUTE" != "false" ] + then + sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=option:router,$GW" >> /etc/dnsmasq.conf + #for now set up ourself as the dns server as well + sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf + if [ "$USE_EXTERNAL_DNS" == "true" ] + then + echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf + else + echo "dhcp-option=6,$ETH0_IP,$NS" >> /etc/dnsmasq.conf + fi + else + sed -i -e "/^[#]*dhcp-option=option:router.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=option:router" >> /etc/dnsmasq.conf + sed -i -e "/^[#]*dhcp-option=6.*$/d" /etc/dnsmasq.conf + echo "dhcp-option=6,$NS" >> /etc/dnsmasq.conf + fi + + sed -i /gateway/d /etc/hosts + echo "$ETH0_IP $NAME" >> /etc/hosts + + if [ "$SSHONGUEST" == "true" ] + then + setup_sshd $ETH0_IP + else + setup_sshd $ETH1_IP + fi + + enable_svc dnsmasq 1 + enable_svc haproxy 0 + enable_svc cloud-passwd-srvr 1 + enable_svc cloud 0 + enable_fwding 0 + chkconfig nfs-common off + if [ "$SSHONGUEST" == "true" ] + then + sed '/3922/i -A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT' /etc/iptables/iptables-router > /etc/iptables/rules + else + cp /etc/iptables/iptables-router /etc/iptables/rules + fi +} + setup_storage_network() { if [ x"$STORAGE_IP" == "x" -o x"$STORAGE_NETMASK" == "x" ] then @@ -570,11 +673,17 @@ setup_elbvm() { setup_common eth0 eth1 sed -i /gateway/d /etc/hosts public_ip=$ETH2_IP - [ "$ETH2_IP" == "0.0.0.0" ] || [ "$ETH2_IP" == "" ] && public_ip=$ETH1_IP + [ "$ETH2_IP" == "0.0.0.0" ] || [ "$ETH2_IP" == "" ] && public_ip=$ETH0_IP echo "$public_ip $NAME" >> /etc/hosts - cp /etc/iptables/iptables-elbvm /etc/iptables/rules - setup_sshd $ETH0_IP + if [ "$SSHONGUEST" == "true" ] + then + sed '/3922/s/eth1/eth0/' + setup_sshd $ETH0_IP + else + cp /etc/iptables/iptables-elbvm /etc/iptables/rules + setup_sshd $ETH1_IP + fi enable_fwding 0 enable_svc haproxy 0 @@ -615,6 +724,10 @@ start() { [ "$NAME" == "" ] && NAME=router setup_router ;; + dhcpsrvr) + [ "$NAME" == "" ] && NAME=dhcpsrvr + setup_dhcpsrvr + ;; secstorage) [ "$NAME" == "" ] && NAME=secstorage setup_secstorage $hyp; @@ -710,6 +823,9 @@ for i in $CMDLINE template) TEMPLATE=$VALUE ;; + sshonguest) + SSHONGUEST=$VALUE + ;; name) NAME=$VALUE ;; From 28335a0ffba7944996e61ede8e47ab36e8aaf477 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 17:44:26 -0700 Subject: [PATCH 49/64] VPC : revert iptables-router --- .../debian/config/etc/iptables/iptables-router | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/patches/systemvm/debian/config/etc/iptables/iptables-router b/patches/systemvm/debian/config/etc/iptables/iptables-router index 193d54fa33e..e1972e3a12d 100644 --- a/patches/systemvm/debian/config/etc/iptables/iptables-router +++ b/patches/systemvm/debian/config/etc/iptables/iptables-router @@ -10,9 +10,20 @@ COMMIT -A INPUT -d 224.0.0.18/32 -j ACCEPT -A INPUT -d 225.0.0.50/32 -j ACCEPT -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -i eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT --A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT +-A INPUT -i eth0 -p udp -m udp --dport 67 -j ACCEPT +-A INPUT -i eth0 -p udp -m udp --dport 53 -j ACCEPT +-A INPUT -i eth1 -p tcp -m state --state NEW --dport 3922 -j ACCEPT +-A INPUT -i eth0 -p tcp -m state --state NEW --dport 8080 -j ACCEPT +-A INPUT -i eth0 -p tcp -m state --state NEW --dport 80 -j ACCEPT +-A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A FORWARD -i eth0 -o eth2 -j ACCEPT +-A FORWARD -i eth2 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A FORWARD -i eth0 -o eth0 -m state --state NEW -j ACCEPT +-A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT COMMIT *mangle :PREROUTING ACCEPT [0:0] From c854cb04e581bf63ddda05ac6f452b5229d2b3d7 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 18:00:06 -0700 Subject: [PATCH 50/64] VPC : add new type vpcrouter in cloud-early-config --- .../config/etc/init.d/cloud-early-config | 73 +++++++++++++++++++ .../config/etc/iptables/iptables-vpcrouter | 25 +++++++ 2 files changed, 98 insertions(+) create mode 100644 patches/systemvm/debian/config/etc/iptables/iptables-vpcrouter diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 9c0d189046f..96fe6b88a89 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -550,6 +550,75 @@ setup_router() { cp /etc/iptables/iptables-router /etc/iptables/rules } + + +setup_vpcrouter() { + log_it "Setting up VPC virtual router system vm" + + if [ "$hyp" == "vmware" ]; then + setup_vmware_extra_nics + fi + + cat > /etc/network/interfaces << EOF +auto lo $1 +iface lo inet loopback +EOF + setup_interface "0" $ETH0_IP $ETH0_MASK $GW + + echo $NAME > /etc/hostname + echo 'AVAHI_DAEMON_DETECT_LOCAL=0' > /etc/default/avahi-daemon + hostname $NAME + + #Nameserver + sed -i -e "/^nameserver.*$/d" /etc/resolv.conf # remove previous entries + sed -i -e "/^nameserver.*$/d" /etc/dnsmasq-resolv.conf # remove previous entries + if [ -n "$internalNS1" ] + then + echo "nameserver $internalNS1" > /etc/dnsmasq-resolv.conf + echo "nameserver $internalNS1" > /etc/resolv.conf + fi + + if [ -n "$internalNS2" ] + then + echo "nameserver $internalNS2" >> /etc/dnsmasq-resolv.conf + echo "nameserver $internalNS2" >> /etc/resolv.conf + fi + if [ -n "$NS1" ] + then + echo "nameserver $NS1" >> /etc/dnsmasq-resolv.conf + echo "nameserver $NS1" >> /etc/resolv.conf + fi + + if [ -n "$NS2" ] + then + echo "nameserver $NS2" >> /etc/dnsmasq-resolv.conf + echo "nameserver $NS2" >> /etc/resolv.conf + fi + if [ -n "$MGMTNET" -a -n "$LOCAL_GW" ] + then + ip route add $MGMTNET via $LOCAL_GW dev eth1 + fi + + ip route delete default + + + sed -i /gateway/d /etc/hosts + + echo "$ETH0_IP $NAME" >> /etc/hosts + setup_sshd $ETH0_IP + + enable_svc dnsmasq 1 + enable_svc haproxy 1 + enable_svc cloud-passwd-srvr 1 + enable_svc cloud 0 + disable_rpfilter_domR + enable_fwding 1 + chkconfig nfs-common off + cp /etc/iptables/iptables-vpcrouter /etc/iptables/rules +} + + + setup_dhcpsrvr() { log_it "Setting up dhcp server system vm" setup_common eth0 eth1 @@ -724,6 +793,10 @@ start() { [ "$NAME" == "" ] && NAME=router setup_router ;; + vpcrouter) + [ "$NAME" == "" ] && NAME=vpcrouter + setup_vpcrouter + ;; dhcpsrvr) [ "$NAME" == "" ] && NAME=dhcpsrvr setup_dhcpsrvr diff --git a/patches/systemvm/debian/config/etc/iptables/iptables-vpcrouter b/patches/systemvm/debian/config/etc/iptables/iptables-vpcrouter new file mode 100644 index 00000000000..c1d0c158cc2 --- /dev/null +++ b/patches/systemvm/debian/config/etc/iptables/iptables-vpcrouter @@ -0,0 +1,25 @@ +*nat +:PREROUTING ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +COMMIT +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] +-A INPUT -d 224.0.0.18/32 -j ACCEPT +-A INPUT -d 225.0.0.50/32 -j ACCEPT +-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -p icmp -j ACCEPT +-A INPUT -i lo -j ACCEPT +-A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT +COMMIT +*mangle +:PREROUTING ACCEPT [0:0] +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +:POSTROUTING ACCEPT [0:0] +-A PREROUTING -m state --state ESTABLISHED,RELATED -j CONNMARK --restore-mark +-A OUTPUT -p udp --dport bootpc -j CHECKSUM --checksum-fill +COMMIT From 389833dfe78a093c723deca0c128792a4ece6d7a Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 18:08:37 -0700 Subject: [PATCH 51/64] VPC : add new dnsmasq.conf for VPC domr --- .../config/etc/init.d/cloud-early-config | 3 + .../debian/config/etc/vpcdnsmasq.conf | 465 ++++++++++++++++++ 2 files changed, 468 insertions(+) create mode 100644 patches/systemvm/debian/config/etc/vpcdnsmasq.conf diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index 96fe6b88a89..b61c8f6091e 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -615,6 +615,9 @@ EOF enable_fwding 1 chkconfig nfs-common off cp /etc/iptables/iptables-vpcrouter /etc/iptables/rules + cp /etc/vpcdnsmasq.conf /etc/dnsmasq.conf + echo "" > /etc/dnsmasq.d/dhcphosts.txt + echo "dhcp-hostsfile=/etc/dnsmasq.d/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf } diff --git a/patches/systemvm/debian/config/etc/vpcdnsmasq.conf b/patches/systemvm/debian/config/etc/vpcdnsmasq.conf new file mode 100644 index 00000000000..3717fc8a80c --- /dev/null +++ b/patches/systemvm/debian/config/etc/vpcdnsmasq.conf @@ -0,0 +1,465 @@ +# Configuration file for dnsmasq. +# +# Format is one option per line, legal options are the same +# as the long options legal on the command line. See +# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details. + +# The following two options make you a better netizen, since they +# tell dnsmasq to filter out queries which the public DNS cannot +# answer, and which load the servers (especially the root servers) +# uneccessarily. If you have a dial-on-demand link they also stop +# these requests from bringing up the link uneccessarily. + +# Never forward plain names (without a dot or domain part) +domain-needed +# Never forward addresses in the non-routed address spaces. +bogus-priv + + +# Uncomment this to filter useless windows-originated DNS requests +# which can trigger dial-on-demand links needlessly. +# Note that (amongst other things) this blocks all SRV requests, +# so don't use it if you use eg Kerberos. +# This option only affects forwarding, SRV records originating for +# dnsmasq (via srv-host= lines) are not suppressed by it. +#filterwin2k + +# Change this line if you want dns to get its upstream servers from +# somewhere other that /etc/resolv.conf +resolv-file=/etc/dnsmasq-resolv.conf + +# By default, dnsmasq will send queries to any of the upstream +# servers it knows about and tries to favour servers to are known +# to be up. Uncommenting this forces dnsmasq to try each query +# with each server strictly in the order they appear in +# /etc/resolv.conf +#strict-order + +# If you don't want dnsmasq to read /etc/resolv.conf or any other +# file, getting its servers from this file instead (see below), then +# uncomment this. +#no-resolv + +# If you don't want dnsmasq to poll /etc/resolv.conf or other resolv +# files for changes and re-read them then uncomment this. +#no-poll + +# Add other name servers here, with domain specs if they are for +# non-public domains. +#server=/localnet/192.168.0.1 + +# Example of routing PTR queries to nameservers: this will send all +# address->name queries for 192.168.3/24 to nameserver 10.1.2.3 +#server=/3.168.192.in-addr.arpa/10.1.2.3 + +# Add local-only domains here, queries in these domains are answered +# from /etc/hosts or DHCP only. +local=/2.vmops-test.vmops.com/ + +# Add domains which you want to force to an IP address here. +# The example below send any host in doubleclick.net to a local +# webserver. +#address=/doubleclick.net/127.0.0.1 + +# If you want dnsmasq to change uid and gid to something other +# than the default, edit the following lines. +#user= +#group= + +# If you want dnsmasq to listen for DHCP and DNS requests only on +# specified interfaces (and the loopback) give the name of the +# interface (eg eth0) here. +# Repeat the line for more than one interface. +#interface=eth0 + +# Or you can specify which interface _not_ to listen on +except-interface=lo + +# Or which to listen on by address (remember to include 127.0.0.1 if +# you use this.) +#listen-address= +# If you want dnsmasq to provide only DNS service on an interface, +# configure it as shown above, and then use the following line to +# disable DHCP on it. +#no-dhcp-interface=eth1 + +# On systems which support it, dnsmasq binds the wildcard address, +# even when it is listening on only some interfaces. It then discards +# requests that it shouldn't reply to. This has the advantage of +# working even when interfaces come and go and change address. If you +# want dnsmasq to really bind only the interfaces it is listening on, +# uncomment this option. About the only time you may need this is when +# running another nameserver on the same machine. +bind-interfaces + +# If you don't want dnsmasq to read /etc/hosts, uncomment the +# following line. +#no-hosts +# or if you want it to read another file, as well as /etc/hosts, use +# this. +#addn-hosts=/etc/banner_add_hosts + +# Set this (and domain: see below) if you want to have a domain +# automatically added to simple names in a hosts-file. +expand-hosts + +# Set the domain for dnsmasq. this is optional, but if it is set, it +# does the following things. +# 1) Allows DHCP hosts to have fully qualified domain names, as long +# as the domain part matches this setting. +# 2) Sets the "domain" DHCP option thereby potentially setting the +# domain of all systems configured by DHCP +# 3) Provides the domain part for "expand-hosts" +#domain=2.vmops-test.vmops.com + +# Uncomment this to enable the integrated DHCP server, you need +# to supply the range of addresses available for lease and optionally +# a lease time. If you have more than one network, you will need to +# repeat this for each network on which you want to supply DHCP +# service. +#dhcp-range=10.1.1.1,static +#dhcp-range=10.0.0.1,10.255.255.255 +#dhcp-hostsfile=/etc/dhcphosts.txt + +# This is an example of a DHCP range where the netmask is given. This +# is needed for networks we reach the dnsmasq DHCP server via a relay +# agent. If you don't know what a DHCP relay agent is, you probably +# don't need to worry about this. +#dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h + +# This is an example of a DHCP range with a network-id, so that +# some DHCP options may be set only for this network. +#dhcp-range=red,192.168.0.50,192.168.0.150 + +# Supply parameters for specified hosts using DHCP. There are lots +# of valid alternatives, so we will give examples of each. Note that +# IP addresses DO NOT have to be in the range given above, they just +# need to be on the same network. The order of the parameters in these +# do not matter, it's permissble to give name,adddress and MAC in any order + +# Always allocate the host with ethernet address 11:22:33:44:55:66 +# The IP address 192.168.0.60 +#dhcp-host=11:22:33:44:55:66,192.168.0.60 + +# Always set the name of the host with hardware address +# 11:22:33:44:55:66 to be "fred" +#dhcp-host=11:22:33:44:55:66,fred + +# Always give the host with ethernet address 11:22:33:44:55:66 +# the name fred and IP address 192.168.0.60 and lease time 45 minutes +#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m + +# Give the machine which says it's name is "bert" IP address +# 192.168.0.70 and an infinite lease +#dhcp-host=bert,192.168.0.70,infinite + +# Always give the host with client identifier 01:02:02:04 +# the IP address 192.168.0.60 +#dhcp-host=id:01:02:02:04,192.168.0.60 + +# Always give the host with client identifier "marjorie" +# the IP address 192.168.0.60 +#dhcp-host=id:marjorie,192.168.0.60 + +# Enable the address given for "judge" in /etc/hosts +# to be given to a machine presenting the name "judge" when +# it asks for a DHCP lease. +#dhcp-host=judge + +# Never offer DHCP service to a machine whose ethernet +# address is 11:22:33:44:55:66 +#dhcp-host=11:22:33:44:55:66,ignore + +# Ignore any client-id presented by the machine with ethernet +# address 11:22:33:44:55:66. This is useful to prevent a machine +# being treated differently when running under different OS's or +# between PXE boot and OS boot. +#dhcp-host=11:22:33:44:55:66,id:* + +# Send extra options which are tagged as "red" to +# the machine with ethernet address 11:22:33:44:55:66 +#dhcp-host=11:22:33:44:55:66,net:red + +# Send extra options which are tagged as "red" to +# any machine with ethernet address starting 11:22:33: +#dhcp-host=11:22:33:*:*:*,net:red + +# Ignore any clients which are specified in dhcp-host lines +# or /etc/ethers. Equivalent to ISC "deny unkown-clients". +# This relies on the special "known" tag which is set when +# a host is matched. +#dhcp-ignore=#known + +# Send extra options which are tagged as "red" to any machine whose +# DHCP vendorclass string includes the substring "Linux" +#dhcp-vendorclass=red,Linux + +# Send extra options which are tagged as "red" to any machine one +# of whose DHCP userclass strings includes the substring "accounts" +#dhcp-userclass=red,accounts + +# Send extra options which are tagged as "red" to any machine whose +# MAC address matches the pattern. +#dhcp-mac=red,00:60:8C:*:*:* + +# If this line is uncommented, dnsmasq will read /etc/ethers and act +# on the ethernet-address/IP pairs found there just as if they had +# been given as --dhcp-host options. Useful if you keep +# MAC-address/host mappings there for other purposes. +#read-ethers + +# Send options to hosts which ask for a DHCP lease. +# See RFC 2132 for details of available options. +# Common options can be given to dnsmasq by name: +# run "dnsmasq --help dhcp" to get a list. +# Note that all the common settings, such as netmask and +# broadcast address, DNS server and default route, are given +# sane defaults by dnsmasq. You very likely will not need +# any dhcp-options. If you use Windows clients and Samba, there +# are some options which are recommended, they are detailed at the +# end of this section. + +# Override the default route supplied by dnsmasq, which assumes the +# router is the same machine as the one running dnsmasq. +#dhcp-option=3,1.2.3.4 + +# Do the same thing, but using the option name +#dhcp-option=option:router,1.2.3.4 + +# Override the default route supplied by dnsmasq and send no default +# route at all. Note that this only works for the options sent by +# default (1, 3, 6, 12, 28) the same line will send a zero-length option +# for all other option numbers. +#dhcp-option=3 + +# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5 +#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5 + +# Set the NTP time server address to be the same machine as +# is running dnsmasq +#dhcp-option=42,0.0.0.0 + +# Set the NIS domain name to "welly" +#dhcp-option=40,welly + +# Set the default time-to-live to 50 +#dhcp-option=23,50 + +# Set the "all subnets are local" flag +#dhcp-option=27,1 + +# Set the domain +dhcp-option=15,"2.vmops-test.vmops.com" + +# Send the etherboot magic flag and then etherboot options (a string). +#dhcp-option=128,e4:45:74:68:00:00 +#dhcp-option=129,NIC=eepro100 + +# Specify an option which will only be sent to the "red" network +# (see dhcp-range for the declaration of the "red" network) +# Note that the net: part must precede the option: part. +#dhcp-option = net:red, option:ntp-server, 192.168.1.1 + +# The following DHCP options set up dnsmasq in the same way as is specified +# for the ISC dhcpcd in +# http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt +# adapted for a typical dnsmasq installation where the host running +# dnsmasq is also the host running samba. +# you may want to uncomment them if you use Windows clients and Samba. +#dhcp-option=19,0 # option ip-forwarding off +#dhcp-option=44,0.0.0.0 # set netbios-over-TCP/IP nameserver(s) aka WINS server(s) +#dhcp-option=45,0.0.0.0 # netbios datagram distribution server +#dhcp-option=46,8 # netbios node type +#dhcp-option=47 # empty netbios scope. + +# Send RFC-3397 DNS domain search DHCP option. WARNING: Your DHCP client +# probably doesn't support this...... +#dhcp-option=option:domain-search,eng.apple.com,marketing.apple.com + +# Send RFC-3442 classless static routes (note the netmask encoding) +#dhcp-option=121,192.168.1.0/24,1.2.3.4,10.0.0.0/8,5.6.7.8 + +# Send vendor-class specific options encapsulated in DHCP option 43. +# The meaning of the options is defined by the vendor-class so +# options are sent only when the client supplied vendor class +# matches the class given here. (A substring match is OK, so "MSFT" +# matches "MSFT" and "MSFT 5.0"). This example sets the +# mtftp address to 0.0.0.0 for PXEClients. +#dhcp-option=vendor:PXEClient,1,0.0.0.0 + +# Send microsoft-specific option to tell windows to release the DHCP lease +# when it shuts down. Note the "i" flag, to tell dnsmasq to send the +# value as a four-byte integer - that's what microsoft wants. See +# http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true +dhcp-option=vendor:MSFT,2,1i + +# Send the Encapsulated-vendor-class ID needed by some configurations of +# Etherboot to allow is to recognise the DHCP server. +#dhcp-option=vendor:Etherboot,60,"Etherboot" + +# Send options to PXELinux. Note that we need to send the options even +# though they don't appear in the parameter request list, so we need +# to use dhcp-option-force here. +# See http://syslinux.zytor.com/pxe.php#special for details. +# Magic number - needed before anything else is recognised +#dhcp-option-force=208,f1:00:74:7e +# Configuration file name +#dhcp-option-force=209,configs/common +# Path prefix +#dhcp-option-force=210,/tftpboot/pxelinux/files/ +# Reboot time. (Note 'i' to send 32-bit value) +#dhcp-option-force=211,30i + +# Set the boot filename for BOOTP. You will only need +# this is you want to boot machines over the network and you will need +# a TFTP server; either dnsmasq's built in TFTP server or an +# external one. (See below for how to enable the TFTP server.) +#dhcp-boot=pxelinux.0 + +# Enable dnsmasq's built-in TFTP server +#enable-tftp + +# Set the root directory for files availble via FTP. +#tftp-root=/var/ftpd + +# Make the TFTP server more secure: with this set, only files owned by +# the user dnsmasq is running as will be send over the net. +#tftp-secure + +# Set the boot file name only when the "red" tag is set. +#dhcp-boot=net:red,pxelinux.red-net + +# An example of dhcp-boot with an external server: the name and IP +# address of the server are given after the filename. +#dhcp-boot=/var/ftpd/pxelinux.0,boothost,192.168.0.3 + +# Set the limit on DHCP leases, the default is 150 +#dhcp-lease-max=150 + +# The DHCP server needs somewhere on disk to keep its lease database. +# This defaults to a sane location, but if you want to change it, use +# the line below. +#dhcp-leasefile=/var/lib/misc/dnsmasq.leases +leasefile-ro + +# Set the DHCP server to authoritative mode. In this mode it will barge in +# and take over the lease for any client which broadcasts on the network, +# whether it has a record of the lease or not. This avoids long timeouts +# when a machine wakes up on a new network. DO NOT enable this if there's +# the slighest chance that you might end up accidentally configuring a DHCP +# server for your campus/company accidentally. The ISC server uses +# the same option, and this URL provides more information: +# http://www.isc.org/index.pl?/sw/dhcp/authoritative.php +#dhcp-authoritative + +# Run an executable when a DHCP lease is created or destroyed. +# The arguments sent to the script are "add" or "del", +# then the MAC address, the IP address and finally the hostname +# if there is one. +#dhcp-script=/bin/echo + +# Set the cachesize here. +#cache-size=150 + +# If you want to disable negative caching, uncomment this. +#no-negcache + +# Normally responses which come form /etc/hosts and the DHCP lease +# file have Time-To-Live set as zero, which conventionally means +# do not cache further. If you are happy to trade lower load on the +# server for potentially stale date, you can set a time-to-live (in +# seconds) here. +#local-ttl= + +# If you want dnsmasq to detect attempts by Verisign to send queries +# to unregistered .com and .net hosts to its sitefinder service and +# have dnsmasq instead return the correct NXDOMAIN response, uncomment +# this line. You can add similar lines to do the same for other +# registries which have implemented wildcard A records. +#bogus-nxdomain=64.94.110.11 + +# If you want to fix up DNS results from upstream servers, use the +# alias option. This only works for IPv4. +# This alias makes a result of 1.2.3.4 appear as 5.6.7.8 +#alias=1.2.3.4,5.6.7.8 +# and this maps 1.2.3.x to 5.6.7.x +#alias=1.2.3.0,5.6.7.0,255.255.255.0 + + +# Change these lines if you want dnsmasq to serve MX records. + +# Return an MX record named "maildomain.com" with target +# servermachine.com and preference 50 +#mx-host=maildomain.com,servermachine.com,50 + +# Set the default target for MX records created using the localmx option. +#mx-target=servermachine.com + +# Return an MX record pointing to the mx-target for all local +# machines. +#localmx + +# Return an MX record pointing to itself for all local machines. +#selfmx + +# Change the following lines if you want dnsmasq to serve SRV +# records. These are useful if you want to serve ldap requests for +# Active Directory and other windows-originated DNS requests. +# See RFC 2782. +# You may add multiple srv-host lines. +# The fields are ,,,, +# If the domain part if missing from the name (so that is just has the +# service and protocol sections) then the domain given by the domain= +# config option is used. (Note that expand-hosts does not need to be +# set for this to work.) + +# A SRV record sending LDAP for the example.com domain to +# ldapserver.example.com port 289 +#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389 + +# A SRV record sending LDAP for the example.com domain to +# ldapserver.example.com port 289 (using domain=) +###domain=example.com +#srv-host=_ldap._tcp,ldapserver.example.com,389 + +# Two SRV records for LDAP, each with different priorities +#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1 +#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2 + +# A SRV record indicating that there is no LDAP server for the domain +# example.com +#srv-host=_ldap._tcp.example.com + +# The following line shows how to make dnsmasq serve an arbitrary PTR +# record. This is useful for DNS-SD. (Note that the +# domain-name expansion done for SRV records _does_not +# occur for PTR records.) +#ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services" + +# Change the following lines to enable dnsmasq to serve TXT records. +# These are used for things like SPF and zeroconf. (Note that the +# domain-name expansion done for SRV records _does_not +# occur for TXT records.) + +#Example SPF. +#txt-record=example.com,"v=spf1 a -all" + +#Example zeroconf +#txt-record=_http._tcp.example.com,name=value,paper=A4 + + +# For debugging purposes, log each DNS query as it passes through +# dnsmasq. +#log-queries + +# Log lots of extra information about DHCP transactions. +#log-dhcp + +log-facility=/var/log/dnsmasq.log + +# Include a another lot of configuration options. +#conf-file=/etc/dnsmasq.more.conf +conf-dir=/etc/dnsmasq.d + +# Don't reply Windows's periodical DNS request +filterwin2k From 372582ca6befb4f36bc691929159a25ca2500af8 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 11 Jun 2012 19:07:36 -0700 Subject: [PATCH 52/64] VPC : vpc_ipassosc.sh --- .../config/opt/cloud/bin/vpc_ipassoc.sh | 244 +----------------- 1 file changed, 4 insertions(+), 240 deletions(-) diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh index 5a116220c60..adf8eb4e510 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh @@ -30,104 +30,8 @@ then fi usage() { - printf "Usage:\n %s -A -l -c [-f] \n" $(basename $0) >&2 - printf " %s -D -l -c [-f] \n" $(basename $0) >&2 -} - -add_fw_chain_for_ip () { - local pubIp=$(echo $1 | awk -F'/' '{print $1}') - if sudo iptables -t mangle -N FIREWALL_$pubIp &> /dev/null - then - logger -t cloud "$(basename $0): created firewall chain for $pubIp" - sudo iptables -t mangle -A FIREWALL_$pubIp -j DROP> /dev/null - #ensure outgoing connections are maintained (first rule in chain) - sudo iptables -t mangle -I FIREWALL_$pubIp -m state --state RELATED,ESTABLISHED -j ACCEPT> /dev/null - #ensure that this table is after VPN chain - sudo iptables -t mangle -I PREROUTING 2 -d $pubIp -j FIREWALL_$pubIp - return $? - fi - logger -t cloud "$(basename $0): firewall chain for $pubIp already exists" -} - -add_vpn_chain_for_ip () { - local pubIp=$(echo $1 | awk -F'/' '{print $1}') - if sudo iptables -t mangle -N VPN_$pubIp &> /dev/null - then - logger -t cloud "$(basename $0): created VPN chain for $pubIp" - #ensure outgoing connections are maintained (first rule in chain) - sudo iptables -t mangle -I VPN_$pubIp -m state --state RELATED,ESTABLISHED -j ACCEPT - sudo iptables -t mangle -A VPN_$pubIp -j RETURN - #ensure that this table is the first - sudo iptables -t mangle -I PREROUTING 1 -d $pubIp -j VPN_$pubIp - return $? - fi - logger -t cloud "$(basename $0): VPN chain for $pubIp already exists" -} - -del_fw_chain_for_ip () { - local pubIp=$(echo $1 | awk -F'/' '{print $1}') - if ! sudo iptables -t mangle -N FIREWALL_$pubIp &> /dev/null - then - logger -t cloud "$(basename $0): destroying firewall chain for $pubIp" - sudo iptables -t mangle -D PREROUTING -d $pubIp -j FIREWALL_$pubIp - sudo iptables -t mangle -F FIREWALL_$pubIp - sudo iptables -t mangle -X FIREWALL_$pubIp - return $? - fi - # firewall chain got created as a result of testing for the chain, cleanup - sudo iptables -t mangle -F FIREWALL_$pubIp - sudo iptables -t mangle -X FIREWALL_$pubIp - logger -t cloud "$(basename $0): firewall chain did not exist for $pubIp, cleaned up" -} - -del_vpn_chain_for_ip () { - local pubIp=$(echo $1 | awk -F'/' '{print $1}') - if ! sudo iptables -t mangle -N VPN_$pubIp &> /dev/null - then - logger -t cloud "$(basename $0): destroying vpn chain for $pubIp" - sudo iptables -t mangle -D PREROUTING -d $pubIp -j VPN_$pubIp - sudo iptables -t mangle -F VPN_$pubIp - sudo iptables -t mangle -X VPN_$pubIp - return $? - fi - # vpn chain got created as a result of testing for the chain, cleanup - sudo iptables -t mangle -F VPN_$pubIp - sudo iptables -t mangle -X VPN_$pubIp - logger -t cloud "$(basename $0): vpn chain did not exist for $pubIp, cleaned up" -} - -convert_primary_to_32() { - local existingIpMask=$(sudo ip addr show dev $ethDev | grep "inet " | awk '{print $2}') - local primary=$(echo $1 | awk -F'/' '{print $1}') -# add 32 mask to the existing primary - for ipMask in $existingIpMask - do - local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') - local mask=$(echo $ipMask | awk -F'/' '{print $2}') - if [ "$ipNoMask" == "$primary" ] - then - continue - fi - if [ "$mask" != "32" ] - then - ip_addr_add $ethDev $ipNoMask/32 - fi - done -#delete primaries - for ipMask in $existingIpMask - do - local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') - local mask=$(echo $ipMask | awk -F'/' '{print $2}') - if [ "$ipNoMask" == "$primary" ] - then - continue - fi - if [ "$mask" != "32" ] - then - # this would have erase all primaries and secondaries in the previous loop, so we need to eat up the error. - sudo ip addr del dev $ethDev $ipNoMask/$mask > /dev/null - fi - done + printf "Usage:\n %s -A -l -c [-f] \n" $(basename $0) >&2 + printf " %s -D -l -c [-f] \n" $(basename $0) >&2 } remove_routing() { @@ -169,8 +73,6 @@ copy_routes_from_main() { ip_addr_add() { local dev="$1" local ip="$2" - local brd=`TERM=linux ipcalc $ip|grep Broadcast|awk -F' ' '{print $2}'` - sudo ip addr add dev $dev $ip broadcast $brd } add_routing() { @@ -207,102 +109,6 @@ add_routing() { fi return 0; } -add_snat() { - local pubIp=$1 - local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') - if [ "$sflag" == "0" ] - then - logger -t cloud "$(basename $0):Remove SourceNAT $pubIp on interface $ethDev if it is present" - sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; - return 0; - fi - # setup default gateway - sudo ip route | grep default - if [ $? -gt 0 ] - then - sudo ip route add default via $defaultGwIP dev $ethDev - fi - - logger -t cloud "$(basename $0):Added SourceNAT $pubIp on interface $ethDev" - sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; - sudo iptables -t nat -A POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; - return $? -} -remove_snat() { - if [ "$sflag" == "0" ] - then - return 0; - fi - - local pubIp=$1 - logger -t cloud "$(basename $0):Removing SourceNAT $pubIp on interface $ethDev" - sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask; - return $? -} -add_first_ip() { - local pubIp=$1 - logger -t cloud "$(basename $0):Adding first ip $pubIp on interface $ethDev" - local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') - local mask=$(echo $1 | awk -F'/' '{print $2}') - sudo ip link show $ethDev | grep "state DOWN" > /dev/null - local old_state=$? - - convert_primary_to_32 $pubIp - ip_addr_add $ethDev $pubIp - if [ "$mask" != "32" ] && [ "$mask" != "" ] - then - # remove if duplicat ip with 32 mask, this happens when we are promting the ip to primary - sudo ip addr del dev $ethDev $ipNoMask/32 > /dev/null - fi - - sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT - sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT - sudo iptables -A FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT - sudo iptables -A FORWARD -i eth0 -o $ethDev -j ACCEPT - - add_snat $1 - if [ $? -gt 0 -a $? -ne 2 ] - then - logger -t cloud "$(basename $0):Failed adding source nat entry for ip $pubIp on interface $ethDev" - return 1 - fi - - logger -t cloud "$(basename $0):Added first ip $pubIp on interface $ethDev" - if [ $if_keep_state -ne 1 -o $old_state -ne 0 ] - then - sudo ip link set $ethDev up - sudo arping -c 3 -I $ethDev -A -U -s $ipNoMask $ipNoMask; - fi - add_routing $1 - - return 0 -} - -remove_first_ip() { - local pubIp=$1 - logger -t cloud "$(basename $0):Removing first ip $pubIp on interface $ethDev" - local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') - local mask=$(echo $1 | awk -F'/' '{print $2}') - - local existingIpMask=$(sudo ip addr show dev $ethDev | grep inet | awk '{print $2}' | grep -w $ipNoMask) - [ "$existingIpMask" == "" ] && return 0 - - [ "$mask" == "" ] && mask="32" - - sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT - sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT - remove_snat $1 - - sudo ip addr del dev $ethDev "$ipNoMask/$mask" - if [ $? -gt 0 -a $? -ne 2 ] - then - remove_routing $1 - return 1 - fi - remove_routing $1 - - return $? -} add_an_ip () { @@ -312,8 +118,7 @@ add_an_ip () { sudo ip link show $ethDev | grep "state DOWN" > /dev/null local old_state=$? - ip_addr_add $ethDev $pubIp - add_snat $1 + sudo ip addr add dev $dev $ip if [ $if_keep_state -ne 1 -o $old_state -ne 0 ] then sudo ip link set $ethDev up @@ -361,29 +166,10 @@ remove_an_ip () { } #set -x -sflag=0 lflag= -fflag= cflag= op="" -is_master=0 -is_redundant=0 -if_keep_state=0 -grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null -if [ $? -eq 0 ] -then - is_redundant=1 - sudo /root/checkrouter.sh --no-lock|grep "Status: MASTER" > /dev/null 2>&1 - if [ $? -eq 0 ] - then - is_master=1 - fi -fi -if [ $is_redundant -eq 1 -a $is_master -ne 1 ] -then - if_keep_state=1 -fi while getopts 'sfADa:l:c:g:' OPTION do @@ -394,10 +180,6 @@ do D) Dflag=1 op="-D" ;; - f) fflag=1 - ;; - s) sflag=1 - ;; l) lflag=1 publicIp="$OPTARG" ;; @@ -427,35 +209,17 @@ then fi -if [ "$fflag" == "1" ] && [ "$Aflag" == "1" ] -then - add_first_ip $publicIp && - add_vpn_chain_for_ip $publicIp && - add_fw_chain_for_ip $publicIp - unlock_exit $? $lock $locked -fi - if [ "$Aflag" == "1" ] -then +then add_an_ip $publicIp && - add_fw_chain_for_ip $publicIp unlock_exit $? $lock $locked fi -if [ "$fflag" == "1" ] && [ "$Dflag" == "1" ] -then - remove_first_ip $publicIp && - del_fw_chain_for_ip $publicIp && - del_vpn_chain_for_ip $publicIp - unlock_exit $? $lock $locked -fi if [ "$Dflag" == "1" ] then remove_an_ip $publicIp && - del_fw_chain_for_ip $publicIp unlock_exit $? $lock $locked fi -unlock_exit 0 $lock $locked From 9c01ca2785157ed7fee5c5cdb3591eb53dad9fa1 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 12 Jun 2012 10:29:33 -0700 Subject: [PATCH 53/64] VPC: ipAssoc consists of 3 parts: plug nic (if needed), associateIp, enableSourceNat(if ip is source nat ip) --- .../cloud/agent/api/SetSourceNatAnswer.java | 24 + .../agent/api/routing/IpAssocVpcCommand.java | 28 + .../api/routing/SetSourceNatCommand.java | 41 ++ .../com/cloud/agent/api/to/IpAddressTO.java | 3 +- .../VirtualNetworkApplianceService.java | 23 - .../VpcVirtualNetworkApplianceService.java | 11 + .../xen/resource/CitrixResourceBase.java | 22 +- .../src/com/cloud/network/NetworkManager.java | 13 + .../com/cloud/network/NetworkManagerImpl.java | 12 + .../network/element/VirtualRouterElement.java | 15 - .../element/VpcVirtualRouterElement.java | 1 - .../VirtualNetworkApplianceManagerImpl.java | 382 +------------- ...VpcVirtualNetworkApplianceManagerImpl.java | 485 +++++++++++++++++- .../com/cloud/vm/VirtualMachineManager.java | 5 +- .../cloud/vm/VirtualMachineManagerImpl.java | 15 +- server/src/com/cloud/vm/dao/NicDao.java | 2 + server/src/com/cloud/vm/dao/NicDaoImpl.java | 13 +- .../vm/MockVirtualMachineManagerImpl.java | 2 +- wscript | 2 +- 19 files changed, 684 insertions(+), 415 deletions(-) create mode 100644 api/src/com/cloud/agent/api/SetSourceNatAnswer.java create mode 100644 api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java create mode 100644 api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java diff --git a/api/src/com/cloud/agent/api/SetSourceNatAnswer.java b/api/src/com/cloud/agent/api/SetSourceNatAnswer.java new file mode 100644 index 00000000000..089f1f72f56 --- /dev/null +++ b/api/src/com/cloud/agent/api/SetSourceNatAnswer.java @@ -0,0 +1,24 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api; + +/** + * @author Alena Prokharchyk + */ +public class SetSourceNatAnswer extends Answer{ + public SetSourceNatAnswer() {} + + public SetSourceNatAnswer(PlugNicCommand cmd, boolean success, String result) { + super(cmd, success, result); + } +} diff --git a/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java b/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java new file mode 100644 index 00000000000..7ab57b4f5c3 --- /dev/null +++ b/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java @@ -0,0 +1,28 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api.routing; + +import com.cloud.agent.api.to.IpAddressTO; + +/** + * @author Alena Prokharchyk + */ +public class IpAssocVpcCommand extends IpAssocCommand{ + protected IpAssocVpcCommand() { + super(); + } + + public IpAssocVpcCommand(IpAddressTO[] ips) { + super(ips); + } +} diff --git a/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java b/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java new file mode 100644 index 00000000000..59d48565229 --- /dev/null +++ b/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java @@ -0,0 +1,41 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.agent.api.routing; + +import com.cloud.agent.api.to.IpAddressTO; + +/** + * @author Alena Prokharchyk + */ +public class SetSourceNatCommand extends NetworkElementCommand{ + IpAddressTO ipAddress; + boolean add; + + protected SetSourceNatCommand() { + } + + public SetSourceNatCommand(IpAddressTO ip, boolean add) { + this.ipAddress = ip; + this.add = add; + } + + @Override + public boolean executeInSequence() { + return false; + } + + public IpAddressTO getIpAddress() { + return ipAddress; + } + +} diff --git a/api/src/com/cloud/agent/api/to/IpAddressTO.java b/api/src/com/cloud/agent/api/to/IpAddressTO.java index 40770bff1ed..b5f2c30cea9 100644 --- a/api/src/com/cloud/agent/api/to/IpAddressTO.java +++ b/api/src/com/cloud/agent/api/to/IpAddressTO.java @@ -32,7 +32,8 @@ public class IpAddressTO { private TrafficType trafficType; private String networkName; - public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, boolean isOneToOneNat) { + public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, + String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, boolean isOneToOneNat) { this.accountId = accountId; this.publicIp = ipAddress; this.add = add; diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index 8a22cf8cd96..8ef4dd814e3 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -58,27 +58,4 @@ public interface VirtualNetworkApplianceService { VirtualRouter destroyRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException; - /** - * @param router - * @param network - * @param isRedundant TODO - * @param setupDns TODO - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - * @throws InsufficientCapacityException - */ - boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; - - /** - * @param router - * @param network - * @param isRedundant TODO - * @return - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) - throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java index 139de989459..b8a37811e16 100644 --- a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java @@ -33,4 +33,15 @@ public interface VpcVirtualNetworkApplianceService { */ boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + /** + * @param router + * @param network + * @param isRedundant + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException; + } diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 3d90bb4c868..9eabb423448 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -115,6 +115,7 @@ import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.RebootRouterCommand; import com.cloud.agent.api.SecurityGroupRuleAnswer; import com.cloud.agent.api.SecurityGroupRulesCmd; +import com.cloud.agent.api.SetSourceNatAnswer; import com.cloud.agent.api.SetupAnswer; import com.cloud.agent.api.SetupCommand; import com.cloud.agent.api.SetupGuestNetworkAnswer; @@ -140,6 +141,7 @@ import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; import com.cloud.agent.api.routing.IpAssocAnswer; import com.cloud.agent.api.routing.IpAssocCommand; +import com.cloud.agent.api.routing.IpAssocVpcCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand; @@ -148,6 +150,7 @@ import com.cloud.agent.api.routing.SetFirewallRulesAnswer; import com.cloud.agent.api.routing.SetFirewallRulesCommand; import com.cloud.agent.api.routing.SetPortForwardingRulesAnswer; import com.cloud.agent.api.routing.SetPortForwardingRulesCommand; +import com.cloud.agent.api.routing.SetSourceNatCommand; import com.cloud.agent.api.routing.SetStaticNatRulesAnswer; import com.cloud.agent.api.routing.SetStaticNatRulesCommand; import com.cloud.agent.api.routing.VmDataCommand; @@ -524,7 +527,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return execute((PlugNicCommand) cmd); } else if (clazz == UnPlugNicCommand.class) { return execute((UnPlugNicCommand) cmd); - }else { + } else if (clazz == IpAssocVpcCommand.class) { + return execute((IpAssocVpcCommand) cmd); + } else if (clazz == SetSourceNatCommand.class) { + return execute((SetSourceNatCommand) cmd); + } else { return Answer.createUnsupportedCommandAnswer(cmd); } } @@ -1804,7 +1811,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new IpAssocAnswer(cmd, results); } - + protected GetVncPortAnswer execute(GetVncPortCommand cmd) { Connection conn = getConnection(); try { @@ -7077,5 +7084,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } + protected IpAssocAnswer execute(IpAssocVpcCommand cmd) { + //FIXME - add implementation here + return null; + } + + + protected SetSourceNatAnswer execute(SetSourceNatCommand cmd) { + //FIXME - add implementation here + return null; + } + } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 18b1154305c..e66c01d90a4 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -12,6 +12,7 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network; +import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -431,6 +432,18 @@ public interface NetworkManager extends NetworkService { * @return */ boolean setupDns(Network network, Provider provider); + + + /** + * @param vmProfile + * @param network + * @param broadcastUri + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + */ + NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) + throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 6d48726f6fa..d51f982310b 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2228,6 +2228,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return profile; } + + @Override + public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) + throws ConcurrentOperationException, ResourceUnavailableException { + NicVO nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString()); + releaseNic(vmProfile, nic, network); + + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, + isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + return profile; + } + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException { diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 47fd9f8853d..dc1a2470cb1 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -54,7 +54,6 @@ import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; -import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.LbStickinessMethod; @@ -80,7 +79,6 @@ import com.cloud.vm.ReservationContext; import com.cloud.vm.UserVmManager; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; -import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.UserVmDao; @@ -208,19 +206,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl DataCenter.class, network.getDataCenterId()); } - if (vm.getType() == Type.User) { - for (VirtualRouter router : routers) { - if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { - //Add router to guest network - if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) { - throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network); - } else { - s_logger.debug("Successfully added router " + router + " to guest network " + network); - } - } - } - } - return true; } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 5534e0df707..ff0ca369c4d 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -36,7 +36,6 @@ import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcManager; import com.cloud.offering.NetworkOffering; -import com.cloud.uservm.UserVm; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 1b43c158e96..fd00f16ef54 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -48,19 +48,12 @@ import com.cloud.agent.api.GetDomRVersionCmd; import com.cloud.agent.api.ModifySshKeysCommand; import com.cloud.agent.api.NetworkUsageAnswer; import com.cloud.agent.api.NetworkUsageCommand; -import com.cloud.agent.api.PlugNicAnswer; -import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.RebootAnswer; -import com.cloud.agent.api.SetupGuestNetworkAnswer; -import com.cloud.agent.api.SetupGuestNetworkCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StopAnswer; -import com.cloud.agent.api.UnPlugNicAnswer; -import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; -import com.cloud.agent.api.routing.IpAssocAnswer; import com.cloud.agent.api.routing.IpAssocCommand; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; @@ -128,8 +121,6 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; -import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PublicIpAddress; @@ -1384,18 +1375,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } finally { startRetry++; } - } - - //3) Plug public nic - boolean addToPublicNtwk = true; - if (sourceNatIp != null) { - Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0); - addToPublicNtwk = addRouterToPublicNetwork(router, publicNetwork, sourceNatIp); - } - - if (!addToPublicNtwk) { - s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up"); - destroyRouter(router.getId()); } return router; @@ -1630,7 +1609,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } String rpFilter = " "; - String type = "router"; + String type = null; + if (router.getVpcId() != null) { + type = "vpcrouter"; + } else { + type = "router"; + } + if (_disable_rp_filter) { rpFilter=" disable_rp_filter=true"; } @@ -1924,20 +1909,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - //Get guest nic info - Map guestNics = new HashMap(); - Map publicNics = new HashMap(); + //Get guest networks info List guestNetworks = new ArrayList(); List routerNics = _nicDao.listByVmId(profile.getId()); for (Nic routerNic : routerNics) { Network network = _networkMgr.getNetwork(routerNic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { - guestNics.put(routerNic, network); guestNetworks.add(network); - } else if (network.getTrafficType() == TrafficType.Public) { - publicNics.put(routerNic, network); - } + } } answer = cmds.getAnswer("getDomRVersion"); @@ -1952,39 +1932,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router.setScriptsVersion(versionAnswer.getScriptsVersion()); router = _routerDao.persist(router, guestNetworks); } - } - - try { - //add router to public and guest networks - for (Nic publicNic : publicNics.keySet()) { - Network publicNtwk = publicNics.get(publicNic); - IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), - publicNic.getIp4Address()); - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), - NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); - if (!addRouterToPublicNetwork(router, publicNtwk, publicIp)) { - s_logger.warn("Failed to plug nic " + publicNic + " to router " + router); - return false; - } - } - - for (Nic guestNic : guestNics.keySet()) { - Network guestNtwk = guestNics.get(guestNic); - //FIXME - move vpc code to the vpc manager - boolean setupDnsRouter = _networkMgr.setupDns(guestNtwk, Provider.VirtualRouter); - boolean setupDnsVpc = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter); - - boolean setupDns = setupDnsRouter ? setupDnsRouter : setupDnsVpc; - - if (!addRouterToGuestNetwork(router, guestNtwk, false, setupDns)) { - s_logger.warn("Failed to plug nic " + guestNic + " to router " + router); - return false; - } - } - } catch (Exception ex) { - s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex); - return false; - } + } return result; } @@ -3018,311 +2966,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected String getRouterIpInNetwork(long networkId, long instanceId) { return _nicDao.getIpAddress(networkId, instanceId); } - - @Override - public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - boolean result = true; - - try { - PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic); - - Commands cmds = new Commands(OnError.Stop); - cmds.addCommand("plugnic", plugNicCmd); - _agentMgr.send(dest.getHost().getId(), cmds); - - PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); - if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { - s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); - result = false; - } - } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network, - dest.getHost().getId(), e); - } - - return result; + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) + throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + //not supported + throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType()); } @Override - public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - - boolean result = true; - DomainRouterVO router = _routerDao.findById(vm.getId()); - try { - UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic); - Commands cmds = new Commands(OnError.Stop); - cmds.addCommand("unplugnic", unplugNicCmd); - _agentMgr.send(dest.getHost().getId(), cmds); - - UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); - if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { - s_logger.warn("Unable to unplug nic from router " + router); - result = false; - } - - } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, - dest.getHost().getId(), e); - } - - return result; - } - - protected boolean setupGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant, - NicProfile guestNic, boolean setupDns) - throws ConcurrentOperationException, ResourceUnavailableException{ - - String networkDomain = network.getNetworkDomain(); - String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); - - boolean result = true; - - Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); - long guestVlanTag = Long.parseLong(nic.getBroadcastUri().getHost()); - - String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); - Integer priority = null; - if (isRedundant) { - List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); - try { - getUpdatedPriority(network, routers, _routerDao.findById(router.getId())); - } catch (InsufficientVirtualNetworkCapcityException e) { - s_logger.error("Failed to get update priority!", e); - throw new CloudRuntimeException("Failed to get update priority!"); - } - } - - String defaultDns1 = null; - String defaultDns2 = null; - - if (setupDns) { - defaultDns1 = guestNic.getDns1(); - defaultDns2 = guestNic.getDns2(); - } - - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - _networkMgr.getNetworkRate(network.getId(), router.getId()), - _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); - - SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, - defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType())); - setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); - setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); - setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway()); - setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd); - setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); - - Commands cmds = new Commands(OnError.Stop); - cmds.addCommand("setupguestnetwork", setupCmd); - sendCommandsToRouter(router, cmds); - - SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class); - String setup = add ? "set" : "destroy"; - if (!(setupAnswer != null && setupAnswer.getResult())) { - s_logger.warn("Unable to " + setup + " guest network on router " + router); - result = false; - } - - return result; - } - - @Override - public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - boolean setupDns = _networkMgr.setupDns(network, Provider.VirtualRouter); - - return addRouterToGuestNetwork(router, network, isRedundant, setupDns); - } - - protected boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - - if (network.getTrafficType() != TrafficType.Guest) { - s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); - return false; - } - - //Add router to the Guest network - boolean result = true; - try { - if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { - DomainRouterVO routerVO = _routerDao.findById(router.getId()); - _routerDao.addRouterToGuestNetwork(routerVO, network); - } - - NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null); - //setup guest network - if (guestNic != null) { - result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns); - } else { - s_logger.warn("Failed to add router " + router + " to guest network " + network); - result = false; - } - } catch (Exception ex) { - s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex); - result = false; - } finally { - if (!result) { - s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup"); - if (removeRouterFromGuestNetwork(router, network, isRedundant)) { - s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup"); - } else { - s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup"); - } - } - } - - return result; - } - - @Override - public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { - if (network.getTrafficType() != TrafficType.Guest) { - s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); - return false; - } - - //Check if router is a part of the Guest network - if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { - s_logger.debug("Router " + router + " is not a part of the Guest network " + network); - return true; - } - - boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false); - if (!result) { - s_logger.warn("Failed to destroy guest network config " + network + " on router " + router); - return false; - } - - result = result && _itMgr.removeVmFromNetwork(router, network); - - if (result) { - if (result) { - //check if router is already part of network - if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { - s_logger.debug("Removing router " + router + " from network" + network); - _routerDao.removeRouterFromNetwork(router.getId(), network.getId()); - } - } - } - return result; + //not supported + throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType()); } - protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, PublicIp sourceNatIp) - throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException { - - if (publicNetwork.getTrafficType() != TrafficType.Public) { - s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); - return false; - } - - //Add router to the Public network - boolean result = true; - try { - NicProfile defaultNic = new NicProfile(); - - defaultNic.setDefaultNic(true); - defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); - defaultNic.setGateway(sourceNatIp.getGateway()); - defaultNic.setNetmask(sourceNatIp.getNetmask()); - defaultNic.setMacAddress(sourceNatIp.getMacAddress()); - defaultNic.setBroadcastType(BroadcastDomainType.Vlan); - defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); - defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); - - NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic); - //setup public network - if (publicNic != null) { - publicNic.setDefaultNic(true); - if (sourceNatIp != null) { - IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); - PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), - NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); - result = setupPublicNetwork(publicNetwork, router, false, publicIp); - } - } else { - result = false; - s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork); - } - } catch (Exception ex) { - s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork + " due to ", ex); - } finally { - if (!result) { - s_logger.debug("Removing the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); - if (removeRouterFromPublicNetwork(router, publicNetwork)) { - s_logger.debug("Removed the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); - } else { - s_logger.warn("Failed to remove the router " + router + " from public network " + publicNetwork + " as a part of cleanup"); - } - } - } - - return result; - } - - - protected boolean removeRouterFromPublicNetwork(VirtualRouter router, Network publicNetwork) - throws ConcurrentOperationException, ResourceUnavailableException { - - if (publicNetwork.getTrafficType() != TrafficType.Public) { - s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); - return false; - } - - //Check if router is a part of the Guest network - if (!_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) { - s_logger.debug("Router " + router + " is not a part of the Public network " + publicNetwork); - return true; - } - - String routerIpStr = router.getPublicIpAddress(); - - IPAddressVO sourceNatIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNetwork.getId(), routerIpStr); - - assert sourceNatIp.isSourceNat() : "Ip " + sourceNatIp + " is not source nat"; - - boolean result = true; - if (sourceNatIp != null) { - IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId()); - _networkMgr.markIpAsUnavailable(ipVO.getId()); - PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), - NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); - result = setupPublicNetwork(publicNetwork, router, false, publicIp); - } - - if (!result) { - s_logger.warn("Failed to destroy public network config " + publicNetwork + " on router " + router); - return false; - } - - result = result && _itMgr.removeVmFromNetwork(router, publicNetwork); - - return result; - } - - protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) - throws ConcurrentOperationException, ResourceUnavailableException{ - - List publicIps = new ArrayList(1); - publicIps.add(ipAddress); - Commands cmds = new Commands(OnError.Stop); - createAssociateIPCommands(router, publicIps, cmds, 0); - sendCommandsToRouter(router, cmds); - - boolean result = true; - IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class); - String setup = add ? "set" : "destroy"; - if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) { - s_logger.warn("Unable to " + setup + " public network on router " + router); - result = false; - } - - return result; - } } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 67e37d59d16..39499aae11a 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -12,6 +12,9 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.router; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,23 +22,51 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager.OnError; +import com.cloud.agent.api.PlugNicAnswer; +import com.cloud.agent.api.PlugNicCommand; +import com.cloud.agent.api.SetupGuestNetworkAnswer; +import com.cloud.agent.api.SetupGuestNetworkCommand; +import com.cloud.agent.api.UnPlugNicAnswer; +import com.cloud.agent.api.UnPlugNicCommand; +import com.cloud.agent.api.routing.IpAssocVpcCommand; +import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.routing.SetSourceNatCommand; +import com.cloud.agent.api.to.IpAddressTO; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.manager.Commands; +import com.cloud.dc.DataCenterVO; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientServerCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapcityException; +import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.network.IPAddressVO; +import com.cloud.network.IpAddress; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; +import com.cloud.network.Networks.BroadcastDomainType; +import com.cloud.network.Networks.IsolationType; +import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; +import com.cloud.network.PublicIpAddress; import com.cloud.network.VirtualRouterProvider; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -44,7 +75,12 @@ import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.Nic; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile.Param; /** @@ -150,7 +186,454 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian boolean setupDns = dnsProvided || dhcpProvided; - return super.addRouterToGuestNetwork(router, network, isRedundant, setupDns); + return addVpcRouterToGuestNetwork(router, network, isRedundant, setupDns); } + protected boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + + if (network.getTrafficType() != TrafficType.Guest) { + s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); + return false; + } + + //Add router to the Guest network + boolean result = true; + try { + if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + DomainRouterVO routerVO = _routerDao.findById(router.getId()); + _routerDao.addRouterToGuestNetwork(routerVO, network); + } + + NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null); + //setup guest network + if (guestNic != null) { + result = setupVpcGuestNetwork(network, router, true, isRedundant, guestNic, setupDns); + } else { + s_logger.warn("Failed to add router " + router + " to guest network " + network); + result = false; + } + } catch (Exception ex) { + s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex); + result = false; + } finally { + if (!result) { + s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup"); + if (removeRouterFromGuestNetwork(router, network, isRedundant)) { + s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup"); + } else { + s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup"); + } + } + } + + return result; + } + + @Override + public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException { + if (network.getTrafficType() != TrafficType.Guest) { + s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); + return false; + } + + //Check if router is a part of the Guest network + if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) { + s_logger.debug("Router " + router + " is not a part of the Guest network " + network); + return true; + } + + boolean result = setupVpcGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false); + if (!result) { + s_logger.warn("Failed to destroy guest network config " + network + " on router " + router); + return false; + } + + result = result && _itMgr.removeVmFromNetwork(router, network, null); + + if (result) { + if (result) { + //check if router is already part of network + if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { + s_logger.debug("Removing router " + router + " from network" + network); + _routerDao.removeRouterFromNetwork(router.getId(), network.getId()); + } + } + } + return result; + } + + protected boolean addPublicIpToVpc(VirtualRouter router, Network publicNetwork, PublicIp ipAddress) + throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException { + + if (publicNetwork.getTrafficType() != TrafficType.Public) { + s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); + return false; + } + + //Add router to the Public network + boolean result = true; + try { + NicProfile defaultNic = new NicProfile(); + if (ipAddress.isSourceNat()) { + defaultNic.setDefaultNic(true); + } + defaultNic.setIp4Address(ipAddress.getAddress().addr()); + defaultNic.setGateway(ipAddress.getGateway()); + defaultNic.setNetmask(ipAddress.getNetmask()); + defaultNic.setMacAddress(ipAddress.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ipAddress.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ipAddress.getVlanTag())); + + NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic); + //setup public network + if (publicNic != null) { + publicNic.setDefaultNic(true); + if (ipAddress != null) { + IPAddressVO ipVO = _ipAddressDao.findById(ipAddress.getId()); + PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), + NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); + result = associtePublicIpInVpc(publicNetwork, router, false, publicIp); + } + } else { + result = false; + s_logger.warn("Failed to plug nic for " + ipAddress + " to VPC router " + router); + } + } catch (Exception ex) { + s_logger.warn("Failed to add ip address " + ipAddress + " from the public network " + publicNetwork + + " to VPC router " + router + " due to ", ex); + result = false; + } + + return result; + } + + + protected boolean removePublicIpFromVpcRouter(VirtualRouter router, Network publicNetwork, PublicIp ipAddress) + throws ConcurrentOperationException, ResourceUnavailableException { + + if (publicNetwork.getTrafficType() != TrafficType.Public) { + s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public); + return false; + } + + boolean result = true; + IPAddressVO ipVO = _ipAddressDao.findById(ipAddress.getId()); + _networkMgr.markIpAsUnavailable(ipVO.getId()); + PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), + NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); + result = associtePublicIpInVpc(publicNetwork, router, false, publicIp); + + if (!result) { + s_logger.warn("Failed to disassociate public ip " + ipAddress + " from router " + router); + return false; + } + + URI broadcastUri = BroadcastDomainType.Vlan.toUri(ipAddress.getVlanTag()); + if (_itMgr.removeVmFromNetwork(router, publicNetwork, broadcastUri)) { + s_logger.debug("Successfully removed router " + router + " from vlan " + ipAddress.getVlanTag() +" of public network " + publicNetwork); + return true; + } else { + s_logger.warn("Failed to remove router " + router + " from vlan " + ipAddress.getVlanTag() +" of public network " + publicNetwork); + return false; + } + } + + protected boolean associtePublicIpInVpc(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) + throws ConcurrentOperationException, ResourceUnavailableException{ + + //1) Associate ip addresses + List publicIps = new ArrayList(1); + publicIps.add(ipAddress); + Commands cmds = new Commands(OnError.Stop); + createVpcAssociateIPCommands(router, publicIps, cmds, 0); + String assoc = add ? "Associating " : "Disassociating"; + StringBuilder debugMsg = new StringBuilder(assoc + " ip address " + ipAddress); + + //2) If sourceNat, setup the source nat + if (ipAddress.isSourceNat()) { + Integer networkRate = _networkMgr.getNetworkRate(ipAddress.getNetworkId(), router.getId()); + String vmGuestAddress = null; + + IpAddressTO ip = new IpAddressTO(ipAddress.getAccountId(), ipAddress.getAddress().addr(), add, false, + true, ipAddress.getVlanTag(), ipAddress.getGateway(), ipAddress.getNetmask(), ipAddress.getMacAddress(), + vmGuestAddress, networkRate, ipAddress.isOneToOneNat()); + + + + ip.setTrafficType(network.getTrafficType()); + ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network)); + + SetSourceNatCommand cmd = new SetSourceNatCommand(ip, true); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddress.getNetworkId(), router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); + DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); + cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); + String enable = add ? "enabling" : "disabling"; + debugMsg.append(" and " + enable + " source nat for it"); + } + + if (sendCommandsToRouter(router, cmds)) { + s_logger.debug("Successfully applied ip associatino for ip " + ipAddress + " in vpc network " + network); + return true; + } else { + s_logger.warn("Failed to associate ip address " + ipAddress + " in vpc network " + network); + return false; + } + } + + + @Override + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, + ReservationContext context) { + + if (!super.finalizeStart(profile, hostId, cmds, context)) { + return false; + } + + DomainRouterVO router = profile.getVirtualMachine(); + + //Get guest nic info + Map guestNics = new HashMap(); + Map publicNics = new HashMap(); + List guestNetworks = new ArrayList(); + + List routerNics = _nicDao.listByVmId(profile.getId()); + for (Nic routerNic : routerNics) { + Network network = _networkMgr.getNetwork(routerNic.getNetworkId()); + if (network.getTrafficType() == TrafficType.Guest) { + guestNics.put(routerNic, network); + guestNetworks.add(network); + } else if (network.getTrafficType() == TrafficType.Public) { + publicNics.put(routerNic, network); + } + } + + try { + //add router to public and guest networks + for (Nic publicNic : publicNics.keySet()) { + Network publicNtwk = publicNics.get(publicNic); + IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), + publicNic.getIp4Address()); + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), + NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); + if (!addPublicIpToVpc(router, publicNtwk, publicIp)) { + s_logger.warn("Failed to add router router " + router + " to public network " + publicNtwk); + return false; + } + } + + for (Nic guestNic : guestNics.keySet()) { + Network guestNtwk = guestNics.get(guestNic); + boolean setupDns = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter); + + if (!addVpcRouterToGuestNetwork(router, guestNtwk, false, setupDns)) { + s_logger.warn("Failed to add router router " + router + " to guest network " + guestNtwk); + return false; + } + } + } catch (Exception ex) { + s_logger.warn("Failed to add router " + router + " to network due to exception ", ex); + return false; + } + + return true; + } + + protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, + boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, + Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, + InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, + StorageUnavailableException, ResourceUnavailableException { + + DomainRouterVO router = + super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, sourceNatIp); + + //Plug public nic + boolean addToPublicNtwk = true; + if (sourceNatIp != null) { + Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0); + addToPublicNtwk = addPublicIpToVpc(router, publicNetwork, sourceNatIp); + } + + if (!addToPublicNtwk) { + s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up"); + destroyRouter(router.getId()); + return null; + } + + return router; + } + + @Override + public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + boolean result = true; + + try { + PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("plugnic", plugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); + if (!(plugNicAnswer != null && plugNicAnswer.getResult())) { + s_logger.warn("Unable to plug nic for vm " + vm.getHostName()); + result = false; + } + + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network, + dest.getHost().getId(), e); + } + + return result; + } + + @Override + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, + ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + + boolean result = true; + DomainRouterVO router = _routerDao.findById(vm.getId()); + try { + UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic); + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("unplugnic", unplugNicCmd); + _agentMgr.send(dest.getHost().getId(), cmds); + + UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); + if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) { + s_logger.warn("Unable to unplug nic from router " + router); + result = false; + } + + } catch (OperationTimedoutException e) { + throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, + dest.getHost().getId(), e); + } + + return result; + } + + protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant, + NicProfile guestNic, boolean setupDns) + throws ConcurrentOperationException, ResourceUnavailableException{ + + String networkDomain = network.getNetworkDomain(); + String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); + + boolean result = true; + + Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId()); + long guestVlanTag = Long.parseLong(nic.getBroadcastUri().getHost()); + + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); + Integer priority = null; + if (isRedundant) { + List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); + try { + getUpdatedPriority(network, routers, _routerDao.findById(router.getId())); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + } + + String defaultDns1 = null; + String defaultDns2 = null; + + if (setupDns) { + defaultDns1 = guestNic.getDns1(); + defaultDns2 = guestNic.getDns2(); + } + + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + _networkMgr.getNetworkRate(network.getId(), router.getId()), + _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network)); + + SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, + defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType())); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId())); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag)); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway()); + setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd); + setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); + + Commands cmds = new Commands(OnError.Stop); + cmds.addCommand("setupguestnetwork", setupCmd); + sendCommandsToRouter(router, cmds); + + SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class); + String setup = add ? "set" : "destroy"; + if (!(setupAnswer != null && setupAnswer.getResult())) { + s_logger.warn("Unable to " + setup + " guest network on router " + router); + result = false; + } + + return result; + } + + private void createVpcAssociateIPCommands(final VirtualRouter router, final List ips, Commands cmds, long vmId) { + + // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc.. + Map> vlanIpMap = new HashMap>(); + for (final PublicIpAddress ipAddress : ips) { + String vlanTag = ipAddress.getVlanTag(); + ArrayList ipList = vlanIpMap.get(vlanTag); + if (ipList == null) { + ipList = new ArrayList(); + } + //VR doesn't support release for sourceNat IP address; so reset the state + if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) { + ipAddress.setState(IpAddress.State.Allocated); + } + ipList.add(ipAddress); + vlanIpMap.put(vlanTag, ipList); + } + + for (Map.Entry> vlanAndIp : vlanIpMap.entrySet()) { + List ipAddrList = vlanAndIp.getValue(); + + // Get network rate - required for IpAssoc + Integer networkRate = _networkMgr.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId()); + Network network = _networkMgr.getNetwork(ipAddrList.get(0).getNetworkId()); + + IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()]; + int i = 0; + + for (final PublicIpAddress ipAddr : ipAddrList) { + boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true); + boolean sourceNat = ipAddr.isSourceNat(); + String vlanId = ipAddr.getVlanTag(); + String vlanGateway = ipAddr.getGateway(); + String vlanNetmask = ipAddr.getNetmask(); + String vifMacAddress = ipAddr.getMacAddress(); + + String vmGuestAddress = null; + + IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, + sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat()); + + ip.setTrafficType(network.getTrafficType()); + ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network)); + ipsToSend[i++] = ip; + } + IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(), router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); + DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); + cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); + + cmds.addCommand("IPAssocVpcCommand", cmd); + } + } + } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 049875b7817..56dc483be34 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -12,11 +12,11 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.vm; +import java.net.URI; import java.util.List; import java.util.Map; import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.AgentUnavailableException; @@ -150,11 +150,12 @@ public interface VirtualMachineManager extends Manager { /** * @param vm * @param network + * @param broadcastUri TODO * @return * @throws ResourceUnavailableException * @throws ConcurrentOperationException */ - boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException; + boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException; /** * @param nic diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 50990e629ff..06699aee022 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -12,6 +12,7 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.vm; +import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -2449,9 +2450,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene DeployDestination dest = new DeployDestination(dc, null, null, host); NicProfile nic = null; - NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId()); - if (nicVO != null) { - nic = _networkMgr.getNicProfile(vm, network.getId()); + String broadcastUri = null; + if (requested != null && requested.getBroadCastUri() != null) { + broadcastUri = requested.getBroadCastUri().toString(); + NicVO nicVO = _nicsDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri); + if (nicVO != null) { + nic = _networkMgr.getNicProfile(vm, network.getId()); + } } if (nic == null) { @@ -2503,7 +2508,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { VMInstanceVO vmVO = _vmDao.findById(vm.getId()); NetworkVO networkVO = _networkDao.findById(network.getId()); ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), @@ -2517,7 +2522,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene DeployDestination dest = new DeployDestination(dc, null, null, host); //1) Release the nic - NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO); + NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO, broadcastUri); //2) Convert vmProfile to vmTO VirtualMachineGuru vmGuru = getVmGuru(vmVO); diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java index 9a62467cfa6..3dca809e3e9 100644 --- a/server/src/com/cloud/vm/dao/NicDao.java +++ b/server/src/com/cloud/vm/dao/NicDao.java @@ -48,4 +48,6 @@ public interface NicDao extends GenericDao { String getIpAddress(long networkId, long instanceId); int countNics(long instanceId); + + NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri); } diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index baa75cd5d2b..77f54ce81cd 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -22,8 +22,8 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.vm.Nic.State; import com.cloud.vm.Nic; +import com.cloud.vm.Nic.State; import com.cloud.vm.NicVO; import com.cloud.vm.VirtualMachine; @@ -44,6 +44,7 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ); AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ); AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ); + AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ); AllFieldsSearch.done(); IpSearch = createSearchBuilder(String.class); @@ -166,4 +167,14 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { return results.get(0); } + + @Override + public NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("network", networkId); + sc.setParameters("instance", instanceId); + sc.setParameters("broadcastUri", broadcastUri); + return findOneBy(sc); + } + } diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java index 465a4a45c66..13389554281 100755 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java @@ -249,7 +249,7 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager { * @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network) */ @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network) { + public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) { // TODO Auto-generated method stub return false; } diff --git a/wscript b/wscript index c8125352b67..17aa4c9ba05 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-11T22:40:12Z' +VERSION = '3.0.3.2012-06-12T00:24:56Z' APPNAME = 'cloud' import shutil,os From 7e463932f0330e432de0f9790c5654155eb51f92 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Jun 2012 11:55:48 -0700 Subject: [PATCH 54/64] VPC : add nic hot plug script --- .../debian/config/etc/cloud-nic.rules | 2 ++ .../config/etc/init.d/cloud-early-config | 3 +- .../debian/config/opt/cloud/bin/cloud-nic.sh | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 patches/systemvm/debian/config/etc/cloud-nic.rules create mode 100755 patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh diff --git a/patches/systemvm/debian/config/etc/cloud-nic.rules b/patches/systemvm/debian/config/etc/cloud-nic.rules new file mode 100644 index 00000000000..56e74ec4e9d --- /dev/null +++ b/patches/systemvm/debian/config/etc/cloud-nic.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="net" KERNEL=="eth*" RUN+="/opt/cloud/bin/cloud-nic.sh $env{ACTION} %k" + diff --git a/patches/systemvm/debian/config/etc/init.d/cloud-early-config b/patches/systemvm/debian/config/etc/init.d/cloud-early-config index b61c8f6091e..31a6e5091f1 100755 --- a/patches/systemvm/debian/config/etc/init.d/cloud-early-config +++ b/patches/systemvm/debian/config/etc/init.d/cloud-early-config @@ -616,8 +616,9 @@ EOF chkconfig nfs-common off cp /etc/iptables/iptables-vpcrouter /etc/iptables/rules cp /etc/vpcdnsmasq.conf /etc/dnsmasq.conf + cp /etc/cloud-nic.rules /etc/udev/rules.d/cloud-nic.rules echo "" > /etc/dnsmasq.d/dhcphosts.txt - echo "dhcp-hostsfile=/etc/dnsmasq.d/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf + echo "dhcp-hostsfile=/etc/dhcphosts.txt" > /etc/dnsmasq.d/cloud.conf } diff --git a/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh new file mode 100755 index 00000000000..1f1e52e08a5 --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + + +plug_nic() { + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -A PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + sudo echo "$tableNo $tableName" >> /etc/iproute2/rt_tables 2>/dev/null + sudo ip rule add fwmark $tableNo table $tableName 2>/dev/null + sudo ip route flush table $tableName + sudo ip route flush cache +} + + +unplug_nic() { + sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null + sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null + + sudo sed -i '/"$tableNo $tableName"/d' /etc/iproute2/rt_tables 2>/dev/null + sudo ip rule delete fwmark $tableNo table $tableName 2>/dev/null + sudo ip route flush table $tableName + sudo ip route flush cache +} + +action=$1 +dev=$2 +tableNo=$(echo $dev | awk -F'eth' '{print $2}') +tableName="Table_$dev" + +if [ $action == 'add' ] +then + plug_nic +else + unplug_nic +fi From 91363d555e65a25abd3fc3ed62eaa2ca0ed53763 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Jun 2012 12:26:31 -0700 Subject: [PATCH 55/64] VPC : fix nic hot plug script --- patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh index 1f1e52e08a5..3f80a4ca9b8 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/cloud-nic.sh @@ -16,9 +16,9 @@ unplug_nic() { sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j MARK --set-mark $tableNo 2>/dev/null sudo iptables -t mangle -D PREROUTING -i $dev -m state --state NEW -j CONNMARK --save-mark 2>/dev/null - sudo sed -i '/"$tableNo $tableName"/d' /etc/iproute2/rt_tables 2>/dev/null - sudo ip rule delete fwmark $tableNo table $tableName 2>/dev/null - sudo ip route flush table $tableName + sudo ip rule del fwmark $tableNo 2>/dev/null + sudo ip route flush table $tableName + sudo sed -i /"$tableNo $tableName"/d /etc/iproute2/rt_tables 2>/dev/null sudo ip route flush cache } From 97ca76856a83271992d51971de176a8515758bd9 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 12 Jun 2012 13:35:03 -0700 Subject: [PATCH 56/64] VPC: more changes to ipAssoc --- .../element/VpcVirtualRouterElement.java | 28 +++- .../VirtualNetworkApplianceManagerImpl.java | 7 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 129 ++++++++++++------ wscript | 2 +- 4 files changed, 118 insertions(+), 48 deletions(-) diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index ff0ca369c4d..ca5f920cfa1 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -16,6 +16,7 @@ package com.cloud.network.element; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ejb.Local; @@ -31,6 +32,7 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkService; +import com.cloud.network.PublicIpAddress; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.vpc.Vpc; @@ -269,12 +271,32 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc return true; } - - @Override protected List getRouters(Network network, DeployDestination dest) { return _vpcMgr.getVpcRouters(network.getVpcId()); } - + @Override + public boolean applyIps(Network network, List ipAddress, Set services) + throws ResourceUnavailableException { + boolean canHandle = true; + for (Service service : services) { + if (!canHandle(network, service)) { + canHandle = false; + break; + } + } + if (canHandle) { + List routers = getRouters(network, null); + if (routers == null || routers.isEmpty()) { + s_logger.debug(this.getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " + + "router doesn't exist in the network " + network.getId()); + return true; + } + + return _vpcRouterMgr.associateIP(network, ipAddress, routers); + } else { + return false; + } + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index fd00f16ef54..a072da662cd 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2641,7 +2641,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean associateIP(Network network, final List ipAddress, List routers) throws ResourceUnavailableException { + public boolean associateIP(Network network, final List ipAddress, List routers) + throws ResourceUnavailableException { if (ipAddress == null || ipAddress.isEmpty()) { s_logger.debug("No ip association rules to be applied for network " + network.getId()); return true; @@ -2750,11 +2751,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return _dnsBasicZoneUpdates; } - private interface RuleApplier { + protected interface RuleApplier { boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException; } - private boolean applyRules(Network network, List routers, String typeString, + protected boolean applyRules(Network network, List routers, String typeString, boolean isPodLevelException, Long podId, boolean failWhenDisconnect, RuleApplier applier) throws ResourceUnavailableException { if (routers == null || routers.isEmpty()) { s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId()); diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 39499aae11a..c3514859a0e 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -156,7 +156,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc); - DomainRouterVO router = deployRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId, + DomainRouterVO router = deployVpcRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId, vpc.getId(), sourceNatIp); routers.add(router); @@ -344,40 +344,13 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian protected boolean associtePublicIpInVpc(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) throws ConcurrentOperationException, ResourceUnavailableException{ - //1) Associate ip addresses List publicIps = new ArrayList(1); publicIps.add(ipAddress); Commands cmds = new Commands(OnError.Stop); createVpcAssociateIPCommands(router, publicIps, cmds, 0); - String assoc = add ? "Associating " : "Disassociating"; - StringBuilder debugMsg = new StringBuilder(assoc + " ip address " + ipAddress); - - //2) If sourceNat, setup the source nat - if (ipAddress.isSourceNat()) { - Integer networkRate = _networkMgr.getNetworkRate(ipAddress.getNetworkId(), router.getId()); - String vmGuestAddress = null; - - IpAddressTO ip = new IpAddressTO(ipAddress.getAccountId(), ipAddress.getAddress().addr(), add, false, - true, ipAddress.getVlanTag(), ipAddress.getGateway(), ipAddress.getNetmask(), ipAddress.getMacAddress(), - vmGuestAddress, networkRate, ipAddress.isOneToOneNat()); - - - - ip.setTrafficType(network.getTrafficType()); - ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network)); - - SetSourceNatCommand cmd = new SetSourceNatCommand(ip, true); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddress.getNetworkId(), router.getId())); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); - DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); - cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); - String enable = add ? "enabling" : "disabling"; - debugMsg.append(" and " + enable + " source nat for it"); - } if (sendCommandsToRouter(router, cmds)) { - s_logger.debug("Successfully applied ip associatino for ip " + ipAddress + " in vpc network " + network); + s_logger.debug("Successfully applied ip association for ip " + ipAddress + " in vpc network " + network); return true; } else { s_logger.warn("Failed to associate ip address " + ipAddress + " in vpc network " + network); @@ -443,7 +416,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return true; } - protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, + protected DomainRouterVO deployVpcRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, @@ -580,8 +553,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return result; } - private void createVpcAssociateIPCommands(final VirtualRouter router, final List ips, Commands cmds, long vmId) { - + private void createVpcAssociateIPCommands(final VirtualRouter router, final List ips, + Commands cmds, long vmId) { + + Pair sourceNatIpAdd = null; + Boolean addSourceNat = null; // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc.. Map> vlanIpMap = new HashMap>(); for (final PublicIpAddress ipAddress : ips) { @@ -610,20 +586,18 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian for (final PublicIpAddress ipAddr : ipAddrList) { boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true); - boolean sourceNat = ipAddr.isSourceNat(); - String vlanId = ipAddr.getVlanTag(); - String vlanGateway = ipAddr.getGateway(); - String vlanNetmask = ipAddr.getNetmask(); - String vifMacAddress = ipAddr.getMacAddress(); - - String vmGuestAddress = null; IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, - sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat()); + ipAddr.isSourceNat(), ipAddr.getVlanTag(), ipAddr.getGateway(), ipAddr.getNetmask(), ipAddr.getMacAddress(), + null, networkRate, ipAddr.isOneToOneNat()); ip.setTrafficType(network.getTrafficType()); ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network)); ipsToSend[i++] = ip; + if (ipAddr.isSourceNat()) { + sourceNatIpAdd = new Pair(ip, ipAddr.getNetworkId()); + addSourceNat = add; + } } IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); @@ -634,6 +608,79 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian cmds.addCommand("IPAssocVpcCommand", cmd); } + + //set source nat ip + if (sourceNatIpAdd != null) { + IpAddressTO sourceNatIp = sourceNatIpAdd.first(); + Long networkId = sourceNatIpAdd.second(); + SetSourceNatCommand cmd = new SetSourceNatCommand(sourceNatIp, addSourceNat); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(networkId, router.getId())); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); + DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn()); + cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); + cmds.addCommand("SetSourceNatCommand", cmd); + } + } + + @Override + public boolean associateIP(Network network, final List ipAddress, List routers) + throws ResourceUnavailableException { + if (ipAddress == null || ipAddress.isEmpty()) { + s_logger.debug("No ip association rules to be applied for network " + network.getId()); + return true; + } + + //1) check which nics need to be plugged and plug them + for (PublicIpAddress ip : ipAddress) { + for (VirtualRouter router : routers) { + URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag()); + Nic nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), router.getId(), + broadcastUri.toString()); + if (nic != null) { + //have to plug the nic(s) + NicProfile defaultNic = new NicProfile(); + if (ip.isSourceNat()) { + defaultNic.setDefaultNic(true); + } + defaultNic.setIp4Address(ip.getAddress().addr()); + defaultNic.setGateway(ip.getGateway()); + defaultNic.setNetmask(ip.getNetmask()); + defaultNic.setMacAddress(ip.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag())); + + NicProfile publicNic = null; + Network publicNtwk = null; + try { + publicNtwk = _networkMgr.getNetwork(ip.getNetworkId()); + publicNic = _itMgr.addVmToNetwork(router, publicNtwk, defaultNic); + } catch (ConcurrentOperationException e) { + s_logger.warn("Failed to add router " + router + " to vlan " + ip.getVlanTag() + + " in public network " + publicNtwk + " due to ", e); + } catch (InsufficientCapacityException e) { + s_logger.warn("Failed to add router " + router + " to vlan " + ip.getVlanTag() + + " in public network " + publicNtwk + " due to ", e); + } finally { + if (publicNic == null) { + s_logger.warn("Failed to add router " + router + " to vlan " + ip.getVlanTag() + + " in public network " + publicNtwk); + return false; + } + } + } + } + } + + //2) apply the ips + return applyRules(network, routers, "vpc ip association", false, null, false, new RuleApplier() { + @Override + public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException { + Commands cmds = new Commands(OnError.Continue); + createVpcAssociateIPCommands(router, ipAddress, cmds, 0); + return sendCommandsToRouter(router, cmds); + } + }); } - } diff --git a/wscript b/wscript index 17aa4c9ba05..b1020cf7b08 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-12T00:24:56Z' +VERSION = '3.0.3.2012-06-12T20:28:54Z' APPNAME = 'cloud' import shutil,os From 4075963767bea058ae832fd9782c8a90773bab10 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Jun 2012 15:32:06 -0700 Subject: [PATCH 57/64] VPC : revert some change --- .../network/guru/ControlNetworkGuru.java | 19 +++++++++++++++++-- .../lb/ElasticLoadBalancerManagerImpl.java | 6 ++++++ .../VirtualNetworkApplianceManagerImpl.java | 18 +++++++++++------- wscript | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java index 807bf312eff..4427be7a064 100755 --- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java @@ -106,7 +106,14 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu @Override public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - + + if(vm.getHypervisorType() == HypervisorType.VMware && vm.getType() != VirtualMachine.Type.DomainRouter) { + NicProfile nicProf = new NicProfile(Nic.ReservationStrategy.Create, null, null, null, null); + String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); + nicProf.setMacAddress(mac); + return nicProf; + } + if (nic != null) { throw new CloudRuntimeException("Does not support nic specification at this time: " + nic); } @@ -130,6 +137,15 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); nic.setMacAddress(mac); return; + } else { + // in basic mode and in VMware case, control network will be shared with guest network + String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId()); + nic.setMacAddress(mac); + nic.setIp4Address("0.0.0.0"); + nic.setNetmask("0.0.0.0"); + nic.setFormat(AddressFormat.Ip4); + nic.setGateway("0.0.0.0"); + return; } } @@ -142,7 +158,6 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu nic.setNetmask("255.255.0.0"); nic.setFormat(AddressFormat.Ip4); nic.setGateway(NetUtils.getLinkLocalGateway()); - nic.setDeviceId(0); } @Override diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 17b4050c006..1870518c2a8 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -856,6 +856,12 @@ public class ElasticLoadBalancerManagerImpl implements // always add management explicit route, for basic networking setup buf.append(" mgmtcidr=").append(_mgmtCidr); buf.append(" localgw=").append(dest.getPod().getGateway()); + + if (dc.getNetworkType() == NetworkType.Basic) { + // ask elb vm to setup SSH on guest network + buf.append(" sshonguest=true"); + } + } controlNic = nic; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a072da662cd..34a132c15d4 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1210,12 +1210,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.error("Didn't support redundant virtual router without public network!"); return null; } - //Check if control network has to be set on VR - boolean controlNetwork = true; - if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { - // in basic mode, use private network as control network - controlNetwork = false; - } + + //1) Get deployment plan and find out the list of routers boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || @@ -1589,6 +1585,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" mgmtcidr=").append(_mgmt_cidr); buf.append(" localgw=").append(dest.getPod().getGateway()); } + + + if (dc.getNetworkType() == NetworkType.Basic) { + // ask domR to setup SSH on guest network + buf.append(" sshonguest=true"); + } + } } else { //Remove public and guest nics from the profile @@ -1704,7 +1707,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian NicProfile controlNic = null; - if( dcVo.getNetworkType() == NetworkType.Basic) { + if(profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) { + // TODO this is a ugly to test hypervisor type here // for basic network mode, we will use the guest NIC for control NIC for (NicProfile nic : profile.getNics()) { if (nic.getTrafficType() == TrafficType.Guest && nic.getIp4Address() != null) { diff --git a/wscript b/wscript index b1020cf7b08..4f61b4810c3 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-12T20:28:54Z' +VERSION = '3.0.3.2012-06-12T21:55:09Z' APPNAME = 'cloud' import shutil,os From d3720c988bb07fc64a18df4be8b7bc326ea4b1af Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Jun 2012 17:09:50 -0700 Subject: [PATCH 58/64] VPC : add vpc_vpn_l2tp.sh --- .../debian/vpn/opt/cloud/bin/vpc_vpn_l2tp.sh | 174 ++++++++++++++++++ wscript | 2 +- 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100755 patches/systemvm/debian/vpn/opt/cloud/bin/vpc_vpn_l2tp.sh diff --git a/patches/systemvm/debian/vpn/opt/cloud/bin/vpc_vpn_l2tp.sh b/patches/systemvm/debian/vpn/opt/cloud/bin/vpc_vpn_l2tp.sh new file mode 100755 index 00000000000..574fd69e794 --- /dev/null +++ b/patches/systemvm/debian/vpn/opt/cloud/bin/vpc_vpn_l2tp.sh @@ -0,0 +1,174 @@ +#!/bin/bash +# Copyright 2012 Citrix Systems, Inc. Licensed under the +# Apache License, Version 2.0 (the "License"); you may not use this +# file except in compliance with the License. Citrix Systems, Inc. +# reserves all rights not expressly granted by the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Automatically generated by addcopyright.py at 04/03/2012 + + + + + + +#set -x +usage() { + printf "Usage:\n" + printf "Create VPN : %s -c -r -l -p -s -D -z < zone cidr> \n" $(basename $0) + printf "Delete VPN : %s -d -l -s -D -z < zone cidr> \n" $(basename $0) + printf "Add VPN User : %s -u \n" $(basename $0) + printf "Remote VPN User: %s -U /etc/ipsec.d/ipsec.any.secrets + sed -i -e "s/^ip range = .*$/ip range = $client_range/" /etc/xl2tpd/xl2tpd.conf + sed -i -e "s/^local ip = .*$/local ip = $local_ip/" /etc/xl2tpd/xl2tpd.conf + + sed -i -e "s/^ms-dns.*$/ms-dns $local_ip/" /etc/ppp/options.xl2tpd + + iptables_ "-D" $public_ip + iptables_ "-I" $public_ip + + ipsec_server "restart" + + ipsec auto --rereadsecrets + ipsec auto --replace L2TP-PSK +} + +destroy_l2tp_ipsec_vpn_server() { + local public_ip=$1 + + ipsec auto --down L2TP-PSK + + iptables_ "-D" $public_ip + + ipsec_server "stop" +} + +remove_l2tp_ipsec_user() { + local u=$1 + sed -i -e "/^$u .*$/d" /etc/ppp/chap-secrets + if [ -x /usr/bin/tdbdump ]; then + pid=$(tdbdump /var/run/pppd2.tdb | grep -w $u | awk -F';' '{print $4}' | awk -F= '{print $2}') + [ "$pid" != "" ] && kill -9 $pid + fi + return 0 +} + +add_l2tp_ipsec_user() { + local u=$1 + local passwd=$2 + + remove_l2tp_ipsec_user $u + echo "$u * $passwd *" >> /etc/ppp/chap-secrets +} + +rflag= +pflag= +lflag= +sflag= +create= +destroy= +useradd= +userdel= + +while getopts 'cdl:p:r:s:u:U:D:z' OPTION +do + case $OPTION in + c) create=1 + ;; + d) destroy=1 + ;; + u) useradd=1 + user_pwd="$OPTARG" + ;; + U) userdel=1 + user="$OPTARG" + ;; + r) rflag=1 + client_range="$OPTARG" + ;; + p) pflag=1 + ipsec_psk="$OPTARG" + ;; + l) lflag=1 + local_ip="$OPTARG" + ;; + s) sflag=1 + server_ip="$OPTARG" + ;; + D) dev="$OPTARG" + ;; + z) zcidr="$OPTARG" + ;; + ?) usage + exit 2 + ;; + esac +done + +[ "$create$destroy" == "11" ] || [ "$create$destroy$useradd$userdel" == "" ] && usage && exit 2 +[ "$create" == "1" ] && [ "$lflag$pflag$rflag$sflag" != "1111" ] && usage && exit 2 + +if [ "$create" == "1" ]; then + create_l2tp_ipsec_vpn_server $ipsec_psk $server_ip $client_range $local_ip + exit $? +fi + +if [ "$destroy" == "1" ]; then + destroy_l2tp_ipsec_vpn_server $server_ip + exit $? +fi + +if [ "$useradd" == "1" ]; then + u=$(echo $user_pwd | awk -F',' '{print $1}') + pwd=$(echo $user_pwd | awk -F',' '{print $2}') + add_l2tp_ipsec_user $u $pwd + exit $? +fi +if [ "$userdel" == "1" ]; then + remove_l2tp_ipsec_user $user + exit $? +fi diff --git a/wscript b/wscript index 4f61b4810c3..cfba1e6c1cd 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-12T21:55:09Z' +VERSION = '3.0.3' APPNAME = 'cloud' import shutil,os From a5f0b645625a801731a1731b568843351b6473fe Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 13 Jun 2012 10:17:04 -0700 Subject: [PATCH 59/64] Added new capabilities to VPN and Firewall services defining if VPN is S2S or Remote access, and if the Firewall rules should be created per cidr or per public ip address --- api/src/com/cloud/network/Network.java | 9 ++++++--- .../element/JuniperSRXExternalFirewallElement.java | 1 + .../com/cloud/network/element/NetscalerElement.java | 2 +- .../cloud/network/element/VirtualRouterElement.java | 5 +++-- .../cloud/network/element/VpcVirtualRouterElement.java | 10 ++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 5c643b25f7e..236a5a84e37 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -37,12 +37,12 @@ public interface Network extends ControlledEntity { public static class Service { private static List supportedServices = new ArrayList(); - public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnTypes); + public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnProtocols, Capability.VpnTypes); public static final Service Dhcp = new Service("Dhcp"); public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification); public static final Service Gateway = new Service("Gateway"); public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, - Capability.MultipleIps, Capability.TrafficStatistics); + Capability.MultipleIps, Capability.TrafficStatistics, Capability.FirewallType); public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps, Capability.SupportedStickinessMethods, Capability.ElasticLb); @@ -152,13 +152,16 @@ public interface Network extends ControlledEntity { public static final Capability SupportedStickinessMethods = new Capability("SupportedStickinessMethods"); public static final Capability MultipleIps = new Capability("MultipleIps"); public static final Capability SupportedSourceNatTypes = new Capability("SupportedSourceNatTypes"); - public static final Capability SupportedVpnTypes = new Capability("SupportedVpnTypes"); + public static final Capability SupportedVpnProtocols = new Capability("SupportedVpnTypes"); + public static final Capability VpnTypes = new Capability("VpnTypes"); public static final Capability TrafficStatistics = new Capability("TrafficStatistics"); public static final Capability LoadBalancingSupportedIps = new Capability("LoadBalancingSupportedIps"); public static final Capability AllowDnsSuffixModification = new Capability("AllowDnsSuffixModification"); public static final Capability RedundantRouter = new Capability("RedundantRouter"); public static final Capability ElasticIp = new Capability("ElasticIp"); public static final Capability ElasticLb = new Capability("ElasticLb"); + public static final Capability FirewallType = new Capability("FirewallType"); + private String name; diff --git a/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java b/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java index 0473291d15d..1aa23daef4a 100644 --- a/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java +++ b/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java @@ -266,6 +266,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp"); firewallCapabilities.put(Capability.MultipleIps, "true"); firewallCapabilities.put(Capability.TrafficStatistics, "per public ip"); + firewallCapabilities.put(Capability.FirewallType, "perpublicip"); capabilities.put(Service.Firewall, firewallCapabilities); // Disabling VPN for Juniper in Acton as it 1) Was never tested 2) probably just doesn't work diff --git a/server/src/com/cloud/network/element/NetscalerElement.java b/server/src/com/cloud/network/element/NetscalerElement.java index 81d5424d4ab..33a82d479c6 100644 --- a/server/src/com/cloud/network/element/NetscalerElement.java +++ b/server/src/com/cloud/network/element/NetscalerElement.java @@ -270,7 +270,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl firewallCapabilities.put(Capability.TrafficStatistics, "per public ip"); firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp"); firewallCapabilities.put(Capability.MultipleIps, "true"); - + firewallCapabilities.put(Capability.FirewallType, "perpublicip"); capabilities.put(Service.Firewall, firewallCapabilities); return capabilities; diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index dc1a2470cb1..0feaa984c28 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -559,12 +559,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl firewallCapabilities.put(Capability.TrafficStatistics, "per public ip"); firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp"); firewallCapabilities.put(Capability.MultipleIps, "true"); - + firewallCapabilities.put(Capability.FirewallType, "perpublicip"); capabilities.put(Service.Firewall, firewallCapabilities); // Set capabilities for vpn Map vpnCapabilities = new HashMap(); - vpnCapabilities.put(Capability.SupportedVpnTypes, "pptp,l2tp,ipsec"); + vpnCapabilities.put(Capability.SupportedVpnProtocols, "pptp,l2tp,ipsec"); + vpnCapabilities.put(Capability.VpnTypes, "removeaccessvpn"); capabilities.put(Service.Vpn, vpnCapabilities); Map dnsCapabilities = new HashMap(); diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index ca5f920cfa1..e5ae27e2675 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -89,6 +89,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + " in the network " + network); return false; + } else if (service == Service.Firewall) { + //todo - get capability here } } @@ -239,6 +241,14 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc sourceNatCapabilities.put(Capability.RedundantRouter, "false"); capabilities.put(Service.SourceNat, sourceNatCapabilities); + Map vpnCapabilities = capabilities.get(Service.Vpn); + vpnCapabilities.put(Capability.VpnTypes, "s2svpn"); + capabilities.put(Service.Vpn, vpnCapabilities); + + Map firewallCapabilities = capabilities.get(Service.Firewall); + firewallCapabilities.put(Capability.FirewallType, "percidr"); + capabilities.put(Service.Firewall, firewallCapabilities); + return capabilities; } From 2412b7837d6afc0935397e03181ce4b265f13830 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 13 Jun 2012 14:56:04 -0700 Subject: [PATCH 60/64] Isolated non-vpc networks: start router with 3 nics from the very beginning --- .../VpcVirtualNetworkApplianceService.java | 3 +- .../VirtualNetworkApplianceManagerImpl.java | 233 ++++++++++++++---- ...VpcVirtualNetworkApplianceManagerImpl.java | 45 +++- wscript | 2 +- 4 files changed, 226 insertions(+), 57 deletions(-) diff --git a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java index b8a37811e16..078d4053534 100644 --- a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java @@ -31,7 +31,8 @@ public interface VpcVirtualNetworkApplianceService { * @throws ResourceUnavailableException * @throws InsufficientCapacityException */ - boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * @param router diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 34a132c15d4..8feda1ee65e 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -121,6 +121,8 @@ import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.Networks.BroadcastDomainType; +import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PublicIpAddress; @@ -1210,8 +1212,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.error("Didn't support redundant virtual router without public network!"); return null; } - - //1) Get deployment plan and find out the list of routers boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || @@ -1248,16 +1248,24 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian offeringId = _offering.getId(); } - //3) Deploy Virtual Router(s) PublicIp sourceNatIp = null; if (publicNetwork) { sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); } + + //Check if control network has to be set on VR + boolean controlNetwork = true; + if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { + // in basic mode, use private network as control network + controlNetwork = false; + } + + //3) deploy virtual router(s) try { int count = routerCount - routers.size(); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, - null, sourceNatIp); + null, sourceNatIp, publicNetwork, controlNetwork, guestNetwork, new Pair(publicNetwork, sourceNatIp)); //add router to router network map if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { DomainRouterVO routerVO = _routerDao.findById(router.getId()); @@ -1275,7 +1283,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, - Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, + Long vpcId, PublicIp sourceNatIp, boolean setupPublicNetwork, boolean setupControlNetwork, Network guestNetwork, + Pair publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1284,8 +1293,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Creating the router " + id + " in datacenter " + dest.getDataCenter()); } - //1) Create router control network - List> networks = createRouterControlNetwork(owner, isRedundant, plan); + //1) Create router networks + List> networks = createRouterNetworks(owner, isRedundant, plan, setupControlNetwork, + guestNetwork, publicNetwork); ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); @@ -1376,17 +1386,85 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return router; } - protected List> createRouterControlNetwork(Account owner, boolean isRedundant, - DeploymentPlan plan) throws ConcurrentOperationException, + protected List> createRouterNetworks(Account owner, boolean isRedundant, + DeploymentPlan plan, boolean setupControlNetwork, Network guestNetwork, Pair publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { - //Form control network - List> networks = new ArrayList>(1); - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - s_logger.debug("Adding nic for Virtual Router in Control network "); - networks.add(new Pair(controlConfig, null)); + + boolean setupPublicNetwork = false; + if (publicNetwork != null) { + setupPublicNetwork = publicNetwork.first(); + } + + //Form networks + List> networks = new ArrayList>(3); + + //1) Guest network + boolean hasGuestNetwork = false; + if (guestNetwork != null) { + s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork); + String defaultNetworkStartIp = null; + if (guestNetwork.getCidr() != null && !setupPublicNetwork) { + String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId()); + if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) { + defaultNetworkStartIp = startIp; + } else if (s_logger.isDebugEnabled()){ + s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + + " is already allocated, can't use it for domain router; will get random ip address from the range"); + } + } + + NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); + if (setupPublicNetwork) { + if (isRedundant) { + gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null)); + } else { + gatewayNic.setIp4Address(guestNetwork.getGateway()); + } + gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri()); + gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType()); + gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri()); + gatewayNic.setMode(guestNetwork.getMode()); + String gatewayCidr = guestNetwork.getCidr(); + gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); + } else { + gatewayNic.setDefaultNic(true); + } + networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); + hasGuestNetwork = true; + } + + //2) Control network + if (setupControlNetwork) { + s_logger.debug("Adding nic for Virtual Router in Control network "); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + networks.add(new Pair(controlConfig, null)); + } + + //3) Public network + if (setupPublicNetwork) { + PublicIp sourceNatIp = publicNetwork.second(); + s_logger.debug("Adding nic for Virtual Router in Public network "); + //if source nat service is supported by the network, get the source nat ip address + NicProfile defaultNic = new NicProfile(); + defaultNic.setDefaultNic(true); + defaultNic.setIp4Address(sourceNatIp.getAddress().addr()); + defaultNic.setGateway(sourceNatIp.getGateway()); + defaultNic.setNetmask(sourceNatIp.getNetmask()); + defaultNic.setMacAddress(sourceNatIp.getMacAddress()); + defaultNic.setBroadcastType(BroadcastDomainType.Vlan); + defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); + defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); + if (hasGuestNetwork) { + defaultNic.setDeviceId(2); + } + NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + networks.add(new Pair(publicNetworks.get(0), defaultNic)); + } + return networks; } @@ -1526,6 +1604,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + boolean dnsProvided = true; + boolean dhcpProvided = true; + boolean publicNetwork = false; DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId()); _dcDao.loadDetails(dc); @@ -1544,14 +1625,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); } - NicProfile controlNic = null; + NicProfile controlNic = null; String defaultDns1 = null; String defaultDns2 = null; - - - Iterator it = profile.getNics().iterator(); - while (it.hasNext()) { - NicProfile nic = it.next(); + for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); @@ -1560,7 +1637,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" gateway=").append(nic.getGateway()); defaultDns1 = nic.getDns1(); defaultDns2 = nic.getDns2(); - } + } if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); @@ -1593,10 +1670,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - } else { - //Remove public and guest nics from the profile - s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from virtual machine profile " + profile.getVirtualMachine()); - it.remove(); + } else if (nic.getTrafficType() == TrafficType.Guest) { + dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); + dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter); + //build bootloader parameter for the guest + buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router)); + } else if (nic.getTrafficType() == TrafficType.Public) { + publicNetwork = true; } } @@ -1615,8 +1695,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String type = null; if (router.getVpcId() != null) { type = "vpcrouter"; + if (_disable_rp_filter) { + rpFilter=" disable_rp_filter=true"; + } + } else if (!publicNetwork) { + type = "dhcpsrvr"; } else { type = "router"; + if (_disable_rp_filter) { + rpFilter=" disable_rp_filter=true"; + } } if (_disable_rp_filter) { @@ -1634,23 +1722,25 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian buf.append(" extra_pubnics=" + _routerExtraPublicNics); } - if (defaultDns1 != null) { + /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response + * to return DNS server rather than + * virtual router itself. */ + if (dnsProvided || dhcpProvided) { buf.append(" dns1=").append(defaultDns1); - } - - if (defaultDns2 != null) { - buf.append(" dns2=").append(defaultDns2); - } + if (defaultDns2 != null) { + buf.append(" dns2=").append(defaultDns2); + } - boolean useExtDns = false; - /* For backward compatibility */ - String use_external_dns = _configDao.getValue(Config.UseExternalDnsServers.key()); - if (use_external_dns != null && use_external_dns.equals("true")) { - useExtDns = true; - } + boolean useExtDns = !dnsProvided; + /* For backward compatibility */ + String use_external_dns = _configDao.getValue(Config.UseExternalDnsServers.key()); + if (use_external_dns != null && use_external_dns.equals("true")) { + useExtDns = true; + } - if (useExtDns) { - buf.append(" useextdns=true"); + if (useExtDns) { + buf.append(" useextdns=true"); + } } if (s_logger.isDebugEnabled()) { @@ -1659,6 +1749,65 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } + + + protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, + String defaultDns2, DomainRouterVO router) { + long guestNetworkId = guestNic.getNetworkId(); + NetworkVO guestNetwork = _networkDao.findById(guestNetworkId); + String dhcpRange = null; + DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId()); + + StringBuilder buf = new StringBuilder(); + + boolean isRedundant = router.getIsRedundantRouter(); + if (isRedundant) { + buf.append(" redundant_router=1"); + List routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER); + try { + int priority = getUpdatedPriority(guestNetwork, routers, router); + router.setPriority(priority); + } catch (InsufficientVirtualNetworkCapcityException e) { + s_logger.error("Failed to get update priority!", e); + throw new CloudRuntimeException("Failed to get update priority!"); + } + Network net = _networkMgr.getNetwork(guestNic.getNetworkId()); + buf.append(" guestgw=").append(net.getGateway()); + String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask())); + buf.append(" guestbrd=").append(brd); + buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask())); + buf.append(" router_pr=").append(router.getPriority()); + } + + //setup network domain + String domain = guestNetwork.getNetworkDomain(); + if (domain != null) { + buf.append(" domain=" + domain); + } + + //setup dhcp range + if (dc.getNetworkType() == NetworkType.Basic) { + if (guestNic.isDefaultNic()) { + long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask()); + String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize); + if (cidr != null) { + dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize); + } + } + } else if (dc.getNetworkType() == NetworkType.Advanced) { + String cidr = guestNetwork.getCidr(); + if (cidr != null) { + dhcpRange = NetUtils.getDhcpRange(cidr); + } + } + + if (dhcpRange != null) { + buf.append(" dhcprange=" + dhcpRange); + } + + return buf; + } + protected String getGuestDhcpRange(NicProfile guestNic, Network guestNetwork, DataCenter dc) { String dhcpRange = null; @@ -1936,7 +2085,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router.setScriptsVersion(versionAnswer.getScriptsVersion()); router = _routerDao.persist(router, guestNetworks); } - } + } return result; } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index c3514859a0e..bc7d3e00213 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -363,8 +363,12 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + + if (!super.finalizeStart(profile, hostId, cmds, context)) { return false; + } else if (profile.getVirtualMachine().getVpcId() == null) { + return true; } DomainRouterVO router = profile.getVirtualMachine(); @@ -372,21 +376,19 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //Get guest nic info Map guestNics = new HashMap(); Map publicNics = new HashMap(); - List guestNetworks = new ArrayList(); List routerNics = _nicDao.listByVmId(profile.getId()); for (Nic routerNic : routerNics) { Network network = _networkMgr.getNetwork(routerNic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { guestNics.put(routerNic, network); - guestNetworks.add(network); } else if (network.getTrafficType() == TrafficType.Public) { publicNics.put(routerNic, network); } } try { - //add router to public and guest networks + //add VPC router to public and guest networks for (Nic publicNic : publicNics.keySet()) { Network publicNtwk = publicNics.get(publicNic); IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), @@ -423,19 +425,18 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian StorageUnavailableException, ResourceUnavailableException { DomainRouterVO router = - super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, sourceNatIp); + super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, sourceNatIp, + false, true, null, null); //Plug public nic - boolean addToPublicNtwk = true; - if (sourceNatIp != null) { + if (router != null && sourceNatIp != null) { Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0); - addToPublicNtwk = addPublicIpToVpc(router, publicNetwork, sourceNatIp); - } - - if (!addToPublicNtwk) { - s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up"); - destroyRouter(router.getId()); - return null; + if (!addPublicIpToVpc(router, publicNetwork, sourceNatIp)) { + s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up"); + destroyRouter(router.getId()); + return null; + } + } return router; @@ -683,4 +684,22 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } }); } + + +// @Override +// public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, +// ReservationContext context) { +// //remove public and guest nics as we will plug them later +// Iterator it = profile.getNics().iterator(); +// while (it.hasNext()) { +// NicProfile nic = it.next(); +// if (nic.getTrafficType() == TrafficType.Public || nic.getTrafficType() == TrafficType.Guest) { +// s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from the nics passed on vm start. " + +// "The nic will be plugged later"); +// it.remove(); +// } +// } +// +// return super.finalizeVirtualMachineProfile(profile, dest, context); +// } } diff --git a/wscript b/wscript index cfba1e6c1cd..f12354c1a4d 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3' +VERSION = '3.0.3.2012-06-13T21:49:04Z' APPNAME = 'cloud' import shutil,os From 8f4ccf9f72f088554594786f4fdc98840a8121d9 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 13 Jun 2012 15:48:39 -0700 Subject: [PATCH 61/64] VPC : revert dnsmasq.conf --- patches/systemvm/debian/config/etc/dnsmasq.conf | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/patches/systemvm/debian/config/etc/dnsmasq.conf b/patches/systemvm/debian/config/etc/dnsmasq.conf index ca328694ca7..8f999a75cb1 100644 --- a/patches/systemvm/debian/config/etc/dnsmasq.conf +++ b/patches/systemvm/debian/config/etc/dnsmasq.conf @@ -70,18 +70,19 @@ local=/2.vmops-test.vmops.com/ # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. # Repeat the line for more than one interface. -#interface=eth0 - +interface=eth0 # Or you can specify which interface _not_ to listen on +except-interface=eth1 +except-interface=eth2 except-interface=lo - # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) #listen-address= # If you want dnsmasq to provide only DNS service on an interface, # configure it as shown above, and then use the following line to # disable DHCP on it. -#no-dhcp-interface=eth1 +no-dhcp-interface=eth1 +no-dhcp-interface=eth2 # On systems which support it, dnsmasq binds the wildcard address, # even when it is listening on only some interfaces. It then discards @@ -110,14 +111,14 @@ expand-hosts # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3) Provides the domain part for "expand-hosts" -#domain=2.vmops-test.vmops.com +domain=2.vmops-test.vmops.com # Uncomment this to enable the integrated DHCP server, you need # to supply the range of addresses available for lease and optionally # a lease time. If you have more than one network, you will need to # repeat this for each network on which you want to supply DHCP # service. -#dhcp-range=10.1.1.1,static +dhcp-range=10.1.1.1,static #dhcp-range=10.0.0.1,10.255.255.255 dhcp-hostsfile=/etc/dhcphosts.txt From 127daa58313048ecaf579532841c1942e408c154 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 13 Jun 2012 16:43:43 -0700 Subject: [PATCH 62/64] Fixed lock problem when add vm to guest network --- .../VirtualNetworkApplianceManagerImpl.java | 96 ++++++++++--------- wscript | 2 +- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 8feda1ee65e..eedd7ea097f 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1181,37 +1181,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork; assert guestNetwork.getTrafficType() == TrafficType.Guest; - - Network network = _networkDao.acquireInLockTable(guestNetwork.getId()); - if (network == null) { - throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); - } - //Check if providers are supported in the physical networks - VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter; - Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); - PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString()); - if (provider == null) { - throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId); - } - VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type); - if (vrProvider == null) { - throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString()+ " as service provider " + provider.getId()); - } - if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { - owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); - } - - //Check if public network has to be set on VR - boolean publicNetwork = false; - if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { - publicNetwork = true; - } - if (isRedundant && !publicNetwork) { - s_logger.error("Didn't support redundant virtual router without public network!"); - return null; - } //1) Get deployment plan and find out the list of routers boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || @@ -1242,26 +1213,59 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (routers.size() >= 5) { s_logger.error("Too much redundant routers!"); } - - Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); - if (offeringId == null) { - offeringId = _offering.getId(); + + Network network = _networkDao.acquireInLockTable(guestNetwork.getId()); + if (network == null) { + throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); } - PublicIp sourceNatIp = null; - if (publicNetwork) { - sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); - } - - //Check if control network has to be set on VR - boolean controlNetwork = true; - if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { - // in basic mode, use private network as control network - controlNetwork = false; - } - - //3) deploy virtual router(s) try { + //Check if providers are supported in the physical networks + VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter; + Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); + PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString()); + if (provider == null) { + throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId); + } + VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type); + if (vrProvider == null) { + throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString()+ " as service provider " + provider.getId()); + } + + if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { + owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); + } + + //Check if public network has to be set on VR + boolean publicNetwork = false; + if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) { + publicNetwork = true; + } + if (isRedundant && !publicNetwork) { + s_logger.error("Didn't support redundant virtual router without public network!"); + return null; + } + + + + Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); + if (offeringId == null) { + offeringId = _offering.getId(); + } + + PublicIp sourceNatIp = null; + if (publicNetwork) { + sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); + } + + //Check if control network has to be set on VR + boolean controlNetwork = true; + if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { + // in basic mode, use private network as control network + controlNetwork = false; + } + + //3) deploy virtual router(s) int count = routerCount - routers.size(); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, diff --git a/wscript b/wscript index f12354c1a4d..2691e5131a7 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-13T21:49:04Z' +VERSION = '3.0.3.2012-06-13T23:38:49Z' APPNAME = 'cloud' import shutil,os From d83c81b6375ce01365a07c5ffbd757546facf5fd Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 13 Jun 2012 19:25:48 -0700 Subject: [PATCH 63/64] VPC : fixed get_domr_version --- scripts/vm/hypervisor/xenserver/vmops | 3 ++- wscript | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index 4b918c70913..e1f96800b16 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -294,7 +294,8 @@ def routerProxy(session, args): cmd.insert(0, "/bin/bash") try: txt = util.pread2(cmd) - txt = 'success' + if txt is None or len(txt) == 0 : + txt = 'success' except: util.SMlog("routerProxy command " + sargs + " failed " ) txt = '' diff --git a/wscript b/wscript index 2691e5131a7..fc404aac841 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-13T23:38:49Z' +VERSION = '3.0.3.2012-06-14T02:14:58Z' APPNAME = 'cloud' import shutil,os From f1738e1e2e444a615291f1a697bd258a1a5ca2ac Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 14 Jun 2012 17:47:43 -0700 Subject: [PATCH 64/64] Changed the command name for adding private gateway --- client/tomcatconf/commands.properties.in | 10 ++++------ wscript | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index ad7fcda55c9..e03602e1255 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -333,7 +333,6 @@ addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1 listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1 deleteNetworkDevice=com.cloud.api.commands.DeleteNetworkDeviceCmd;1 - ### VPC commands createVPC=com.cloud.api.commands.CreateVPCCmd;15 listVPCs=com.cloud.api.commands.ListVPCsCmd;15 @@ -347,12 +346,11 @@ updateVPCOffering=com.cloud.api.commands.UpdateVPCOfferingCmd;1 deleteVPCOffering=com.cloud.api.commands.DeleteVPCOfferingCmd;1 listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15 -#### VPC gateway commands -createVPCGateway=com.cloud.api.commands.CreateVPCGatewayCmd;15 -listVPCGateways=com.cloud.api.commands.ListVPCGatewaysCmd;15 -deleteVPCGateway=com.cloud.api.commands.DeleteVPCGatewayCmd;15 +#### Private gateway commands +#createPrivateGateway=com.cloud.api.commands.CreatePrivateGatewayCmd;15 +#listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;15 +#deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;15 #### Private network command createPrivateNetwork=com.cloud.api.commands.CreatePrivateNetworkCmd;1 -deletePrivateNetwork=com.cloud.api.commands.CreatePrivateNetworkCmd;1 diff --git a/wscript b/wscript index fc404aac841..b6608c015c6 100644 --- a/wscript +++ b/wscript @@ -5,7 +5,7 @@ # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-14T02:14:58Z' +VERSION = '3.0.3.2012-06-15T00:14:17Z' APPNAME = 'cloud' import shutil,os