In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Development background:
Due to the record of overheated migration failure on OpenStack, the virtual machine remount disk will report an error, and the data disk will not be mounted, so you need to find all virtual machine processing on OpenStack that has overheated migration and failed migration, so as to avoid subsequent remount failure.
Development environment:
Centos,Python 2.7.5,OpenStack
Specific ideas:
Shell filter command
Nova list-all, find all virtual machines.
Nova instance-action-list virtual machine ID | egrep-in 'live-migration | error' filters out virtual machines with corresponding actions.
Use shell script filtering, but because the execution of the nova instance-action-list command is too slow, consider using Python to find this part of the virtual machine through the interface of OS.
Through the API interface call of OpenStack, find out all the virtual machines, and query all the actions of each virtual machine, filter out the virtual machine with live-migration action and message as Error, then output the virtual machine name and virtual machine ID.
Key steps:
1. Login authentication implementation: OpenStack mainly provides authentication services through keystoneauth components. I initialize a Session object through the keystoneauth2.session.Session class of keystoneauth components, which can store user name, password, token and other information.
2. The shell command corresponds to the method query of the novaclient library, mainly through the official document of OpenStack: https://docs.openstack.org/python-novaclient/latest/reference/index.html to query the desired method and the parameters of the method.
Specific source code #! / usr/bin/python2#-*-coding: utf-8-*-from novaclient import clientfrom keystoneauth2 import sessionfrom keystoneauth2.identity import v3import requests# login authentication auth = v3.Password (user_domain_name='Default', username='*', password='*', project_domain_name='Default' Project_name='admin', auth_url=' http://IP:35357/v3')sess = session.Session (auth=auth) nova = client.Client (2 Session=sess) # query all virtual machines instances = nova.servers.list (search_opts= {'all_tenants':'1'}) # Loop for instance in instances: # query the actions of each virtual machine for i in nova.instance_action.list (instance.id): # filter out the actions of live-migration and the result is Error if i.to_dict () [' action'] = =' Live-migration' and i.to_dict () ['message'] = =' Error': # output virtual machine name and virtual machine ID print instance.name Instance.id break summary
Python's novaclient library and keystoneauth2 library have encapsulated the specific request process. Basically, you only need to fill in the key information and then you can directly call the API API to obtain virtual machine information. The main problem encountered is that there are few API interface materials of OpenStack, and basically you need to read official documents.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.