Add disable node to osclient
Change-Id: Id924081ce32c2bbe6ce8cd92c3e322682f42e8c0
This commit is contained in:
+1
-1
@@ -17,4 +17,4 @@
|
||||
import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo('osha').version_string()
|
||||
__version__ = pbr.version.VersionInfo('osha').version_string()
|
||||
|
||||
@@ -16,6 +16,9 @@ from keystoneclient.auth.identity import v3
|
||||
from keystoneclient import session
|
||||
from novaclient.v2 import client as novaclient
|
||||
from neutronclient.v2_0 import client as neutronclient
|
||||
from oslo_log import log
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class OSClient:
|
||||
@@ -130,3 +133,30 @@ class OSClient:
|
||||
def get_session(self):
|
||||
auth_session = session.Session(auth=self.authSession.auth)
|
||||
return auth_session
|
||||
|
||||
def disable_node(self, hostname):
|
||||
auth_session = session.Session(auth=self.authSession.auth)
|
||||
nova = novaclient.Client(session=auth_session,
|
||||
endpoint_type=self.endpoint_type)
|
||||
try:
|
||||
node = nova.services.find(host=hostname)
|
||||
except Exception as e:
|
||||
LOG.error(e)
|
||||
return False
|
||||
|
||||
if not node:
|
||||
return False
|
||||
node = node.to_dict()
|
||||
try:
|
||||
res = nova.services.disable_log_reason(
|
||||
host=node.get('host'),
|
||||
binary=node.get('binary'),
|
||||
reason='Host Failed and node evacuated.'
|
||||
)
|
||||
LOG.info('Compute host: %s has been disabled to be evacuated. '
|
||||
'Host details: %s' % (node.get('host'), str(node)))
|
||||
except Exception as e:
|
||||
LOG.error(e)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
+28
-19
@@ -11,24 +11,33 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from osha.monitor import Monitor
|
||||
import osclient
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from osha.common.osclient import OSClient
|
||||
|
||||
password = 'a22dQNcT'
|
||||
user_id = None
|
||||
username = 'admin'
|
||||
auth_url = 'http://192.168.245.9:35357/v3'
|
||||
project_name = 'demo'
|
||||
project_id = None
|
||||
user_domain_name = 'Default'
|
||||
project_domain_name = 'Default'
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
client = osclient.OSClient(authurl=auth_url,
|
||||
username=username,
|
||||
password=password,
|
||||
user_domain_name=user_domain_name,
|
||||
project_name=project_name,
|
||||
project_domain_name=project_domain_name,
|
||||
endpoint_type='internal')
|
||||
monitor = Monitor(client, 1)
|
||||
monitor.monitor()
|
||||
|
||||
class EvacuationManager(object):
|
||||
"""
|
||||
The Evacuation procedure is as follow:
|
||||
1- Put node in maintenance mode (disable node )
|
||||
2- make sure it's in maintenance mode or disabled
|
||||
3- try to fence node and shutdown it
|
||||
4- make sure node is down
|
||||
5- Get a list of instances running on this node
|
||||
6- Evacuate :)
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
@todo we cannot get the credentials from monitoring so, we need to get
|
||||
it from keystone section and we need to review that for code in other
|
||||
parts
|
||||
:return:
|
||||
"""
|
||||
credentials = CONF.get('monitoring')
|
||||
self.client = OSClient(
|
||||
authurl=credentials.get('endpoint'),
|
||||
username=credentials.get()
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from osha.monitors.common.manager import MonitorManager
|
||||
from osha.fencers.common.manager import FencerManager
|
||||
from osha.common.osclient import OSClient
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
@@ -26,10 +27,21 @@ def main():
|
||||
config.setup_logging()
|
||||
LOG.info('Starting osha ... ')
|
||||
# load and initialize the monitoring driver
|
||||
mon = CONF.get('monitoring')
|
||||
client = OSClient(
|
||||
authurl=mon.get('endpoint'),
|
||||
username=mon.get('username'),
|
||||
password=mon.get('password'),
|
||||
**mon.get('kwargs')
|
||||
)
|
||||
client.disable_node('padawan-ccp-comp0003-mgmt')
|
||||
#client.set_in_maintance(['padawan-ccp-comp0003-mgmt'])
|
||||
exit()
|
||||
monitor = MonitorManager()
|
||||
# Do the monitoring procedure
|
||||
# Monitor, analyse, nodes down ?, wait, double check ? evacuate ..
|
||||
nodes = monitor.monitor()
|
||||
|
||||
if nodes:
|
||||
# @todo put node in maintenance mode :) Not working with virtual
|
||||
# deployments
|
||||
|
||||
@@ -53,7 +53,7 @@ class MonitorManager(object):
|
||||
# of failed nodes
|
||||
nodes_down = self.driver.analyze_nodes(nodes=data)
|
||||
if not nodes_down:
|
||||
LOG.info('No nodes reported down from %s')
|
||||
LOG.info('No nodes reported down')
|
||||
return 0 # for the time being we will exit with no error !
|
||||
|
||||
LOG.info('Nodes Down are: %s will be double checked again after %s '
|
||||
|
||||
Reference in New Issue
Block a user