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 <aprateek@apache.org>
This commit is contained in:
Bharat Kumar 2013-06-05 21:52:57 +05:30 committed by Abhinandan Prateek
parent 358f3edc57
commit 360eae3687
4 changed files with 109 additions and 21 deletions

View File

@ -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<IpAliasTO> 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<IpAliasTO> 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;
}

View File

@ -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: <domR eth1 ip> <path_to_new_config_file>\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 $?

View File

@ -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 <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \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"

View File

@ -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 <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \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"