use of com.cloud.agent.api.routing.DhcpEntryCommand in project CloudStack-archive by CloudStack-extras.
the class SimulatorManagerImpl method simulate.
@DB
@Override
public Answer simulate(Command cmd, String hostGuid) {
Transaction txn = Transaction.currentTxn();
txn.transitToUserManagedConnection(_concierge.conn());
try {
MockHost host = _mockHost.findByGuid(hostGuid);
String cmdName = cmd.toString();
int index = cmdName.lastIndexOf(".");
if (index != -1) {
cmdName = cmdName.substring(index + 1);
}
MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
SimulatorInfo info = new SimulatorInfo();
info.setHostUuid(hostGuid);
if (config != null) {
Map<String, String> configParameters = config.getParameters();
for (Map.Entry<String, String> entry : configParameters.entrySet()) {
if (entry.getKey().equalsIgnoreCase("enabled")) {
info.setEnabled(Boolean.parseBoolean(entry.getValue()));
} else if (entry.getKey().equalsIgnoreCase("timeout")) {
try {
info.setTimeout(Integer.valueOf(entry.getValue()));
} catch (NumberFormatException e) {
s_logger.debug("invalid timeout parameter: " + e.toString());
}
} else if (entry.getKey().equalsIgnoreCase("wait")) {
try {
int wait = Integer.valueOf(entry.getValue());
Thread.sleep(wait * 1000);
} catch (NumberFormatException e) {
s_logger.debug("invalid timeout parameter: " + e.toString());
} catch (InterruptedException e) {
s_logger.debug("thread is interrupted: " + e.toString());
}
}
}
}
if (cmd instanceof GetHostStatsCommand) {
return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
} else if (cmd instanceof CheckHealthCommand) {
return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
} else if (cmd instanceof PingTestCommand) {
return _mockAgentMgr.pingTest((PingTestCommand) cmd);
} else if (cmd instanceof MigrateCommand) {
return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
} else if (cmd instanceof StartCommand) {
return _mockVmMgr.startVM((StartCommand) cmd, info);
} else if (cmd instanceof CheckSshCommand) {
return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesCommand) {
return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
} else if (cmd instanceof NetworkUsageCommand) {
return _mockVmMgr.getNetworkUsage((NetworkUsageCommand) cmd);
} else if (cmd instanceof IpAssocCommand) {
return _mockVmMgr.IpAssoc((IpAssocCommand) cmd);
} else if (cmd instanceof LoadBalancerConfigCommand) {
return _mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
} else if (cmd instanceof DhcpEntryCommand) {
return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
} else if (cmd instanceof VmDataCommand) {
return _mockVmMgr.setVmData((VmDataCommand) cmd);
} else if (cmd instanceof CleanupNetworkRulesCmd) {
return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
} else if (cmd instanceof CheckNetworkCommand) {
return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
} else if (cmd instanceof StopCommand) {
return _mockVmMgr.stopVM((StopCommand) cmd);
} else if (cmd instanceof RebootCommand) {
return _mockVmMgr.rebootVM((RebootCommand) cmd);
} else if (cmd instanceof GetVncPortCommand) {
return _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof SecurityGroupRulesCmd) {
return _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
} else if (cmd instanceof SavePasswordCommand) {
return _mockVmMgr.SavePassword((SavePasswordCommand) cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof CreateCommand) {
return _mockStorageMgr.createVolume((CreateCommand) cmd);
} else if (cmd instanceof AttachVolumeCommand) {
return _mockStorageMgr.AttachVolume((AttachVolumeCommand) cmd);
} else if (cmd instanceof AttachIsoCommand) {
return _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
} else if (cmd instanceof DeleteStoragePoolCommand) {
return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
} else if (cmd instanceof ModifyStoragePoolCommand) {
return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
} else if (cmd instanceof CreateStoragePoolCommand) {
return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
} else if (cmd instanceof SecStorageSetupCommand) {
return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
} else if (cmd instanceof ListTemplateCommand) {
return _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
} else if (cmd instanceof DestroyCommand) {
return _mockStorageMgr.Destroy((DestroyCommand) cmd);
} else if (cmd instanceof DownloadProgressCommand) {
return _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
} else if (cmd instanceof DownloadCommand) {
return _mockStorageMgr.Download((DownloadCommand) cmd);
} else if (cmd instanceof GetStorageStatsCommand) {
return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
} else if (cmd instanceof ManageSnapshotCommand) {
return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
} else if (cmd instanceof DeleteSnapshotBackupCommand) {
return _mockStorageMgr.DeleteSnapshotBackup((DeleteSnapshotBackupCommand) cmd);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof DeleteTemplateCommand) {
return _mockStorageMgr.DeleteTemplate((DeleteTemplateCommand) cmd);
} else if (cmd instanceof SecStorageVMSetupCommand) {
return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof ComputeChecksumCommand) {
return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof MaintainCommand) {
return _mockAgentMgr.MaintainCommand((MaintainCommand) cmd);
} else if (cmd instanceof GetVmStatsCommand) {
return _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
} else if (cmd instanceof ClusterSyncCommand) {
return new Answer(cmd);
} else if (cmd instanceof CopyVolumeCommand) {
return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
} catch (Exception e) {
s_logger.debug("Failed execute cmd: " + e.toString());
txn.rollback();
return new Answer(cmd, false, e.toString());
} finally {
txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
}
}
use of com.cloud.agent.api.routing.DhcpEntryCommand in project cloudstack by apache.
the class VirtualRoutingResourceTest method generateDhcpEntryCommand2.
protected DhcpEntryCommand generateDhcpEntryCommand2() {
final DhcpEntryCommand cmd = new DhcpEntryCommand("12:34:56:78:90:AB", null, "vm1", "2001:db8:0:0:0:ff00:42:8329", true);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
cmd.setDuid(NetUtils.getDuidLL(cmd.getVmMac()));
return cmd;
}
use of com.cloud.agent.api.routing.DhcpEntryCommand in project cloudstack by apache.
the class VirtualRoutingResourceTest method generateDhcpEntryCommand1.
protected DhcpEntryCommand generateDhcpEntryCommand1() {
final DhcpEntryCommand cmd = new DhcpEntryCommand("12:34:56:78:90:AB", "10.1.10.2", "vm1", null, true);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
return cmd;
}
use of com.cloud.agent.api.routing.DhcpEntryCommand in project cloudstack by apache.
the class DhcpEntryConfigItem method generateConfig.
@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
final DhcpEntryCommand command = (DhcpEntryCommand) cmd;
final VmDhcpConfig vmDhcpConfig = new VmDhcpConfig(command.getVmName(), command.getVmMac(), command.getVmIpAddress(), command.getVmIp6Address(), command.getDuid(), command.getDefaultDns(), command.getDefaultRouter(), command.getStaticRoutes(), command.isDefault(), command.isRemove());
return generateConfigItems(vmDhcpConfig);
}
use of com.cloud.agent.api.routing.DhcpEntryCommand in project cloudstack by apache.
the class BaremetalDhcpManagerImpl method addVirtualMachineIntoNetwork.
@Override
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
Long zoneId = profile.getVirtualMachine().getDataCenterId();
Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
if (hosts.size() == 0) {
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
}
if (hosts.size() > 1) {
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
}
HostVO h = hosts.get(0);
String dns = nic.getIPv4Dns1();
if (dns == null) {
dns = nic.getIPv4Dns2();
}
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd());
String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
// prepareBareMetalDhcpEntry(nic, dhcpCommand);
try {
Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
if (ans.getResult()) {
s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
return true;
} else {
s_logger.debug(errMsg + " " + ans.getDetails());
throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
}
} catch (Exception e) {
s_logger.debug(errMsg, e);
throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
}
}
Aggregations