Support both keystone v2.0 and v3 authentication
Change-Id: Iae2aad3b3d78cc901ccbdde8bab62c75ae1e2e92
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenStackEndPointCompleter.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenStackEndPointCompleter.java
index 26aa5be..cf2901c 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenStackEndPointCompleter.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenStackEndPointCompleter.java
@@ -27,15 +27,21 @@
*/
public class OpenStackEndPointCompleter implements Completer {
- private static final String OPENSTACK_ENDPOINT_EXAMPLE =
+ private static final String OPENSTACK_ENDPOINT_EXAMPLE_V2 =
"http://IP address of OpenStack end point:35357/v2.0 ProjectName ID Password";
+ private static final String OPENSTACK_ENDPOINT_EXAMPLE_V3 =
+ "http://IP address of OpenStack end point/identity/v3 ProjectName ID Password";
+ private static final String SEPARATOR = "\n or \n";
+
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
- strings.add(OPENSTACK_ENDPOINT_EXAMPLE);
+ strings.add(OPENSTACK_ENDPOINT_EXAMPLE_V2);
+ strings.add(SEPARATOR);
+ strings.add(OPENSTACK_ENDPOINT_EXAMPLE_V3);
return delegate.complete(buffer, cursor, candidates);
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
index b9b96de..c311889 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
@@ -78,20 +78,43 @@
private static final String DEVICE_OWNER_GW = "network:router_gateway";
private static final String DEVICE_OWNER_IFACE = "network:router_interface";
+ private static final String KEYSTONE_V2 = "v2.0";
+ private static final String KEYSTONE_V3 = "v3";
+
@Override
protected void execute() {
OpenstackSecurityGroupAdminService osSgAdminService = get(OpenstackSecurityGroupAdminService.class);
OpenstackNetworkAdminService osNetAdminService = get(OpenstackNetworkAdminService.class);
OpenstackRouterAdminService osRouterAdminService = get(OpenstackRouterAdminService.class);
- OSClient.OSClientV3 osClient;
- try {
- osClient = OSFactory.builderV3()
- .endpoint(this.endpoint)
- .credentials(this.user, this.password, Identifier.byName(DOMAIN_DEFUALT))
- .scopeToProject(Identifier.byName(this.tenant), Identifier.byName(DOMAIN_DEFUALT))
- .authenticate();
+ OSClient osClient;
+ try {
+ if (endpoint != null) {
+ if (endpoint.contains(KEYSTONE_V2)) {
+ osClient = OSFactory.builderV2()
+ .endpoint(this.endpoint)
+ .tenantName(this.tenant)
+ .credentials(this.user, this.password)
+ .authenticate();
+ } else if (endpoint.contains(KEYSTONE_V3)) {
+
+ Identifier project = Identifier.byName(this.tenant);
+ Identifier domain = Identifier.byName(DOMAIN_DEFUALT);
+
+ osClient = OSFactory.builderV3()
+ .endpoint(this.endpoint)
+ .credentials(this.user, this.password, domain)
+ .scopeToProject(project, domain)
+ .authenticate();
+ } else {
+ print("Unrecognized keystone version type");
+ return;
+ }
+ } else {
+ print("Need to specify a valid endpoint");
+ return;
+ }
} catch (AuthenticationException e) {
print("Authentication failed");
return;