From commits-return-77905-archive-asf-public=cust-asf.ponee.io@cloudstack.apache.org Thu Jun 14 13:24:24 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id EE0C7180600 for ; Thu, 14 Jun 2018 13:24:23 +0200 (CEST) Received: (qmail 88334 invoked by uid 500); 14 Jun 2018 11:24:23 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 88325 invoked by uid 99); 14 Jun 2018 11:24:22 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2018 11:24:22 +0000 From: GitBox To: commits@cloudstack.apache.org Subject: [GitHub] fmaximus commented on a change in pull request #2595: CLOUDSTACK-10199: Support requesting a specific IPv4 address Message-ID: <152897546241.13148.11203903747343032786.gitbox@gitbox.apache.org> Date: Thu, 14 Jun 2018 11:24:22 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit fmaximus commented on a change in pull request #2595: CLOUDSTACK-10199: Support requesting a specific IPv4 address URL: https://github.com/apache/cloudstack/pull/2595#discussion_r195386818 ########## File path: engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java ########## @@ -869,6 +871,76 @@ public void saveExtraDhcpOptions(final String networkUuid, final Long nicId, fin return new Pair(vmNic, Integer.valueOf(deviceId)); } + /** + * If the requested IPv4 address from the NicProfile was configured then it configures the IPv4 address, Netmask and Gateway to deploy the VM with the requested IP. + */ + protected void configureNicProfileBasedOnRequestedIp(NicProfile requestedNicProfile, NicProfile nicProfile, Network network) { + if (requestedNicProfile == null) { + return; + } + String requestedIpv4Address = requestedNicProfile.getRequestedIPv4(); + if (requestedIpv4Address == null) { + return; + } + if (!NetUtils.isValidIp4(requestedIpv4Address)) { + throw new InvalidParameterValueException(String.format("The requested [IPv4 address='%s'] is not a valid IP address", requestedIpv4Address)); + } + + VlanVO vlanVo = _vlanDao.findByNetworkIdAndIpv4(network.getId(), requestedIpv4Address); + if (vlanVo == null) { + throw new InvalidParameterValueException(String.format("Trying to configure a Nic with the requested [IPv4='%s'] but cannot find a Vlan for the [network id='%s']", + requestedIpv4Address, network.getId())); + } + + String ipv4Gateway = vlanVo.getVlanGateway(); + String ipv4Netmask = vlanVo.getVlanNetmask(); + + if (!NetUtils.isValidIp4(ipv4Gateway)) { + throw new InvalidParameterValueException(String.format("The [IPv4Gateway='%s'] from [VlanId='%s'] is not valid", ipv4Gateway, vlanVo.getId())); + } + if (!NetUtils.isValidIp4Netmask(ipv4Netmask)) { + throw new InvalidParameterValueException(String.format("The [IPv4Netmask='%s'] from [VlanId='%s'] is not valid", ipv4Netmask, vlanVo.getId())); + } + + acquireLockAndCheckIfIpv4IsFree(network, requestedIpv4Address); + + nicProfile.setIPv4Address(requestedIpv4Address); + nicProfile.setIPv4Gateway(ipv4Gateway); + nicProfile.setIPv4Netmask(ipv4Netmask); + + if (nicProfile.getMacAddress() == null) { + try { + String macAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId()); + nicProfile.setMacAddress(macAddress); + } catch (InsufficientAddressCapacityException e) { + throw new CloudRuntimeException(String.format("Cannot get next available mac address in [network id='%s']", network.getId()), e); + } + } + } + + /** + * Acquires lock of in table "user_ip_address" and checks if the requested IPv4 address is Free. + */ + protected void acquireLockAndCheckIfIpv4IsFree(Network network, String requestedIpv4Address) { Review comment: @rafaelweingartner The issue is that when a user selects a guest IP, it won't be found by _ipAddressDao, because IPAddressVO is for public IP's, not for guest IP's. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services