1 # -*- coding: utf-8 -*-
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
25 This is thread that interact with the host and the libvirt to manage VM
26 One thread will be launched per host
28 __author__
= "Alfonso Tierno"
29 __date__
= "$10-feb-2017 12:07:15$"
39 # from logging import Logger
40 # import auxiliary_functions as af
42 # TODO: insert a logging system
45 class vim_thread(threading
.Thread
):
47 def __init__(self
, vimconn
, name
=None):
52 'host','user': host ip or name to manage and user
53 'db', 'db_lock': database class and lock to use it in exclusion
55 threading
.Thread
.__init
__(self
)
58 self
.name
= vimconn
["id"] + "-" + vimconn
["config"]["datacenter_tenant_id"]
62 self
.logger
= logging
.getLogger('openmano.vim.'+self
.name
)
64 self
.queueLock
= threading
.Lock()
65 self
.taskQueue
= Queue
.Queue(2000)
68 def insert_task(self
, task
, *aditional
):
70 self
.queueLock
.acquire()
71 task
= self
.taskQueue
.put( (task
,) + aditional
, timeout
=5)
72 self
.queueLock
.release()
75 return -1, "timeout inserting a task over host " + self
.name
78 self
.logger
.debug("Starting")
82 self
.queueLock
.acquire()
83 if not self
.taskQueue
.empty():
84 task
= self
.taskQueue
.get()
87 self
.queueLock
.release()
94 if task
[0] == 'instance':
96 elif task
[0] == 'image':
98 elif task
[0] == 'exit':
99 print self
.name
, ": processing task exit"
102 elif task
[0] == 'reload':
103 print self
.name
, ": processing task reload terminating and relaunching"
106 elif task
[0] == 'edit-iface':
108 elif task
[0] == 'restore-iface':
110 elif task
[0] == 'new-ovsbridge':
112 elif task
[0] == 'new-vxlan':
114 elif task
[0] == 'del-ovsbridge':
116 elif task
[0] == 'del-vxlan':
118 elif task
[0] == 'create-ovs-bridge-port':
120 elif task
[0] == 'del-ovs-port':
123 self
.logger
.error("unknown task %s", str(task
))
125 self
.logger
.debug("Finishing")