Search in sources :

Example 1 with CloudSshKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys in project cloudbreak by hortonworks.

the class PlatformParameterV1Controller method getCloudSshKeys.

@Override
public PlatformSshKeysResponse getCloudSshKeys(PlatformResourceRequestJson resourceRequestJson) {
    resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
    PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
    CloudSshKeys cloudSshKeys = cloudParameterService.getCloudSshKeys(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
    return conversionService.convert(cloudSshKeys, PlatformSshKeysResponse.class);
}
Also used : CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) PlatformResourceRequest(com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)

Example 2 with CloudSshKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys in project cloudbreak by hortonworks.

the class AwsPlatformResources method sshKeys.

@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Map<String, Set<CloudSshKey>> result = new HashMap<>();
    for (Region actualRegion : regions(cloudCredential, region, new HashMap<>()).getCloudRegions().keySet()) {
        // If region is provided then should filter for those region
        if (regionMatch(actualRegion, region)) {
            Set<CloudSshKey> cloudSshKeys = new HashSet<>();
            AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), actualRegion.value());
            // create sshkey filter view
            PlatformResourceSshKeyFilterView filter = new PlatformResourceSshKeyFilterView(filters);
            DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
            // If the filtervalue is provided then we should filter only for those securitygroups
            if (!Strings.isNullOrEmpty(filter.getKeyName())) {
                describeKeyPairsRequest.withKeyNames(filter.getKeyName());
            }
            for (KeyPairInfo keyPairInfo : ec2Client.describeKeyPairs(describeKeyPairsRequest).getKeyPairs()) {
                Map<String, Object> properties = new HashMap<>();
                properties.put("fingerPrint", keyPairInfo.getKeyFingerprint());
                cloudSshKeys.add(new CloudSshKey(keyPairInfo.getKeyName(), properties));
            }
            result.put(actualRegion.value(), cloudSshKeys);
        }
    }
    return new CloudSshKeys(result);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) PlatformResourceSshKeyFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSshKeyFilterView) Set(java.util.Set) HashSet(java.util.HashSet) DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) HashMap(java.util.HashMap) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) CloudSshKey(com.sequenceiq.cloudbreak.cloud.model.CloudSshKey) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) Region(com.sequenceiq.cloudbreak.cloud.model.Region) HashSet(java.util.HashSet)

Example 3 with CloudSshKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method sshKeys.

@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
    Set<CloudSshKey> cloudSshKeys = new HashSet<>();
    for (Keypair keypair : osClient.compute().keypairs().list()) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("fingerprint", keypair.getFingerprint());
        properties.put("id", keypair.getId());
        properties.put("publicKey", keypair.getPublicKey());
        properties.put("createdAt", keypair.getCreatedAt());
        CloudSshKey cloudSshKey = new CloudSshKey();
        cloudSshKey.setName(keypair.getName());
        cloudSshKey.setProperties(properties);
        cloudSshKeys.add(cloudSshKey);
    }
    Map<String, Set<CloudSshKey>> result = new HashMap<>();
    result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSshKeys);
    LOGGER.info("openstack cloud ssh keys result: {}", result);
    return new CloudSshKeys(result);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) CloudSshKey(com.sequenceiq.cloudbreak.cloud.model.CloudSshKey) Keypair(org.openstack4j.model.compute.Keypair) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) HashSet(java.util.HashSet)

Example 4 with CloudSshKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys in project cloudbreak by hortonworks.

the class GetPlatformSshKeysHandler method accept.

@Override
public void accept(Event<GetPlatformSshKeysRequest> getPlatformSshKeysRequest) {
    LOGGER.info("Received event: {}", getPlatformSshKeysRequest);
    GetPlatformSshKeysRequest request = getPlatformSshKeysRequest.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudSshKeys cloudSshKeys = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().sshKeys(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformSshKeysResult getPlatformSshKeysResult = new GetPlatformSshKeysResult(request, cloudSshKeys);
        request.getResult().onNext(getPlatformSshKeysResult);
        LOGGER.info("Query platform networks types finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new GetPlatformSshKeysResult(e.getMessage(), e, request));
    }
}
Also used : GetPlatformSshKeysRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformSshKeysRequest) GetPlatformSshKeysResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformSshKeysResult) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)

Aggregations

CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)4 CloudSshKey (com.sequenceiq.cloudbreak.cloud.model.CloudSshKey)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeKeyPairsRequest (com.amazonaws.services.ec2.model.DescribeKeyPairsRequest)1 KeyPairInfo (com.amazonaws.services.ec2.model.KeyPairInfo)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 GetPlatformSshKeysRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformSshKeysRequest)1 GetPlatformSshKeysResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformSshKeysResult)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 PlatformResourceSshKeyFilterView (com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSshKeyFilterView)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 PlatformResourceRequest (com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)1 Keypair (org.openstack4j.model.compute.Keypair)1