mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Feat/add vdisk UUID to list volume (#5848)
* get vdisk uuid from vcenter and store it into database * add vdisk uuid as external_uuid to listVolume response * add sql upgrade file * Update vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> * update sql add column external_uuid * Update server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java Co-authored-by: Wei Zhou <weizhou@apache.org> * adapt param description for externalUuid * add 'idempotent column add' to create external_uuid col * rename method to getExternalDiskUUID * remove line disk_offering.system_use Co-authored-by: DK101010 <dirk.klahre@itelligence.de> Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Co-authored-by: Wei Zhou <weizhou@apache.org>
This commit is contained in:
parent
c339f6eef9
commit
ccac1a383f
@ -243,4 +243,8 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
|
|||||||
boolean isDisplay();
|
boolean isDisplay();
|
||||||
|
|
||||||
boolean isDeployAsIs();
|
boolean isDeployAsIs();
|
||||||
|
|
||||||
|
String getExternalUuid();
|
||||||
|
|
||||||
|
void setExternalUuid(String externalUuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,6 +166,7 @@ public class ApiConstants {
|
|||||||
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
|
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
|
||||||
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
|
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
|
||||||
public static final String EXTERNAL = "external";
|
public static final String EXTERNAL = "external";
|
||||||
|
public static final String EXTERNAL_UUID = "externaluuid";
|
||||||
public static final String FENCE = "fence";
|
public static final String FENCE = "fence";
|
||||||
public static final String FETCH_LATEST = "fetchlatest";
|
public static final String FETCH_LATEST = "fetchlatest";
|
||||||
public static final String FIRSTNAME = "firstname";
|
public static final String FIRSTNAME = "firstname";
|
||||||
|
|||||||
@ -280,6 +280,10 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
@Param(description = "pod name of the volume")
|
@Param(description = "pod name of the volume")
|
||||||
private String podName;
|
private String podName;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.EXTERNAL_UUID)
|
||||||
|
@Param(description = "volume uuid that is given by virtualisation provider (only for VMware)")
|
||||||
|
private String externalUuid;
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@ -793,4 +797,12 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
public void setPodName(String podName) {
|
public void setPodName(String podName) {
|
||||||
this.podName = podName;
|
this.podName = podName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExternalUuid() {
|
||||||
|
return externalUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalUuid(String externalUuid) {
|
||||||
|
this.externalUuid = externalUuid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -160,6 +160,9 @@ public class VolumeVO implements Volume {
|
|||||||
@Column(name = "iso_id")
|
@Column(name = "iso_id")
|
||||||
private Long isoId;
|
private Long isoId;
|
||||||
|
|
||||||
|
@Column(name = "external_uuid")
|
||||||
|
private String externalUuid = null;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
// @Column(name="reservation")
|
// @Column(name="reservation")
|
||||||
String reservationId;
|
String reservationId;
|
||||||
@ -266,6 +269,7 @@ public class VolumeVO implements Volume {
|
|||||||
provisioningType = that.getProvisioningType();
|
provisioningType = that.getProvisioningType();
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
deployAsIs = that.isDeployAsIs();
|
deployAsIs = that.isDeployAsIs();
|
||||||
|
externalUuid = that.getExternalUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -648,4 +652,15 @@ public class VolumeVO implements Volume {
|
|||||||
public String getVolumeDescription(){
|
public String getVolumeDescription(){
|
||||||
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "name", "uuid");
|
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "name", "uuid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExternalUuid() {
|
||||||
|
return externalUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExternalUuid(String externalUuid) {
|
||||||
|
this.externalUuid = externalUuid;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -220,6 +220,24 @@ CREATE VIEW `cloud`.`service_offering_view` AS
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
`service_offering`.`id`;
|
`service_offering`.`id`;
|
||||||
|
|
||||||
|
|
||||||
|
--;
|
||||||
|
-- Stored procedure to do idempotent column add;
|
||||||
|
-- This is copied from schema-41000to41100.sql
|
||||||
|
--;
|
||||||
|
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||||
|
|
||||||
|
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||||
|
IN in_table_name VARCHAR(200),
|
||||||
|
IN in_column_name VARCHAR(200),
|
||||||
|
IN in_column_definition VARCHAR(1000)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||||
|
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes','external_uuid', 'VARCHAR(40) DEFAULT null ');
|
||||||
|
|
||||||
DROP VIEW IF EXISTS `cloud`.`volume_view`;
|
DROP VIEW IF EXISTS `cloud`.`volume_view`;
|
||||||
CREATE VIEW `cloud`.`volume_view` AS
|
CREATE VIEW `cloud`.`volume_view` AS
|
||||||
SELECT
|
SELECT
|
||||||
@ -240,6 +258,7 @@ CREATE VIEW `cloud`.`volume_view` AS
|
|||||||
volumes.format,
|
volumes.format,
|
||||||
volumes.path,
|
volumes.path,
|
||||||
volumes.chain_info,
|
volumes.chain_info,
|
||||||
|
volumes.external_uuid,
|
||||||
account.id account_id,
|
account.id account_id,
|
||||||
account.uuid account_uuid,
|
account.uuid account_uuid,
|
||||||
account.account_name account_name,
|
account.account_name account_name,
|
||||||
@ -641,7 +660,6 @@ CREATE VIEW `cloud`.`domain_router_view` AS
|
|||||||
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
|
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
|
||||||
and async_job.instance_type = 'DomainRouter'
|
and async_job.instance_type = 'DomainRouter'
|
||||||
and async_job.job_status = 0;
|
and async_job.job_status = 0;
|
||||||
|
|
||||||
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), 3, 'listConfigurations', 'ALLOW', (SELECT MAX(`sort_order`)+1 FROM `cloud`.`role_permissions`) ON DUPLICATE KEY UPDATE rule=rule;
|
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), 3, 'listConfigurations', 'ALLOW', (SELECT MAX(`sort_order`)+1 FROM `cloud`.`role_permissions`) ON DUPLICATE KEY UPDATE rule=rule;
|
||||||
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), 3, 'updateConfiguration', 'ALLOW', (SELECT MAX(`sort_order`)+1 FROM `cloud`.`role_permissions`) ON DUPLICATE KEY UPDATE rule=rule;
|
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) SELECT UUID(), 3, 'updateConfiguration', 'ALLOW', (SELECT MAX(`sort_order`)+1 FROM `cloud`.`role_permissions`) ON DUPLICATE KEY UPDATE rule=rule;
|
||||||
|
|
||||||
|
|||||||
@ -833,4 +833,14 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
public Class<?> getEntityType() {
|
public Class<?> getEntityType() {
|
||||||
return Volume.class;
|
return Volume.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExternalUuid() {
|
||||||
|
return volumeVO.getExternalUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExternalUuid(String externalUuid) {
|
||||||
|
volumeVO.setExternalUuid(externalUuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2149,6 +2149,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||||||
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, dsMo.getName());
|
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, dsMo.getName());
|
||||||
chainInfo = _gson.toJson(diskInfo);
|
chainInfo = _gson.toJson(diskInfo);
|
||||||
|
|
||||||
|
answer.setContextParam("vdiskUuid",vmMo.getExternalDiskUUID(datastoreVolumePath));
|
||||||
|
|
||||||
if (isManaged) {
|
if (isManaged) {
|
||||||
expandVirtualDisk(vmMo, datastoreVolumePath, volumeTO.getSize());
|
expandVirtualDisk(vmMo, datastoreVolumePath, volumeTO.getSize());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -269,6 +269,7 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
|
|||||||
}
|
}
|
||||||
|
|
||||||
volResponse.setObjectName("volume");
|
volResponse.setObjectName("volume");
|
||||||
|
volResponse.setExternalUuid(volume.getExternalUuid());
|
||||||
return volResponse;
|
return volResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -272,6 +272,9 @@ public class VolumeJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||||||
@Column(name = "chain_info", length = 65535)
|
@Column(name = "chain_info", length = 65535)
|
||||||
String chainInfo;
|
String chainInfo;
|
||||||
|
|
||||||
|
@Column(name = "external_uuid")
|
||||||
|
private String externalUuid = null;
|
||||||
|
|
||||||
public VolumeJoinVO() {
|
public VolumeJoinVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,6 +602,14 @@ public class VolumeJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||||||
return chainInfo;
|
return chainInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExternalUuid() {
|
||||||
|
return externalUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalUuid(String externalUuid) {
|
||||||
|
this.externalUuid = externalUuid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getEntityType() {
|
public Class<?> getEntityType() {
|
||||||
return Volume.class;
|
return Volume.class;
|
||||||
|
|||||||
@ -3854,6 +3854,12 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
_volsDao.update(volumeToAttach.getId(), volumeToAttach);
|
_volsDao.update(volumeToAttach.getId(), volumeToAttach);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (answer.getContextParam("vdiskUuid") != null) {
|
||||||
|
volumeToAttach = _volsDao.findById(volumeToAttach.getId());
|
||||||
|
volumeToAttach.setExternalUuid(answer.getContextParam("vdiskUuid"));
|
||||||
|
_volsDao.update(volumeToAttach.getId(), volumeToAttach);
|
||||||
|
}
|
||||||
|
|
||||||
String chainInfo = answer.getContextParam("chainInfo");
|
String chainInfo = answer.getContextParam("chainInfo");
|
||||||
if (chainInfo != null) {
|
if (chainInfo != null) {
|
||||||
volumeToAttach = _volsDao.findById(volumeToAttach.getId());
|
volumeToAttach = _volsDao.findById(volumeToAttach.getId());
|
||||||
|
|||||||
@ -3649,6 +3649,24 @@ public class VirtualMachineMO extends BaseMO {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExternalDiskUUID(String datastoreVolumePath) throws Exception{
|
||||||
|
List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
|
||||||
|
if (CollectionUtils.isEmpty(devices) || datastoreVolumePath == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VirtualDevice device : devices) {
|
||||||
|
if (device instanceof VirtualDisk && device.getBacking() instanceof VirtualDiskFlatVer2BackingInfo){
|
||||||
|
VirtualDiskFlatVer2BackingInfo backingInfo = (VirtualDiskFlatVer2BackingInfo) device.getBacking();
|
||||||
|
if(backingInfo.getFileName().equals(datastoreVolumePath)){
|
||||||
|
return backingInfo.getUuid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean consolidateVmDisks() throws Exception {
|
public boolean consolidateVmDisks() throws Exception {
|
||||||
ManagedObjectReference morTask = _context.getService().consolidateVMDisksTask(_mor);
|
ManagedObjectReference morTask = _context.getService().consolidateVMDisksTask(_mor);
|
||||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user