Skip to content

Commit a1633ff

Browse files
committed
updating to use keystone v3 api
1 parent 1c30ef1 commit a1633ff

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

server/externalscripts/openstack-discovery

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ from sys import argv
66
from sys import stderr
77
import json
88
from datetime import datetime
9-
import re
9+
from urlparse import urlparse
1010

1111

1212
try:
13-
from keystoneclient.v2_0 import client as keystone_client
14-
from keystoneclient.auth.identity import v2
13+
from keystoneclient.v3 import client as keystone_client
14+
from keystoneclient.auth.identity import v3
1515
from keystoneclient import session
1616
from novaclient import client as nova_client
1717
except ImportError:
1818
print 'ZBX_NOTSUPPORTED\x00 Failed to import openstack python modules'
1919
exit(1)
2020

2121
def get_host_port(url):
22-
m = re.match('https?://(\d+\.\d+\.\d+\.\d+):(\d+)',url)
23-
if m:
24-
return (m.group(1),m.group(2))
22+
parsed = urlparse(url)
23+
if parsed:
24+
return (parsed.hostname, parsed.port)
2525

2626
def print_json(data):
2727
print json.dumps({'data':data},sort_keys=True,indent=7,separators=(',',':'))
@@ -31,15 +31,17 @@ def discover_endpoints(auth_url, tenant_name, username, password):
3131

3232
services = []
3333
for e in conn.endpoints.list():
34-
host = get_host_port(e.publicurl)
34+
if e.interface != 'public':
35+
continue
36+
host = get_host_port(e.url)
3537
if e.enabled:
3638
service = conn.services.get(e.service_id)
37-
services.append({'{#OS_SERVICENAME}':service.name, '{#OS_SERVICEURL}':e.publicurl, '{#OS_SERVICEHOST}':host[0], '{#OS_SERVICEPORT}':host[1] })
39+
services.append({'{#OS_SERVICENAME}':service.name, '{#OS_SERVICEURL}':e.url, '{#OS_SERVICEHOST}':host[0], '{#OS_SERVICEPORT}':host[1] })
3840

3941
print_json(services)
4042

4143
def discover_hypervisors(auth_url, tenant_name, username, password):
42-
auth = v2.Password(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
44+
auth = v3.Password(username=username, password=password, user_domain_name='Default', project_name=tenant_name, project_domain_name='Default', auth_url=auth_url)
4345
sess = session.Session(auth=auth)
4446

4547
conn = nova_client.Client(2, session=sess)

0 commit comments

Comments
 (0)