Skip to content

Commit 360eae3

Browse files
bvbharatAbhinandan Prateek
authored andcommitted
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>
1 parent 358f3ed commit 360eae3

4 files changed

Lines changed: 109 additions & 21 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class VirtualRoutingResource implements Manager {
111111
private String _routerProxyPath;
112112
private String _createIpAliasPath;
113113
private String _deleteIpAliasPath;
114-
private String _configDhcpPath;
114+
private String _callDnsMasqPath;
115115

116116
private int _timeout;
117117
private int _startTimeout;
@@ -625,7 +625,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) {
625625
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
626626
final Script command = new Script(_createIpAliasPath, _timeout, s_logger);
627627
List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
628-
String args=routerIp+" ";
628+
String args = "";
629+
command.add(routerIp);
629630
for (IpAliasTO ipaliasto : ipAliasTOs) {
630631
args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
631632
}
@@ -637,7 +638,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) {
637638
protected Answer execute(final DeleteIpAliasCommand cmd) {
638639
final Script command = new Script(_deleteIpAliasPath, _timeout, s_logger);
639640
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
640-
String args = "";
641+
String args ="";
642+
command.add(routerIp);
641643
List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
642644
for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
643645
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
@@ -653,32 +655,26 @@ protected Answer execute(final DeleteIpAliasCommand cmd) {
653655
}
654656

655657
protected Answer execute(final DnsMasqConfigCommand cmd) {
656-
final Script command = new Script(_configDhcpPath, _timeout, s_logger);
658+
final Script command = new Script(_callDnsMasqPath, _timeout, s_logger);
657659
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
658660
DnsMasqConfigurator configurator = new DnsMasqConfigurator();
659661
String [] config = configurator.generateConfiguration(cmd);
660-
File tmpCfgFile = null;
662+
String cfgFileName = routerIp.replace(".","-")+"dns.cgf";
663+
String tmpCfgFileContents = "";
664+
for (int i = 0; i < config.length; i++) {
665+
tmpCfgFileContents += config[i];
666+
tmpCfgFileContents += "\n";
667+
}
668+
File permKey = new File("/root/.ssh/id_rsa.cloud");
669+
String cfgFilePath = "/tmp/"+cfgFileName;
661670
try {
662-
String cfgFilePath = "";
663-
if (routerIp != null) {
664-
tmpCfgFile = File.createTempFile(routerIp.replace('.', '_'), "cfg");
665-
final PrintWriter out
666-
= new PrintWriter(new BufferedWriter(new FileWriter(tmpCfgFile)));
667-
for (int i=0; i < config.length; i++) {
668-
out.println(config[i]);
669-
}
670-
out.close();
671-
cfgFilePath = tmpCfgFile.getAbsolutePath();
672-
}
671+
SshHelper.scpTo(routerIp, 3922, "root", permKey, null, "/tmp/", tmpCfgFileContents.getBytes(), cfgFileName, null);
672+
command.add(routerIp);
673673
command.add(cfgFilePath);
674674
final String result = command.execute();
675675
return new Answer(cmd, result == null, result);
676-
} catch (final IOException e) {
676+
} catch (Exception e) {
677677
return new Answer(cmd, false, e.getMessage());
678-
} finally {
679-
if (tmpCfgFile != null) {
680-
tmpCfgFile.delete();
681-
}
682678
}
683679
}
684680

@@ -1209,6 +1205,18 @@ public boolean configure(final String name, final Map<String, Object> params) th
12091205
if (_routerProxyPath == null) {
12101206
throw new ConfigurationException("Unable to find router_proxy.sh");
12111207
}
1208+
_createIpAliasPath = findScript("createipAlias.sh");
1209+
if (_createIpAliasPath == null) {
1210+
throw new ConfigurationException("unable to find createipAlias.sh");
1211+
}
1212+
_deleteIpAliasPath = findScript("deleteipAlias.sh");
1213+
if (_deleteIpAliasPath == null) {
1214+
throw new ConfigurationException("unable to find deleteipAlias.sh");
1215+
}
1216+
_callDnsMasqPath = findScript("call_dnsmasq.sh");
1217+
if (_callDnsMasqPath == null) {
1218+
throw new ConfigurationException("unable to find call_dnsmasq.sh");
1219+
}
12121220

12131221
return true;
12141222
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
usage() {
20+
printf "Usage: %s: <domR eth1 ip> <path_to_new_config_file>\n" $(basename $0) >&2
21+
}
22+
23+
set -x
24+
25+
cert="/root/.ssh/id_rsa.cloud"
26+
27+
ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/dnsmasq.sh $2"
28+
exit $?
29+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
20+
usage() {
21+
printf " %s routerip <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
22+
}
23+
24+
set -x
25+
cert="/root/.ssh/id_rsa.cloud"
26+
ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/createIpAlias.sh $2"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
usage() {
20+
printf " %s routerip <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
21+
}
22+
23+
set -x
24+
cert="/root/.ssh/id_rsa.cloud"
25+
ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/deleteIpAlias.sh $2 $3"

0 commit comments

Comments
 (0)