当前位置: 首页>>代码示例>>Java>>正文


Java Keystone.token方法代码示例

本文整理汇总了Java中com.woorea.openstack.keystone.Keystone.token方法的典型用法代码示例。如果您正苦于以下问题:Java Keystone.token方法的具体用法?Java Keystone.token怎么用?Java Keystone.token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.woorea.openstack.keystone.Keystone的用法示例。


在下文中一共展示了Keystone.token方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
	Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);
	Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
			.withTenantName(ExamplesConfiguration.TENANT_NAME)
			.execute();

	//use the token in the following requests
	keystone.token(access.getToken().getId());

	Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId()));
	novaClient.token(access.getToken().getId());

	Servers servers = novaClient.servers().list(true).execute();
	if(servers.getList().size() > 0) {

		// Server has to be in activated state.
		ServersResource.StopServer stopServer = novaClient.servers().stop(servers.getList().get(0).getId());
		stopServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT);
		stopServer.execute();

		// Wait until server shutdown. Or 400 error occurs.
		Thread.sleep(5000);

		ServersResource.StartServer startServer = novaClient.servers().start(servers.getList().get(0).getId());
		startServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT);
		startServer.execute();
	}
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:29,代码来源:NovaStopStartServer.java

示例2: main

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);
	Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
			.withTenantName("demo")
			.execute();
	
	//use the token in the following requests
	keystone.token(access.getToken().getId());
		
	//NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId());
	Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId()));
	novaClient.token(access.getToken().getId());
	//novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024);
	
	Servers servers = novaClient.servers().list(true).execute();
	for(Server server : servers) {
		System.out.println(server);
	}
	
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:24,代码来源:NovaListServers.java

示例3: getAccessWithTenantId

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
private Access getAccessWithTenantId(){
  if(PREFERENCES_INITIALIZED == false){
    loadPreferences();
    PREFERENCES_INITIALIZED = true;
  }
	Keystone keystone = new Keystone(KEYSTONE_AUTH_URL,	new JerseyConnector());
	TokensResource tokens = keystone.tokens();
	UsernamePassword credentials = new UsernamePassword(KEYSTONE_USERNAME,  KEYSTONE_PASSWORD);
	Access access = tokens.authenticate(credentials).withTenantName(TENANT_NAME).execute();
	keystone.token(access.getToken().getId());

	Tenants tenants = keystone.tenants().list().execute();

	List<Tenant> tenantsList = tenants.getList();

	if (tenants.getList().size() > 0) {
		for (Iterator<Tenant> iterator = tenantsList.iterator(); iterator.hasNext();) {
			Tenant tenant = (Tenant) iterator.next();
			if (tenant.getName().compareTo(TENANT_NAME) == 0) {
				TENANT_ID = tenant.getId();
				break;
			}
		}
	} else {
		throw new RuntimeException("No tenants found!");
	}

	TokenAuthentication tokenAuth = new TokenAuthentication(access.getToken().getId());
	access = tokens.authenticate(tokenAuth).withTenantId(TENANT_ID).execute();

	return access;
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:33,代码来源:OpenstackClient.java

示例4: main

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	
	Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);
	Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)).execute();
	
	//use the token in the following requests
	keystone.token(access.getToken().getId());
	
	Tenants tenants = keystone.tenants().list().execute();
	
	//try to exchange token using the first tenant
	if(tenants.getList().size() > 0) {
		
		access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId()))
				.withTenantId(tenants.getList().get(0).getId())
				.execute();
		
		//NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId());
		Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId()));
		novaClient.token(access.getToken().getId());
		//novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024);
		
		Images images = novaClient.images().list(true).execute();
		for(Image image : images) {
			System.out.println(image);
		}
		
	} else {
		System.out.println("No tenants found!");
	}
	
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:36,代码来源:NovaListImages.java

示例5: main

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);
	Access access = keystone.tokens().authenticate(
			new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
			.execute();
	
	//use the token in the following requests
	keystone.token(access.getToken().getId());
	
	Tenants tenants = keystone.tenants().list().execute();
	
	//try to exchange token using the first tenant
	if(tenants.getList().size() > 0) {
		
		access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute();
		
		//NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId());
		Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId()));
		novaClient.token(access.getToken().getId());
		//novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024);
		
		Flavors flavors = novaClient.flavors().list(true).execute();
		for(Flavor flavor : flavors) {
			System.out.println(flavor);
		}
		
	} else {
		System.out.println("No tenants found!");
	}
	
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:35,代码来源:NovaListFlavors.java

示例6: main

import com.woorea.openstack.keystone.Keystone; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
  Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);
  // access with unscoped token
  Access access = keystone
      .tokens()
      .authenticate()
      .withUsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)
      .execute();

  // use the token in the following requests
  keystone.token(access.getToken().getId());

  Tenants tenants = keystone.tenants().list().execute();

  // try to exchange token using the first tenant
  if (tenants.getList().size() > 0) {

    access = keystone.tokens().authenticate()
        .withToken(access.getToken().getId())
        .withTenantId(tenants.getList().get(0).getId()).execute();

    // NovaClient novaClient = new
    // NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(),
    // "compute", null, "public"), access.getToken().getId());
    Nova nova = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat(tenants
        .getList().get(0).getId()));
    nova.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken()
        .getId()));
    // novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024);
    // create a new keypair
    // KeyPair keyPair =
    // novaClient.execute(KeyPairsExtension.createKeyPair("mykeypair"));
    // System.out.println(keyPair.getPrivateKey());

    // create security group
    // SecurityGroup securityGroup =
    // novaClient.execute(SecurityGroupsExtension.createSecurityGroup("mysecuritygroup",
    // "description"));

    // novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(),
    // "UDP", 9090, 9092, "0.0.0.0/0"));
    // novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(),
    // "TCP", 8080, 8080, "0.0.0.0/0"));

    KeyPairs keysPairs = nova.keyPairs().list().execute();

    Images images = nova.images().list(true).execute();

    Flavors flavors = nova.flavors().list(true).execute();

    ServerForCreate serverForCreate = new ServerForCreate();
    serverForCreate.setName("woorea");
    serverForCreate.setFlavorRef(flavors.getList().get(0).getId());
    serverForCreate.setImageRef(images.getList().get(1).getId());
    serverForCreate.setKeyName(keysPairs.getList().get(0).getName());
    serverForCreate.getSecurityGroups()
        .add(new ServerForCreate.SecurityGroup("default"));
    // serverForCreate.getSecurityGroups().add(new
    // ServerForCreate.SecurityGroup(securityGroup.getName()));

    Server server = nova.servers().boot(serverForCreate).execute();
    System.out.println(server);

  } else {
    System.out.println("No tenants found!");
  }

}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:72,代码来源:NovaCreateServer.java


注:本文中的com.woorea.openstack.keystone.Keystone.token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。