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


Java KeystoneUtils类代码示例

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


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

示例1: createNovaClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
/**
 * Create a Nova Client Resource by authenticating with Keystone to gain
 * access to the specified tenant.
 * 
 * Note: if the user does not have access to the tenant, will return null
 * 
 * @param Tenant who we are binding the Nova to
 * @return Nova
 */
private Nova createNovaClient(Tenant tenant) {
	Access access = getAccess(tenant);
	if (access == null) {
		return null;	// Our user may not have access to this tenant
	}
	String region = null; // Don't care which region
	
	// Find the appropriate Nova endpoint from the access credentials
	// NOTE: the Nova endpoint is specific to the tenant used to authenticate - cannot see compute resources from other tenants!!!
	String apiEndpoint = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", region, facing);
	Nova nova = new Nova(apiEndpoint, connector);
	nova.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));		

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

示例2: createGlanceClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
/**
 * Create a Glance Client Resource by asking Keystone
 * 
 * @return Glance
 */
private Glance createGlanceClient() {
	Access access = getAccess();
	String region = null; // Don't care which region
	
	// Find the appropriate Glance endpoint from the access credentials
	String apiEndpoint = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "image", region, facing);

	if (!apiEndpoint.endsWith("/v1") && !apiEndpoint.endsWith("/v1/") &&
			!apiEndpoint.endsWith("/v2") && !apiEndpoint.endsWith("/v2/")) {
		// FIXME: Why do I need to explicitly add an API version!?
		// Without this a 300 Multiple Choices error is returned
		apiEndpoint += "/v1";
	}
	Glance glance = new Glance(apiEndpoint, connector);
	glance.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));		

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

示例3: getCeilometerClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
public static Ceilometer getCeilometerClient(String osAuthUrl,
                                             String osPassword,
                                             String osTenantName,
                                             String osUsername) {

    Keystone keystoneClient = new Keystone(osAuthUrl);

    // Set account information, and issue an authentication request.
    Access access = keystoneClient.tokens()
        .authenticate(new UsernamePassword(osUsername, osPassword))
        .withTenantName(osTenantName)
        .execute();

    String ceilometerEndpoint = KeystoneUtils
        .findEndpointURL(access.getServiceCatalog(),
                         "metering", null, "public");
    if (jopst.isDebug()) {
        System.out.println("DEBUG: " + ceilometerEndpoint);
    }
    // Create a Nova client object.
    Ceilometer ceilometerClient = new Ceilometer(ceilometerEndpoint);
    ceilometerClient.token(access.getToken().getId());
    return ceilometerClient;
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:25,代码来源:Jceilometer.java

示例4: getGlanceClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
private static Glance getGlanceClient() {
    Keystone keystoneClient = new Keystone(jopst.getOsAuthUrl());

    // Set account information, and issue an authentication request.
    Access access = keystoneClient.tokens()
        .authenticate(new UsernamePassword(jopst.getOsUsername(),
                                           jopst.getOsPassword()))
        .withTenantName(jopst.getOsTenantName())
        .execute();

    String glanceEndpoint = KeystoneUtils
        .findEndpointURL(access.getServiceCatalog(),
                         "image", null, "public");
    if (jopst.isDebug()) {
        System.out.println("DEBUG: " + glanceEndpoint);
    }
    // Create a Glance client object.
    Glance glanceClient = new Glance(glanceEndpoint);
    glanceClient.token(access.getToken().getId());

    return glanceClient;
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:23,代码来源:Jglance.java

示例5: getNeutronClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
public static Quantum getNeutronClient(String osAuthUrl, String osPassword,
                                 String osTenantName, String osUsername) {
    // Set account information, and issue an authentication request.
    Keystone keystoneClient = new Keystone(jopst.getOsAuthUrl());

    Access access = keystoneClient.tokens()
        .authenticate(new UsernamePassword(jopst.getOsUsername(),
                                           jopst.getOsPassword()))
        .withTenantName(jopst.getOsTenantName())
        .execute();

    String neutronEndpoint = KeystoneUtils
        .findEndpointURL(access.getServiceCatalog(),
                         "network", null, "public");
    if (jopst.isDebug()) {
        System.out.println("DEBUG: " + neutronEndpoint);
    }
    // Create a Quantum/Neutron client object.
    Quantum neutronClient = new Quantum(neutronEndpoint);
    neutronClient.token(access.getToken().getId());
    //tenantId = access.getToken().getTenant().getId();
    return neutronClient;
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:24,代码来源:Jneutron.java

示例6: getCinderClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
public static Cinder getCinderClient(String osAuthUrl, String osPassword,
                                 String osTenantName, String osUsername) {
    Keystone keystoneClient = new Keystone(jopst.getOsAuthUrl());

    // Set account information, and issue an authentication request.
    Access access = keystoneClient.tokens()
        .authenticate(new UsernamePassword(jopst.getOsUsername(),
                                           jopst.getOsPassword()))
        .withTenantName(jopst.getOsTenantName())
        .execute();

    String cinderEndpoint = KeystoneUtils
        .findEndpointURL(access.getServiceCatalog(),
                             "volume", null, "public");
    if (jopst.isDebug()) {
        System.out.println("DEBUG: " + cinderEndpoint);
    }
    // Create a Cinder client object.
    Cinder cinderClient = new Cinder(cinderEndpoint);
    cinderClient.token(access.getToken().getId());

    return cinderClient;
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:24,代码来源:Jcinder.java

示例7: getSwiftClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
private static Swift getSwiftClient() {

        Keystone keystoneClient = new Keystone(jopst.getOsAuthUrl());

        // Set account information, and issue an authentication request.
        Access access = keystoneClient.tokens()
            .authenticate(new UsernamePassword(jopst.getOsUsername(),
                                                   jopst.getOsPassword()))
            .withTenantName(jopst.getOsTenantName())
            .execute();

        String swiftEndpoint = KeystoneUtils
            .findEndpointURL(access.getServiceCatalog(),
                                 "object-store", null, "public");
        if (jopst.isDebug()) {
            System.out.println("DEBUG: " + swiftEndpoint);
        }
        // Create a Nova client object.
        Swift swiftClient = new Swift(swiftEndpoint);
        swiftClient.token(access.getToken().getId());

        return swiftClient;
    }
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:24,代码来源:Jswift.java

示例8: main

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

示例9: main

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

示例10: main

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws InterruptedException {
    KeystoneTokenProvider keystone = new KeystoneTokenProvider(
            ExamplesConfiguration.KEYSTONE_ENDPOINT,
            ExamplesConfiguration.KEYSTONE_USERNAME,
            ExamplesConfiguration.KEYSTONE_PASSWORD
    );

    Access access = keystone.getAccessByTenant(ExamplesConfiguration.TENANT_NAME);

    String endpointURL = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "orchestration", null, "public");


    Heat heat = new Heat(endpointURL);
    heat.setTokenProvider(keystone
            .getProviderByTenant(ExamplesConfiguration.TENANT_NAME));

    CreateStackParam param = new CreateStackParam();
    param.setStackName("helloWorld");
    param.setTimeoutMinutes(1);
    param.setParameters(Collections.<String, String>emptyMap());
    param.setTemplate(TEMPLATE);

    System.out.printf("Create: " + heat.getStacks().create(param).execute());
    Thread.sleep(3000);

    for (Stack s : heat.getStacks().list().execute()) {
        System.out.println(s.getDescription());
        System.out.println(s.getId());
        System.out.println(s.getStackName());
        System.out.println(s.getStackStatus());
        System.out.println(s.getCreationTime());
        System.out.println(s.getUpdatedTime());
        System.out.println(s.getLinks());

        System.out.println(heat.getStacks().byName(s.getStackName()).execute());


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

示例11: stack

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
public static void stack(String[] args) {
    if(jopst.isDebug()) {
        System.out.println("stack() called."); 
    }

    String command = args[0];

    if (command.equals("stack-list")) {

        Keystone keystoneClient = new Keystone(jopst.getOsAuthUrl());

        Access access = keystoneClient.tokens()
            .authenticate(new UsernamePassword(jopst.getOsUsername(),
                                               jopst.getOsPassword()))
            .withTenantName(jopst.getOsTenantName())
            .execute();
    
        String heatEndpoint = KeystoneUtils
            .findEndpointURL(access.getServiceCatalog(),
                             "orchestration", null, "public");
        if (jopst.isDebug()) {
            System.out.println("DEBUG: " + heatEndpoint);
        }
        Heat heatClient = new Heat(heatEndpoint);
        heatClient.token(access.getToken().getId());

        // heat stack-list
        Stacks stacks = heatClient.stacks().list().execute();
        util.printJson(stacks);
        if (jopst.isDebug()) {
            System.out.println(stacks);
        }
    }
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:35,代码来源:Jheat.java

示例12: main

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

示例13: getNovaClient

import com.woorea.openstack.keystone.utils.KeystoneUtils; //导入依赖的package包/类
public static Nova getNovaClient(String osAuthUrl, String osPassword,
                                 String osTenantName, String osUsername) {
    

    try {
        // First, create a Keystone cliet class instance.
        Keystone keystoneClient = new Keystone(osAuthUrl);

        // Set account information, and issue an authentication request.
        Access access = keystoneClient.tokens()
            .authenticate(new UsernamePassword(osUsername, osPassword))
            .withTenantName(osTenantName)
            .execute();
    
        String novaEndpoint = KeystoneUtils
            .findEndpointURL(access.getServiceCatalog(),
                             "compute", null, "public");
        if (jopst.isDebug()) {
            System.out.println("DEBUG: " + novaEndpoint);
        }
        /*  
         * The above contains TENANT_ID like:
         *   http://SERVICE_HOST:PORT/v1.1/TENANT_ID
         * according to endpoints definition in keystone configuration.
         * It's the same as keystone endpoint-list.
         *
         * Note that we don't need to append a '/' to the URL because
         * openstack-java-sdk library codes add it.
         *   Nova novaClient = new Nova(novaEndpoint.concat("/"));
         */

        // Create a Nova client object.
        Nova novaClient = new Nova(novaEndpoint);

        /*
         * Set the token now we got for the following requests.
         * Note that we can use the same token in the above keystone 
         * response unless it's not expired.
         */
        novaClient.token(access.getToken().getId());

        return novaClient;

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Failed to create/initialize a Nova client.");
        System.exit(0);
    }
    // never here
    return null;
}
 
开发者ID:thatsdone,项目名称:openstack-java-cli,代码行数:52,代码来源:Jnova.java


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