• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Tenants类的典型用法和代码示例

java 1次浏览

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

Tenants类属于com.woorea.openstack.keystone.model包,在下文中一共展示了Tenants类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getAccessWithTenantId

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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

示例2: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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

示例3: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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

示例4: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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(
			new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
			.execute();
	// use the token in the following requests
	keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));

	Tenants tenants = keystone.tenants().list().execute();
	// try to exchange token using the first tenant
	if (tenants.getList().size() > 0) {
		// access with tenant
		access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute();

		Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network",	null, "public"));
		quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));

		Networks networks = quantum.networks().list().execute();
		for (Network network : networks) {
			System.out.println(network);
		}
	} else {
		System.out.println("No tenants found!");
	}
}
 

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

示例5: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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(
			new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
			.execute();
	// use the token in the following requests
	keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));

	Tenants tenants = keystone.tenants().list().execute();
	// try to exchange token using the first tenant
	if (tenants.getList().size() > 0) {
		// access with tenant
		access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute();

		Quantum quantumClient = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network",	null, "public"));
		quantumClient.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));

		Network networkQuery = new Network();
		networkQuery.setName("benn.cs");
		networkQuery.setAdminStateUp(true);
		/*
		Networks networks = quantumClient.execute(NetworkQuery.queryNetworks(networkQuery));

		for (Network network : networks) {
			System.out.println(network);
		}

		Subnet subnetQuery = new Subnet();
		subnetQuery.setIpversion(Subnet.IpVersion.IPV4);
		Subnets Subnets = quantumClient.execute(NetworkQuery.querySubnets(subnetQuery));
		for (Subnet subnet : Subnets) {
			System.out.println(subnet);
		}
		*/
	} else {
		System.out.println("No tenants found!");
	}
}
 

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

示例6: execute

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的package包/类
@Override
public void execute(Keystone keystone, CommandLine args) {
	
	final Tenants tenants = keystone.tenants().list().execute();
	
	Table t = new Table(new TableModel<Tenant>(tenants.getList()) {

		@Override
		public Column[] getHeaders() {
			return new Column[]{
				new Column("id", 32, Column.ALIGN_LEFT),
				new Column("name", 32, Column.ALIGN_LEFT),
				new Column("description", 32, Column.ALIGN_LEFT),
				new Column("enabled", 7, Column.ALIGN_LEFT)
			};
		}

		@Override
		public String[] getRow(Tenant tenant) {
			return new String[]{
				tenant.getId(),
				tenant.getName(),
				tenant.getDescription(),
				tenant.getEnabled().toString()
			};
		}
	});
	System.out.println(t.render());
}
 

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

示例7: showAllTenants

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的package包/类
private void showAllTenants() {
	System.out.println("\n\nTenants:");
	Tenants tenants = keystone.tenants().list().execute();
	for (Tenant tenant : tenants) {
		System.out.println("  " + tenant.getId() + ", " + tenant.getName() + ", " + tenant.getDescription() + ", " + (tenant.getEnabled() ? "ENABLED" : "DISABLED"));
	}
}
 

开发者ID:jdutton,
项目名称:java-openstack-sdk-cli-example,
代码行数:8,
代码来源:Cli.java

示例8: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的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

示例9: main

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的package包/类
/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL);		
		//access with unscoped token
		Access access = keystone.tokens().authenticate(
				new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD))
				.execute();
		
		//use the token in the following requests
		keystone.setTokenProvider(new OpenStackSimpleTokenProvider(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();
			
			Swift swift = new Swift(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "object-store", null, "public"));
			swift.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));
		
			//swiftClient.execute(new DeleteContainer("navidad2"));
			
			swift.containers().create("navidad2").execute();
			
			System.out.println(swift.containers().list());
			
			ObjectForUpload upload = new ObjectForUpload();
			upload.setContainer("navidad2");
			upload.setName("example2");
			upload.setInputStream(new FileInputStream(TEST_FILE));
			swift.containers().container("navidad2").upload(upload).execute();
			
//			System.out.println(swiftClient.execute(new ListObjects("navidad2", new HashMap<String, String>() {{
//				put("path", "");
//			}})).get(0).getContentType());
			
			
			ObjectDownload download = swift.containers().container("navidad").download("example2").execute();
			write(download.getInputStream(), "example2");
		}

	}
 

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

示例10: List

点赞 2

import com.woorea.openstack.keystone.model.Tenants; //导入依赖的package包/类
public List() {
	super(client, HttpMethod.GET, "/tenants", null, Tenants.class);
}
 

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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)