forked from godaddy/node-openstack-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
101 lines (90 loc) · 3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var Keystone = require('./lib/keystone');
var Glance = require('./lib/glance');
var Neutron = require('./lib/neutron');
var Octavia = require('./lib/octavia');
var Nova = require('./lib/nova');
//A convenience method for quick/dirty work for those that already have a project_id
//calls back with (error, project) where project already has all the individual objects setup
//ie: project.nova, project.glance, etc..
function getSimpleProject(username, password, project_id, keystone_url, cb)
{
var keystone = new Keystone(keystone_url);
var return_object = {};
var glance_url = '';
var neutron_url = '';
var nova_url = '';
var octavia_url = '';
var catalog_array = [];
var n = 0;
var j = 0;
var endpoint_type = '';
keystone.getToken(username, password, function(error, token){
if(error)
{
cb(error);
return;
}
//else
keystone.getProjectToken(token.token, project_id, function(error, project_token){
if(error)
{
cb(error);
return;
}
//else
catalog_array = project_token.catalog;
for(n = 0; n < catalog_array.length; n++)
{
//ELS Puppet sometimes screws up Keystone and puts in duplicate service entries
//that have no endpoints.. ignore these.
if(!catalog_array[n].endpoints || !catalog_array[n].endpoints.length)
{
continue;
}
endpoints_array = catalog_array[n].endpoints;
endpoint_type = catalog_array[n].type;
for(j = 0; j < endpoints_array.length; j++)
{
if(endpoints_array[j].interface == 'public')
{
endpoints_array[j].url = endpoints_array[j].url.replace(/\/$/, "");//yank any trailing /'s,
if(endpoint_type == 'image')
{
//we have to add the v2 to the end to get the most current functionality
glance_url = endpoints_array[j].url + '/v2.0';
}
else if(endpoint_type == 'network')
{
//we have to add the v2 to the end to get the most current functionality
neutron_url = endpoints_array[j].url + '/v2.0';
}
else if(endpoint_type == 'compute')
{
nova_url = endpoints_array[j].url;
}
else if (endpoint_type == 'load-balancer')
{
octavia_url = endpoints_array[j].url;
}
break;
}
}
}
return_object.general_token = token;
return_object.project_token = project_token;
return_object.glance = new Glance(glance_url, project_token.token);
return_object.neutron = new Neutron(neutron_url, project_token.token);
return_object.nova = new Nova(nova_url, project_token.token);
return_object.octavia = new Octavia(octavia_url, project_token.token);
cb(null, return_object);
});
});
}
module.exports = {
Glance: Glance,
Keystone: Keystone,
Neutron: Neutron,
Octavia: Octavia,
Nova: Nova,
getSimpleProject: getSimpleProject
}