mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
merge with master
This commit is contained in:
commit
f84b6abde0
53
api/src/com/cloud/agent/api/to/DnsmasqTO.java
Normal file
53
api/src/com/cloud/agent/api/to/DnsmasqTO.java
Normal file
@ -0,0 +1,53 @@
|
||||
// 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.
|
||||
package com.cloud.agent.api.to;
|
||||
|
||||
public class DnsmasqTO {
|
||||
String routerIp;
|
||||
String gateway;
|
||||
String netmask;
|
||||
|
||||
public DnsmasqTO(String routerIp, String gateway, String netmask) {
|
||||
this.routerIp = routerIp;
|
||||
this.gateway = gateway;
|
||||
this.netmask =netmask;
|
||||
}
|
||||
|
||||
public void setRouterIp(String routerIp){
|
||||
this.routerIp = routerIp;
|
||||
}
|
||||
|
||||
public void setGateway(String gateway) {
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
public void setNetmask(String netmask) {
|
||||
this.netmask = netmask ;
|
||||
}
|
||||
|
||||
public String getRouterIp() {
|
||||
return routerIp;
|
||||
}
|
||||
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
package com.cloud.exception;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
public class MissingParameterValueException extends CloudRuntimeException {
|
||||
|
||||
public MissingParameterValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@ -28,4 +28,6 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface DhcpServiceProvider extends NetworkElement {
|
||||
boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
|
||||
boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
|
||||
boolean removeDhcpSupportForSubnet(Network network);
|
||||
}
|
||||
|
||||
45
api/src/com/cloud/vm/NicIpAlias.java
Normal file
45
api/src/com/cloud/vm/NicIpAlias.java
Normal file
@ -0,0 +1,45 @@
|
||||
// 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.
|
||||
package com.cloud.vm;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
/** Each entry represents the alis ip of a perticular nic.
|
||||
*
|
||||
*/
|
||||
public interface NicIpAlias extends ControlledEntity, Identity, InternalIdentity{
|
||||
/**
|
||||
* @return id in the CloudStack database
|
||||
*/
|
||||
enum state {
|
||||
active,
|
||||
revoked,
|
||||
}
|
||||
long getId();
|
||||
long getNicId();
|
||||
String getIp4Address();
|
||||
String getIp6Address();
|
||||
long getNetworkId();
|
||||
long getVmId();
|
||||
Long getAliasCount();
|
||||
String getNetmask();
|
||||
String getGateway();
|
||||
|
||||
|
||||
}
|
||||
@ -260,6 +260,7 @@
|
||||
<bean id="nicDaoImpl" class="com.cloud.vm.dao.NicDaoImpl" />
|
||||
<bean id="nicDetailDaoImpl" class="com.cloud.vm.dao.NicDetailDaoImpl" />
|
||||
<bean id="nicSecondaryIpDaoImpl" class="com.cloud.vm.dao.NicSecondaryIpDaoImpl" />
|
||||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />
|
||||
<bean id="ovsTunnelInterfaceDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelInterfaceDaoImpl" />
|
||||
<bean id="ovsTunnelNetworkDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelNetworkDaoImpl" />
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
package com.cloud.agent.api.routing;
|
||||
import java.util.List;
|
||||
public class CreateIpAliasCommand extends NetworkElementCommand {
|
||||
String routerip;
|
||||
List<IpAliasTO> ipAliasTOs;
|
||||
|
||||
|
||||
public CreateIpAliasCommand(String routerip, List<IpAliasTO> ipAliasTOs){
|
||||
this.routerip = routerip;
|
||||
this.ipAliasTOs = ipAliasTOs;
|
||||
}
|
||||
|
||||
public String getRouterip (){
|
||||
return routerip;
|
||||
}
|
||||
|
||||
public List<IpAliasTO> getIpAliasList() {
|
||||
return ipAliasTOs;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
package com.cloud.agent.api.routing;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteIpAliasCommand extends NetworkElementCommand {
|
||||
String routerip;
|
||||
List<IpAliasTO> deleteIpAliasTOs;
|
||||
List<IpAliasTO> createIpAliasTos;
|
||||
|
||||
|
||||
public DeleteIpAliasCommand( String routerip, List<IpAliasTO> deleteIpAliasTOs, List<IpAliasTO> createIpAliasTos){
|
||||
this.routerip = routerip;
|
||||
this.deleteIpAliasTOs = deleteIpAliasTOs;
|
||||
this.createIpAliasTos = createIpAliasTos;
|
||||
|
||||
}
|
||||
|
||||
public String getRouterip (){
|
||||
return routerip;
|
||||
}
|
||||
|
||||
public List<IpAliasTO> getDeleteIpAliasTos() {
|
||||
return deleteIpAliasTOs;
|
||||
}
|
||||
|
||||
public List<IpAliasTO> getCreateIpAliasTos() {
|
||||
return createIpAliasTos;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
// 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.
|
||||
package com.cloud.agent.api.routing;
|
||||
|
||||
import com.cloud.agent.api.to.DnsmasqTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DnsMasqConfigCommand extends NetworkElementCommand {
|
||||
String domain;
|
||||
String dns1;
|
||||
String dns2;
|
||||
String internal_dns1;
|
||||
String internal_dns2;
|
||||
List<DnsmasqTO> dnsmasqTOs;
|
||||
|
||||
public DnsMasqConfigCommand(String domain, List<DnsmasqTO> dnsmasqTOs, String dns1, String dns2, String internal_dns1, String internal_dns2) {
|
||||
this.domain = domain;
|
||||
this.dnsmasqTOs = dnsmasqTOs;
|
||||
this.dns1= dns1;
|
||||
this.dns2= dns2;
|
||||
this.internal_dns1 = internal_dns1;
|
||||
this.internal_dns2 = internal_dns2;
|
||||
|
||||
}
|
||||
|
||||
public List<DnsmasqTO> getIps() {
|
||||
return dnsmasqTOs;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public String getDns1() {
|
||||
return dns1;
|
||||
}
|
||||
|
||||
public String getDns2() {
|
||||
return dns2;
|
||||
}
|
||||
|
||||
public String getInternal_dns1() {
|
||||
return internal_dns1;
|
||||
}
|
||||
|
||||
public String getInternal_dns2() {
|
||||
return internal_dns2;
|
||||
}
|
||||
|
||||
}
|
||||
42
core/src/com/cloud/agent/api/routing/IpAliasTO.java
Normal file
42
core/src/com/cloud/agent/api/routing/IpAliasTO.java
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.
|
||||
package com.cloud.agent.api.routing;
|
||||
|
||||
|
||||
public class IpAliasTO {
|
||||
String routerip;
|
||||
String netmask;
|
||||
String alias_count;
|
||||
|
||||
public IpAliasTO(String routerip, String netmask, String alias_count) {
|
||||
this.routerip = routerip;
|
||||
this.netmask = netmask;
|
||||
this.alias_count = alias_count;
|
||||
}
|
||||
|
||||
public String getRouterip() {
|
||||
return routerip;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
public String getAlias_count() {
|
||||
return alias_count;
|
||||
}
|
||||
}
|
||||
@ -16,28 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.agent.resource.virtualnetwork;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.BumpUpPriorityCommand;
|
||||
import com.cloud.agent.api.CheckRouterAnswer;
|
||||
@ -50,7 +28,11 @@ import com.cloud.agent.api.GetDomRVersionCmd;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.CreateIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DeleteIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.DnsMasqConfigCommand;
|
||||
import com.cloud.agent.api.routing.IpAliasTO;
|
||||
import com.cloud.agent.api.routing.IpAssocAnswer;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
@ -74,6 +56,7 @@ import com.cloud.agent.api.to.IpAddressTO;
|
||||
import com.cloud.agent.api.to.PortForwardingRuleTO;
|
||||
import com.cloud.agent.api.to.StaticNatRuleTO;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.network.DnsMasqConfigurator;
|
||||
import com.cloud.network.HAProxyConfigurator;
|
||||
import com.cloud.network.LoadBalancerConfigurator;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
@ -84,6 +67,26 @@ import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SshHelper;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* VirtualNetworkResource controls and configures virtual networking
|
||||
@ -106,6 +109,9 @@ public class VirtualRoutingResource implements Manager {
|
||||
private String _privateEthIf;
|
||||
private String _bumpUpPriorityPath;
|
||||
private String _routerProxyPath;
|
||||
private String _createIpAliasPath;
|
||||
private String _deleteIpAliasPath;
|
||||
private String _configDhcpPath;
|
||||
|
||||
private int _timeout;
|
||||
private int _startTimeout;
|
||||
@ -137,6 +143,12 @@ public class VirtualRoutingResource implements Manager {
|
||||
return execute((SavePasswordCommand)cmd);
|
||||
} else if (cmd instanceof DhcpEntryCommand) {
|
||||
return execute((DhcpEntryCommand)cmd);
|
||||
} else if (cmd instanceof CreateIpAliasCommand) {
|
||||
return execute((CreateIpAliasCommand) cmd);
|
||||
} else if (cmd instanceof DnsMasqConfigCommand) {
|
||||
return execute((DnsMasqConfigCommand) cmd);
|
||||
} else if (cmd instanceof DeleteIpAliasCommand) {
|
||||
return execute((DeleteIpAliasCommand) cmd);
|
||||
} else if (cmd instanceof VmDataCommand) {
|
||||
return execute ((VmDataCommand)cmd);
|
||||
} else if (cmd instanceof CheckRouterCommand) {
|
||||
@ -609,6 +621,67 @@ public class VirtualRoutingResource implements Manager {
|
||||
return new Answer(cmd, result==null, result);
|
||||
}
|
||||
|
||||
protected Answer execute(final CreateIpAliasCommand cmd) {
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
final Script command = new Script(_createIpAliasPath, _timeout, s_logger);
|
||||
List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
|
||||
String args=routerIp+" ";
|
||||
for (IpAliasTO ipaliasto : ipAliasTOs) {
|
||||
args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
|
||||
}
|
||||
command.add(args);
|
||||
final String result = command.execute();
|
||||
return new Answer(cmd, result==null, result);
|
||||
}
|
||||
|
||||
protected Answer execute(final DeleteIpAliasCommand cmd) {
|
||||
final Script command = new Script(_deleteIpAliasPath, _timeout, s_logger);
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
String args = "";
|
||||
List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
|
||||
for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
args = args + " " ;
|
||||
List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
|
||||
for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
command.add(args);
|
||||
final String result = command.execute();
|
||||
return new Answer(cmd, result==null, result);
|
||||
}
|
||||
|
||||
protected Answer execute(final DnsMasqConfigCommand cmd) {
|
||||
final Script command = new Script(_configDhcpPath, _timeout, s_logger);
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
DnsMasqConfigurator configurator = new DnsMasqConfigurator();
|
||||
String [] config = configurator.generateConfiguration(cmd);
|
||||
File tmpCfgFile = null;
|
||||
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();
|
||||
}
|
||||
command.add(cfgFilePath);
|
||||
final String result = command.execute();
|
||||
return new Answer(cmd, result == null, result);
|
||||
} catch (final IOException e) {
|
||||
return new Answer(cmd, false, e.getMessage());
|
||||
} finally {
|
||||
if (tmpCfgFile != null) {
|
||||
tmpCfgFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getRouterStatus(String routerIP) {
|
||||
return routerProxyWithParser("checkrouter.sh", routerIP, null);
|
||||
}
|
||||
|
||||
118
core/src/com/cloud/network/DnsMasqConfigurator.java
Normal file
118
core/src/com/cloud/network/DnsMasqConfigurator.java
Normal file
@ -0,0 +1,118 @@
|
||||
// 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.
|
||||
package com.cloud.network;
|
||||
|
||||
import com.cloud.agent.api.routing.DnsMasqConfigCommand;
|
||||
import com.cloud.agent.api.to.DnsmasqTO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
public class DnsMasqConfigurator {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(DnsMasqConfigurator.class);
|
||||
private static String[] Dnsmasq_config = {"# Never forward plain names (without a dot or domain part) \ndomain-needed\n",
|
||||
"# Never forward addresses in the non-routed address spaces. \nbogus-priv\n",
|
||||
"# Uncomment this to filter useless windows-originated DNS requests # which can trigger dial-on-demand links needlessly. \n # Note that (amongst other things) this blocks all SRV requests, # so don't use it if you use eg Kerberos, SIP, XMMP or Google-talk.# This option only affects forwarding, SRV records originating for # dnsmasq (via srv-host= lines) are not suppressed by it. \nfilterwin2k\n",
|
||||
"# Change this line if you want dns to get its upstream servers from# somewhere other that /etc/resolv.conf \nresolv-file=/etc/dnsmasq-resolv.conf\n",
|
||||
"# Add local-only domains here, queries in these domains are answered\n # from /etc/hosts or DHCP only.\n local=/cs1cloud.internal/",
|
||||
"# If you want dnsmasq to listen for DHCP and DNS requests only on\n #specified interfaces (and the loopback) give the name of the\n# interface (eg eth0) here.\n# Repeat the line for more than one interface.\ninterface=eth0\n",
|
||||
"# Or you can specify which interface _not_ to listen on\nexcept-interface=eth1\nexcept-interface=eth2\nexcept-interface=lo\n",
|
||||
"# Or which to listen on by address (remember to include 127.0.0.1 if\n# you use this.)\n#listen-address=?\n",
|
||||
"# If you want dnsmasq to provide only DNS service on an interface,\n# configure it as shown above, and then use the following line to\n#disable DHCP and TFTP on it.\nno-dhcp-interface=eth1\nno-dhcp-interface=eth2\n",
|
||||
"# On systems which support it, dnsmasq binds the wildcard address,\n" +
|
||||
"# even when it is listening on only some interfaces. It then discards\n" +
|
||||
"# requests that it shouldn't reply to. This has the advantage of\n" +
|
||||
"# working even when interfaces come and go and change address. If you\n" +
|
||||
"# want dnsmasq to really bind only the interfaces it is listening on,\n" +
|
||||
"# uncomment this option. About the only time you may need this is when\n" +
|
||||
"# running another nameserver on the same machine.\n" +
|
||||
"bind-interfaces\n",
|
||||
"# Set this (and domain: see below) if you want to have a domain\n" +
|
||||
"# automatically added to simple names in a hosts-file.\n" +
|
||||
"expand-hosts\n",
|
||||
"# Set the domain for dnsmasq. this is optional, but if it is set, it\n" +
|
||||
"# does the following things.\n" +
|
||||
"# 1) Allows DHCP hosts to have fully qualified domain names, as long\n" +
|
||||
"# as the domain part matches this setting.\n" +
|
||||
"# 2) Sets the \"domain\" DHCP option thereby potentially setting the\n" +
|
||||
"# domain of all systems configured by DHCP\n" +
|
||||
"# 3) Provides the domain part for \"expand-hosts\"\n",
|
||||
"domain=cs1cloud.internal\n",
|
||||
"# Set a different domain for a particular subnet\n",
|
||||
"domain=cs1cloud.internal\n",
|
||||
"# Same idea, but range rather then subnet\n",
|
||||
"domain=cs1cloud.internal\n",
|
||||
"# Uncomment this to enable the integrated DHCP server, you need\n" +
|
||||
"# to supply the range of addresses available for lease and optionally\n" +
|
||||
"# a lease time. If you have more than one network, you will need to\n" +
|
||||
"# repeat this for each network on which you want to supply DHCP\n" +
|
||||
"# service.\n",
|
||||
"dhcp-range=set:net1,ipaddress,static\n",
|
||||
"dhcp-hostsfile=/etc/dhcphosts.txt\n",
|
||||
"log-facility=/var/log/dnsmasq.log\n",
|
||||
"conf-dir=/etc/dnsmasq.d\n",
|
||||
"dhcp-option=tag:net1,3,ipaddress\n",
|
||||
"dhcp-option=tag:net1,1,netmask\n",
|
||||
"dhcp-option=6,10.147.28.149,8.8.8.8\n",
|
||||
"dhcp-optsfile=/etc/dhcpopts.txt\n",
|
||||
|
||||
|
||||
};
|
||||
|
||||
public String[] generateConfiguration(DnsMasqConfigCommand dnsMasqconfigcmd) {
|
||||
List<DnsmasqTO> dnsmasqTOs = dnsMasqconfigcmd.getIps();
|
||||
List <String> dnsMasqconf = Arrays.asList(Dnsmasq_config);
|
||||
String range="";
|
||||
String gateway="";
|
||||
String netmask="";
|
||||
String domain= dnsMasqconfigcmd.getDomain();
|
||||
String dnsServers="";
|
||||
int i=0;
|
||||
for (; i< dnsmasqTOs.size(); i++) {
|
||||
range=range + "dhcp-range=set:range"+i+","+dnsmasqTOs.get(i).getRouterIp()+",static\n";
|
||||
gateway=gateway +"dhcp-option=tag:range"+i+",3,"+dnsmasqTOs.get(i).getGateway()+"\n";
|
||||
netmask=netmask +"dhcp-option=tag:range"+i+",1,"+dnsmasqTOs.get(i).getNetmask()+"\n";
|
||||
}
|
||||
dnsMasqconf.set(12, "domain="+domain+"\n");
|
||||
dnsMasqconf.set(14, "domain="+domain+"\n");
|
||||
dnsMasqconf.set(16,"domain="+domain+"\n");
|
||||
dnsMasqconf.set(18, range);
|
||||
dnsMasqconf.set(22, gateway);
|
||||
dnsMasqconf.set(23, netmask);
|
||||
if (dnsMasqconfigcmd.getInternal_dns1() != null) {
|
||||
dnsServers = dnsServers+dnsMasqconfigcmd.getInternal_dns1()+",";
|
||||
}
|
||||
if (dnsMasqconfigcmd.getInternal_dns2() != null) {
|
||||
dnsServers = dnsServers+dnsMasqconfigcmd.getInternal_dns2()+",";
|
||||
}
|
||||
if (dnsMasqconfigcmd.getDns1() != null) {
|
||||
dnsServers = dnsServers+dnsMasqconfigcmd.getDns1()+",";
|
||||
}
|
||||
if (dnsMasqconfigcmd.getDns2() != null) {
|
||||
dnsServers = dnsServers+dnsMasqconfigcmd.getDns2()+",";
|
||||
}
|
||||
dnsServers = dnsServers +"*";
|
||||
dnsServers = dnsServers.replace(";*", "");
|
||||
dnsMasqconf.set(24,"dhcp-option=6,"+dnsServers);
|
||||
return dnsMasqconf.toArray( new String[dnsMasqconf.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,13 +16,13 @@
|
||||
// under the License.
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface VlanDao extends GenericDao<VlanVO, Long> {
|
||||
|
||||
VlanVO findByZoneAndVlanId(long zoneId, String vlanId);
|
||||
@ -52,4 +52,6 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
|
||||
List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId);
|
||||
|
||||
List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId);
|
||||
|
||||
List<VlanVO> listVlansByNetworkIdAndGateway(long networkid, String gateway);
|
||||
}
|
||||
|
||||
@ -16,19 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.AccountVlanMapVO;
|
||||
import com.cloud.dc.PodVlanMapVO;
|
||||
import com.cloud.dc.Vlan;
|
||||
@ -43,6 +30,17 @@ import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Local(value={VlanDao.class})
|
||||
@ -59,6 +57,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
||||
protected SearchBuilder<VlanVO> NetworkVlanSearch;
|
||||
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
|
||||
protected SearchBuilder<VlanVO> ZoneWideNonDedicatedVlanSearch;
|
||||
protected SearchBuilder<VlanVO> VlanGatewaysearch;
|
||||
|
||||
protected SearchBuilder<AccountVlanMapVO> AccountVlanMapSearch;
|
||||
|
||||
@ -103,6 +102,11 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
||||
PhysicalNetworkVlanSearch = createSearchBuilder();
|
||||
PhysicalNetworkVlanSearch.and("physicalNetworkId", PhysicalNetworkVlanSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
|
||||
PhysicalNetworkVlanSearch.done();
|
||||
|
||||
VlanGatewaysearch = createSearchBuilder();
|
||||
VlanGatewaysearch.and("gateway", VlanGatewaysearch.entity().getVlanGateway(), SearchCriteria.Op.EQ);
|
||||
VlanGatewaysearch.and("networkid", VlanGatewaysearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
VlanGatewaysearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -317,6 +321,14 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VlanVO> listVlansByNetworkIdAndGateway(long networkid, String gateway){
|
||||
SearchCriteria<VlanVO> sc = VlanGatewaysearch.create();
|
||||
sc.setParameters("networkid", networkid);
|
||||
sc.setParameters("gateway", gateway);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId) {
|
||||
SearchCriteria<VlanVO> sc = PhysicalNetworkVlanSearch.create();
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
// under the License.
|
||||
package com.cloud.network.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.net.Ip;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
|
||||
|
||||
IPAddressVO markAsUnavailable(long ipAddressId);
|
||||
@ -68,4 +68,8 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
|
||||
IPAddressVO findByAssociatedVmIdAndVmIp(long vmId, String vmIp);
|
||||
|
||||
IPAddressVO findByIpAndNetworkId(long networkId, String ipAddress);
|
||||
|
||||
IPAddressVO findByIpAndVlanId(String ipAddress, long vlanid);
|
||||
|
||||
long countFreeIpsInVlan(long vlanDbId);
|
||||
}
|
||||
|
||||
@ -16,26 +16,12 @@
|
||||
// under the License.
|
||||
package com.cloud.network.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.dc.dao.VlanDaoImpl;
|
||||
import com.cloud.network.IpAddress.State;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.tags.dao.ResourceTagDao;
|
||||
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
@ -46,6 +32,16 @@ import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Local(value = { IPAddressDao.class })
|
||||
@ -192,6 +188,14 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPAddressVO findByIpAndVlanId(String ipAddress, long vlanid) {
|
||||
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("ipAddress", ipAddress);
|
||||
sc.setParameters("vlan", vlanid);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPAddressVO findByIpAndDcId(long dcId, String ipAddress) {
|
||||
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
|
||||
@ -332,6 +336,13 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
|
||||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countFreeIpsInVlan(long vlanDbId) {
|
||||
SearchCriteria<IPAddressVO> sc = VlanDbIdSearchUnallocated.create();
|
||||
sc.setParameters("vlanDbId", vlanDbId);
|
||||
return listBy(sc).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IPAddressVO> listByAssociatedVpc(long vpcId, Boolean isSourceNat) {
|
||||
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
// under the License.
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NicDao extends GenericDao<NicVO, Long> {
|
||||
List<NicVO> listByVmId(long instanceId);
|
||||
|
||||
@ -66,4 +66,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
||||
List<NicVO> listPlaceholderNicsByNetworkId(long networkId);
|
||||
|
||||
List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType);
|
||||
|
||||
NicVO findByInstanceIdAndIpAddressAndVmtype(long instanceId, String ipaddress, VirtualMachine.Type type);
|
||||
}
|
||||
|
||||
@ -16,12 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
@ -32,6 +26,10 @@ import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.Nic.State;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Local(value=NicDao.class)
|
||||
@ -119,6 +117,15 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
||||
sc.setParameters("instance", instanceId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicVO findByInstanceIdAndIpAddressAndVmtype(long instanceId, String ipaddress, VirtualMachine.Type type) {
|
||||
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instance", instanceId);
|
||||
sc.setParameters("address", ipaddress);
|
||||
sc.setParameters("vmType", type);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId) {
|
||||
|
||||
@ -772,9 +772,8 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
return future;
|
||||
}
|
||||
CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volume, future);
|
||||
AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().registerVolumeCallback(null, null))
|
||||
.setContext(context);
|
||||
AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().resizeVolumeCallback(caller, context)).setContext(context);
|
||||
volume.getDataStore().getDriver().resize(volume, caller);
|
||||
return future;
|
||||
}
|
||||
|
||||
35
patches/systemvm/debian/config/root/createIpAlias.sh
Executable file
35
patches/systemvm/debian/config/root/createIpAlias.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/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 <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
set -x
|
||||
var="$1"
|
||||
cert="/root/.ssh/id_rsa.cloud"
|
||||
|
||||
while [ -n "$var" ]
|
||||
do
|
||||
var1=$(echo $var | cut -f1 -d "-")
|
||||
alias_count=$( echo $var1 | cut -f1 -d ":" )
|
||||
routerip=$(echo $var1 | cut -f2 -d ":")
|
||||
netmask=$(echo $var1 | cut -f3 -d ":")
|
||||
ifconfig eth0:$alias_count $routerip netmask $netmask up
|
||||
var=$( echo $var | sed "s/${var1}-//" )
|
||||
done
|
||||
43
patches/systemvm/debian/config/root/deleteIpAlias.sh
Executable file
43
patches/systemvm/debian/config/root/deleteIpAlias.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/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 <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
set -x
|
||||
var="$1"
|
||||
cert="/root/.ssh/id_rsa.cloud"
|
||||
|
||||
while [ -n "$var" ]
|
||||
do
|
||||
var1=$(echo $var | cut -f1 -d "-")
|
||||
alias_count=$( echo $var1 | cut -f1 -d ":" )
|
||||
ifconfig eth0:$alias_count down
|
||||
var=$( echo $var | sed "s/${var1}-//" )
|
||||
done
|
||||
|
||||
#recreating the active ip aliases
|
||||
sh /root/createIpAlias.sh $2
|
||||
result=$?
|
||||
if [ "$result" -ne "0" ]
|
||||
then
|
||||
exit $result
|
||||
fi
|
||||
|
||||
exit 0
|
||||
43
patches/systemvm/debian/config/root/dnsmasq.sh
Executable file
43
patches/systemvm/debian/config/root/dnsmasq.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/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: <path to new dnsmasq config file>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
set -x
|
||||
#backup the old config file
|
||||
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
|
||||
|
||||
#apply the new confg
|
||||
echo $1
|
||||
cp $1 /etc/dnsmasq.conf
|
||||
|
||||
#restart the dnsmasq
|
||||
service dnsmasq restart
|
||||
result=$?
|
||||
if [ "$result" -ne "0" ]
|
||||
then
|
||||
echo "could not configure dnsmasq"
|
||||
echo "reverting to the old config"
|
||||
cp /etc/dnsmasq.config.bak /etc/dnsmasq.conf
|
||||
service dnsmasq restart
|
||||
exit 2
|
||||
fi
|
||||
rm $1
|
||||
echo "success"
|
||||
@ -18,21 +18,9 @@
|
||||
// Automatically generated by addcopyright.py at 01/29/2013
|
||||
package com.cloud.baremetal.networkservice;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.baremetal.database.BaremetalDhcpVO;
|
||||
import com.cloud.baremetal.database.BaremetalPxeVO;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -40,14 +28,13 @@ import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.element.DhcpServiceProvider;
|
||||
import com.cloud.network.element.IpDeployer;
|
||||
import com.cloud.network.element.NetworkElement;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
@ -56,13 +43,16 @@ import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.*;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Local(value = NetworkElement.class)
|
||||
public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProvider {
|
||||
@ -175,4 +165,15 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
|
||||
}
|
||||
return _dhcpMgr.addVirtualMachineIntoNetwork(network, nic, vm, dest, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDhcpSupportForSubnet(Network network) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,32 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.NDC;
|
||||
|
||||
import com.cloud.agent.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
@ -133,7 +107,11 @@ import com.cloud.agent.api.ValidateSnapshotCommand;
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.routing.CreateIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DeleteIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.DnsMasqConfigCommand;
|
||||
import com.cloud.agent.api.routing.IpAliasTO;
|
||||
import com.cloud.agent.api.routing.IpAssocAnswer;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocVpcCommand;
|
||||
@ -200,10 +178,10 @@ import com.cloud.hypervisor.vmware.mo.VirtualSwitchType;
|
||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
|
||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary;
|
||||
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareGuestOsMapper;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||
import com.cloud.network.DnsMasqConfigurator;
|
||||
import com.cloud.network.HAProxyConfigurator;
|
||||
import com.cloud.network.LoadBalancerConfigurator;
|
||||
import com.cloud.network.Networks;
|
||||
@ -256,9 +234,7 @@ import com.vmware.vim25.PerfMetricIntSeries;
|
||||
import com.vmware.vim25.PerfMetricSeries;
|
||||
import com.vmware.vim25.PerfQuerySpec;
|
||||
import com.vmware.vim25.PerfSampleInfo;
|
||||
import com.vmware.vim25.RuntimeFault;
|
||||
import com.vmware.vim25.RuntimeFaultFaultMsg;
|
||||
import com.vmware.vim25.ToolsUnavailable;
|
||||
import com.vmware.vim25.ToolsUnavailableFaultMsg;
|
||||
import com.vmware.vim25.VimPortType;
|
||||
import com.vmware.vim25.VirtualDevice;
|
||||
@ -274,6 +250,30 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
|
||||
import com.vmware.vim25.VirtualMachinePowerState;
|
||||
import com.vmware.vim25.VirtualMachineRuntimeInfo;
|
||||
import com.vmware.vim25.VirtualSCSISharing;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.NDC;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService {
|
||||
@ -367,6 +367,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
answer = execute((SavePasswordCommand) cmd);
|
||||
} else if (clz == DhcpEntryCommand.class) {
|
||||
answer = execute((DhcpEntryCommand) cmd);
|
||||
} else if (clz == CreateIpAliasCommand.class) {
|
||||
return execute((CreateIpAliasCommand) cmd);
|
||||
} else if (clz == DnsMasqConfigCommand.class) {
|
||||
return execute((DnsMasqConfigCommand) cmd);
|
||||
} else if (clz == DeleteIpAliasCommand.class) {
|
||||
return execute((DeleteIpAliasCommand) cmd);
|
||||
} else if (clz == VmDataCommand.class) {
|
||||
answer = execute((VmDataCommand) cmd);
|
||||
} else if (clz == ReadyCommand.class) {
|
||||
@ -1837,6 +1843,141 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final CreateIpAliasCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing createipAlias command: " + _gson.toJson(cmd));
|
||||
}
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
|
||||
String args=routerIp+" ";
|
||||
for (IpAliasTO ipaliasto : ipAliasTOs) {
|
||||
args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createipAlias " + args);
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
String controlIp = getRouterSshControlIp(cmd);
|
||||
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
|
||||
"/root/createipAlias.sh " + args);
|
||||
|
||||
if (!result.first()) {
|
||||
s_logger.error("ipAlias command on domr " + controlIp + " failed, message: " + result.second());
|
||||
|
||||
return new Answer(cmd, false, "createipAlias failed due to " + result.second());
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("createipAlias command on domain router " + controlIp + " completed");
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
String msg = "createipAlias failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final DeleteIpAliasCommand cmd) {
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
|
||||
List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing deleteipAlias command: " + _gson.toJson(cmd));
|
||||
}
|
||||
String args=routerIp+" ";
|
||||
for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
args = args + " " ;
|
||||
for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteipAlias " + args);
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
String controlIp = getRouterSshControlIp(cmd);
|
||||
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
|
||||
"/root/deleteipAlias.sh " + args);
|
||||
|
||||
if (!result.first()) {
|
||||
s_logger.error("ipAlias command on domr " + controlIp + " failed, message: " + result.second());
|
||||
|
||||
return new Answer(cmd, false, "deleteipAlias failed due to " + result.second());
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("deleteipAlias command on domain router " + controlIp + " completed");
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
String msg = "deleteipAlias failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final DnsMasqConfigCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing deleteipAlias command: " + _gson.toJson(cmd));
|
||||
}
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
String controlIp = getRouterSshControlIp(cmd);
|
||||
|
||||
assert(controlIp != null);
|
||||
|
||||
DnsMasqConfigurator configurator = new DnsMasqConfigurator();
|
||||
String [] config = configurator.generateConfiguration(cmd);
|
||||
String tmpConfigFilePath = "/tmp/"+ routerIp.replace(".","-")+".cfg";
|
||||
String tmpConfigFileContents = "";
|
||||
for (int i = 0; i < config.length; i++) {
|
||||
tmpConfigFileContents += config[i];
|
||||
tmpConfigFileContents += "\n";
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/dnsmasq.sh " +"config file at" + tmpConfigFilePath);
|
||||
}
|
||||
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
File keyFile = mgr.getSystemVMKeyFile();
|
||||
|
||||
try {
|
||||
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpConfigFileContents.getBytes(), routerIp.replace('.', '_') + ".cfg", null);
|
||||
|
||||
try {
|
||||
|
||||
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "scp" + tmpConfigFilePath + "/root/dnsmasq.sh");
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh");
|
||||
}
|
||||
|
||||
if (!result.first()) {
|
||||
s_logger.error("Unable to copy dnsmasq configuration file");
|
||||
return new Answer(cmd, false, "dnsmasq config failed due to uanble to copy dnsmasq configuration file");
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("dnsmasq config command on domain router " + routerIp + " completed");
|
||||
}
|
||||
} finally {
|
||||
SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "rm " + tmpConfigFilePath);
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("Unexpected exception: " + e.toString(), e);
|
||||
return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to " + VmwareHelper.getExceptionMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
protected CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + _gson.toJson(cmd));
|
||||
|
||||
@ -17,53 +17,6 @@
|
||||
package com.cloud.hypervisor.xen.resource;
|
||||
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import com.cloud.agent.api.*;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import com.cloud.agent.api.to.*;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.cloud.agent.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
@ -137,6 +90,8 @@ import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.RebootRouterCommand;
|
||||
import com.cloud.agent.api.RevertToVMSnapshotAnswer;
|
||||
import com.cloud.agent.api.RevertToVMSnapshotCommand;
|
||||
import com.cloud.agent.api.ScaleVmAnswer;
|
||||
import com.cloud.agent.api.ScaleVmCommand;
|
||||
import com.cloud.agent.api.SecurityGroupRuleAnswer;
|
||||
import com.cloud.agent.api.SecurityGroupRulesCmd;
|
||||
import com.cloud.agent.api.SetupAnswer;
|
||||
@ -161,7 +116,11 @@ import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.CreateIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DeleteIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.DnsMasqConfigCommand;
|
||||
import com.cloud.agent.api.routing.IpAliasTO;
|
||||
import com.cloud.agent.api.routing.IpAssocAnswer;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocVpcCommand;
|
||||
@ -195,6 +154,7 @@ import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.agent.api.storage.ResizeVolumeAnswer;
|
||||
import com.cloud.agent.api.storage.ResizeVolumeCommand;
|
||||
import com.cloud.agent.api.to.FirewallRuleTO;
|
||||
import com.cloud.agent.api.to.IpAddressTO;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.PortForwardingRuleTO;
|
||||
@ -207,6 +167,7 @@ import com.cloud.agent.api.to.VolumeTO;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.DnsMasqConfigurator;
|
||||
import com.cloud.network.HAProxyConfigurator;
|
||||
import com.cloud.network.LoadBalancerConfigurator;
|
||||
import com.cloud.network.Networks;
|
||||
@ -226,6 +187,7 @@ import com.cloud.network.ovs.OvsFetchInterfaceCommand;
|
||||
import com.cloud.network.ovs.OvsSetTagAndFlowAnswer;
|
||||
import com.cloud.network.ovs.OvsSetTagAndFlowCommand;
|
||||
import com.cloud.network.ovs.OvsSetupBridgeCommand;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.hypervisor.HypervisorResource;
|
||||
import com.cloud.storage.Storage;
|
||||
@ -279,6 +241,48 @@ import com.xensource.xenapi.VLAN;
|
||||
import com.xensource.xenapi.VM;
|
||||
import com.xensource.xenapi.VMGuestMetrics;
|
||||
import com.xensource.xenapi.XenAPIObject;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* CitrixResourceBase encapsulates the calls to the XenServer Xapi process
|
||||
@ -460,6 +464,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
return execute((SavePasswordCommand) cmd);
|
||||
} else if (clazz == DhcpEntryCommand.class) {
|
||||
return execute((DhcpEntryCommand) cmd);
|
||||
} else if (clazz == CreateIpAliasCommand.class) {
|
||||
return execute((CreateIpAliasCommand) cmd);
|
||||
} else if (clazz == DnsMasqConfigCommand.class) {
|
||||
return execute((DnsMasqConfigCommand) cmd);
|
||||
} else if (clazz == DeleteIpAliasCommand.class) {
|
||||
return execute((DeleteIpAliasCommand) cmd);
|
||||
} else if (clazz == VmDataCommand.class) {
|
||||
return execute((VmDataCommand) cmd);
|
||||
} else if (clazz == ReadyCommand.class) {
|
||||
@ -1889,6 +1899,68 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final CreateIpAliasCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
|
||||
String args=routerIp+" ";
|
||||
for (IpAliasTO ipaliasto : ipAliasTOs) {
|
||||
args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
|
||||
}
|
||||
String result = callHostPlugin(conn, "vmops", "createipAlias", "args", args);
|
||||
if (result == null || result.isEmpty()) {
|
||||
return new Answer(cmd, false, "CreateIPAliasCommand failed\n");
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final DeleteIpAliasCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
|
||||
String args=routerIp+" ";
|
||||
for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
args = args + " " ;
|
||||
List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
|
||||
for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
|
||||
args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
|
||||
}
|
||||
String result = callHostPlugin(conn, "vmops", "deleteipAlias", "args", args);
|
||||
if (result == null || result.isEmpty()) {
|
||||
return new Answer(cmd, false, "DeleteipAliasCommand failed\n");
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final DnsMasqConfigCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
DnsMasqConfigurator configurator = new DnsMasqConfigurator();
|
||||
String [] config = configurator.generateConfiguration(cmd);
|
||||
String tmpConfigFilePath = "/tmp/"+ routerIp.replace(".","-")+".cfg";
|
||||
String tmpConfigFileContents = "";
|
||||
for (int i = 0; i < config.length; i++) {
|
||||
tmpConfigFileContents += config[i];
|
||||
tmpConfigFileContents += "\n";
|
||||
}
|
||||
|
||||
String result = callHostPlugin(conn, "vmops", "createFileInDomr", "filepath", tmpConfigFilePath, "filecontents", tmpConfigFileContents, "domrip" ,routerIp);
|
||||
if (result == null || result.isEmpty()) {
|
||||
return new Answer(cmd, false, "DnsMasqConfigCommand failed to create DnsMasq cfg file.");
|
||||
}
|
||||
result = callHostPlugin(conn, "vmops", "configdnsmasq", "routerip", routerIp, "filepath", tmpConfigFilePath);
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
return new Answer(cmd, false, "DnsMasqconfigCommand failed");
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
|
||||
}
|
||||
protected Answer execute(final LoadBalancerConfigCommand cmd) {
|
||||
if ( cmd.getVpcId() != null ) {
|
||||
return VPCLoadBalancerConfig(cmd);
|
||||
|
||||
@ -19,54 +19,67 @@
|
||||
|
||||
package com.cloud.network.element;
|
||||
|
||||
import com.cloud.network.*;
|
||||
import com.cloud.network.element.SimpleFirewallRule;
|
||||
import com.cloud.agent.api.to.FirewallRuleTO;
|
||||
import com.cloud.agent.api.to.NetworkACLTO;
|
||||
import com.cloud.agent.api.to.PortForwardingRuleTO;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.network.Networks;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.StaticNat;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.rules.StaticNat;
|
||||
import com.cloud.network.vpc.VpcManager;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.*;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.google.common.collect.*;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.midokura.midonet.client.MidonetApi;
|
||||
import com.midokura.midonet.client.dto.DtoRule;
|
||||
import com.midokura.midonet.client.resource.*;
|
||||
import com.midokura.midonet.client.resource.Bridge;
|
||||
import com.midokura.midonet.client.resource.BridgePort;
|
||||
import com.midokura.midonet.client.resource.DhcpHost;
|
||||
import com.midokura.midonet.client.resource.DhcpSubnet;
|
||||
import com.midokura.midonet.client.resource.Port;
|
||||
import com.midokura.midonet.client.resource.ResourceCollection;
|
||||
import com.midokura.midonet.client.resource.Route;
|
||||
import com.midokura.midonet.client.resource.Router;
|
||||
import com.midokura.midonet.client.resource.RouterPort;
|
||||
import com.midokura.midonet.client.resource.Rule;
|
||||
import com.midokura.midonet.client.resource.RuleChain;
|
||||
import com.sun.jersey.core.util.MultivaluedMapImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
import com.cloud.network.vpc.PrivateGateway;
|
||||
import com.cloud.network.vpc.StaticRouteProfile;
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.network.vpc.VpcGateway;
|
||||
import com.cloud.network.vpc.VpcManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
import java.lang.Class;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Component
|
||||
@ -432,6 +445,16 @@ public class MidoNetElement extends AdapterBase implements
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDhcpSupportForSubnet(Network network) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
private void removeMidonetStaticNAT(RuleChain preFilter, RuleChain preNat, RuleChain postNat,
|
||||
String floatingIp, String fixedIp,
|
||||
Router providerRouter) {
|
||||
|
||||
26
scripts/vm/hypervisor/xenserver/createipAlias.sh
Executable file
26
scripts/vm/hypervisor/xenserver/createipAlias.sh
Executable 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"
|
||||
25
scripts/vm/hypervisor/xenserver/deleteipAlias.sh
Normal file
25
scripts/vm/hypervisor/xenserver/deleteipAlias.sh
Normal 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"
|
||||
@ -355,7 +355,47 @@ def setLoadBalancerRule(session, args):
|
||||
txt = ''
|
||||
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def configdnsmasq(session, args):
|
||||
routerip = args['routerip']
|
||||
filepath = args['filepath']
|
||||
target = "root@"+routerip
|
||||
try:
|
||||
util.pread2(['ssh','-p','3922','-q','-o','StrictHostKeyChecking=no','-i','/root/.ssh/id_rsa.cloud',target,'/root/dnsmasq.sh',filepath])
|
||||
txt='success'
|
||||
except:
|
||||
util.SMlog("failed to config dnsmasq server")
|
||||
txt=''
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def createipAlias(session, args):
|
||||
args = args['args']
|
||||
cmd = args.split(' ')
|
||||
cmd.insert(0, "/opt/xensource/bin/createipAlias.sh")
|
||||
cmd.insert(0, "bin/bash")
|
||||
try:
|
||||
txt=util.pread2(cmd)
|
||||
txt='success'
|
||||
except:
|
||||
util.SMlog("failed to create ip alias on router vm")
|
||||
txt=''
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def deleteipAlias(session, args):
|
||||
args = args['args']
|
||||
cmd = args.split(' ')
|
||||
cmd.insert(0, "/opt/xensource/bin/deleteipAlias.sh")
|
||||
cmd.insert(0, "bin/bash")
|
||||
try:
|
||||
txt=util.pread2(cmd)
|
||||
txt='success'
|
||||
except:
|
||||
util.SMlog("failed to create ip alias on router vm")
|
||||
txt=''
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def createFile(session, args):
|
||||
file_path = args['filepath']
|
||||
@ -1672,6 +1712,9 @@ if __name__ == "__main__":
|
||||
"destroy_network_rules_for_vm":destroy_network_rules_for_vm,
|
||||
"default_network_rules_systemvm":default_network_rules_systemvm,
|
||||
"network_rules_vmSecondaryIp":network_rules_vmSecondaryIp,
|
||||
"createipAlias":createipAlias,
|
||||
"configdnsmasq":configdnsmasq,
|
||||
"deleteipAlias":deleteipAlias,
|
||||
"get_rule_logs_for_vms":get_rule_logs_for_vms,
|
||||
"add_to_VCPUs_params_live":add_to_VCPUs_params_live,
|
||||
"setLinkLocalIP":setLinkLocalIP,
|
||||
|
||||
@ -40,6 +40,8 @@ make_migratable.sh=..,0755,/opt/xensource/bin
|
||||
setup_iscsi.sh=..,0755,/opt/xensource/bin
|
||||
pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
createipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -38,6 +38,8 @@ make_migratable.sh=..,0755,/opt/xensource/bin
|
||||
setup_iscsi.sh=..,0755,/opt/xensource/bin
|
||||
cloud-setup-bonding.sh=..,0755,/opt/xensource/bin
|
||||
pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
createipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -37,6 +37,8 @@ setupxenserver.sh=..,0755,/opt/xensource/bin
|
||||
make_migratable.sh=..,0755,/opt/xensource/bin
|
||||
setup_iscsi.sh=..,0755,/opt/xensource/bin
|
||||
pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
createipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -40,6 +40,8 @@ id_rsa.cloud=../../../systemvm,0600,/root/.ssh
|
||||
network_info.sh=..,0755,/opt/xensource/bin
|
||||
setupxenserver.sh=..,0755,/opt/xensource/bin
|
||||
make_migratable.sh=..,0755,/opt/xensource/bin
|
||||
createipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=../../..,0755,/opt/xensource/bin
|
||||
setup_iscsi.sh=..,0755,/opt/xensource/bin
|
||||
pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -152,8 +152,6 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
*/
|
||||
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
|
||||
|
||||
boolean releasePublicIpRange(long userId, long vlanDbId, Account caller);
|
||||
|
||||
/**
|
||||
* Converts a comma separated list of tags to a List
|
||||
*
|
||||
|
||||
@ -80,7 +80,20 @@ import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.AccountVlanMapVO;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterDetailsVO;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterIpAddressVO;
|
||||
import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.DcDetailVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.dc.PodVlanMapVO;
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||
@ -99,14 +112,18 @@ import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventUtils;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.MissingParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
@ -118,6 +135,7 @@ import com.cloud.network.NetworkService;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
@ -128,6 +146,7 @@ import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
|
||||
import com.cloud.network.dao.PhysicalNetworkVO;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.network.element.DhcpServiceProvider;
|
||||
import com.cloud.network.vpc.VpcManager;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
@ -154,6 +173,14 @@ import com.cloud.storage.s3.S3Manager;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.swift.SwiftManager;
|
||||
import com.cloud.test.IPRangeConfig;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountDetailVO;
|
||||
import com.cloud.user.AccountDetailsDao;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.StringUtils;
|
||||
@ -165,10 +192,65 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.NicIpAlias;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
|
||||
import com.cloud.vm.dao.NicIpAliasDao;
|
||||
import com.cloud.vm.dao.NicIpAliasVO;
|
||||
import com.cloud.vm.dao.NicSecondaryIpDao;
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
import org.apache.cloudstack.acl.SecurityChecker;
|
||||
import org.apache.cloudstack.api.ApiConstants.LDAPParams;
|
||||
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import java.net.URI;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@Local(value = { ConfigurationManager.class, ConfigurationService.class })
|
||||
@ -259,6 +341,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
AccountDetailsDao _accountDetailsDao;
|
||||
@Inject
|
||||
PrimaryDataStoreDao _storagePoolDao;
|
||||
@Inject
|
||||
NicSecondaryIpDao _nicSecondaryIpDao;
|
||||
@Inject
|
||||
NicIpAliasDao _nicIpAliasDao;
|
||||
|
||||
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
|
||||
@Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao;
|
||||
@ -2228,8 +2314,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
Long podId = cmd.getPodId();
|
||||
String startIP = cmd.getStartIp();
|
||||
String endIP = cmd.getEndIp();
|
||||
String vlanGateway = cmd.getGateway();
|
||||
String vlanNetmask = cmd.getNetmask();
|
||||
String newVlanGateway = cmd.getGateway();
|
||||
String newVlanNetmask = cmd.getNetmask();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
String vlanId = cmd.getVlan();
|
||||
Boolean forVirtualNetwork = cmd.isForVirtualNetwork();
|
||||
@ -2387,6 +2473,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
}
|
||||
}
|
||||
|
||||
boolean sameSubnet=false;
|
||||
// Can add vlan range only to the network which allows it
|
||||
if (!network.getSpecifyIpRanges()) {
|
||||
throw new InvalidParameterValueException("Network " + network + " doesn't support adding ip ranges");
|
||||
@ -2398,44 +2485,30 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
throw new InvalidParameterValueException("Can execute createVLANIpRanges on shared guest network, but type of this guest network "
|
||||
+ network.getId() + " is " + network.getGuestType());
|
||||
}
|
||||
|
||||
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
|
||||
VlanVO vlan = vlans.get(0);
|
||||
if ( vlans != null && vlans.size() > 0 ) {
|
||||
VlanVO vlan = vlans.get(0);
|
||||
if ( vlanId == null ) {
|
||||
vlanId = vlan.getVlanTag();
|
||||
} else if ( vlan.getVlanTag() != vlanId ) {
|
||||
throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" +
|
||||
+ network.getId() + ", only one vlan is allowed on guest network");
|
||||
}
|
||||
if (ipv4) {
|
||||
vlanGateway = vlan.getVlanGateway();
|
||||
vlanNetmask = vlan.getVlanNetmask();
|
||||
// Check if ip addresses are in network range
|
||||
if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) {
|
||||
throw new InvalidParameterValueException("Start ip is not in vlan range!");
|
||||
}
|
||||
if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) {
|
||||
throw new InvalidParameterValueException("End ip is not in vlan range!");
|
||||
}
|
||||
}
|
||||
if (ipv6) {
|
||||
if (ip6Gateway != null && !ip6Gateway.equals(network.getIp6Gateway())) {
|
||||
throw new InvalidParameterValueException("The input gateway " + ip6Gateway + " is not same as network gateway " + network.getIp6Gateway());
|
||||
}
|
||||
if (ip6Cidr != null && !ip6Cidr.equals(network.getIp6Cidr())) {
|
||||
throw new InvalidParameterValueException("The input cidr " + ip6Cidr + " is not same as network ciddr " + network.getIp6Cidr());
|
||||
}
|
||||
ip6Gateway = network.getIp6Gateway();
|
||||
ip6Cidr = network.getIp6Cidr();
|
||||
_networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
}
|
||||
}
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
|
||||
sameSubnet=validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr,startIPv6, endIPv6, network);
|
||||
|
||||
}
|
||||
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
|
||||
}
|
||||
else if (zone.getNetworkType() == NetworkType.Basic){
|
||||
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
|
||||
sameSubnet=validateIpRange(startIP,endIP,newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr, startIPv6, endIPv6, network);
|
||||
}
|
||||
|
||||
if (zoneId == null || (ipv4 && (vlanGateway == null || vlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
|
||||
if (zoneId == null || (ipv4 && (newVlanGateway == null || newVlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
|
||||
throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
|
||||
}
|
||||
|
||||
@ -2448,7 +2521,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
_resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountIpRange);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the IP range overlaps with the private ip
|
||||
if (ipv4) {
|
||||
checkOverlapPrivateIpRange(zoneId, startIP, endIP);
|
||||
@ -2457,13 +2529,75 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
txn.start();
|
||||
|
||||
Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP,
|
||||
endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
endIP, newVlanGateway, newVlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
//create an entry in the nic_secondary table. This will be the new gateway that will be configured on the corresponding routervm.
|
||||
if (sameSubnet == false) {
|
||||
s_logger.info("adding a new subnet to the network "+network.getId());
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
return vlan;
|
||||
}
|
||||
|
||||
public boolean validateIpRange(String startIP, String endIP, String newVlanGateway, String newVlanNetmask, List<VlanVO> vlans, boolean ipv4, boolean ipv6, String ip6Gateway, String ip6Cidr, String startIPv6, String endIPv6, Network network) {
|
||||
String vlanGateway;
|
||||
String vlanNetmask;
|
||||
boolean sameSubnet = false;
|
||||
if ( vlans != null && vlans.size() > 0 ) {
|
||||
|
||||
for (VlanVO vlan : vlans) {
|
||||
if (ipv4) {
|
||||
vlanGateway = vlan.getVlanGateway();
|
||||
vlanNetmask = vlan.getVlanNetmask();
|
||||
// Check if ip addresses are in network range
|
||||
if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) {
|
||||
if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) {
|
||||
// check if the the new subnet is not a superset of the existing subnets.
|
||||
if (NetUtils.isNetworkAWithinNetworkB(NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask), NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask))){
|
||||
throw new InvalidParameterValueException ("The new subnet is a superset of the existing subnet");
|
||||
}
|
||||
// check if the new subnet is not a subset of the existing subnet.
|
||||
if (NetUtils.isNetworkAWithinNetworkB(NetUtils.ipAndNetMaskToCidr(startIP, newVlanNetmask), NetUtils.getCidrFromGatewayAndNetmask(vlanGateway,vlanNetmask))){
|
||||
throw new InvalidParameterValueException("The new subnet is a subset of the existing subnet");
|
||||
}
|
||||
}
|
||||
} else if (NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)){
|
||||
// trying to add to the same subnet.
|
||||
sameSubnet = true;
|
||||
if (newVlanGateway == null) {
|
||||
newVlanGateway = vlanGateway;
|
||||
}
|
||||
if (!newVlanGateway.equals(vlanGateway)){
|
||||
throw new InvalidParameterValueException("The gateway of the ip range is not same as the gateway of the subnet.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
throw new InvalidParameterValueException("Start ip and End ip is not in vlan range!");
|
||||
}
|
||||
}
|
||||
if (ipv6) {
|
||||
if (ip6Gateway != null && !ip6Gateway.equals(network.getIp6Gateway())) {
|
||||
throw new InvalidParameterValueException("The input gateway " + ip6Gateway + " is not same as network gateway " + network.getIp6Gateway());
|
||||
}
|
||||
if (ip6Cidr != null && !ip6Cidr.equals(network.getIp6Cidr())) {
|
||||
throw new InvalidParameterValueException("The input cidr " + ip6Cidr + " is not same as network ciddr " + network.getIp6Cidr());
|
||||
}
|
||||
ip6Gateway = network.getIp6Gateway();
|
||||
ip6Cidr = network.getIp6Cidr();
|
||||
_networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
}
|
||||
}
|
||||
if (sameSubnet == false) {
|
||||
if (newVlanGateway ==null) {
|
||||
throw new MissingParameterValueException("The gateway for the new subnet is not specified.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return sameSubnet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId,
|
||||
@ -2683,20 +2817,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for the guest network in zone " + zone.getName());
|
||||
}
|
||||
|
||||
// For untagged vlan check if vlan per pod already exists. If yes,
|
||||
// verify that new vlan range has the same netmask and gateway
|
||||
if (zone.getNetworkType() == NetworkType.Basic && vlanId.equalsIgnoreCase(Vlan.UNTAGGED) && podId != null) {
|
||||
List<VlanVO> podVlans = _vlanDao.listVlansForPodByType(podId, VlanType.DirectAttached);
|
||||
if (podVlans != null && !podVlans.isEmpty()) {
|
||||
VlanVO podVlan = podVlans.get(0);
|
||||
if (!podVlan.getVlanNetmask().equals(vlanNetmask)) {
|
||||
throw new InvalidParameterValueException("Vlan netmask is different from the netmask of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId);
|
||||
} else if (!podVlan.getVlanGateway().equals(vlanGateway)) {
|
||||
throw new InvalidParameterValueException("Vlan gateway is different from the gateway of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String ipRange = null;
|
||||
|
||||
if (ipv4) {
|
||||
@ -2746,28 +2866,28 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) {
|
||||
VlanVO vlan = _vlanDao.findById(vlanDbId);
|
||||
if (vlan == null) {
|
||||
public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) {
|
||||
VlanVO vlanRange = _vlanDao.findById(vlanDbId);
|
||||
if (vlanRange == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid IP range id.");
|
||||
}
|
||||
|
||||
boolean isAccountSpecific = false;
|
||||
List<AccountVlanMapVO> acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlan.getId());
|
||||
List<AccountVlanMapVO> acctVln = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanRange.getId());
|
||||
// Check for account wide pool. It will have an entry for account_vlan_map.
|
||||
if (acctVln != null && !acctVln.isEmpty()) {
|
||||
isAccountSpecific = true;
|
||||
}
|
||||
|
||||
// Check if the VLAN has any allocated public IPs
|
||||
long allocIpCount = _publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true);
|
||||
long allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true);
|
||||
List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
|
||||
boolean success = true;
|
||||
if (allocIpCount > 0) {
|
||||
if (isAccountSpecific) {
|
||||
try {
|
||||
vlan = _vlanDao.acquireInLockTable(vlanDbId, 30);
|
||||
if (vlan == null) {
|
||||
vlanRange = _vlanDao.acquireInLockTable(vlanDbId, 30);
|
||||
if (vlanRange == null) {
|
||||
throw new CloudRuntimeException("Unable to acquire vlan configuration: " + vlanDbId);
|
||||
}
|
||||
|
||||
@ -2800,33 +2920,127 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
} finally {
|
||||
_vlanDao.releaseFromLockTable(vlanDbId);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses.");
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
// Delete all public IPs in the VLAN
|
||||
if (!deletePublicIPRange(vlanDbId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if ip range is dedicated to an account generate usage events for release of every ip in the range
|
||||
if(isAccountSpecific) {
|
||||
for (IPAddressVO ip : ips) {
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getId(),
|
||||
ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(),
|
||||
ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlanRange.getVlanType().toString(),
|
||||
ip.getSystem(), ip.getClass().getName(), ip.getUuid());
|
||||
}
|
||||
}
|
||||
if (_networkModel.areServicesSupportedInNetwork(vlanRange.getNetworkId(), Service.Dhcp)) {
|
||||
Network network = _networkDao.findById(vlanRange.getNetworkId());
|
||||
DhcpServiceProvider dhcpServiceProvider = _networkMgr.getDhcpServiceProvider(network);
|
||||
if (!dhcpServiceProvider.getProvider().getName().equalsIgnoreCase(Provider.VirtualRouter.getName())) {
|
||||
if (!deletePublicIPRange(vlanDbId)) {
|
||||
return false;
|
||||
}
|
||||
_vlanDao.expunge(vlanDbId);
|
||||
return true;
|
||||
}
|
||||
//search if the vlan has any allocated ips.
|
||||
boolean aliasIpBelongsToThisVlan = false;
|
||||
long freeIpsInsubnet = 0;
|
||||
NicIpAliasVO ipAlias = null;
|
||||
allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId, true);
|
||||
if (allocIpCount > 1) {
|
||||
throw new InvalidParameterValueException ("cannot delete this range as some of the vlans are in use.");
|
||||
}
|
||||
if (allocIpCount == 0){
|
||||
//remove the vlan range.
|
||||
if (!deletePublicIPRange(vlanDbId)) {
|
||||
return false;
|
||||
}
|
||||
_vlanDao.expunge(vlanDbId);
|
||||
return true;
|
||||
}
|
||||
//check if this allocated ip is being used as an ipAlias on the router.
|
||||
ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), vlanRange.getNetworkId(), NicIpAlias.state.active);
|
||||
//check if this ip belongs to this vlan and is allocated.
|
||||
IPAddressVO ip = _publicIpAddressDao.findByIpAndVlanId(ipAlias.getIp4Address(), vlanDbId);
|
||||
if (ip != null && ip.getState() == IpAddress.State.Allocated) {
|
||||
aliasIpBelongsToThisVlan =true;
|
||||
//check if there any other vlan ranges in the same subnet having free ips
|
||||
List<VlanVO> vlanRanges = _vlanDao.listVlansByNetworkIdAndGateway(vlanRange.getNetworkId(), vlanRange.getVlanGateway());
|
||||
//if there is no other vlanrage in this subnet. free the ip and delete the vlan.
|
||||
if (vlanRanges.size() == 1){
|
||||
boolean result = dhcpServiceProvider.removeDhcpSupportForSubnet(network);
|
||||
if (result == false) {
|
||||
s_logger.debug("Failed to delete the vlan range as we could not free the ip used to provide the dhcp service.");
|
||||
}
|
||||
else {
|
||||
_publicIpAddressDao.unassignIpAddress(ip.getId());
|
||||
if (!deletePublicIPRange(vlanDbId)) {
|
||||
return false;
|
||||
}
|
||||
_vlanDao.expunge(vlanDbId);
|
||||
_nicIpAliasDao.expunge(ipAlias.getId());
|
||||
}
|
||||
} else {
|
||||
// if there are more vlans in the subnet check if there are free ips.
|
||||
List<Long> vlanDbIdList = new ArrayList<Long>();
|
||||
for (VlanVO vlanrange : vlanRanges) {
|
||||
if (vlanrange.getId() != vlanDbId) {
|
||||
vlanDbIdList.add(vlanrange.getId());
|
||||
}
|
||||
}
|
||||
s_logger.info("vlan Range"+vlanRange.getId()+" id being deleted, one of the Ips in this range is used to provide the dhcp service, trying to free this ip and allocate a new one.");
|
||||
for (VlanVO vlanrange : vlanRanges) {
|
||||
if (vlanrange.getId() != vlanDbId) {
|
||||
freeIpsInsubnet = _publicIpAddressDao.countFreeIpsInVlan(vlanrange.getId());
|
||||
if (freeIpsInsubnet > 0){
|
||||
//assign one free ip to the router for creating ip Alias.
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
//changing the state to revoked so that removeDhcpSupport for subnet sses it.
|
||||
ipAlias.setState(NicIpAlias.state.revoked);
|
||||
_nicIpAliasDao.update(ipAlias.getId(), ipAlias);
|
||||
boolean result = false;
|
||||
try {
|
||||
PublicIp routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(network.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, network.getId(), null, false);
|
||||
s_logger.info("creating a db entry for the new ip alias.");
|
||||
NicIpAliasVO newipAlias = new NicIpAliasVO(ipAlias.getNicId(), routerPublicIP.getAddress().addr(), ipAlias.getVmId(), ipAlias.getAccountId(), network.getDomainId(), network.getId(), ipAlias.getGateway(), ipAlias.getNetmask());
|
||||
newipAlias.setAliasCount(routerPublicIP.getIpMacAddress());
|
||||
_nicIpAliasDao.persist(newipAlias);
|
||||
//we revoke all the rules and apply all the rules as a part of the removedhcp config. so the new ip will get configured when we delete the old ip.
|
||||
|
||||
// Delete the VLAN
|
||||
return _vlanDao.expunge(vlanDbId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
catch (InsufficientAddressCapacityException e) {
|
||||
txn.rollback();
|
||||
txn.close();
|
||||
throw new InvalidParameterValueException("cannot delete vlan range"+ vlanRange.getId()+"one of the ips in this range is benig used to provide dhcp service. Cannot use some other ip as there are no free ips in this subnet");
|
||||
}
|
||||
s_logger.info("removing the old ip alias on router");
|
||||
result = dhcpServiceProvider.removeDhcpSupportForSubnet(network);
|
||||
if (result == false) {
|
||||
s_logger.debug("could't delete the ip alias on the router");
|
||||
txn.rollback();
|
||||
txn.close();
|
||||
return false;
|
||||
}
|
||||
_publicIpAddressDao.unassignIpAddress(ip.getId());
|
||||
if (!deletePublicIPRange(vlanDbId)) {
|
||||
return false;
|
||||
}
|
||||
_vlanDao.expunge(vlanDbId);
|
||||
txn.commit();
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
throw new InvalidParameterValueException("One of the ips in the range is used to provide Dhcp service to this subnet. cannot delete this range as ");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DEDICATE, eventDescription = "dedicating vlan ip range", async = false)
|
||||
@ -2926,7 +3140,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
return releasePublicIpRange(vlanDbId, UserContext.current().getCallerUserId(), UserContext.current().getCaller());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@DB
|
||||
public boolean releasePublicIpRange(long vlanDbId, long userId, Account caller) {
|
||||
VlanVO vlan = _vlanDao.findById(vlanDbId);
|
||||
@ -3297,7 +3511,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", async = false)
|
||||
public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) {
|
||||
public boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) {
|
||||
Long vlanDbId = cmd.getId();
|
||||
|
||||
VlanVO vlan = _vlanDao.findById(vlanDbId);
|
||||
|
||||
@ -19,6 +19,7 @@ package com.cloud.network;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.network.element.DhcpServiceProvider;
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
@ -349,4 +350,7 @@ public interface NetworkManager {
|
||||
|
||||
NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType);
|
||||
|
||||
DhcpServiceProvider getDhcpServiceProvider(Network network);
|
||||
|
||||
PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException;
|
||||
}
|
||||
|
||||
@ -275,6 +275,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException {
|
||||
return fetchNewPublicIp(dcId, podId, vlanDbIds , owner, type, networkId, false, true, requestedIp, isSystem, null);
|
||||
}
|
||||
@DB
|
||||
public PublicIp fetchNewPublicIp(long dcId, Long podId, List<Long> vlanDbIds, Account owner, VlanType vlanUse,
|
||||
Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId)
|
||||
@ -1608,7 +1612,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
}
|
||||
}
|
||||
|
||||
protected void prepareElement(NetworkElement element, NetworkVO network,
|
||||
protected boolean prepareElement(NetworkElement element, NetworkVO network,
|
||||
NicProfile profile, VirtualMachineProfile<? extends VMInstanceVO> vmProfile,
|
||||
DeployDestination dest, ReservationContext context) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
@ -1618,6 +1622,9 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) &&
|
||||
element instanceof DhcpServiceProvider) {
|
||||
DhcpServiceProvider sp = (DhcpServiceProvider) element;
|
||||
if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
|
||||
return false;
|
||||
}
|
||||
sp.addDhcpEntry(network, profile, vmProfile, dest, context);
|
||||
}
|
||||
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) &&
|
||||
@ -1627,6 +1634,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@DB
|
||||
@ -1729,7 +1737,9 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
|
||||
}
|
||||
prepareElement(element, network, profile, vmProfile, dest, context);
|
||||
if(!prepareElement(element, network, profile, vmProfile, dest, context)) {
|
||||
throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity",Network.class, network.getId());
|
||||
}
|
||||
}
|
||||
|
||||
profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
|
||||
@ -1988,7 +1998,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
if ( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
|
||||
throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone");
|
||||
}
|
||||
if ( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup)) {
|
||||
if (!( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup))) {
|
||||
throw new InvalidParameterValueException("network must have SecurityGroup provider in security group enabled zone");
|
||||
}
|
||||
}
|
||||
@ -2852,6 +2862,20 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
return (UserDataServiceProvider)_networkModel.getElementImplementingProvider(SSHKeyProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DhcpServiceProvider getDhcpServiceProvider(Network network) {
|
||||
String DhcpProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.UserData);
|
||||
|
||||
if (DhcpProvider == null) {
|
||||
s_logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
return (DhcpServiceProvider)_networkModel.getElementImplementingProvider(DhcpProvider);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected boolean isSharedNetworkWithServices(Network network) {
|
||||
assert(network != null);
|
||||
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
|
||||
|
||||
@ -219,4 +219,8 @@ public class PublicIp implements PublicIpAddress {
|
||||
public String getVmIp() {
|
||||
return _addr.getVmIp();
|
||||
}
|
||||
|
||||
public Long getIpMacAddress() {
|
||||
return _addr.getMacAddress();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VirtualRouterProvider;
|
||||
import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
@ -89,6 +90,18 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
|
||||
DhcpServiceProvider.class, UserDataServiceProvider.class,
|
||||
@ -130,6 +143,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
VirtualRouterProviderDao _vrProviderDao;
|
||||
@Inject
|
||||
IPAddressDao _ipAddressDao;
|
||||
|
||||
protected boolean canHandle(Network network, Service service) {
|
||||
Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network);
|
||||
@ -825,6 +840,50 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
if (canHandle(network, Service.Dhcp)) {
|
||||
if (vm.getType() != VirtualMachine.Type.User) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
|
||||
List<DomainRouterVO> routers = getRouters(network, dest);
|
||||
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
return _routerMgr.configDhcpForSubnet(network, nic, uservm, dest, routers);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDhcpSupportForSubnet(Network network) {
|
||||
if (canHandle(network, Service.Dhcp)) {
|
||||
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
|
||||
try {
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
}
|
||||
catch (ResourceUnavailableException e) {
|
||||
s_logger.debug("could not find any router on this network");
|
||||
}
|
||||
try {
|
||||
return _routerMgr.removeDhcpSupportForSubnet(network, routers);
|
||||
}
|
||||
catch (ResourceUnavailableException e) {
|
||||
s_logger.debug("Router resource unavailable ");
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
DeployDestination dest, ReservationContext context)
|
||||
|
||||
@ -16,9 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.network.router;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -39,6 +36,9 @@ import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* NetworkManager manages the network for the different end users.
|
||||
*
|
||||
@ -107,4 +107,9 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
|
||||
|
||||
boolean applyLoadBalancingRules(Network network, List<? extends LoadBalancingRule> rules, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
|
||||
|
||||
}
|
||||
|
||||
boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile<UserVm> uservm, DeployDestination dest, List<DomainRouterVO> routers) throws ResourceUnavailableException ;
|
||||
|
||||
boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException;
|
||||
|
||||
}
|
||||
@ -17,34 +17,6 @@
|
||||
|
||||
package com.cloud.network.router;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.server.ConfigurationServer;
|
||||
import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
import com.cloud.agent.Listener;
|
||||
@ -66,7 +38,11 @@ import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.routing.CreateIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DeleteIpAliasCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.DnsMasqConfigCommand;
|
||||
import com.cloud.agent.api.routing.IpAliasTO;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||
@ -78,6 +54,7 @@ import com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
|
||||
import com.cloud.agent.api.to.DnsmasqTO;
|
||||
import com.cloud.agent.api.to.FirewallRuleTO;
|
||||
import com.cloud.agent.api.to.IpAddressTO;
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
@ -100,6 +77,8 @@ import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
@ -185,6 +164,7 @@ import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.server.ConfigurationServer;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
@ -224,6 +204,7 @@ import com.cloud.utils.net.MacAddress;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicIpAlias;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
@ -239,9 +220,36 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.NicIpAliasDao;
|
||||
import com.cloud.vm.dao.NicIpAliasVO;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.UserVmDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances available in the Cloud Stack.
|
||||
@ -320,6 +328,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
@Inject
|
||||
NicDao _nicDao;
|
||||
@Inject
|
||||
NicIpAliasDao _nicIpAliasDao;
|
||||
@Inject
|
||||
VolumeDao _volumeDao = null;
|
||||
@Inject
|
||||
UserVmDetailsDao _vmDetailsDao;
|
||||
@ -2431,6 +2441,23 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
createApplyLoadBalancingRulesCommands(lbRules, router, cmds, guestNetworkId);
|
||||
}
|
||||
}
|
||||
//Reapply dhcp and dns configuration.
|
||||
if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Dhcp, provider)) {
|
||||
List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(guestNetworkId, NicIpAlias.state.revoked);
|
||||
s_logger.debug("Found" + revokedIpAliasVOs.size() + "ip Aliases to apply on the router as a part of dhco configuration");
|
||||
List<IpAliasTO> revokedIpAliasTOs = new ArrayList<IpAliasTO>();
|
||||
for (NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
|
||||
revokedIpAliasTOs.add(new IpAliasTO(revokedAliasVO.getIp4Address(), revokedAliasVO.getNetmask(), revokedAliasVO.getAliasCount().toString()));
|
||||
}
|
||||
List<NicIpAliasVO> aliasVOs = _nicIpAliasDao.listByNetworkIdAndState(guestNetworkId, NicIpAlias.state.active);
|
||||
s_logger.debug("Found" + aliasVOs.size() + "ip Aliases to apply on the router as a part of dhco configuration");
|
||||
List<IpAliasTO> activeIpAliasTOs = new ArrayList<IpAliasTO>();
|
||||
for (NicIpAliasVO aliasVO : aliasVOs) {
|
||||
activeIpAliasTOs.add(new IpAliasTO(aliasVO.getIp4Address(), aliasVO.getNetmask(), aliasVO.getAliasCount().toString()));
|
||||
}
|
||||
createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, guestNetworkId, cmds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalizeIpAssocForNetwork(Commands cmds, VirtualRouter router, Provider provider,
|
||||
@ -2672,7 +2699,129 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
throw new CloudRuntimeException("Unable to stop " + router, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configDhcpForSubnet(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile, DeployDestination dest, List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
_userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine());
|
||||
|
||||
final VirtualMachineProfile<UserVm> updatedProfile = profile;
|
||||
final boolean isZoneBasic = (dest.getDataCenter().getNetworkType() == NetworkType.Basic);
|
||||
final Long podId = isZoneBasic ? dest.getPod().getId() : null;
|
||||
|
||||
//Asuming we have only one router per network For Now.
|
||||
DomainRouterVO router = routers.get(0);
|
||||
if (router.getState() != State.Running) {
|
||||
s_logger.warn("Failed to add/remove VPN users: router not in running state");
|
||||
throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " +
|
||||
router.getState(), DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
//check if this is not the primary subnet.
|
||||
|
||||
|
||||
//check if the the ip Alias is configured on the virtualrouter.
|
||||
UserVm vm = updatedProfile.getVirtualMachine();
|
||||
NicVO domr_guest_nic = _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(nic.getNetworkId(), router.getId()), VirtualMachine.Type.DomainRouter);
|
||||
//check if the router ip address and the vm ip address belong to same subnet.
|
||||
//if they do not belong to same netwoek check for the alias ips. if not create one.
|
||||
// This should happen only in case of Basic and Advanced SG enabled networks.
|
||||
if (!NetUtils.sameSubnet(domr_guest_nic.getIp4Address(), nic.getIp4Address(), nic.getNetmask())){
|
||||
List<NicIpAliasVO> aliasIps = _nicIpAliasDao.listByNetworkIdAndState(domr_guest_nic.getNetworkId(), NicIpAlias.state.active);
|
||||
boolean ipInVmsubnet =false;
|
||||
for (NicIpAliasVO alias : aliasIps) {
|
||||
//check if any of the alias ips belongs to the Vm's subnet.
|
||||
if (NetUtils.sameSubnet(alias.getIp4Address(),nic.getIp4Address(),nic.getNetmask())){
|
||||
ipInVmsubnet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PublicIp routerPublicIP = null;
|
||||
String routerAliasIp =null;
|
||||
DataCenter dc = _dcDao.findById(router.getDataCenterId());
|
||||
if (ipInVmsubnet == false) {
|
||||
try {
|
||||
if (network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared) {
|
||||
Pod pod = _podDao.findById(vm.getPodIdToDeployIn());
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<VlanVO> vlanList = _vlanDao.listVlansByNetworkIdAndGateway(network.getId(), nic.getGateway());
|
||||
List<Long> vlanDbIdList = new ArrayList<Long>();
|
||||
for (VlanVO vlan : vlanList) {
|
||||
vlanDbIdList.add(vlan.getId());
|
||||
}
|
||||
routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
|
||||
routerAliasIp = routerPublicIP.getAddress().addr();
|
||||
}
|
||||
}
|
||||
catch (InsufficientAddressCapacityException e){
|
||||
s_logger.info(e.getMessage());
|
||||
s_logger.info("unable to configure dhcp for this VM.");
|
||||
return false;
|
||||
}
|
||||
//this means we did not create a ip alis on the router.
|
||||
NicIpAliasVO alias = new NicIpAliasVO(domr_guest_nic.getId(), routerAliasIp, router.getId(), UserContext.current().getAccountId(), network.getDomainId(), nic.getNetworkId(),nic.getGateway(), nic.getNetmask());
|
||||
alias.setAliasCount((routerPublicIP.getIpMacAddress()));
|
||||
_nicIpAliasDao.persist(alias);
|
||||
List<IpAliasTO> ipaliasTo = new ArrayList<IpAliasTO>();
|
||||
ipaliasTo.add(new IpAliasTO(routerAliasIp, alias.getNetmask(), alias.getAliasCount().toString()));
|
||||
Commands cmds = new Commands(OnError.Stop);
|
||||
createIpAlias(router, ipaliasTo, alias.getNetworkId(), cmds);
|
||||
//also add the required configuration to the dnsmasq for supporting dhcp and dns on the new ip.
|
||||
configDnsMasq(router, network, cmds);
|
||||
boolean result = sendCommandsToRouter(router, cmds);
|
||||
if (result == false) {
|
||||
NicIpAliasVO ipAliasVO = _nicIpAliasDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
|
||||
_nicIpAliasDao.expunge(ipAliasVO.getId());
|
||||
_ipAddressDao.unassignIpAddress(routerPublicIP.getId());
|
||||
throw new CloudRuntimeException("failed to configure ip alias on the router as a part of dhcp config");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
|
||||
throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " +
|
||||
network.getId(), DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
boolean agentResults = true;
|
||||
|
||||
for (DomainRouterVO router : routers) {
|
||||
if (router.getState() != State.Running) {
|
||||
s_logger.warn("Failed to add/remove VPN users: router not in running state");
|
||||
throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " +
|
||||
router.getState(), DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.state.revoked);
|
||||
s_logger.debug("Found" + revokedIpAliasVOs.size() + "ip Aliases to apply on the router as a part of dhco configuration");
|
||||
List<IpAliasTO> revokedIpAliasTOs = new ArrayList<IpAliasTO>();
|
||||
for (NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
|
||||
revokedIpAliasTOs.add(new IpAliasTO(revokedAliasVO.getIp4Address(), revokedAliasVO.getNetmask(), revokedAliasVO.getAliasCount().toString()));
|
||||
}
|
||||
List<NicIpAliasVO> aliasVOs = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.state.active);
|
||||
s_logger.debug("Found" + aliasVOs.size() + "ip Aliases to apply on the router as a part of dhco configuration");
|
||||
List<IpAliasTO> activeIpAliasTOs = new ArrayList<IpAliasTO>();
|
||||
for (NicIpAliasVO aliasVO : aliasVOs) {
|
||||
activeIpAliasTOs.add(new IpAliasTO(aliasVO.getIp4Address(), aliasVO.getNetmask(), aliasVO.getAliasCount().toString()));
|
||||
}
|
||||
createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, network.getId(), cmds);
|
||||
configDnsMasq(router, network, cmds);
|
||||
boolean result = sendCommandsToRouter(router, cmds);
|
||||
if (result) {
|
||||
for (NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
|
||||
_nicIpAliasDao.expunge(revokedAliasVO.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile,
|
||||
DeployDestination dest, List<DomainRouterVO> routers)
|
||||
@ -2705,7 +2854,19 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
});
|
||||
}
|
||||
|
||||
private String findDefaultDnsIp(long userVmId) {
|
||||
private void createDeleteIpAliasCommand(DomainRouterVO router, List<IpAliasTO> deleteIpAliasTOs, List<IpAliasTO> createIpAliasTos, long networkId, Commands cmds) {
|
||||
String routerip = getRouterIpInNetwork(networkId, router.getId());
|
||||
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
DeleteIpAliasCommand deleteIpaliasCmd = new DeleteIpAliasCommand(routerip, deleteIpAliasTOs, createIpAliasTos);
|
||||
deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
|
||||
deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
|
||||
deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,routerip);
|
||||
deleteIpaliasCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
|
||||
|
||||
cmds.addCommand("deleteIpalias", deleteIpaliasCmd);
|
||||
}
|
||||
|
||||
private NicVO findDefaultDnsIp(long userVmId) {
|
||||
NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
|
||||
|
||||
//check if DNS provider is the domR
|
||||
@ -2728,12 +2889,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
} else{
|
||||
domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter);
|
||||
}
|
||||
return domrDefaultNic.getIp4Address();
|
||||
return domrDefaultNic;
|
||||
}
|
||||
|
||||
private String findGatewayIp(long userVmId) {
|
||||
private NicVO findGatewayIp(long userVmId) {
|
||||
NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
|
||||
return defaultNic.getGateway();
|
||||
return defaultNic;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -3159,7 +3320,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
private void createDhcpEntryCommand(VirtualRouter router, UserVm vm, NicVO nic, Commands cmds) {
|
||||
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address());
|
||||
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
String gatewayIp = findGatewayIp(vm.getId());
|
||||
Nic defaultNic = findGatewayIp(vm.getId());
|
||||
String gatewayIp = defaultNic.getGateway();
|
||||
boolean needGateway = true;
|
||||
if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) {
|
||||
needGateway = false;
|
||||
@ -3178,7 +3340,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
}
|
||||
dhcpCommand.setDefaultRouter(gatewayIp);
|
||||
dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
|
||||
dhcpCommand.setDefaultDns(findDefaultDnsIp(vm.getId()));
|
||||
String ipaddress=null;
|
||||
NicVO domrDefaultNic = findDefaultDnsIp(vm.getId());
|
||||
if (domrDefaultNic != null){
|
||||
ipaddress = domrDefaultNic.getIp4Address();
|
||||
}
|
||||
dhcpCommand.setDefaultDns(ipaddress);
|
||||
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
|
||||
dhcpCommand.setDefault(nic.isDefaultNic());
|
||||
|
||||
@ -3190,6 +3357,42 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
cmds.addCommand("dhcp", dhcpCommand);
|
||||
}
|
||||
|
||||
private void configDnsMasq(VirtualRouter router, Network network, Commands cmds) {
|
||||
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
List<NicIpAliasVO> ipAliasVOList = _nicIpAliasDao.getAliasIpForVm(router.getId());
|
||||
List<DnsmasqTO> ipList = new ArrayList<DnsmasqTO>();
|
||||
|
||||
NicVO router_guest_ip = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId());
|
||||
ipList.add(new DnsmasqTO(router_guest_ip.getIp4Address(),router_guest_ip.getGateway(),router_guest_ip.getNetmask()));
|
||||
for (NicIpAliasVO ipAliasVO : ipAliasVOList) {
|
||||
DnsmasqTO dnsmasqTO = new DnsmasqTO(ipAliasVO.getStartIpOfSubnet(), ipAliasVO.getGateway(), ipAliasVO.getNetmask());
|
||||
ipList.add(dnsmasqTO);
|
||||
}
|
||||
DataCenterVO dcvo = _dcDao.findById(router.getDataCenterId());
|
||||
DnsMasqConfigCommand dnsMasqConfigCmd = new DnsMasqConfigCommand(network.getNetworkDomain(),ipList, dcvo.getDns1(), dcvo.getDns2(), dcvo.getInternalDns1(), dcvo.getInternalDns2());
|
||||
dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
|
||||
dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
|
||||
dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId()));
|
||||
dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
|
||||
|
||||
cmds.addCommand("dhcpConfig" ,dnsMasqConfigCmd);
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
private void createIpAlias(VirtualRouter router, List<IpAliasTO> ipAliasTOs, Long networkid, Commands cmds) {
|
||||
|
||||
String routerip = getRouterIpInNetwork(networkid, router.getId());
|
||||
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
CreateIpAliasCommand ipaliasCmd = new CreateIpAliasCommand(routerip, ipAliasTOs);
|
||||
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
|
||||
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
|
||||
ipaliasCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,routerip);
|
||||
ipaliasCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
|
||||
|
||||
cmds.addCommand("ipalias", ipaliasCmd);
|
||||
}
|
||||
|
||||
private void createDhcpEntryCommandsForVMs(DomainRouterVO router, Commands cmds, long guestNetworkId) {
|
||||
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(guestNetworkId, State.Running, State.Migrating, State.Stopping);
|
||||
DataCenterVO dc = _dcDao.findById(router.getDataCenterId());
|
||||
|
||||
61
server/src/com/cloud/vm/dao/NicIpAliasDao.java
Normal file
61
server/src/com/cloud/vm/dao/NicIpAliasDao.java
Normal file
@ -0,0 +1,61 @@
|
||||
// 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.
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.NicIpAlias;
|
||||
|
||||
public interface NicIpAliasDao extends GenericDao<NicIpAliasVO, Long> {
|
||||
List<NicIpAliasVO> listByVmId(long instanceId);
|
||||
|
||||
List<String> listAliasIpAddressInNetwork(long networkConfigId);
|
||||
List<NicIpAliasVO> listByNetworkId(long networkId);
|
||||
|
||||
NicIpAliasVO findByInstanceIdAndNetworkId(long networkId, long instanceId);
|
||||
|
||||
NicIpAliasVO findByIp4AddressAndNetworkId(String ip4Address, long networkId);
|
||||
|
||||
/**
|
||||
* @param networkId
|
||||
* @param instanceId
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<NicIpAliasVO> getAliasIpForVm(long vmId);
|
||||
|
||||
List<NicIpAliasVO> listByNicId(long nicId);
|
||||
|
||||
List<NicIpAliasVO> listByNicIdAndVmid(long nicId, long vmId);
|
||||
|
||||
NicIpAliasVO findByIp4AddressAndNicId(String ip4Address, long nicId);
|
||||
|
||||
NicIpAliasVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId,
|
||||
Long vmId, String vmIp);
|
||||
|
||||
List<String> getAliasIpAddressesForNic(long nicId);
|
||||
|
||||
Integer countAliasIps(long NicId);
|
||||
|
||||
public NicIpAliasVO findByIp4AddressAndVmId(String ip4Address, long vmId);
|
||||
|
||||
NicIpAliasVO findByGatewayAndNetworkIdAndState(String gateway, long networkId, NicIpAlias.state state);
|
||||
|
||||
List<NicIpAliasVO> listByNetworkIdAndState(long networkId, NicIpAlias.state state);
|
||||
|
||||
List<NicIpAliasVO> listByNetworkIdAndAliasIpAndState(long networkId, String aliasIpOfSubnet, NicIpAlias.state state);
|
||||
}
|
||||
186
server/src/com/cloud/vm/dao/NicIpAliasDaoImpl.java
Normal file
186
server/src/com/cloud/vm/dao/NicIpAliasDaoImpl.java
Normal file
@ -0,0 +1,186 @@
|
||||
// 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.
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.vm.NicIpAlias;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
@Local(value=NicIpAliasDao.class)
|
||||
public class NicIpAliasDaoImpl extends GenericDaoBase<NicIpAliasVO, Long> implements NicIpAliasDao {
|
||||
private final SearchBuilder<NicIpAliasVO> AllFieldsSearch;
|
||||
private final GenericSearchBuilder<NicIpAliasVO, String> IpSearch;
|
||||
|
||||
protected NicIpAliasDaoImpl() {
|
||||
super();
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getVmId(), Op.EQ);
|
||||
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ);
|
||||
AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ);
|
||||
AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getGateway(), Op.EQ);
|
||||
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
IpSearch = createSearchBuilder(String.class);
|
||||
IpSearch.select(null, Func.DISTINCT, IpSearch.entity().getIp4Address());
|
||||
IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ);
|
||||
IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL);
|
||||
IpSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByVmId(long instanceId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instanceId", instanceId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByNicId(long nicId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("nicId", nicId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listAliasIpAddressInNetwork(long networkId) {
|
||||
SearchCriteria<String> sc = IpSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByNetworkId(long networkId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByNetworkIdAndState(long networkId, NicIpAlias.state state) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("state", state);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByNetworkIdAndAliasIpAndState(long networkId, String aliasIpOfSubnet, NicIpAlias.state state) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("address", aliasIpOfSubnet);
|
||||
sc.setParameters("state", state);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> listByNicIdAndVmid(long nicId, long vmId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("nicId", nicId);
|
||||
sc.setParameters("instanceId", vmId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicIpAliasVO> getAliasIpForVm(long vmId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instanceId", vmId);
|
||||
sc.setParameters("state", NicIpAlias.state.active);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliasIpAddressesForNic(long nicId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("nicId", nicId);
|
||||
List<NicIpAliasVO> results = search(sc, null);
|
||||
List<String> ips = new ArrayList<String>(results.size());
|
||||
for (NicIpAliasVO result : results) {
|
||||
ips.add(result.getIp4Address());
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicIpAliasVO findByInstanceIdAndNetworkId(long networkId, long instanceId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("instanceId", instanceId);
|
||||
sc.setParameters("state", NicIpAlias.state.active);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicIpAliasVO findByIp4AddressAndNetworkId(String ip4Address, long networkId) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicIpAliasVO findByGatewayAndNetworkIdAndState(String gateway, long networkId, NicIpAlias.state state) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("gateway", gateway);
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("state", state);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicIpAliasVO findByIp4AddressAndVmId(String ip4Address, long vmId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("address", ip4Address);
|
||||
sc.setParameters("instanceId", vmId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
@Override
|
||||
public NicIpAliasVO findByIp4AddressAndNicId(String ip4Address, long nicId) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("address", ip4Address);
|
||||
sc.setParameters("nicId", nicId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicIpAliasVO findByIp4AddressAndNetworkIdAndInstanceId(
|
||||
long networkId, Long vmId, String vmIp) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("instanceId", vmId);
|
||||
sc.setParameters("address", vmIp);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countAliasIps(long id) {
|
||||
SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instanceId",id);
|
||||
List<NicIpAliasVO> list = listBy(sc);
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
226
server/src/com/cloud/vm/dao/NicIpAliasVO.java
Normal file
226
server/src/com/cloud/vm/dao/NicIpAliasVO.java
Normal file
@ -0,0 +1,226 @@
|
||||
// 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.
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.NicIpAlias;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "nic_ip_alias")
|
||||
public class NicIpAliasVO implements NicIpAlias {
|
||||
|
||||
public NicIpAliasVO(Long nicId, String ipaddr, Long vmId,
|
||||
Long accountId, Long domainId, Long networkId, String gateway, String netmask) {
|
||||
this.nicId = nicId;
|
||||
this.vmId = vmId;
|
||||
this.ip4Address = ipaddr;
|
||||
this.accountId = accountId;
|
||||
this.domainId = domainId;
|
||||
this.networkId = networkId;
|
||||
this.netmask =netmask;
|
||||
this.gateway = gateway;
|
||||
this.state = NicIpAlias.state.active;
|
||||
String cidr = NetUtils.getCidrFromGatewayAndNetmask(gateway, netmask);
|
||||
String[] cidrPair = cidr.split("\\/");
|
||||
String cidrAddress = cidrPair[0];
|
||||
long cidrSize = Long.parseLong(cidrPair[1]);
|
||||
this.startIpOfSubnet = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
|
||||
}
|
||||
|
||||
protected NicIpAliasVO() {
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
long id;
|
||||
|
||||
@Column(name = "nic_Id")
|
||||
long nicId;
|
||||
|
||||
@Column(name="domain_id", updatable=false)
|
||||
long domainId;
|
||||
|
||||
@Column(name="account_id", updatable=false)
|
||||
private Long accountId;
|
||||
|
||||
@Column(name = "ip4_address")
|
||||
String ip4Address;
|
||||
|
||||
@Column(name = "ip6_address")
|
||||
String ip6Address;
|
||||
|
||||
@Column(name = "netmask")
|
||||
String netmask;
|
||||
|
||||
@Column(name = "network_id")
|
||||
long networkId;
|
||||
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
@Column(name = "uuid")
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
@Column(name = "vmId")
|
||||
Long vmId;
|
||||
|
||||
@Column(name = "alias_count")
|
||||
Long aliasCount;
|
||||
|
||||
@Column(name = "gateway")
|
||||
String gateway;
|
||||
|
||||
@Column(name= "state")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
NicIpAlias.state state;
|
||||
|
||||
@Column(name = "start_ip_of_subnet")
|
||||
String startIpOfSubnet;
|
||||
|
||||
|
||||
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getNicId() {
|
||||
return nicId;
|
||||
}
|
||||
|
||||
public void setNicId(long nicId) {
|
||||
this.nicId = nicId;
|
||||
}
|
||||
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(Long accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public String getIp4Address() {
|
||||
return ip4Address;
|
||||
}
|
||||
|
||||
public void setIp4Address(String ip4Address) {
|
||||
this.ip4Address = ip4Address;
|
||||
}
|
||||
|
||||
public String getIp6Address() {
|
||||
return ip6Address;
|
||||
}
|
||||
|
||||
public void setIp6Address(String ip6Address) {
|
||||
this.ip6Address = ip6Address;
|
||||
}
|
||||
|
||||
public long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public void setNetworkId(long networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public long getVmId() {
|
||||
return vmId;
|
||||
}
|
||||
|
||||
public void setVmId(Long vmId) {
|
||||
this.vmId = vmId;
|
||||
}
|
||||
|
||||
public Long getAliasCount() {
|
||||
return aliasCount;
|
||||
}
|
||||
|
||||
public void setAliasCount(long count) {
|
||||
this.aliasCount = count;
|
||||
}
|
||||
|
||||
public void setNetmask(String netmask){
|
||||
this.netmask = netmask;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
public void setGateway(String gateway) {
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
public NicIpAlias.state getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(NicIpAlias.state state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getStartIpOfSubnet() {
|
||||
return startIpOfSubnet;
|
||||
}
|
||||
|
||||
}
|
||||
71
server/test/com/cloud/configuration/ValidateIpRangeTest.java
Normal file
71
server/test/com/cloud/configuration/ValidateIpRangeTest.java
Normal file
@ -0,0 +1,71 @@
|
||||
// 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.
|
||||
package com.cloud.configuration;
|
||||
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ValidateIpRangeTest {
|
||||
@Mock NetworkModel _networkModel;
|
||||
@Mock VlanVO vlan;
|
||||
@Mock Network network;
|
||||
ConfigurationManagerImpl configurationMgr = new ConfigurationManagerImpl();
|
||||
List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
configurationMgr._networkModel = _networkModel;
|
||||
vlanVOList.add(vlan);
|
||||
when(vlan.getVlanGateway()).thenReturn("10.147.33.1");
|
||||
when(vlan.getVlanNetmask()).thenReturn("255.255.255.128");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SameSubnetTest() {
|
||||
boolean sameSubnet=configurationMgr.validateIpRange("10.147.33.104", "10.147.33.105", "10.147.33.1", "255.255.255.128", vlanVOList, true, false, null, null, null, null,network);
|
||||
Assert.assertTrue(sameSubnet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void NewSubnetTest() {
|
||||
boolean sameSubnet= configurationMgr.validateIpRange("10.147.33.140", "10.147.33.145", "10.147.33.129", "255.255.255.191", vlanVOList, true, false, null, null, null, null,network);
|
||||
Assert.assertTrue(!sameSubnet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SuperSetTest() {
|
||||
try {
|
||||
configurationMgr.validateIpRange("10.147.33.140", "10.147.33.143", "10.147.33.140", "255.255.255.191", vlanVOList, true, false, null, null, null, null,network);
|
||||
} catch (Exception e) {
|
||||
junit.framework.Assert.assertTrue(e.getMessage().contains("superset"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -50,6 +50,7 @@ import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.GuestVlan;
|
||||
import com.cloud.network.element.DhcpServiceProvider;
|
||||
import com.cloud.network.element.LoadBalancingServiceProvider;
|
||||
import com.cloud.network.element.StaticNatServiceProvider;
|
||||
import com.cloud.network.element.UserDataServiceProvider;
|
||||
@ -919,4 +920,14 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DhcpServiceProvider getDhcpServiceProvider(Network network) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,40 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.vpc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.configuration.Configuration;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.ConfigurationService;
|
||||
@ -82,6 +48,37 @@ import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
|
||||
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
|
||||
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
@Local(value = { ConfigurationManager.class, ConfigurationService.class })
|
||||
@ -627,11 +624,5 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releasePublicIpRange(long userId, long vlanDbId,
|
||||
Account caller) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -67,10 +67,7 @@ import com.cloud.network.dao.AccountGuestVlanMapVO;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.element.LoadBalancingServiceProvider;
|
||||
import com.cloud.network.element.NetworkElement;
|
||||
import com.cloud.network.element.StaticNatServiceProvider;
|
||||
import com.cloud.network.element.UserDataServiceProvider;
|
||||
import com.cloud.network.element.*;
|
||||
import com.cloud.network.guru.NetworkGuru;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
@ -1420,13 +1417,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeVmSecondaryIpsOfNic(long nicId) {
|
||||
// TODO Auto-generated method stub
|
||||
@ -1434,14 +1424,21 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DhcpServiceProvider getDhcpServiceProvider(Network network) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -212,6 +212,16 @@ VpcVirtualNetworkApplianceService {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile<UserVm> uservm, DeployDestination dest, List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.VirtualNetworkApplianceService#startRouter(long, boolean)
|
||||
*/
|
||||
|
||||
@ -17,22 +17,6 @@
|
||||
|
||||
package org.apache.cloudstack.networkoffering;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
@ -52,6 +36,19 @@ import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/createNetworkOffering.xml")
|
||||
|
||||
@ -34,13 +34,14 @@
|
||||
<ref bean="transactionContextBuilder" />
|
||||
<ref bean="actionEventInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
|
||||
<property name="name" value="ConfigurationManager"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
|
||||
|
||||
</beans>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
|
||||
<property name="name" value="ConfigurationManager"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
|
||||
|
||||
</beans>
|
||||
|
||||
@ -1581,4 +1581,22 @@ INSERT INTO `cloud`.`network_acl_item` (id, uuid, acl_id, state, protocol, creat
|
||||
INSERT INTO `cloud`.`network_acl` (id, uuid, vpc_id, description, name) values (2, UUID(), 0, "Default Network ACL Allow All", "default_allow");
|
||||
INSERT INTO `cloud`.`network_acl_item` (id, uuid, acl_id, state, protocol, created, traffic_type, cidr, number, action) values (3, UUID(), 2, "Active", "all", now(), "Ingress", "0.0.0.0/0", 1, "Allow");
|
||||
INSERT INTO `cloud`.`network_acl_item` (id, uuid, acl_id, state, protocol, created, traffic_type, cidr, number, action) values (4, UUID(), 2, "Active", "all", now(), "Egress", "0.0.0.0/0", 2, "Allow");
|
||||
>>>>>>> master
|
||||
|
||||
CREATE TABLE `cloud`.`nic_ip_alias` (
|
||||
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`uuid` VARCHAR(40) NOT NULL ,
|
||||
`nic_id` BIGINT(20) UNSIGNED NULL ,
|
||||
`ip4_address` CHAR(40) NULL ,
|
||||
`ip6_address` CHAR(40) NULL ,
|
||||
`netmask` CHAR(40) NULL ,
|
||||
`gateway` CHAR(40) NULL ,
|
||||
`start_ip_of_subnet` CHAR(40),
|
||||
`network_id` BIGINT(20) UNSIGNED NULL ,
|
||||
`vmId` BIGINT(20) UNSIGNED NULL ,
|
||||
`alias_count` BIGINT(20) UNSIGNED NULL ,
|
||||
`created` DATETIME NOT NULL ,
|
||||
`account_id` BIGINT(20) UNSIGNED NOT NULL ,
|
||||
`domain_id` BIGINT(20) UNSIGNED NOT NULL ,
|
||||
`state` char(32) NOT NULL,
|
||||
PRIMARY KEY (`id`) ,
|
||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC) );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user