Skip to content

Commit 14a2e8e

Browse files
committed
fixes, sharedfs restore, restrict unsupported instances
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent bc7ec16 commit 14a2e8e

21 files changed

Lines changed: 445 additions & 62 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class DeployVMCmdByAdmin extends DeployVMCmd implements AdminCmd {
4747
since = "4.23.0")
4848
private Boolean blankInstance;
4949

50+
// Internal flag to allow deploying instance with a given type
51+
private String instanceType;
52+
53+
/////////////////////////////////////////////////////
54+
////////////////// Getters //////////////////////////
55+
/////////////////////////////////////////////////////
56+
5057
public Long getPodId() {
5158
return podId;
5259
}
@@ -60,6 +67,14 @@ public boolean isBlankInstance() {
6067
return Boolean.TRUE.equals(blankInstance);
6168
}
6269

70+
@Override
71+
public String getInstanceType() {
72+
if (!isBlankInstance()) {
73+
return null;
74+
}
75+
return instanceType;
76+
}
77+
6378
/////////////////////////////////////////////////////
6479
////////////////// Setters //////////////////////////
6580
/////////////////////////////////////////////////////
@@ -71,4 +86,8 @@ public void setClusterId(Long clusterId) {
7186
public void setBlankInstance(boolean blankInstance) {
7287
this.blankInstance = blankInstance;
7388
}
89+
90+
public void setInstanceType(String instanceType) {
91+
this.instanceType = instanceType;
92+
}
7493
}

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.apache.cloudstack.api.command.admin.vm;
1818

1919
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.Parameter;
2022
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2123
import org.apache.cloudstack.api.command.admin.AdminCmd;
2224
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
@@ -27,4 +29,20 @@
2729
@APICommand(name = "destroyVirtualMachine", description = "Destroys an Instance. Once destroyed, only the administrator can recover it.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
2830
requestHasSensitiveInfo = false,
2931
responseHasSensitiveInfo = true)
30-
public class DestroyVMCmdByAdmin extends DestroyVMCmd implements AdminCmd {}
32+
public class DestroyVMCmdByAdmin extends DestroyVMCmd implements AdminCmd {
33+
34+
@Parameter( name = ApiConstants.FORCED,
35+
type = CommandType.BOOLEAN,
36+
description = "Force destroy the Instance",
37+
since = "4.23.0")
38+
Boolean forced;
39+
40+
@Override
41+
public boolean isForced() {
42+
return Boolean.TRUE.equals(forced);
43+
}
44+
45+
public void setForced(Boolean forced) {
46+
this.forced = forced;
47+
}
48+
}

api/src/main/java/org/apache/cloudstack/api/command/user/vm/BaseDeployVMCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
168168
@ACL
169169
@Parameter(name = ApiConstants.SECURITY_GROUP_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = SecurityGroupResponse.class, description = "comma separated list of security groups id that going to be applied to the virtual machine. "
170170
+ "Should be passed only when vm is created from a zone with Basic Network support." + " Mutually exclusive with securitygroupnames parameter")
171-
private List<Long> securityGroupIdList;
171+
protected List<Long> securityGroupIdList;
172172

173173
@ACL
174174
@Parameter(name = ApiConstants.SECURITY_GROUP_NAMES, type = CommandType.LIST, collectionType = CommandType.STRING, entityType = SecurityGroupResponse.class, description = "comma separated list of security groups names that going to be applied to the virtual machine."
@@ -799,6 +799,10 @@ public IoDriverPolicy getIoDriverPolicy() {
799799
return null;
800800
}
801801

802+
public String getInstanceType() {
803+
return null;
804+
}
805+
802806
/////////////////////////////////////////////////////
803807
/////////////// API Implementation///////////////////
804808
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ public void setSshKeyPairNames(List<String> sshKeyPairNames) {
191191
this.sshKeyPairNames = sshKeyPairNames;
192192
}
193193

194+
public void setSecurityGroupList(List<Long> securityGroupIdList) {
195+
this.securityGroupIdList = securityGroupIdList;
196+
}
197+
194198
@Override
195199
public void execute() {
196200
UserVm result;

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public List<Long> getVolumeIds() {
9090
return volumeIds;
9191
}
9292

93+
public boolean isForced() {
94+
return false;
95+
}
96+
9397
/////////////////////////////////////////////////////
9498
/////////////// API Implementation///////////////////
9599
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import org.apache.cloudstack.api.command.user.storage.sharedfs.ChangeSharedFSServiceOfferingCmd;
2424
import org.apache.cloudstack.api.command.user.storage.sharedfs.CreateSharedFSCmd;
2525
import org.apache.cloudstack.api.command.user.storage.sharedfs.DestroySharedFSCmd;
26+
import org.apache.cloudstack.api.command.user.storage.sharedfs.ListSharedFSCmd;
27+
import org.apache.cloudstack.api.command.user.storage.sharedfs.UpdateSharedFSCmd;
28+
import org.apache.cloudstack.api.response.ListResponse;
29+
import org.apache.cloudstack.api.response.SharedFSResponse;
2630

2731
import com.cloud.exception.InsufficientCapacityException;
2832
import com.cloud.exception.ManagementServerException;
@@ -31,11 +35,6 @@
3135
import com.cloud.exception.ResourceUnavailableException;
3236
import com.cloud.exception.VirtualMachineMigrationException;
3337

34-
import org.apache.cloudstack.api.command.user.storage.sharedfs.ListSharedFSCmd;
35-
import org.apache.cloudstack.api.command.user.storage.sharedfs.UpdateSharedFSCmd;
36-
import org.apache.cloudstack.api.response.SharedFSResponse;
37-
import org.apache.cloudstack.api.response.ListResponse;
38-
3938
public interface SharedFSService {
4039

4140
List<SharedFSProvider> getSharedFSProviders();
@@ -69,4 +68,10 @@ public interface SharedFSService {
6968
SharedFS recoverSharedFS(Long sharedFSId);
7069

7170
void deleteSharedFS(Long sharedFSId);
71+
72+
SharedFS getSharedFSByUuid(String uuid);
73+
74+
SharedFS getSharedFSForVmId(long vmId);
75+
76+
SharedFS updateSharedFSPostRestore(long sharedFsId, long volumeId);
7277
}

engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ public interface SharedFSDao extends GenericDao<SharedFSVO, Long>, StateDao<Shar
2929
List<SharedFSVO> listSharedFSToBeDestroyed(Date date);
3030

3131
SharedFSVO findSharedFSByNameAccountDomain(String name, Long accountId, Long domainId);
32+
33+
SharedFSVO findByVm(long vmId);
3234
}

engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDaoImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,14 @@ public SharedFSVO findSharedFSByNameAccountDomain(String name, Long accountId, L
114114
sc.setParameters("domainId", domainId);
115115
return findOneBy(sc);
116116
}
117+
118+
@Override
119+
public SharedFSVO findByVm(long vmId) {
120+
SearchBuilder<SharedFSVO> sb = createSearchBuilder();
121+
sb.and("vmId", sb.entity().getVmId(), SearchCriteria.Op.EQ);
122+
sb.done();
123+
SearchCriteria<SharedFSVO> sc = sb.create();
124+
sc.setParameters("vmId", vmId);
125+
return findOneBy(sc);
126+
}
117127
}

0 commit comments

Comments
 (0)