Handle OpenStack authenticate exception and show warnings

Change-Id: Id7ac38c4dab1e43cf46bc8262adf98ea0a7d3558
This commit is contained in:
Hyunsun Moon 2016-06-30 10:55:10 -07:00 committed by Gerrit Code Review
parent d45d42c732
commit d0bfe67c3c
2 changed files with 22 additions and 10 deletions

View File

@ -25,6 +25,7 @@ import org.onosproject.xosclient.api.VtnPortId;
import org.onosproject.xosclient.api.VtnServiceId; import org.onosproject.xosclient.api.VtnServiceId;
import org.onosproject.xosclient.api.XosAccess; import org.onosproject.xosclient.api.XosAccess;
import org.openstack4j.api.OSClient; import org.openstack4j.api.OSClient;
import org.openstack4j.api.exceptions.AuthenticationException;
import org.openstack4j.model.network.IP; import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.Port; import org.openstack4j.model.network.Port;
import org.openstack4j.openstack.OSFactory; import org.openstack4j.openstack.OSFactory;
@ -132,10 +133,15 @@ public final class DefaultVtnPortApi extends XosApi implements VtnPortApi {
// creating a client every time must be inefficient, but this method // creating a client every time must be inefficient, but this method
// will be removed once XOS provides equivalent APIs // will be removed once XOS provides equivalent APIs
return OSFactory.builder() try {
.endpoint(osAccess.endpoint()) return OSFactory.builder()
.credentials(osAccess.user(), osAccess.password()) .endpoint(osAccess.endpoint())
.tenantName(osAccess.tenant()) .credentials(osAccess.user(), osAccess.password())
.authenticate(); .tenantName(osAccess.tenant())
.authenticate();
} catch (AuthenticationException e) {
log.warn("Failed to authenticate OpenStack API with {}", osAccess);
return null;
}
} }
} }

View File

@ -28,6 +28,7 @@ import org.onosproject.xosclient.api.VtnService;
import org.onosproject.xosclient.api.VtnServiceId; import org.onosproject.xosclient.api.VtnServiceId;
import org.openstack4j.api.OSClient; import org.openstack4j.api.OSClient;
import org.openstack4j.api.exceptions.AuthenticationException;
import org.openstack4j.model.network.Network; import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Subnet; import org.openstack4j.model.network.Subnet;
import org.openstack4j.openstack.OSFactory; import org.openstack4j.openstack.OSFactory;
@ -162,11 +163,16 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi
// creating a client every time must be inefficient, but this method // creating a client every time must be inefficient, but this method
// will be removed once XOS provides equivalent APIs // will be removed once XOS provides equivalent APIs
return OSFactory.builder() try {
.endpoint(osAccess.endpoint()) return OSFactory.builder()
.credentials(osAccess.user(), osAccess.password()) .endpoint(osAccess.endpoint())
.tenantName(osAccess.tenant()) .credentials(osAccess.user(), osAccess.password())
.authenticate(); .tenantName(osAccess.tenant())
.authenticate();
} catch (AuthenticationException e) {
log.warn("Failed to authenticate OpenStack API with {}", osAccess);
return null;
}
} }
// TODO remove this when XOS provides this information // TODO remove this when XOS provides this information