From issues-return-93417-archive-asf-public=cust-asf.ponee.io@cloudstack.apache.org Mon Nov 12 12:48:53 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 2B1F6180660 for ; Mon, 12 Nov 2018 12:48:53 +0100 (CET) Received: (qmail 53130 invoked by uid 500); 12 Nov 2018 11:48:52 -0000 Mailing-List: contact issues-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 issues@cloudstack.apache.org Received: (qmail 53117 invoked by uid 500); 12 Nov 2018 11:48:52 -0000 Delivered-To: apmail-incubator-cloudstack-issues@incubator.apache.org Received: (qmail 53113 invoked by uid 99); 12 Nov 2018 11:48:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Nov 2018 11:48:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id D2C8DD15BB for ; Mon, 12 Nov 2018 11:48:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id o5p4caN6_G5T for ; Mon, 12 Nov 2018 11:48:48 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 8ACB86235D for ; Mon, 12 Nov 2018 11:42:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C5E78E25D5 for ; Mon, 12 Nov 2018 11:42:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 73AB2266FF for ; Mon, 12 Nov 2018 11:42:00 +0000 (UTC) Date: Mon, 12 Nov 2018 11:42:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: cloudstack-issues@incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CLOUDSTACK-10199) Support requesting a specific IPv4 address in Basic Networking during Instance creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CLOUDSTACK-10199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16683645#comment-16683645 ] ASF GitHub Bot commented on CLOUDSTACK-10199: --------------------------------------------- GabrielBrascher 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_r232626456 ########## File path: engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java ########## @@ -883,6 +885,73 @@ 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) { + String requestedIpv4Address = requestedNicProfile.getRequestedIPv4(); + if (requestedIpv4Address == null) { + s_logger.debug(String.format("The requested [IPv4 address=%s] is null", requestedIpv4Address)); + return; + } + if (org.apache.commons.lang3.StringUtils.isBlank(requestedIpv4Address)) { + throw new InvalidParameterValueException(String.format("The requested [IPv4 address='%s'] is empty or blank", requestedIpv4Address)); + } + if (!NetUtils.isValidIp4(requestedIpv4Address)) { + throw new InvalidParameterValueException(String.format("The requested [IPv4 address='%s'] is not a valid IP address", requestedIpv4Address)); + } + + VlanVO vlanVo = _vlanDao.findByNetworkId(network.getId()); + if (vlanVo == null) { + throw new CloudRuntimeException(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())); + } + + acquireLockAndCheckIfIpv4IsFree(network, requestedIpv4Address); + + String ipv4Gateway = vlanVo.getVlanGateway(); + String ipv4Netmask = vlanVo.getVlanNetmask(); + + if (org.apache.commons.lang3.StringUtils.isBlank(ipv4Gateway) || !NetUtils.isValidIp4(ipv4Gateway)) { + throw new CloudRuntimeException(String.format("The [IPv4Gateway='%s'] from [VlanId='%s'] is not valid", ipv4Gateway, vlanVo.getId())); + } + if (org.apache.commons.lang3.StringUtils.isBlank(ipv4Netmask) || !NetUtils.isValidIp4Netmask(ipv4Netmask)) { + throw new CloudRuntimeException(String.format("The [IPv4Netmask='%s'] from [VlanId='%s'] is not valid", ipv4Netmask, vlanVo.getId())); + } + + 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) { + e.printStackTrace(); + } + } + } + + /** + * Acquires lock of in table "user_ip_address" and checks if the requested IPv4 address is Free. + */ + protected void acquireLockAndCheckIfIpv4IsFree(Network network, String requestedIpv4Address) { + IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIpv4Address); + if (ipVO == null) { + throw new CloudRuntimeException(String.format("Cannot find IPAddressVO for guest [IPv4 address='%s'] and [network id=%s]", requestedIpv4Address, network.getId())); + } + IPAddressVO lockedIpVO = _ipAddressDao.acquireInLockTable(ipVO.getId()); Review comment: @marcaurele are you LGTM on this one? Thanks for your reviews and hard work :+1: ---------------------------------------------------------------- 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 > Support requesting a specific IPv4 address in Basic Networking during Instance creation > --------------------------------------------------------------------------------------- > > Key: CLOUDSTACK-10199 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10199 > Project: CloudStack > Issue Type: Improvement > Security Level: Public(Anyone can view this level - this is the default.) > Components: API > Environment: CloudStack 4.10 > Reporter: Wido den Hollander > Priority: Major > Labels: basic-networking > > DirectPodBasedNetworkGuru does not support requesting a custom IP-Address while creating a new NIC/Instance. > {quote} > Error 530: Does not support custom ip allocation at this time: NicProfile[0-0-null-null-null > { > "cserrorcode": 4250, > "errorcode": 530, > "errortext": "Does not support custom ip allocation at this time: NicProfile[0-0-null-null-null", > "uuidList": [] > } > {quote} > Some use-cases prefer the ability to request the IPv4 address which the Instance will get. -- This message was sent by Atlassian JIRA (v7.6.3#76005)