티스토리 뷰

openstack client

Jacob_baek 2017. 7. 3. 13:53

openstack API를 활용한 VM live_migration을 수행하는 python script 이다.


import os

from keystoneauth1.identity import v3
from keystoneauth1 import session
from novaclient import client

def auth(user, passwd, url):
    auth = v3.Password(auth_url=url,
                       username=user,
                       password=passwd,
                       project_name='admin',
                       user_domain_id='default',
                       project_domain_name='default')
    sess = session.Session(auth=auth, verify=False)
    return sess

def migrate(srv, new_host):
    return srv.live_migrate(host=new_host, block_migration=False)

def main():
    user = 'admin'
    passwd = 'Password'
    sess = auth(user, passwd, 'http://192.168.1.1:5000/v3')
    nova = client.Client(2, session=sess)

    for srv in nova.servers.list():
        hostname = getattr(srv, "OS-EXT-SRV-ATTR:host")
        if (srv.name.find('TESTVM1') is 0) and \
           (hostname != "overcloud-compute-2.localdomain"):
           migrate(srv, "overcloud-compute-2.localdomain")
           print srv.name, hostname
        if (srv.name.find('TESTVM2') is 0) and \
           (hostname != "overcloud-compute-0.localdomain"):
           migrate(srv, "overcloud-compute-0.localdomain")
           print srv.name, hostname

if __name__ == '__main__':
    main()

아래 base.py에 보면 일반적으로 사용되는 function들이 나와있다. 참고하도록 한다.

- https://github.com/openstack/python-novaclient/blob/master/novaclient/base.py


참고사이트

- https://gist.github.com/djoreilly/888abbfc3425e54fa290

- https://www.ibm.com/developerworks/cloud/library/cl-openstack-pythonapis/index.html

'' 카테고리의 다른 글

attached to none on /dev/vda  (0) 2017.07.14
error about security group in use  (0) 2017.07.12
openstack client  (0) 2017.07.03
spice console  (0) 2017.06.19
error message about mysql is not running with galera  (0) 2017.06.15
no valid host error  (0) 2017.06.13
댓글
댓글쓰기 폼