From 360eae368767f374fe13d5ba2b8a9056d0ef8633 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Date: Wed, 5 Jun 2013 21:52:57 +0530 Subject: [PATCH] Cloudstack-2854 [Multiple_IP_Ranges] Failed to create ip alias on VR while deploying guest vm with ip address from new CIDR Signed-off-by: Abhinandan Prateek --- .../VirtualRoutingResource.java | 50 +++++++++++-------- scripts/network/domr/call_dnsmasq.sh | 29 +++++++++++ scripts/network/domr/createipAlias.sh | 26 ++++++++++ scripts/network/domr/deleteipAlias.sh | 25 ++++++++++ 4 files changed, 109 insertions(+), 21 deletions(-) create mode 100755 scripts/network/domr/call_dnsmasq.sh create mode 100755 scripts/network/domr/createipAlias.sh create mode 100755 scripts/network/domr/deleteipAlias.sh diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 9e40eefc11a..dae1c8591f4 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -111,7 +111,7 @@ public class VirtualRoutingResource implements Manager { private String _routerProxyPath; private String _createIpAliasPath; private String _deleteIpAliasPath; - private String _configDhcpPath; + private String _callDnsMasqPath; private int _timeout; private int _startTimeout; @@ -625,7 +625,8 @@ public class VirtualRoutingResource implements Manager { String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final Script command = new Script(_createIpAliasPath, _timeout, s_logger); List ipAliasTOs = cmd.getIpAliasList(); - String args=routerIp+" "; + String args = ""; + command.add(routerIp); for (IpAliasTO ipaliasto : ipAliasTOs) { args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-"; } @@ -637,7 +638,8 @@ public class VirtualRoutingResource implements Manager { protected Answer execute(final DeleteIpAliasCommand cmd) { final Script command = new Script(_deleteIpAliasPath, _timeout, s_logger); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - String args = ""; + String args =""; + command.add(routerIp); List revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); for (IpAliasTO ipAliasTO : revokedIpAliasTOs) { args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-"; @@ -653,32 +655,26 @@ public class VirtualRoutingResource implements Manager { } protected Answer execute(final DnsMasqConfigCommand cmd) { - final Script command = new Script(_configDhcpPath, _timeout, s_logger); + final Script command = new Script(_callDnsMasqPath, _timeout, s_logger); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); DnsMasqConfigurator configurator = new DnsMasqConfigurator(); String [] config = configurator.generateConfiguration(cmd); - File tmpCfgFile = null; + String cfgFileName = routerIp.replace(".","-")+"dns.cgf"; + String tmpCfgFileContents = ""; + for (int i = 0; i < config.length; i++) { + tmpCfgFileContents += config[i]; + tmpCfgFileContents += "\n"; + } + File permKey = new File("/root/.ssh/id_rsa.cloud"); + String cfgFilePath = "/tmp/"+cfgFileName; try { - String cfgFilePath = ""; - if (routerIp != null) { - tmpCfgFile = File.createTempFile(routerIp.replace('.', '_'), "cfg"); - final PrintWriter out - = new PrintWriter(new BufferedWriter(new FileWriter(tmpCfgFile))); - for (int i=0; i < config.length; i++) { - out.println(config[i]); - } - out.close(); - cfgFilePath = tmpCfgFile.getAbsolutePath(); - } + SshHelper.scpTo(routerIp, 3922, "root", permKey, null, "/tmp/", tmpCfgFileContents.getBytes(), cfgFileName, null); + command.add(routerIp); command.add(cfgFilePath); final String result = command.execute(); return new Answer(cmd, result == null, result); - } catch (final IOException e) { + } catch (Exception e) { return new Answer(cmd, false, e.getMessage()); - } finally { - if (tmpCfgFile != null) { - tmpCfgFile.delete(); - } } } @@ -1209,6 +1205,18 @@ public class VirtualRoutingResource implements Manager { if (_routerProxyPath == null) { throw new ConfigurationException("Unable to find router_proxy.sh"); } + _createIpAliasPath = findScript("createipAlias.sh"); + if (_createIpAliasPath == null) { + throw new ConfigurationException("unable to find createipAlias.sh"); + } + _deleteIpAliasPath = findScript("deleteipAlias.sh"); + if (_deleteIpAliasPath == null) { + throw new ConfigurationException("unable to find deleteipAlias.sh"); + } + _callDnsMasqPath = findScript("call_dnsmasq.sh"); + if (_callDnsMasqPath == null) { + throw new ConfigurationException("unable to find call_dnsmasq.sh"); + } return true; } diff --git a/scripts/network/domr/call_dnsmasq.sh b/scripts/network/domr/call_dnsmasq.sh new file mode 100755 index 00000000000..097e18572a2 --- /dev/null +++ b/scripts/network/domr/call_dnsmasq.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +usage() { + printf "Usage: %s: \n" $(basename $0) >&2 +} + +set -x + +cert="/root/.ssh/id_rsa.cloud" + +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/dnsmasq.sh $2" +exit $? + diff --git a/scripts/network/domr/createipAlias.sh b/scripts/network/domr/createipAlias.sh new file mode 100755 index 00000000000..c35658e6679 --- /dev/null +++ b/scripts/network/domr/createipAlias.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +usage() { + printf " %s routerip \n" $(basename $0) >&2 +} + +set -x +cert="/root/.ssh/id_rsa.cloud" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/createIpAlias.sh $2" diff --git a/scripts/network/domr/deleteipAlias.sh b/scripts/network/domr/deleteipAlias.sh new file mode 100755 index 00000000000..6816edd524c --- /dev/null +++ b/scripts/network/domr/deleteipAlias.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +usage() { + printf " %s routerip \n" $(basename $0) >&2 +} + +set -x +cert="/root/.ssh/id_rsa.cloud" +ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/deleteIpAlias.sh $2 $3"