use of com.cloud.agent.api.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.
the class SecondaryStorageManagerImpl method generateFirewallConfiguration.
@Override
public boolean generateFirewallConfiguration(final Long ssAHostId) {
if (ssAHostId == null) {
return true;
}
final HostVO ssAHost = _hostDao.findById(ssAHostId);
final SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
if (thisSecStorageVm == null) {
logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
return false;
}
final String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
final SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
final List<HostVO> ssvms = sc.list();
for (final HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
final Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
if (answer != null && answer.getResult()) {
logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
} else {
logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
return false;
}
}
final SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
for (final HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
}
final Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
if (answer != null && answer.getResult()) {
logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
} else {
logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
return false;
}
return true;
}
use of com.cloud.agent.api.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.
the class RequestTest method testSerDeser.
@Test
@Ignore
public void testSerDeser() {
s_logger.info("Testing serializing and deserializing works as expected");
s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging");
final UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
final SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
s_logger.info("GetHostStatsCommand should not show up at all in debug level");
final GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
cmd2.addPortConfig("abc", "24", true, "eth0");
cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
final Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
sreq.setSequence(892403717);
final Logger logger = LoggerFactory.getLogger(GsonHelper.class);
// logger.setLevel(Level.DEBUG);
String log = sreq.log("Debug", true);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
// logger.setLevel(Level.TRACE);
log = sreq.log("Trace", true);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
// logger.setLevel(Level.INFO);
log = sreq.log("Info", true);
assert (log == null);
// logger.setLevel(level);
byte[] bytes = sreq.getBytes();
assert Request.getSequence(bytes) == 892403717;
assert Request.getManagementServerId(bytes) == 3;
assert Request.getAgentId(bytes) == 2;
assert Request.getViaAgentId(bytes) == 2;
Request creq = null;
try {
creq = Request.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert creq != null : "Couldn't get the request back";
compareRequest(creq, sreq);
final Answer ans = new Answer(cmd1, true, "No Problem");
final Response cresp = new Response(creq, ans);
bytes = cresp.getBytes();
Response sresp = null;
try {
sresp = Response.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert sresp != null : "Couldn't get the response back";
compareRequest(cresp, sresp);
}
use of com.cloud.agent.api.SecStorageFirewallCfgCommand in project cloudstack by apache.
the class RequestTest method testSerDeser.
public void testSerDeser() {
s_logger.info("Testing serializing and deserializing works as expected");
s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging");
UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
s_logger.info("GetHostStatsCommand should not show up at all in debug level");
GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
cmd2.addPortConfig("abc", "24", true, "eth0");
cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
sreq.setSequence(892403717);
Logger logger = Logger.getLogger(GsonHelper.class);
Level level = logger.getLevel();
logger.setLevel(Level.DEBUG);
String log = sreq.log("Debug", true, Level.DEBUG);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
logger.setLevel(Level.TRACE);
log = sreq.log("Trace", true, Level.TRACE);
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
assert (!log.contains("username"));
assert (!log.contains("password"));
logger.setLevel(Level.INFO);
log = sreq.log("Info", true, Level.INFO);
assert (log == null);
logger.setLevel(level);
byte[] bytes = sreq.getBytes();
assert Request.getSequence(bytes) == 892403717;
assert Request.getManagementServerId(bytes) == 3;
assert Request.getAgentId(bytes) == 2;
assert Request.getViaAgentId(bytes) == 2;
Request creq = null;
try {
creq = Request.parse(bytes);
} catch (ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert creq != null : "Couldn't get the request back";
compareRequest(creq, sreq);
Answer ans = new Answer(cmd1, true, "No Problem");
Response cresp = new Response(creq, ans);
bytes = cresp.getBytes();
Response sresp = null;
try {
sresp = Response.parse(bytes);
} catch (ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert sresp != null : "Couldn't get the response back";
compareRequest(cresp, sresp);
}
use of com.cloud.agent.api.SecStorageFirewallCfgCommand in project cloudstack by apache.
the class SimulatorManagerImpl method simulate.
@DB
@Override
public Answer simulate(final Command cmd, final String hostGuid) {
s_logger.debug("Simulate command " + cmd);
Answer answer = null;
Exception exception = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
final MockHost host = _mockHost.findByGuid(hostGuid);
String cmdName = cmd.toString();
final int index = cmdName.lastIndexOf(".");
if (index != -1) {
cmdName = cmdName.substring(index + 1);
}
final SimulatorInfo info = new SimulatorInfo();
info.setHostUuid(hostGuid);
final MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
if (config != null && (config.getCount() == null || config.getCount().intValue() > 0)) {
final Map<String, String> configParameters = config.getParameters();
for (final 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 (final NumberFormatException e) {
s_logger.debug("invalid timeout parameter: " + e.toString());
}
}
if (entry.getKey().equalsIgnoreCase("wait")) {
try {
final int wait = Integer.valueOf(entry.getValue());
Thread.sleep(wait);
} catch (final NumberFormatException e) {
s_logger.debug("invalid wait parameter: " + e.toString());
} catch (final InterruptedException e) {
s_logger.debug("thread is interrupted: " + e.toString());
}
}
if (entry.getKey().equalsIgnoreCase("result")) {
final String value = entry.getValue();
if (value.equalsIgnoreCase("fail")) {
answer = new Answer(cmd, false, "Simulated failure");
} else if (value.equalsIgnoreCase("fault")) {
exception = new Exception("Simulated fault");
}
}
}
if (exception != null) {
throw exception;
}
if (answer == null) {
final String message = config.getJsonResponse();
if (message != null) {
// json response looks like {"<Type>":....}
final String objectType = message.split(":")[0].substring(2).replace("\"", "");
final String objectData = message.substring(message.indexOf(':') + 1, message.length() - 1);
if (objectType != null) {
Class<?> clz = null;
try {
clz = Class.forName(objectType);
} catch (final ClassNotFoundException e) {
}
if (clz != null) {
final StringReader reader = new StringReader(objectData);
final JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
answer = (Answer) s_gson.fromJson(jsonReader, clz);
}
}
}
}
}
if (answer == null) {
if (cmd instanceof GetHostStatsCommand) {
answer = _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
} else if (cmd instanceof CheckHealthCommand) {
answer = _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
} else if (cmd instanceof PingTestCommand) {
answer = _mockAgentMgr.pingTest((PingTestCommand) cmd);
} else if (cmd instanceof SetupKeyStoreCommand) {
answer = _mockAgentMgr.setupKeyStore((SetupKeyStoreCommand) cmd);
} else if (cmd instanceof DiagnosticsCommand) {
answer = _mockAgentMgr.runDiagnostics((DiagnosticsCommand) cmd);
} else if (cmd instanceof SetupCertificateCommand) {
answer = _mockAgentMgr.setupCertificate((SetupCertificateCommand) cmd);
} else if (cmd instanceof PrepareForMigrationCommand) {
answer = _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
} else if (cmd instanceof MigrateCommand) {
answer = _mockVmMgr.migrate((MigrateCommand) cmd, info);
} else if (cmd instanceof StartCommand) {
answer = _mockVmMgr.startVM((StartCommand) cmd, info);
} else if (cmd instanceof CheckSshCommand) {
answer = _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
} else if (cmd instanceof CheckVirtualMachineCommand) {
answer = _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
answer = _mockNetworkMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof SetFirewallRulesCommand) {
answer = _mockNetworkMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesCommand) {
answer = _mockNetworkMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
} else if (cmd instanceof NetworkUsageCommand) {
answer = _mockNetworkMgr.getNetworkUsage((NetworkUsageCommand) cmd);
} else if (cmd instanceof IpAssocCommand) {
answer = _mockNetworkMgr.IpAssoc((IpAssocCommand) cmd);
} else if (cmd instanceof LoadBalancerConfigCommand) {
answer = _mockNetworkMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
} else if (cmd instanceof DhcpEntryCommand) {
answer = _mockNetworkMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
} else if (cmd instanceof VmDataCommand) {
answer = _mockVmMgr.setVmData((VmDataCommand) cmd);
} else if (cmd instanceof CleanupNetworkRulesCmd) {
answer = _mockVmMgr.cleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
} else if (cmd instanceof CheckNetworkCommand) {
answer = _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
} else if (cmd instanceof StopCommand) {
answer = _mockVmMgr.stopVM((StopCommand) cmd);
} else if (cmd instanceof RebootCommand) {
answer = _mockVmMgr.rebootVM((RebootCommand) cmd);
} else if (cmd instanceof GetVncPortCommand) {
answer = _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
answer = _mockVmMgr.checkConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
answer = _mockVmMgr.watchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof SecurityGroupRulesCmd) {
answer = _mockVmMgr.addSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
} else if (cmd instanceof SavePasswordCommand) {
answer = _mockVmMgr.savePassword((SavePasswordCommand) cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
answer = _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof CreateCommand) {
answer = _mockStorageMgr.createVolume((CreateCommand) cmd);
} else if (cmd instanceof AttachIsoCommand) {
answer = _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
} else if (cmd instanceof DeleteStoragePoolCommand) {
answer = _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
} else if (cmd instanceof ModifyStoragePoolCommand) {
answer = _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
} else if (cmd instanceof CreateStoragePoolCommand) {
answer = _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
} else if (cmd instanceof SecStorageSetupCommand) {
answer = _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
} else if (cmd instanceof ListTemplateCommand) {
answer = _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
} else if (cmd instanceof ListVolumeCommand) {
answer = _mockStorageMgr.ListVolumes((ListVolumeCommand) cmd);
} else if (cmd instanceof DestroyCommand) {
answer = _mockStorageMgr.Destroy((DestroyCommand) cmd);
} else if (cmd instanceof DownloadProgressCommand) {
answer = _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
} else if (cmd instanceof DownloadCommand) {
answer = _mockStorageMgr.Download((DownloadCommand) cmd);
} else if (cmd instanceof GetStorageStatsCommand) {
answer = _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
} else if (cmd instanceof GetVolumeStatsCommand) {
answer = _mockStorageMgr.getVolumeStats((GetVolumeStatsCommand) cmd);
} else if (cmd instanceof ManageSnapshotCommand) {
answer = _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
answer = _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
answer = _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof DeleteCommand) {
answer = _mockStorageMgr.Delete((DeleteCommand) cmd);
} else if (cmd instanceof SecStorageVMSetupCommand) {
answer = _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
answer = _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof ComputeChecksumCommand) {
answer = _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
answer = _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof UploadStatusCommand) {
answer = _mockStorageMgr.getUploadStatus((UploadStatusCommand) cmd);
} else if (cmd instanceof MaintainCommand) {
answer = _mockAgentMgr.maintain((MaintainCommand) cmd);
} else if (cmd instanceof GetVmStatsCommand) {
answer = _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
} else if (cmd instanceof CheckRouterCommand) {
answer = _mockVmMgr.checkRouter((CheckRouterCommand) cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
answer = _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
} else if (cmd instanceof CopyVolumeCommand) {
answer = _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
} else if (cmd instanceof PlugNicCommand) {
answer = _mockNetworkMgr.plugNic((PlugNicCommand) cmd);
} else if (cmd instanceof UnPlugNicCommand) {
answer = _mockNetworkMgr.unplugNic((UnPlugNicCommand) cmd);
} else if (cmd instanceof ReplugNicCommand) {
answer = _mockNetworkMgr.replugNic((ReplugNicCommand) cmd);
} else if (cmd instanceof IpAssocVpcCommand) {
answer = _mockNetworkMgr.ipAssoc((IpAssocVpcCommand) cmd);
} else if (cmd instanceof SetSourceNatCommand) {
answer = _mockNetworkMgr.setSourceNat((SetSourceNatCommand) cmd);
} else if (cmd instanceof SetNetworkACLCommand) {
answer = _mockNetworkMgr.setNetworkAcl((SetNetworkACLCommand) cmd);
} else if (cmd instanceof SetupGuestNetworkCommand) {
answer = _mockNetworkMgr.setUpGuestNetwork((SetupGuestNetworkCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesVpcCommand) {
answer = _mockNetworkMgr.setVpcPortForwards((SetPortForwardingRulesVpcCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
answer = _mockNetworkMgr.setVPCStaticNatRules((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof SetStaticRouteCommand) {
answer = _mockNetworkMgr.setStaticRoute((SetStaticRouteCommand) cmd);
} else if (cmd instanceof Site2SiteVpnCfgCommand) {
answer = _mockNetworkMgr.siteToSiteVpn((Site2SiteVpnCfgCommand) cmd);
} else if (cmd instanceof CheckS2SVpnConnectionsCommand) {
answer = _mockNetworkMgr.checkSiteToSiteVpnConnection((CheckS2SVpnConnectionsCommand) cmd);
} else if (cmd instanceof CreateVMSnapshotCommand) {
answer = _mockVmMgr.createVmSnapshot((CreateVMSnapshotCommand) cmd);
} else if (cmd instanceof DeleteVMSnapshotCommand) {
answer = _mockVmMgr.deleteVmSnapshot((DeleteVMSnapshotCommand) cmd);
} else if (cmd instanceof RevertToVMSnapshotCommand) {
answer = _mockVmMgr.revertVmSnapshot((RevertToVMSnapshotCommand) cmd);
} else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) {
answer = _mockVmMgr.plugSecondaryIp((NetworkRulesVmSecondaryIpCommand) cmd);
} else if (cmd instanceof ScaleVmCommand) {
answer = _mockVmMgr.scaleVm((ScaleVmCommand) cmd);
} else if (cmd instanceof PvlanSetupCommand) {
answer = _mockNetworkMgr.setupPVLAN((PvlanSetupCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
answer = storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (cmd instanceof FenceCommand) {
answer = _mockVmMgr.fence((FenceCommand) cmd);
} else if (cmd instanceof HandleConfigDriveIsoCommand) {
answer = _mockStorageMgr.handleConfigDriveIso((HandleConfigDriveIsoCommand) cmd);
} else if (cmd instanceof GetRouterAlertsCommand || cmd instanceof VpnUsersCfgCommand || cmd instanceof RemoteAccessVpnCfgCommand || cmd instanceof SetMonitorServiceCommand || cmd instanceof AggregationControlCommand || cmd instanceof SecStorageFirewallCfgCommand) {
answer = new Answer(cmd);
} else {
s_logger.error("Simulator does not implement command of type " + cmd.toString());
answer = Answer.createUnsupportedCommandAnswer(cmd);
}
}
if (config != null && config.getCount() != null && config.getCount().intValue() > 0) {
if (answer != null) {
config.setCount(config.getCount().intValue() - 1);
_mockConfigDao.update(config.getId(), config);
}
}
s_logger.debug("Finished simulate command " + cmd);
return answer;
} catch (final Exception e) {
s_logger.error("Failed execute cmd: ", e);
txn.rollback();
return new Answer(cmd, false, e.toString());
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.agent.api.SecStorageFirewallCfgCommand in project cloudstack by apache.
the class SecondaryStorageManagerImpl method generateFirewallConfiguration.
@Override
public boolean generateFirewallConfiguration(Long ssAHostId) {
if (ssAHostId == null) {
return true;
}
HostVO ssAHost = _hostDao.findById(ssAHostId);
String hostName = ssAHost.getName();
SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(hostName);
if (thisSecStorageVm == null) {
s_logger.warn(String.format("Secondary storage VM [%s] does not exist.", hostName));
return false;
}
String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
List<HostVO> ssvms = sc.list();
for (HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
hostName = ssvm.getName();
Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Successfully created firewall rules into secondary storage VM [%s].", hostName));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Failed to create firewall rules into secondary storage VM [%s].", hostName));
}
return false;
}
}
SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
for (HostVO ssvm : ssvms) {
if (ssvm.getId() == ssAHostId) {
continue;
}
allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
}
hostName = thisSecStorageVm.getHostName();
Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Successfully created firewall rules into secondary storage VM [%s].", hostName));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Failed to create firewall rules into secondary storage VM [%s] due to [%s].", hostName, answer == null ? "answer null" : answer.getDetails()));
}
return false;
}
return true;
}
Aggregations