Example #1
0
 @SuppressWarnings("ConstantConditions")
 protected EndPoint determineCurrentEndPoint() {
   if (currentEndPoint != null) {
     return currentEndPoint;
   }
   ServiceCatalog objectStoreCatalog = getObjectStoreCatalog();
   if (objectStoreCatalog == null) {
     HttpStatusExceptionUtil.throwException(
         HttpStatus.SC_NOT_FOUND, CommandExceptionError.NO_SERVICE_CATALOG_FOUND);
   }
   this.currentEndPoint = objectStoreCatalog.getRegion(getPreferredRegion());
   if (this.currentEndPoint == null) {
     HttpStatusExceptionUtil.throwException(
         HttpStatus.SC_NOT_FOUND, CommandExceptionError.NO_END_POINT_FOUND);
   }
   return this.currentEndPoint;
 }
  private static AuthenticateResponse getServiceResponse() {
    AuthenticateResponse rsp = new AuthenticateResponse();

    Token token = new Token();
    token.setId("tokenid");
    GregorianCalendar cal = new GregorianCalendar(2013, 11, 12);
    token.setExpires(new XMLGregorianCalendarImpl(cal));
    TenantForAuthenticateResponse tenantForAuthenticateResponse =
        new TenantForAuthenticateResponse();
    tenantForAuthenticateResponse.setId("tenantId");
    tenantForAuthenticateResponse.setName("tenantName");
    token.setTenant(tenantForAuthenticateResponse);
    rsp.setToken(token);

    ServiceCatalog catalog = new ServiceCatalog();
    List<ServiceForCatalog> serviceCatalogList = new ArrayList<>();
    ServiceForCatalog serviceForCatalog = new ServiceForCatalog();
    serviceForCatalog.setName("catName");
    serviceForCatalog.setType("type");
    serviceCatalogList.add(serviceForCatalog);
    catalog.getService().addAll(serviceCatalogList);

    rsp.setServiceCatalog(catalog);

    UserForAuthenticateResponse user = new UserForAuthenticateResponse();
    user.setId("userId");
    user.setName("userName");
    RoleList roles = new RoleList();

    Role role = new Role();
    role.setDescription("role description");
    role.setId("roleId");
    role.setName("roleName");
    role.setServiceId("serviceId");
    role.setTenantId("roleTenantId");
    roles.getRole().add(role);

    user.setRoles(roles);

    rsp.setUser(user);

    return rsp;
  }
Example #3
0
  @Test
  public void testGetAccess() throws InterruptedException {
    OpenStackCredentials creds =
        new OpenStackCredentials(
            new AuthenticationCredentials(
                new PasswordCredentials("vcgAdmin", "pr0t3ctth1s"), "VCGs"));
    ServiceCatalog ep = new ServiceCatalog("http://control.dev.intercloud.net:5000", creds);
    Access access = ep.getAccess();
    access.localhostHack = true;
    ComputeEndpoint cep = access.getComputeEndpoint("RegionOne", "publicURL");
    VolumeEndpoint vep = access.getVolumeEndpoint("RegionOne", "publicURL");
    List<Image> images = cep.listImages();
    List<Flavor> flavors = cep.listFlavors();
    System.out.println(vep.listVolumes());
    System.out.println(cep.listKeyPairs());
    // System.out.println(cep.listAddresses());

    // Volume v = vep.createVolume("test", "test", 1, new HashMap<String, String>(), "nova");

    // vep.deleteVolume(v);
    //		IPAddressPool pool = null;
    //		for (IPAddressPool p : cep.listPools()) {
    //			if (p.getName().equals("vcgs")) {
    //				pool = p;
    //			}
    //		}
    //		IPAddress ip = pool.getIPAddresses().get(0);
    //		Server server = cep.createServer("test", ip, images.get(0), flavors.get(0), null,
    // null).waitUntilRunning(100000);
    //
    //		// System.out.println(server);
    //		cep.associateIp(server, ip);
    //		System.out.println(cep.listVolumeAttachments(server));
    //
    //
    //		System.out.println(cep.attachVolume(server.getId(), vep.listVolumes().get(0).getId(),
    // "/dev/sda"));
    //		server.delete();
  }