use of com.cloud.hypervisor.kvm.resource.LibvirtVmDef.InterfaceDef in project cloudstack by apache.
the class LibvirtComputingResource method defaultNetworkRules.
public boolean defaultNetworkRules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final String secIpStr) {
if (!_canBridgeFirewall) {
return false;
}
final List<InterfaceDef> intfs = getInterfaces(conn, vmName);
if (intfs.size() == 0 || intfs.size() < nic.getDeviceId()) {
return false;
}
final InterfaceDef intf = intfs.get(nic.getDeviceId());
final String brname = intf.getBrName();
final String vif = intf.getDevName();
final Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
cmd.add("default_network_rules");
cmd.add("--vmname", vmName);
cmd.add("--vmid", vmId.toString());
if (nic.getIp() != null) {
cmd.add("--vmip", nic.getIp());
}
if (nic.getIp6Address() != null) {
cmd.add("--vmip6", nic.getIp6Address());
}
cmd.add("--vmmac", nic.getMac());
cmd.add("--vif", vif);
cmd.add("--brname", brname);
cmd.add("--nicsecips", secIpStr);
final String result = cmd.execute();
if (result != null) {
return false;
}
return true;
}
use of com.cloud.hypervisor.kvm.resource.LibvirtVmDef.InterfaceDef in project cloudstack by apache.
the class LibvirtComputingResource method prepareNetworkElementCommand.
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
Connect conn;
final NicTO nic = cmd.getNic();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
conn = LibvirtConnection.getConnectionByVmName(routerName);
final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
InterfaceDef routerNic = null;
for (final InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
routerNic = pluggedNic;
break;
}
}
if (routerNic == null) {
return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
}
return new ExecutionResult(true, null);
} catch (final LibvirtException e) {
final String msg = "Creating guest network failed due to " + e.toString();
s_logger.warn(msg, e);
return new ExecutionResult(false, msg);
}
}
use of com.cloud.hypervisor.kvm.resource.LibvirtVmDef.InterfaceDef in project cloudstack by apache.
the class IvsVifDriver method plug.
@Override
public InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter) throws InternalErrorException, LibvirtException {
LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
String vNetId = null;
String protocol = null;
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) {
vNetId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
protocol = Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()).scheme();
}
String vlanId = null;
String logicalSwitchUuid = null;
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) {
vlanId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
logicalSwitchUuid = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) {
// TODO consider moving some of this functionality from NetUtils to Networks....
vlanId = NetUtils.getPrimaryPvlanFromUri(nic.getBroadcastUri());
}
String trafficLabel = nic.getName();
Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0;
if (nic.getType() == Networks.TrafficType.Guest) {
if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) && !vlanId.equalsIgnoreCase("untagged")) {
if (trafficLabel != null && !trafficLabel.isEmpty()) {
s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel);
intf.defEthernet("ivsnet-" + nic.getUuid().substring(0, 5), nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _ivsIfUpPath, networkRateKBps);
} else {
throw new InternalErrorException("no traffic label ");
}
}
} else if (nic.getType() == Networks.TrafficType.Control) {
/* Make sure the network is still there */
createControlNetwork();
intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
} else if (nic.getType() == Networks.TrafficType.Public) {
if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
if (trafficLabel != null && !trafficLabel.isEmpty()) {
s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel);
String brName = createVnetBr(vNetId, trafficLabel, protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
} else {
String brName = createVnetBr(vNetId, "public", protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else {
intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else if (nic.getType() == Networks.TrafficType.Management) {
intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
} else if (nic.getType() == Networks.TrafficType.Storage) {
String storageBrName = nic.getName() == null ? _bridges.get("private") : nic.getName();
intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
}
if (nic.getPxeDisable() == true) {
intf.setPxeDisable(true);
}
return intf;
}
use of com.cloud.hypervisor.kvm.resource.LibvirtVmDef.InterfaceDef in project cloudstack by apache.
the class LibvirtComputingResource method post_default_network_rules.
protected boolean post_default_network_rules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final InetAddress dhcpServerIp, final String hostIp, final String hostMacAddr) {
if (!_canBridgeFirewall) {
return false;
}
final List<InterfaceDef> intfs = getInterfaces(conn, vmName);
if (intfs.size() < nic.getDeviceId()) {
return false;
}
final InterfaceDef intf = intfs.get(nic.getDeviceId());
final String brname = intf.getBrName();
final String vif = intf.getDevName();
final Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
cmd.add("post_default_network_rules");
cmd.add("--vmname", vmName);
cmd.add("--vmid", vmId.toString());
cmd.add("--vmip", nic.getIp());
cmd.add("--vmmac", nic.getMac());
cmd.add("--vif", vif);
cmd.add("--brname", brname);
if (dhcpServerIp != null) {
cmd.add("--dhcpSvr", dhcpServerIp.getHostAddress());
}
cmd.add("--hostIp", hostIp);
cmd.add("--hostMacAddr", hostMacAddr);
final String result = cmd.execute();
if (result != null) {
return false;
}
return true;
}
use of com.cloud.hypervisor.kvm.resource.LibvirtVmDef.InterfaceDef in project cloudstack by apache.
the class LibvirtComputingResource method getInterfaces.
public List<InterfaceDef> getInterfaces(final Connect conn, final String vmName) {
final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
Domain dm = null;
try {
dm = conn.domainLookupByName(vmName);
parser.parseDomainXML(dm.getXMLDesc(0));
return parser.getInterfaces();
} catch (final LibvirtException e) {
s_logger.debug("Failed to get dom xml: " + e.toString());
return new ArrayList<InterfaceDef>();
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
s_logger.trace("Ignoring libvirt error.", e);
}
}
}
Aggregations