Skip to content

Commit

Permalink
Merge pull request #1 from thotypous/master
Browse files Browse the repository at this point in the history
Remove deprecated direct DB access in favor of RPC API
  • Loading branch information
jay-tsu authored Aug 10, 2016
2 parents f7993bd + 88399d8 commit 807c1d8
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions faulty_device_cleanup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2014 - 2015 EMC Corporation, Inc.
# Copyright (c) 2016 Federal University of Sao Carlos
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -22,6 +23,7 @@
0.1.2 - Use nova.db.sqlalchemy instead of MySQLdb for DB access
0.1.3 - Add more meaningful output
0.1.4 - Fix 'NoneType' and 'KeyError' issues
0.1.5 - Remove deprecated direct DB access in favor of RPC API
"""

import glob
Expand All @@ -31,13 +33,19 @@
import string
import sys

from oslo.config import cfg
from oslo_config import cfg

from nova import context
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models
import nova.context
from nova import utils

from nova.conductor import rpcapi as conductor_rpcapi
from nova import objects
from nova.objects import base as objects_base
from nova import rpc

import logging
logging.basicConfig()

CONF = cfg.CONF


Expand Down Expand Up @@ -66,15 +74,15 @@ def _get_host_name(self):
def _get_ncpu_emc_target_info_list(self):
target_info_list = []
# Find the targets used by VM on the compute node
bdms = db_api.model_query(context.get_admin_context(),
models.BlockDeviceMapping,
session=db_api.get_session())
bdms = bdms.filter(models.BlockDeviceMapping.connection_info != None)
bdms = bdms.join(models.BlockDeviceMapping.instance).filter_by(
host=string.strip(self.host_name))
context = nova.context.get_admin_context()
host_name = string.strip(self.host_name)
instance_uuids = [inst.uuid for inst in
objects.InstanceList.get_by_host(context, host_name)]
bdms = objects.BlockDeviceMappingList\
.get_by_instance_uuids(context, instance_uuids)

for bdm in bdms:
conn_info = json.loads(bdm.connection_info)
conn_info = bdm.connection_info and json.loads(bdm.connection_info)

if conn_info is not None and 'data' in conn_info:
if 'target_iqns' in conn_info['data']:
Expand Down Expand Up @@ -295,6 +303,14 @@ def main():

CONF(sys.argv[1:])

rpc.set_defaults(control_exchange='nova')
rpc.init(CONF)

utils.monkey_patch()
objects.register_all()
objects_base.NovaObject.indirection_api = \
conductor_rpcapi.ConductorAPI()

# connect_volume and disconnect_volume in nova/virt/libvirt/volume.py
# need be adjusted to take the same 'external=True' lock for
# synchronization
Expand Down

0 comments on commit 807c1d8

Please sign in to comment.