Andrew Bogott has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/346048 )

Change subject: instance-info-dumper:  Use mwopenstackclient rather than the 
nova client directly.
......................................................................

instance-info-dumper:  Use mwopenstackclient rather than the nova client 
directly.

This uses keystone/nova/glance properly rather than pushing everything
through the old nova api, and also uses observer creds rather than admin
creds.

Bug: T158650
Change-Id: I1cbd913cfe43a3c633c4946ac4b893cb72b8b2d8
---
M modules/role/files/labs/instance-info-dumper.py
M modules/role/manifests/labs/instance_info_dumper.pp
2 files changed, 18 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/48/346048/1

diff --git a/modules/role/files/labs/instance-info-dumper.py 
b/modules/role/files/labs/instance-info-dumper.py
index e5593ab..adaf6ca 100644
--- a/modules/role/files/labs/instance-info-dumper.py
+++ b/modules/role/files/labs/instance-info-dumper.py
@@ -2,16 +2,16 @@
 """
 Dump info about all instances in all projects to a JSON file
 """
-from novaclient import client as novaclient
 import yaml
 import json
 import requests
 
+import mwopenstackclients
 
-image_name_cache = {}
+all_images = None
 
 
-def get_image_name(client, id):
+def get_image_name(clients, id):
     """
     Find name of an image with given id
 
@@ -22,13 +22,16 @@
 
     Returns name of the image, or None if it can't be found
     """
-    if id not in image_name_cache:
-        try:
-            image_name_cache[id] = client.images.get(id).name
-        except novaclient.exceptions.NotFound:
-            image_name_cache[id] = None
+    global all_images
 
-    return image_name_cache[id]
+    if not all_images:
+        global_images = clients.globalimages()
+        all_images = {image.id: image for image in global_images}
+
+    if id in all_images:
+        return all_images[id].name
+    else:
+        return None
 
 
 def get_enc_info(api_host, project, instance):
@@ -51,12 +54,11 @@
 
 
 def main():
-    with open('/etc/instance-dumper.yaml') as f:
+    with open('/home/andrew/instance-dumper.yaml') as f:
         config = yaml.safe_load(f)
 
-    client = novaclient.Client("2.0", project_id='admin', 
**config['credentials'])
-
-    servers = client.servers.list(search_opts={'all_tenants': 1})
+    clients = mwopenstackclients.Clients(envfile='/etc/novaobserver.yaml')
+    servers = clients.allinstances()
 
     data = {}
     for s in servers:
@@ -67,7 +69,7 @@
             'status': s.status,
             'project': s.tenant_id,
             'ips': s.networks['public'],
-            'image': get_image_name(client, s.image['id']),
+            'image': get_image_name(clients, s.image['id']),
         }
         server_info.update(get_enc_info(config['enc_host'], s.tenant_id, 
s.name))
         if s.tenant_id in data:
diff --git a/modules/role/manifests/labs/instance_info_dumper.pp 
b/modules/role/manifests/labs/instance_info_dumper.pp
index ed27435..c0f7342 100644
--- a/modules/role/manifests/labs/instance_info_dumper.pp
+++ b/modules/role/manifests/labs/instance_info_dumper.pp
@@ -5,8 +5,6 @@
 class role::labs::instance_info_dumper {
     require_package('python-requests')
 
-    $novaconfig = hiera_hash('novaconfig', {})
-
     file { '/usr/local/sbin/instance-info-dumper':
         ensure => present,
         source => 'puppet:///modules/role/labs/instance-info-dumper.py',
@@ -16,13 +14,8 @@
     }
 
     $config = {
-        'credentials' => {
-            'username' => 'novaadmin',
-            'api_key'  => $novaconfig['ldap_user_pass'],
-            'auth_url' => 
"http://${novaconfig['controller_hostname']}:35357/v2.0",
-        },
-    'enc_host'    => hiera('labs_puppet_master'),
-    'output_path' => '/srv/instance-info.yaml',
+        'enc_host'    => hiera('labs_puppet_master'),
+        'output_path' => '/srv/instance-info.yaml',
     }
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/346048
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1cbd913cfe43a3c633c4946ac4b893cb72b8b2d8
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott <abog...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to