Search in sources :

Example 6 with KeystoneCredentialView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView 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 7 with KeystoneCredentialView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method securityGroups.

@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
    Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
    List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list();
    LOGGER.info("security groups from openstack: {}", osSecurityGroups);
    for (SecGroupExtension secGroup : osSecurityGroups) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("tenantId", secGroup.getTenantId());
        properties.put("rules", secGroup.getRules());
        CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties);
        cloudSecurityGroups.add(cloudSecurityGroup);
    }
    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups);
    LOGGER.info("openstack security groups result: {}", result);
    return new CloudSecurityGroups(result);
}
Also used : SecGroupExtension(org.openstack4j.model.compute.SecGroupExtension) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 8 with KeystoneCredentialView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView in project cloudbreak by hortonworks.

the class OpenStackClient method getV2TenantId.

public String getV2TenantId(AuthenticatedContext authenticatedContext) {
    KeystoneCredentialView osCredential = createKeystoneCredential(authenticatedContext);
    String facing = authenticatedContext.getCloudCredential().getStringParameter(FACING);
    Access access = authenticatedContext.getParameter(Access.class);
    return OSFactory.clientFromAccess(access, Facing.value(facing)).identity().tenants().getByName(osCredential.getTenantName()).getId();
}
Also used : Access(org.openstack4j.model.identity.v2.Access) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)

Aggregations

KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)8 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Keypair (org.openstack4j.model.compute.Keypair)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudSecurityGroup (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup)1 CloudSecurityGroups (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups)1 CloudSshKey (com.sequenceiq.cloudbreak.cloud.model.CloudSshKey)1 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)1 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)1 NovaInstanceView (com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView)1 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)1 FreeMarkerTemplateUtils.processTemplateIntoString (com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString)1 OS4JException (org.openstack4j.api.exceptions.OS4JException)1