本文整理汇总了Java中com.woorea.openstack.keystone.model.Access类的典型用法代码示例。如果您正苦于以下问题:Java Access类的具体用法?Java Access怎么用?Java Access使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Access类属于com.woorea.openstack.keystone.model包,在下文中一共展示了Access类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.woorea.openstack.keystone.model.Access; //导入依赖的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();
}
}
示例2: main
import com.woorea.openstack.keystone.model.Access; //导入依赖的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);
}
}
示例3: getAccess
import com.woorea.openstack.keystone.model.Access; //导入依赖的package包/类
private Access getAccess(Tenant tenant) {
if (getAccess().getToken().getTenant().getId() == tenant.getId()) {
return getAccess();
}
// Use our existing token to authenticate with Keystone to create new tenant-specific tokens
Authentication tokenAuth = new TokenAuthentication(getAccess().getToken().getId());
// Now, *try* to create a NEW token on this tenant.
// NOTE: even "admin" users are not authorized on every tenant, though
// oddly they are authorized to add themselves to tenants!?
try {
return keystone.tokens()
.authenticate(tokenAuth)
.withTenantId(tenant.getId())
.execute();
} catch (OpenStackResponseException err) {
System.out.println("\nFailed to access tenant \"" + tenant.getName() + "\" - user must not have authorization for this tenant!");
return null; // Cannot access nova
}
}
示例4: createNovaClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例5: createGlanceClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例6: getCeilometerClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例7: getGlanceClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例8: getNeutronClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例9: getCinderClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例10: getSwiftClient
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例11: getAccessWithTenantId
import com.woorea.openstack.keystone.model.Access; //导入依赖的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;
}
示例12: getHypervisors
import com.woorea.openstack.keystone.model.Access; //导入依赖的package包/类
private ArrayList<String> getHypervisors(){
Access access = getAccessWithTenantId();
Nova novaClient = new Nova(NOVA_ENDPOINT.concat("/").concat(TENANT_ID));
novaClient.token(access.getToken().getId());
OpenStackRequest<String> request = new OpenStackRequest<String>(
novaClient, HttpMethod.GET, "/os-hypervisors", null,
String.class);
String hypervisors = null;
try{
hypervisors = novaClient.execute(request);
} catch(OpenStackResponseException e){
LOGGER.log(Level.SEVERE, e.getMessage());
return null;
}
ArrayList<String> hypervisors_list = new ArrayList<String>() ;
try{
JSONParser parser = new JSONParser() ;
JSONObject object = (JSONObject) parser.parse(hypervisors) ;
JSONArray json_hypervisors = (JSONArray) object.get("hypervisors") ;
for (Object o : json_hypervisors){
JSONObject obj = (JSONObject) o ;
hypervisors_list.add(obj.get("hypervisor_hostname").toString()) ;
}
}catch(ParseException pe){
LOGGER.log(Level.WARNING,"Cannot parse result.");
}
return hypervisors_list;
}
示例13: findEndpointByType
import com.woorea.openstack.keystone.model.Access; //导入依赖的package包/类
/**
* タイプ、アクセス情報からエンドポイントを取得します。
* @param type タイプ
* @param access アクセス情報
* @param region リージョン
* @return エンドポイント
*/
public static String findEndpointByType(String type, Access access, String region) {
if (access == null) return null;
List<Service> services = access.getServiceCatalog();
for (Service service : services) {
if (!type.equals(service.getType())) continue;
for (Endpoint e : service.getEndpoints()) {
if (!region.equals(e.getRegion())) continue;
return e.getPublicURL();
}
}
return null;
}
示例14: AuthenticationCriteria
import com.woorea.openstack.keystone.model.Access; //导入依赖的package包/类
@Test
public void 登録されているユーザの場合はアクセス情報が取得できる() {
AuthenticationCriteria criteria = new AuthenticationCriteria();
criteria.setUsername("user01");
criteria.setPassword("user01");
criteria.setTenantName("ctc01");
WooreaAuthentication authentication = connector.authentication(criteria);
assertThat(authentication, notNullValue());
Access access = authentication.entity();
assertThat(access, notNullValue());
assertThat(access.getUser().getName(), is("user01"));
}
示例15: main
import com.woorea.openstack.keystone.model.Access; //导入依赖的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!");
}
}