mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CS-14770. ec2-run-instances and ec2-describe-instances don't return keypair information. Component: AWSAPI.
This commit is contained in:
parent
a52889bb6a
commit
8c3450b503
@ -158,6 +158,9 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
|
||||
private List<ResourceTagResponse> tags;
|
||||
|
||||
@SerializedName(ApiConstants.SSH_KEYPAIR) @Param(description="ssh key-pair")
|
||||
private String keyPairName;
|
||||
|
||||
public void setHypervisor(String hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
@ -348,4 +351,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
public void setTags(List<ResourceTagResponse> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public void setKeyPairName(String keyPairName) {
|
||||
this.keyPairName = keyPairName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1378,7 +1378,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
||||
param7.setPrivateDnsName( "" );
|
||||
param7.setDnsName( "" );
|
||||
param7.setReason( "" );
|
||||
param7.setKeyName( "" );
|
||||
param7.setKeyName( inst.getKeyPairName());
|
||||
param7.setAmiLaunchIndex( "" );
|
||||
param7.setInstanceType( inst.getServiceOffering());
|
||||
|
||||
@ -1700,7 +1700,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
||||
param7.setPrivateDnsName( "" );
|
||||
param7.setDnsName( "" );
|
||||
param7.setReason( "" );
|
||||
param7.setKeyName( "" );
|
||||
param7.setKeyName( inst.getKeyPairName());
|
||||
param7.setAmiLaunchIndex( "" );
|
||||
|
||||
ProductCodesSetType param9 = new ProductCodesSetType();
|
||||
|
||||
@ -1521,6 +1521,7 @@ public class EC2Engine {
|
||||
vm.setDomainId(resp.getDomainId());
|
||||
vm.setHypervisor(resp.getHypervisor());
|
||||
vm.setServiceOffering( svcOffering.getName());
|
||||
vm.setKeyPairName(resp.getKeyPairName());
|
||||
instances.addInstance(vm);
|
||||
countCreated++;
|
||||
}
|
||||
@ -1905,7 +1906,8 @@ public class EC2Engine {
|
||||
ec2Vm.setRootDeviceType(cloudVm.getRootDeviceType());
|
||||
ec2Vm.setRootDeviceId(cloudVm.getRootDeviceId());
|
||||
ec2Vm.setServiceOffering(serviceOfferingIdToInstanceType(cloudVm.getServiceOfferingId().toString()));
|
||||
|
||||
ec2Vm.setKeyPairName(cloudVm.getKeyPairName());
|
||||
|
||||
List<CloudStackNic> nics = cloudVm.getNics();
|
||||
for(CloudStackNic nic : nics) {
|
||||
if(nic.getIsDefault()) {
|
||||
|
||||
@ -40,6 +40,7 @@ public class EC2Instance {
|
||||
private String hypervisor;
|
||||
private String rootDeviceType;
|
||||
private String rootDeviceId;
|
||||
private String keyPairName;
|
||||
private List<String> groupSet;
|
||||
private List<EC2TagKeyValue> tagsSet;
|
||||
|
||||
@ -60,6 +61,7 @@ public class EC2Instance {
|
||||
hypervisor = null;
|
||||
rootDeviceType = null;
|
||||
rootDeviceId = null;
|
||||
keyPairName = null;
|
||||
groupSet = new ArrayList<String>();
|
||||
tagsSet = new ArrayList<EC2TagKeyValue>();
|
||||
}
|
||||
@ -192,6 +194,14 @@ public class EC2Instance {
|
||||
rootDeviceId = param;
|
||||
}
|
||||
|
||||
public String getKeyPairName() {
|
||||
return keyPairName;
|
||||
}
|
||||
|
||||
public void setKeyPairName(String param) {
|
||||
keyPairName = param;
|
||||
}
|
||||
|
||||
public void addGroupName( String param ) {
|
||||
groupSet.add( param );
|
||||
}
|
||||
|
||||
@ -67,6 +67,8 @@ public class CloudStackUserVm {
|
||||
private String jobId;
|
||||
@SerializedName(ApiConstants.JOB_STATUS)
|
||||
private Integer jobStatus;
|
||||
@SerializedName(ApiConstants.SSH_KEYPAIR)
|
||||
private String keyPairName;
|
||||
@SerializedName(ApiConstants.MEMORY)
|
||||
private Integer memory;
|
||||
@SerializedName(ApiConstants.NAME)
|
||||
@ -340,6 +342,13 @@ public class CloudStackUserVm {
|
||||
return serviceOfferingName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sshKeyPairName
|
||||
*/
|
||||
public String getKeyPairName() {
|
||||
return keyPairName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state
|
||||
*/
|
||||
|
||||
@ -125,10 +125,12 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountDetailsDao;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.SSHKeyPairVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.SSHKeyPairDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.user.dao.UserStatisticsDao;
|
||||
import com.cloud.uservm.UserVm;
|
||||
@ -139,6 +141,7 @@ import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.UserVmDetailVO;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
@ -148,6 +151,7 @@ import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.UserVmData;
|
||||
import com.cloud.vm.dao.UserVmDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
public class ApiDBUtils {
|
||||
@ -206,6 +210,8 @@ public class ApiDBUtils {
|
||||
private static HighAvailabilityManager _haMgr;
|
||||
private static VpcManager _vpcMgr;
|
||||
private static TaggedResourceService _taggedResourceService;
|
||||
private static UserVmDetailsDao _userVmDetailsDao;
|
||||
private static SSHKeyPairDao _sshKeyPairDao;
|
||||
|
||||
static {
|
||||
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
|
||||
@ -263,6 +269,8 @@ public class ApiDBUtils {
|
||||
_haMgr = locator.getManager(HighAvailabilityManager.class);
|
||||
_vpcMgr = locator.getManager(VpcManager.class);
|
||||
_taggedResourceService = locator.getManager(TaggedResourceService.class);
|
||||
_sshKeyPairDao = locator.getDao(SSHKeyPairDao.class);
|
||||
_userVmDetailsDao = locator.getDao(UserVmDetailsDao.class);
|
||||
|
||||
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
|
||||
_statsCollector = StatsCollector.getInstance();
|
||||
@ -803,4 +811,13 @@ public class ApiDBUtils {
|
||||
public static List<? extends ResourceTag> listByResourceTypeAndId(TaggedResourceType type, long resourceId) {
|
||||
return _taggedResourceService.listByResourceTypeAndId(type, resourceId);
|
||||
}
|
||||
|
||||
public static String getKeyPairName(String sshPublicKey) {
|
||||
SSHKeyPairVO sshKeyPair = _sshKeyPairDao.findByPublicKey(sshPublicKey);
|
||||
return sshKeyPair.getName();
|
||||
}
|
||||
|
||||
public static UserVmDetailVO findPublicKeyByVmId(long vmId) {
|
||||
return _userVmDetailsDao.findDetail(vmId, "SSH.PublicKey");
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +211,7 @@ import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.UserVmDetailVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
@ -3332,6 +3333,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
userVmResponse.setTags(tagResponses);
|
||||
|
||||
UserVmDetailVO userVmDetail = ApiDBUtils.findPublicKeyByVmId(userVmData.getId());
|
||||
if (userVmDetail != null && userVmDetail.getValue() != null) {
|
||||
String keyPairName = ApiDBUtils.getKeyPairName(userVmDetail.getValue());
|
||||
userVmResponse.setKeyPairName(keyPairName);
|
||||
}
|
||||
|
||||
return userVmResponse;
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@ public interface SSHKeyPairDao extends GenericDao<SSHKeyPairVO, Long> {
|
||||
|
||||
public SSHKeyPairVO findByName(long accountId, long domainId, String name);
|
||||
|
||||
public SSHKeyPairVO findByPublicKey(String publicKey);
|
||||
|
||||
public boolean deleteByName(long accountId, long domainId, String name);
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +61,14 @@ public class SSHKeyPairDaoImpl extends GenericDaoBase<SSHKeyPairVO, Long> implem
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, name);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SSHKeyPairVO findByPublicKey(String publicKey) {
|
||||
SearchCriteria<SSHKeyPairVO> sc = createSearchCriteria();
|
||||
sc.addAnd("publicKey", SearchCriteria.Op.EQ, publicKey);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByName(long accountId, long domainId, String name) {
|
||||
SSHKeyPairVO pair = findByName(accountId, domainId, name);
|
||||
|
||||
@ -70,6 +70,7 @@ public class UserVmData {
|
||||
private Long publicIpId;
|
||||
private String publicIp;
|
||||
private String instanceName;
|
||||
private String sshPublicKey;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
@ -710,5 +711,13 @@ public class UserVmData {
|
||||
public void setInstanceName(String instanceName) {
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
public String getSshPublicKey() {
|
||||
return sshPublicKey;
|
||||
}
|
||||
|
||||
public void setSshPublicKey(String sshPublicKey) {
|
||||
this.sshPublicKey = sshPublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ public class UserVmDetailsDaoImpl extends GenericDaoBase<UserVmDetailVO, Long> i
|
||||
VmSearch.done();
|
||||
|
||||
DetailSearch = createSearchBuilder();
|
||||
DetailSearch.and("hostId", DetailSearch.entity().getVmId(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.and("vmId", DetailSearch.entity().getVmId(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.done();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user