Skip to content

Commit fb389e8

Browse files
author
Alex Huang
committed
Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss
2 parents 20b2608 + 55e4253 commit fb389e8

14 files changed

Lines changed: 157 additions & 54 deletions

File tree

‎api/src/com/cloud/storage/Volume.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ enum State {
3737
Destroyed
3838
}
3939

40+
enum SourceType {
41+
Snapshot,DiskOffering,Template,Blank
42+
}
4043
/**
4144
* @return the volume name
4245
*/
@@ -75,4 +78,12 @@ enum State {
7578
Long getPoolId();
7679

7780
State getState();
81+
82+
SourceType getSourceType();
83+
84+
void setSourceType(SourceType sourceType);
85+
86+
void setSourceId(Long sourceId);
87+
88+
Long getSourceId();
7889
}

‎client/tomcatconf/components.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149

150150
<adapters key="com.cloud.resource.Discoverer">
151151
<adapter name="SecondaryStorage" class="com.cloud.storage.secondary.SecondaryStorageDiscoverer"/>
152+
<adapter name="XCP Agent" class="com.cloud.hypervisor.xen.discoverer.XcpServerDiscoverer"/>
152153
<adapter name="KVM Agent" class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer"/>
153154
</adapters>
154155

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,9 +3491,25 @@ protected boolean patchspecialvm(String vmname, String device, String vmtype) {
34913491

34923492
protected String callHostPlugin(String plugin, String cmd, String... params) {
34933493
Map<String, String> args = new HashMap<String, String>();
3494+
Session slaveSession = null;
3495+
Connection slaveConn = null;
34943496
try {
3495-
Connection conn = getConnection();
3496-
Host host = Host.getByUuid(conn, _host.uuid);
3497+
URL slaveUrl = null;
3498+
try {
3499+
slaveUrl = new URL("http://" + _host.ip);
3500+
} catch (MalformedURLException e) {
3501+
// TODO Auto-generated catch block
3502+
e.printStackTrace();
3503+
}
3504+
slaveConn = new Connection(slaveUrl, 10);
3505+
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
3506+
3507+
if (s_logger.isDebugEnabled()) {
3508+
s_logger.debug("Slave logon successful. session= " + slaveSession);
3509+
}
3510+
Host host = Host.getByUuid(slaveConn, _host.uuid);
3511+
3512+
34973513
for (int i = 0; i < params.length; i += 2) {
34983514
args.put(params[i], params[i + 1]);
34993515
}
@@ -3502,7 +3518,7 @@ protected String callHostPlugin(String plugin, String cmd, String... params) {
35023518
s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
35033519
}
35043520

3505-
String result = host.callPlugin(conn, plugin, cmd, args);
3521+
String result = host.callPlugin(slaveConn, plugin, cmd, args);
35063522
if (s_logger.isTraceEnabled()) {
35073523
s_logger.trace("callHostPlugin Result: " + result);
35083524
}
@@ -3511,6 +3527,13 @@ protected String callHostPlugin(String plugin, String cmd, String... params) {
35113527
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString());
35123528
} catch (XmlRpcException e) {
35133529
s_logger.debug("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage());
3530+
} finally {
3531+
if( slaveSession != null) {
3532+
try {
3533+
slaveSession.localLogout(slaveConn);
3534+
} catch (Exception e) {
3535+
}
3536+
}
35143537
}
35153538
return null;
35163539
}
@@ -3979,6 +4002,10 @@ protected void getPVISO(StartupStorageCommand sscmd) {
39794002
s_logger.debug("Can't get xs-tools.iso: " + e.toString());
39804003
}
39814004
}
4005+
4006+
protected boolean can_bridge_firewall() {
4007+
return false;
4008+
}
39824009

39834010
protected boolean getHostInfo() throws IllegalArgumentException{
39844011
Connection conn = getConnection();
@@ -3998,7 +4025,7 @@ protected boolean getHostInfo() throws IllegalArgumentException{
39984025
return false;
39994026
}
40004027

4001-
_canBridgeFirewall = Boolean.valueOf(callHostPlugin("vmops", "can_bridge_firewall", "host_uuid", _host.uuid));
4028+
_canBridgeFirewall = can_bridge_firewall();
40024029

40034030
Nic privateNic = getLocalNetwork(conn, name);
40044031
if (privateNic == null) {
@@ -4008,6 +4035,7 @@ protected boolean getHostInfo() throws IllegalArgumentException{
40084035
s_logger.warn("Unable to determine the private network for host " + _host.ip);
40094036
return false;
40104037
}
4038+
_privateNetworkName = name;
40114039
privateNic = getLocalNetwork(conn, name);
40124040
if (privateNic == null) {
40134041
s_logger.warn("Unable to get private network " + name);
@@ -4026,6 +4054,7 @@ protected boolean getHostInfo() throws IllegalArgumentException{
40264054
}
40274055
} else {
40284056
guestNic = privateNic;
4057+
_guestNetworkName = _privateNetworkName;
40294058
}
40304059
_host.guestNetwork = guestNic.nr.uuid;
40314060
_host.guestPif = guestNic.pr.uuid;
@@ -4039,6 +4068,7 @@ protected boolean getHostInfo() throws IllegalArgumentException{
40394068
}
40404069
} else {
40414070
publicNic = guestNic;
4071+
_publicNetworkName = _guestNetworkName;
40424072
}
40434073
_host.publicPif = publicNic.pr.uuid;
40444074
_host.publicNetwork = publicNic.nr.uuid;
@@ -4061,6 +4091,7 @@ protected boolean getHostInfo() throws IllegalArgumentException{
40614091
_host.storagePif2 = storageNic2.pr.uuid;
40624092

40634093
s_logger.info("Private Network is " + _privateNetworkName + " for host " + _host.ip);
4094+
s_logger.info("Guest Network is " + _guestNetworkName + " for host " + _host.ip);
40644095
s_logger.info("Public Network is " + _publicNetworkName + " for host " + _host.ip);
40654096
s_logger.info("Storage Network 1 is " + _storageNetworkName1 + " for host " + _host.ip);
40664097
s_logger.info("Storage Network 2 is " + _storageNetworkName2 + " for host " + _host.ip);

‎core/src/com/cloud/storage/StorageResource.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ protected List<VolumeVO> getVolumes(final String rootdiskFolder, final String da
195195
String path = rootdiskFolder + File.separator + "rootdisk";
196196
long totalSize = getVolumeSize(path);
197197

198-
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
198+
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
199199
vols.add(vol);
200200

201201
// Get the datadisk volume
202202
if (datadiskFolder != null && datadiskName != null) {
203203
path = datadiskFolder + File.separator + datadiskName;
204204
totalSize = getVolumeSize(path);
205205

206-
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
206+
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
207207
vols.add(vol);
208208
}
209209

@@ -216,7 +216,7 @@ protected List<VolumeVO> getVolumes(final String imagePath) {
216216
String path = getVolumeName(imagePath, null);
217217
long totalSize = getVolumeSize(path);
218218

219-
VolumeVO vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
219+
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
220220

221221
vols.add(vol);
222222

@@ -225,7 +225,7 @@ protected List<VolumeVO> getVolumes(final String imagePath) {
225225
totalSize = getVolumeSize(path);
226226

227227

228-
vol = new VolumeVO(null, null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
228+
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
229229
vols.add(vol);
230230
}
231231

‎core/src/com/cloud/storage/VolumeVO.java‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ public class VolumeVO implements Volume {
149149
@Enumerated(value=EnumType.STRING)
150150
private State state;
151151

152+
@Column(name="source_type")
153+
@Enumerated(value=EnumType.STRING)
154+
Volume.SourceType sourceType;
155+
156+
@Column(name="source_id")
157+
Long sourceId;
158+
152159
/**
153160
* Constructor for data disk.
154161
* @param type
@@ -178,8 +185,7 @@ public VolumeVO(VolumeType type, long instanceId, String name, long dcId, long p
178185
}
179186

180187
// Real Constructor
181-
public VolumeVO(long id, VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
182-
this.id = id;
188+
public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
183189
this.volumeType = type;
184190
this.name = name;
185191
this.dataCenterId = dcId;
@@ -212,8 +218,7 @@ public VolumeVO(VolumeType type, long instanceId, long templateId, String name,
212218
}
213219

214220

215-
public VolumeVO(Long id, String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) {
216-
this.id = id;
221+
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.VolumeType vType) {
217222
this.name = name;
218223
this.accountId = accountId;
219224
this.domainId = domainId;
@@ -510,4 +515,24 @@ protected String getIscsiName() {
510515
public String toString() {
511516
return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
512517
}
518+
519+
@Override
520+
public SourceType getSourceType() {
521+
return this.sourceType;
522+
}
523+
524+
@Override
525+
public void setSourceType(SourceType sourceType) {
526+
this.sourceType = sourceType;
527+
}
528+
529+
@Override
530+
public void setSourceId(Long sourceId){
531+
this.sourceId = sourceId;
532+
}
533+
534+
@Override
535+
public Long getSourceId(){
536+
return this.sourceId;
537+
}
513538
}

‎scripts/vm/hypervisor/xenserver/hostvmstats.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
import logging
88
logging.basicConfig(filename='/tmp/xapilog',level=logging.DEBUG)
99

10-
def get_xapi_session():
11-
xapi = XenAPI.xapi_local();
12-
xapi.login_with_password("","")
13-
return xapi._session
14-
15-
def get_stats(collect_host_stats, consolidation_function, interval, start_time):
10+
def get_stats(session, collect_host_stats, consolidation_function, interval, start_time):
1611
try:
17-
session = get_xapi_session()
1812

1913
if collect_host_stats == "true" :
2014
url = "http://localhost/rrd_updates?"

‎scripts/vm/hypervisor/xenserver/vmops‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os, sys, time
66
import XenAPIPlugin
7+
import XenAPI
78
sys.path.append("/opt/xensource/sm/")
89
import SR, VDI, SRCommand, util, lvutil
910
from util import CommandException
@@ -35,13 +36,20 @@ def echo(fn):
3536
return res
3637
return wrapped
3738

39+
40+
def get_xapi_session():
41+
xapi = XenAPI.xapi_local();
42+
xapi.login_with_password("","")
43+
return xapi._session
44+
3845
@echo
3946
def gethostvmstats(session, args):
4047
collect_host_stats = args['collectHostStats']
4148
consolidation_function = args['consolidationFunction']
4249
interval = args['interval']
4350
start_time = args['startTime']
44-
result = hostvmstats.get_stats(collect_host_stats, consolidation_function, interval, start_time)
51+
session = get_xapi_session()
52+
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
4553
return result
4654

4755
@echo
@@ -454,7 +462,9 @@ def heartbeat(session, args):
454462
txt='fail'
455463
return txt
456464

457-
def get_private_nic(session, args):
465+
def get_private_nic( args):
466+
session = get_xapi_session()
467+
vms = session.xenapi.VM.get_all()
458468
host_uuid = args.get('host_uuid')
459469
host = session.xenapi.host.get_by_uuid(host_uuid)
460470
piflist = session.xenapi.host.get_PIFs(host)
@@ -481,7 +491,7 @@ def can_bridge_firewall(session, args):
481491
util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT'])
482492
except:
483493
util.SMlog('Chain BRIDGE-FIREWALL already exists')
484-
privnic = get_private_nic(session, args)
494+
privnic = get_private_nic(args)
485495
result = 'true'
486496
try:
487497
util.pread2(['/bin/bash', '-c', 'iptables -n -L FORWARD | grep BRIDGE-FIREWALL'])
@@ -496,8 +506,8 @@ def can_bridge_firewall(session, args):
496506
if not os.path.exists('/var/run/cloud'):
497507
os.makedirs('/var/run/cloud')
498508

499-
cleanup_rules_for_dead_vms(session)
500-
cleanup_rules(session)
509+
cleanup_rules_for_dead_vms()
510+
cleanup_rules()
501511

502512
return result
503513

@@ -875,6 +885,8 @@ def get_rule_log_for_vm(session, vmName):
875885
def get_rule_logs_for_vms(session, args):
876886
host_uuid = args.pop('host_uuid')
877887
try:
888+
session = get_xapi_session()
889+
878890
thishost = session.xenapi.host.get_by_uuid(host_uuid)
879891
hostrec = session.xenapi.host.get_record(thishost)
880892
vms = hostrec.get('resident_VMs')
@@ -897,7 +909,9 @@ def get_rule_logs_for_vms(session, args):
897909
return ";".join(result)
898910

899911
@echo
900-
def cleanup_rules_for_dead_vms(session):
912+
def cleanup_rules_for_dead_vms():
913+
try:
914+
session = get_xapi_session()
901915
vms = session.xenapi.VM.get_all()
902916
cleaned = 0
903917
for vm_name in [session.xenapi.VM.get_name_label(x) for x in vms]:
@@ -913,9 +927,16 @@ def cleanup_rules_for_dead_vms(session):
913927
cleaned = cleaned+1
914928

915929
util.SMlog("Cleaned up rules for " + str(cleaned) + " vms")
930+
except:
931+
util.SMlog("Failed to cleanup rules for dead vms!")
932+
933+
916934

917935
@echo
918-
def cleanup_rules(session):
936+
def cleanup_rules():
937+
try:
938+
session = get_xapi_session()
939+
919940
chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2"
920941
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
921942
cleaned = 0
@@ -942,6 +963,8 @@ def cleanup_rules(session):
942963
destroy_network_rules_for_vm(session, {'vmName':vmname})
943964

944965
util.SMlog("Cleaned up rules for " + str(len(cleanup)) + " chains")
966+
except:
967+
util.SMlog("Failed to cleanup rules !")
945968

946969
@echo
947970
def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno):
@@ -1005,6 +1028,8 @@ def remove_rule_log_for_vm(vmName):
10051028

10061029
@echo
10071030
def network_rules(session, args):
1031+
try:
1032+
session = get_xapi_session()
10081033
vm_name = args.get('vmName')
10091034
vmName = vm_name
10101035
vm_ip = args.get('vmIP')
@@ -1101,6 +1126,8 @@ def network_rules(session, args):
11011126
return 'false'
11021127

11031128
return 'true'
1129+
except:
1130+
util.SMlog("Failed to network rule !")
11041131

11051132

11061133

‎server/src/com/cloud/api/BaseCmd.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ public enum Properties {
337337
STATE("state", BaseCmd.TYPE_STRING, "state"),
338338
STOPPED_VMS("stoppedvms", BaseCmd.TYPE_LONG, "stoppedvms"),
339339
STORAGE("storage", BaseCmd.TYPE_LONG, "storage"),
340+
SOURCE_ID("sourceid", BaseCmd.TYPE_LONG, "sourceid"),
341+
SOURCE_TYPE("sourcetype",BaseCmd.TYPE_STRING,"sourcetype"),
340342
STORAGE_TYPE("storagetype", BaseCmd.TYPE_STRING, "storageType"),
341343
SUCCESS("success", BaseCmd.TYPE_BOOLEAN, "success"),
342344
SUM_ACROSS_ZONE("sumacrosszone", BaseCmd.TYPE_BOOLEAN, "sumAcrossZone"),

‎server/src/com/cloud/api/commands/ListVolumesCmd.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ public List<Pair<String, Object>> execute(Map<String, Object> params) {
223223
Long poolId = volume.getPoolId();
224224
String poolName = (poolId == null) ? "none" : getManagementServer().findPoolById(poolId).getName();
225225
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.STORAGE.getName(), poolName));
226-
226+
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.SOURCE_ID.getName(),volume.getSourceId()));
227+
volumeData.add(new Pair<String, Object>(BaseCmd.Properties.SOURCE_TYPE.getName(),volume.getSourceType().toString()));
228+
227229
vTag[i++] = volumeData;
228230
}
229231
Pair<String, Object> volumeTag = new Pair<String, Object>("volume", vTag);

0 commit comments

Comments
 (0)