use of org.onap.so.heatbridge.openstack.api.OpenstackClientException in project so by onap.
the class MsoCloudClientFactoryImpl method getOpenstackClient.
@Override
public OpenstackClient getOpenstackClient(@Nonnull String url, @Nonnull String msoId, @Nonnull String msoPass, @Nonnull String regionId, @Nonnull String tenantId, @Nonnull String keystoneVersion, String userDomainName, String projectDomainName) throws HeatBridgeException {
Objects.requireNonNull(url, "Null openstack url!");
Objects.requireNonNull(msoId, "Null openstack user id!");
Objects.requireNonNull(msoPass, "Null openstack password!");
Objects.requireNonNull(regionId, "Null regionId ID!");
Objects.requireNonNull(tenantId, "Null tenant ID!");
Objects.requireNonNull(keystoneVersion, "Null keystone version");
if (userDomainName == null) {
userDomainName = HeatBridgeConstants.OS_DEFAULT_DOMAIN_NAME;
}
if (projectDomainName == null) {
projectDomainName = HeatBridgeConstants.OS_DEFAULT_DOMAIN_NAME;
}
try {
final OpenstackAccess osAccess = // keystone URL
new OpenstackAccessBuilder().setBaseUrl(url).setUser(// keystone username
msoId).setPassword(// keystone decrypted password
CryptoUtils.decryptCloudConfigPassword(msoPass)).setRegion(// openstack region
regionId).setDomainName(userDomainName).setProjectName(projectDomainName).setTenantId(// tenantId
tenantId).build();
// Identify the Keystone version
if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V2_KEY)) {
return openstackClientFactory.createOpenstackV2Client(osAccess);
} else if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V3_KEY)) {
return openstackClientFactory.createOpenstackV3Client(osAccess);
}
throw new OpenstackClientException("Unsupported keystone version! " + keystoneVersion);
} catch (OpenstackClientException osClientEx) {
logger.error("Error creating OS Client", osClientEx);
throw new HeatBridgeException("Client error when authenticating with the Openstack", osClientEx);
}
}
use of org.onap.so.heatbridge.openstack.api.OpenstackClientException in project so by onap.
the class OpenstackClientFactoryImpl method createOpenstackV3Client.
@Override
public OpenstackClient createOpenstackV3Client(OpenstackAccess osAccess) throws OpenstackClientException {
Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v3 Auth: endpoint not set.");
Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v3 Auth: username not set.");
Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v3 Auth: password not set.");
Preconditions.checkNotNull(osAccess.getDomainNameIdentifier(), "Keystone-v3 Auth: domain not set.");
Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v3 Auth: region not set.");
Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v3 Auth: tenant-id not set.");
OSClientV3 client;
try {
OSFactory.enableHttpLoggingFilter(true);
client = OSFactory.builderV3().endpoint(osAccess.getUrl()).credentials(osAccess.getUser(), osAccess.getPassword(), osAccess.getDomainNameIdentifier()).scopeToProject(Identifier.byId(osAccess.getTenantId()), osAccess.getProjectNameIdentifier()).authenticate().useRegion(osAccess.getRegion());
return new OpenstackV3ClientImpl(client);
} catch (AuthenticationException exception) {
throw new OpenstackClientException("Failed to authenticate with Keystone-v3: " + osAccess.getUrl(), exception);
}
}
use of org.onap.so.heatbridge.openstack.api.OpenstackClientException in project so by onap.
the class OpenstackClientFactoryImpl method createOpenstackV2Client.
@Override
public OpenstackClient createOpenstackV2Client(OpenstackAccess osAccess) throws OpenstackClientException {
Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v2 Auth: endpoint not set.");
Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v2 Auth: username not set.");
Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v2 Auth: password not set.");
Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v2 Auth: tenant-id not set.");
Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v2 Auth: region not set.");
OSClientV2 client;
try {
OSFactory.enableHttpLoggingFilter(true);
client = OSFactory.builderV2().endpoint(osAccess.getUrl()).credentials(osAccess.getUser(), osAccess.getPassword()).tenantId(osAccess.getTenantId()).authenticate().useRegion(osAccess.getRegion());
return new OpenstackV2ClientImpl(client);
} catch (AuthenticationException exception) {
throw new OpenstackClientException("Failed to authenticate with Keystone-v2.0: " + osAccess.getUrl(), exception);
}
}
Aggregations