简体   繁体   中英

Authenticate Username and Password in OpenStack with pkgcloud

I'm trying to call an API for password authentication in OpenStack. This is API that I curl and get the access token: Password authentication with unscoped authorization

I want to do the same thing in NodeJS and I'm a little confused. Can I do it cause I'm thinking maybe the problem is that it is not possible to do it like this; however this is the code that I've been trying:

var pkgcloud = require('pkgcloud');

var client = pkgcloud.compute.createClient({
    provider: 'openstack',
    username: <username>,
    password: <password>,
    authUrl: 'http://<ip>:<port>/',
    basePath: 'v3'
});
  client.getFlavors(function (err, flavors) {
    console.log("Error", err)
    console.log("Flavors", flavors)
})

client.getServers(function (err, servers) {
    console.log("Error", err)
    console.log("Servers", servers)
})

The getFlavors and getServers functions return 405 Method Not Allowed - The method is not allowed for the requested URL.

what is wrong with my code? and if I have to use another URL for getFlavors or any other function, where should I put it?

I did what Iarsks has said and also added a tenant id and it worked fine.

This is the config that I used:

var config = {
    provider: 'openstack',
    keystoneAuthVersion: 'v3',
    authUrl: '...',
    domainId: 'default',
    username: <username>,
    password: <password>,
    region: <region name which is provided in the cloud.yaml file in OpenStack>,
    tenantId: <the same as the Project ID>
}

First, rather than specifying basePath: 'v3' , you should explicitly be setting the Keystone version via keystoneAUthVersion . Simply setting basePath like that will ultimately result in bad requests.

When using v3 authentication, you need to provide a domainId (or domainName ) as part of your request.

Lastly, you may need to ensure you are providing a valid region .

The following works correctly against my OpenStack environment:

var pkgcloud = require('pkgcloud');

var client = pkgcloud.compute.createClient({
    provider: 'openstack',
    keystoneAuthVersion: 'v3',
    authUrl: '...',
    domainId: 'default',
    username: 'lars',
    password: '...',
    region: 'my-region'
})

client.getFlavors(function (err, flavors) {
    console.log("Error", err)
    console.log("Flavors", flavors)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM