mirror of https://github.com/apache/cloudstack.git
Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss
This commit is contained in:
commit
5411e6d91f
|
|
@ -12,5 +12,6 @@
|
|||
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/libvirt-0.4.5.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import javax.ejb.Local;
|
|||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.libvirt.Connect;
|
||||
import org.libvirt.Domain;
|
||||
import org.libvirt.DomainInfo;
|
||||
|
|
@ -78,6 +79,7 @@ import com.cloud.agent.api.CheckHealthCommand;
|
|||
import com.cloud.agent.api.CheckStateCommand;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||
|
|
@ -104,16 +106,17 @@ import com.cloud.agent.api.ManageSnapshotAnswer;
|
|||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.MigrateAnswer;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.MirrorCommand;
|
||||
import com.cloud.agent.api.ModifySshKeysCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
|
||||
import com.cloud.agent.api.NetworkUsageAnswer;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.PingRoutingCommand;
|
||||
import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.ReadyAnswer;
|
||||
import com.cloud.agent.api.ReadyCommand;
|
||||
|
|
@ -165,8 +168,9 @@ import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
|
|||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.RouterPrivateIpStrategy;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.ServerResourceBase;
|
||||
|
|
@ -798,8 +802,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
return execute((GetHostStatsCommand)cmd);
|
||||
} else if (cmd instanceof CheckStateCommand) {
|
||||
return executeRequest(cmd);
|
||||
} else if (cmd instanceof MirrorCommand) {
|
||||
return executeRequest(cmd);
|
||||
} else if (cmd instanceof CheckHealthCommand) {
|
||||
return execute((CheckHealthCommand)cmd);
|
||||
} else if (cmd instanceof PrepareForMigrationCommand) {
|
||||
|
|
@ -866,6 +868,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
return execute((CheckSshCommand) cmd);
|
||||
} else if (cmd instanceof NetworkUsageCommand) {
|
||||
return execute((NetworkUsageCommand) cmd);
|
||||
} else if (cmd instanceof NetworkRulesSystemVmCommand) {
|
||||
return execute((NetworkRulesSystemVmCommand)cmd);
|
||||
} else if (cmd instanceof CleanupNetworkRulesCmd) {
|
||||
return execute((CleanupNetworkRulesCmd)cmd);
|
||||
} else {
|
||||
s_logger.warn("Unsupported command ");
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
|
|
@ -887,7 +893,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
}
|
||||
|
||||
KVMHABase.NfsStoragePool sp = new KVMHABase.NfsStoragePool(cmd.getPool().getUuid(),
|
||||
cmd.getPool().getHostAddress(),
|
||||
cmd.getPool().getHost(),
|
||||
cmd.getPool().getPath(),
|
||||
_mountPoint + File.separator + cmd.getPool().getUuid(),
|
||||
PoolType.PrimaryStorage);
|
||||
|
|
@ -1083,7 +1089,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
String result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to backup snaptshot: " + result);
|
||||
return new BackupSnapshotAnswer(cmd, false, result, null);
|
||||
return new BackupSnapshotAnswer(cmd, false, result, null, true);
|
||||
}
|
||||
/*Delete the snapshot on primary*/
|
||||
|
||||
|
|
@ -1119,15 +1125,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
result = command.execute();
|
||||
if (result != null) {
|
||||
s_logger.debug("Failed to backup snapshot: " + result);
|
||||
return new BackupSnapshotAnswer(cmd, false, "Failed to backup snapshot: " + result, null);
|
||||
return new BackupSnapshotAnswer(cmd, false, "Failed to backup snapshot: " + result, null, true);
|
||||
}
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
return new BackupSnapshotAnswer(cmd, false, e.toString(), null);
|
||||
return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
|
||||
} catch (URISyntaxException e) {
|
||||
return new BackupSnapshotAnswer(cmd, false, e.toString(), null);
|
||||
return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
|
||||
}
|
||||
return new BackupSnapshotAnswer(cmd, true, null, snapshotDestPath + File.separator + snapshotName);
|
||||
return new BackupSnapshotAnswer(cmd, true, null, snapshotDestPath + File.separator + snapshotName, true);
|
||||
}
|
||||
|
||||
protected DeleteSnapshotBackupAnswer execute(final DeleteSnapshotBackupCommand cmd) {
|
||||
|
|
@ -1571,6 +1577,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
}
|
||||
}
|
||||
|
||||
private Answer execute(CleanupNetworkRulesCmd cmd) {
|
||||
boolean result = cleanup_rules();
|
||||
return new Answer(cmd, result, "");
|
||||
}
|
||||
|
||||
protected GetVncPortAnswer execute(GetVncPortCommand cmd) {
|
||||
try {
|
||||
Connect conn = LibvirtConnection.getConnection();
|
||||
|
|
@ -1725,6 +1736,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
_vms.put(cmd.getVmName(), State.Running);
|
||||
}
|
||||
}
|
||||
|
||||
return new CheckVirtualMachineAnswer(cmd, state, vncPort);
|
||||
} catch (LibvirtException e) {
|
||||
return new CheckVirtualMachineAnswer(cmd, e.getMessage());
|
||||
|
|
@ -1816,26 +1828,44 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
}
|
||||
|
||||
private synchronized Answer execute(PrepareForMigrationCommand cmd) {
|
||||
// final String vmName = cmd.getVmName();
|
||||
// String result = null;
|
||||
//
|
||||
// if (cmd.getVnet() != null && !isDirectAttachedNetwork(cmd.getVnet())) {
|
||||
// final String vnet = getVnetId(cmd.getVnet());
|
||||
// if (vnet != null) {
|
||||
// try {
|
||||
// createVnet(vnet, _pifs.first()); /*TODO: Need to add public network for domR*/
|
||||
// } catch (InternalErrorException e) {
|
||||
// return new PrepareForMigrationAnswer(cmd, false, result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// synchronized(_vms) {
|
||||
// _vms.put(vmName, State.Migrating);
|
||||
// }
|
||||
//
|
||||
// return new PrepareForMigrationAnswer(cmd, result == null, result);
|
||||
return null;
|
||||
|
||||
VirtualMachineTO vm = cmd.getVirtualMachine();
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Preparing host for migrating " + vm);
|
||||
}
|
||||
|
||||
NicTO[] nics = vm.getNics();
|
||||
try {
|
||||
Connect conn = LibvirtConnection.getConnection();
|
||||
for (NicTO nic : nics) {
|
||||
String vlanId = null;
|
||||
if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
|
||||
URI broadcastUri = nic.getBroadcastUri();
|
||||
vlanId = broadcastUri.getHost();
|
||||
}
|
||||
if (nic.getType() == TrafficType.Guest) {
|
||||
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")){
|
||||
createVlanBr(vlanId, _pifs.first());
|
||||
}
|
||||
} else if (nic.getType() == TrafficType.Control) {
|
||||
/*Make sure the network is still there*/
|
||||
createControlNetwork(conn);
|
||||
} else if (nic.getType() == TrafficType.Public) {
|
||||
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
|
||||
createVlanBr(vlanId, _pifs.second());
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (_vms) {
|
||||
_vms.put(vm.getName(), State.Migrating);
|
||||
}
|
||||
|
||||
return new PrepareForMigrationAnswer(cmd);
|
||||
} catch (LibvirtException e) {
|
||||
return new PrepareForMigrationAnswer(cmd, e.toString());
|
||||
} catch (InternalErrorException e) {
|
||||
return new PrepareForMigrationAnswer(cmd, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void createVnet(String vnetId, String pif) throws InternalErrorException {
|
||||
|
|
@ -2207,7 +2237,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
if (vmSpec.getType() != VirtualMachine.Type.User) {
|
||||
default_network_rules_for_systemvm(vmName);
|
||||
} else {
|
||||
default_network_rules(vmName, vmSpec.getNics()[0].getIp(), vmSpec.getId(), vmSpec.getNics()[0].getMac());
|
||||
NicTO[] nics = vmSpec.getNics();
|
||||
for (NicTO nic : nics) {
|
||||
if (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
|
||||
default_network_rules(vmName, vmSpec.getNics()[0].getIp(), vmSpec.getId(), vmSpec.getNics()[0].getMac());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attach each data volume to the VM, if there is a deferred attached disk
|
||||
|
|
@ -2220,8 +2255,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
return new StartAnswer(cmd);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Exception ", e);
|
||||
if (conn != null)
|
||||
handleVmStartFailure(conn, vmName, vm);
|
||||
if (conn != null) {
|
||||
handleVmStartFailure(conn, vmName, vm);
|
||||
}
|
||||
return new StartAnswer(cmd, e.getMessage());
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
|
|
@ -3472,6 +3508,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean cleanup_rules() {
|
||||
if (!_can_bridge_firewall) {
|
||||
return false;
|
||||
}
|
||||
Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
|
||||
cmd.add("cleanup_rules");
|
||||
String result = cmd.execute();
|
||||
if (result != null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String get_rule_logs_for_vms() {
|
||||
Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
|
||||
cmd.add("get_rule_logs_for_vms");
|
||||
|
|
@ -3575,4 +3624,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
private Answer execute(NetworkRulesSystemVmCommand cmd) {
|
||||
boolean success = false;
|
||||
if (cmd.getType() != VirtualMachine.Type.User) {
|
||||
success = default_network_rules_for_systemvm(cmd.getVmName());
|
||||
}
|
||||
|
||||
return new Answer(cmd, success, "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@
|
|||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
|
||||
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
|||
|
|
@ -20,14 +20,16 @@ package com.cloud.agent.api;
|
|||
|
||||
public class BackupSnapshotAnswer extends Answer {
|
||||
private String backupSnapshotName;
|
||||
private boolean full;
|
||||
|
||||
protected BackupSnapshotAnswer() {
|
||||
|
||||
}
|
||||
|
||||
public BackupSnapshotAnswer(BackupSnapshotCommand cmd, boolean success, String result, String backupSnapshotName) {
|
||||
public BackupSnapshotAnswer(BackupSnapshotCommand cmd, boolean success, String result, String backupSnapshotName, boolean full) {
|
||||
super(cmd, success, result);
|
||||
this.backupSnapshotName = backupSnapshotName;
|
||||
this.full = full;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,4 +38,8 @@ public class BackupSnapshotAnswer extends Answer {
|
|||
public String getBackupSnapshotName() {
|
||||
return backupSnapshotName;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return full;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.agent.api.to.HostTO;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Host;
|
||||
|
||||
public class CheckOnHostCommand extends Command {
|
||||
HostTO host;
|
||||
|
|
@ -27,7 +27,7 @@ public class CheckOnHostCommand extends Command {
|
|||
}
|
||||
|
||||
|
||||
public CheckOnHostCommand(HostVO host) {
|
||||
public CheckOnHostCommand(Host host) {
|
||||
this.host = new HostTO(host);
|
||||
}
|
||||
|
||||
|
|
@ -21,34 +21,34 @@ package com.cloud.agent.api;
|
|||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
public class DeleteStoragePoolCommand extends Command {
|
||||
|
||||
StoragePoolVO pool;
|
||||
StorageFilerTO pool;
|
||||
public static final String LOCAL_PATH_PREFIX="/mnt/";
|
||||
String localPath;
|
||||
|
||||
|
||||
public DeleteStoragePoolCommand() {
|
||||
|
||||
}
|
||||
|
||||
public DeleteStoragePoolCommand(StoragePoolVO pool, String localPath) {
|
||||
this.pool = new StoragePoolVO(pool);
|
||||
public DeleteStoragePoolCommand(StoragePool pool, String localPath) {
|
||||
this.pool = new StorageFilerTO(pool);
|
||||
this.localPath = localPath;
|
||||
}
|
||||
|
||||
public DeleteStoragePoolCommand(StoragePoolVO pool) {
|
||||
this(new StoragePoolVO(pool), LOCAL_PATH_PREFIX + File.separator + UUID.nameUUIDFromBytes((pool.getHostAddress() + pool.getPath()).getBytes()));
|
||||
public DeleteStoragePoolCommand(StoragePool pool) {
|
||||
this(pool, LOCAL_PATH_PREFIX + File.separator + UUID.nameUUIDFromBytes((pool.getHostAddress() + pool.getPath()).getBytes()));
|
||||
}
|
||||
|
||||
public StoragePoolVO getPool() {
|
||||
public StorageFilerTO getPool() {
|
||||
return pool;
|
||||
}
|
||||
|
||||
public void setPool(StoragePoolVO pool) {
|
||||
this.pool = new StoragePoolVO(pool);
|
||||
public void setPool(StoragePool pool) {
|
||||
this.pool = new StorageFilerTO(pool);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
public class FenceCommand extends Command {
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ public class FenceCommand extends Command {
|
|||
String hostGuid;
|
||||
String hostIp;
|
||||
|
||||
public FenceCommand(VMInstanceVO vm, HostVO host) {
|
||||
public FenceCommand(VirtualMachine vm, Host host) {
|
||||
super();
|
||||
vmName = vm.getInstanceName();
|
||||
hostGuid = host.getGuid();
|
||||
|
|
@ -21,6 +21,7 @@ package com.cloud.agent.api;
|
|||
public class NetworkUsageCommand extends Command {
|
||||
private String privateIP;
|
||||
private String domRName;
|
||||
private String option;
|
||||
|
||||
protected NetworkUsageCommand() {
|
||||
|
||||
|
|
@ -31,6 +32,13 @@ public class NetworkUsageCommand extends Command {
|
|||
this.privateIP = privateIP;
|
||||
this.domRName = domRName;
|
||||
}
|
||||
|
||||
public NetworkUsageCommand(String privateIP, String domRName, String option)
|
||||
{
|
||||
this.privateIP = privateIP;
|
||||
this.domRName = domRName;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public String getPrivateIP() {
|
||||
return privateIP;
|
||||
|
|
@ -40,6 +48,10 @@ public class NetworkUsageCommand extends Command {
|
|||
return domRName;
|
||||
}
|
||||
|
||||
public String getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (C) 2010 Cloud.com. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later
|
||||
version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
|
||||
public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand {
|
||||
HashMap<String, Pair<Long, Long>> newGroupStates;
|
||||
|
||||
protected PingRoutingWithNwGroupsCommand() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, State> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
|
||||
super(type, id, states);
|
||||
newGroupStates = nwGrpStates;
|
||||
}
|
||||
|
||||
public HashMap<String, Pair<Long, Long>> getNewGroupStates() {
|
||||
return newGroupStates;
|
||||
}
|
||||
|
||||
public void setNewGroupStates(HashMap<String, Pair<Long, Long>> newGroupStates) {
|
||||
this.newGroupStates = newGroupStates;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,7 @@
|
|||
*/
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
|
||||
public class PrepareForMigrationCommand extends StartCommand {
|
||||
|
||||
|
|
@ -31,10 +28,6 @@ public class PrepareForMigrationCommand extends StartCommand {
|
|||
super(vm);
|
||||
}
|
||||
|
||||
public PrepareForMigrationCommand(String vmName, String vnet, String[] storageHosts, List<VolumeVO> vols, boolean mirrored) {
|
||||
//super(vmName, storageHosts, vols, mirrored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
|
|
@ -18,74 +18,17 @@
|
|||
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.transport.Request;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class SecStorageFirewallCfgCommand extends Command {
|
||||
private static final Logger s_logger = Logger.getLogger(SecStorageFirewallCfgCommand.class);
|
||||
|
||||
|
||||
public static class PortConfigListTypeAdaptor implements JsonDeserializer<List<PortConfig>>, JsonSerializer<List<PortConfig>> {
|
||||
static final GsonBuilder s_gBuilder;
|
||||
static {
|
||||
s_gBuilder = Request.initBuilder();
|
||||
}
|
||||
|
||||
static final Type listType = new TypeToken<List<PortConfig>>() {}.getType();
|
||||
|
||||
public PortConfigListTypeAdaptor() {
|
||||
}
|
||||
|
||||
public JsonElement serialize(List<PortConfig> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src.size() == 0) {
|
||||
s_logger.info("Returning JsonNull");
|
||||
return new JsonNull();
|
||||
}
|
||||
Gson json = s_gBuilder.create();
|
||||
s_logger.debug("Returning gson tree");
|
||||
JsonArray array = new JsonArray();
|
||||
for (PortConfig pc : src) {
|
||||
array.add(json.toJsonTree(pc));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public List<PortConfig> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
if (json.isJsonNull()) {
|
||||
return new ArrayList<PortConfig>();
|
||||
}
|
||||
Gson jsonp = s_gBuilder.create();
|
||||
List<PortConfig> pcs = new ArrayList<PortConfig>();
|
||||
JsonArray array = json.getAsJsonArray();
|
||||
Iterator<JsonElement> it = array.iterator();
|
||||
while (it.hasNext()) {
|
||||
JsonElement element = it.next();
|
||||
pcs.add(jsonp.fromJson(element, PortConfig.class));
|
||||
}
|
||||
return pcs;
|
||||
}
|
||||
|
||||
}
|
||||
public static class PortConfig {
|
||||
@Expose boolean add;
|
||||
@Expose String sourceIp;
|
||||
|
|
@ -20,7 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.NetworkEnums.RouterPrivateIpStrategy;
|
||||
import com.cloud.network.Networks.RouterPrivateIpStrategy;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public class StartupRoutingCommand extends StartupCommand {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue