4 from contextlib
import contextmanager
8 from hypervisor_base
import HypervisorBase
11 logger = logging.getLogger(__name__)
49 def _error_handling(self, nfioError):
53 logger.error(ex.message, exc_info=
False)
64 def _is_empty(self, string):
65 return string
is None or string.strip() ==
""
67 def _validate_host(self, host):
71 def _validate_image_name(self, image_name):
75 def _validate_cont_name(self, cont_name):
100 def _get_client(self, host):
103 return docker.Client(
110 def _lookup_vnf(self, host, user, vnf_name):
112 vnf_fullname = user +
'-' + vnf_name
116 inspect_data = dcx.inspect_container(container=vnf_fullname)
117 return dcx, vnf_fullname, inspect_data
131 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
132 return inspect_data[
'Id'].encode(
'ascii')
146 if self.
guest_status(host, user, vnf_name) !=
'running':
148 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
149 return inspect_data[
'NetworkSettings'][
'IPAddress'].encode(
'ascii')
166 def deploy(self, host, user, image_name, vnf_name, is_privileged=True):
169 vnf_fullname = user +
'-' + vnf_name
174 host_config[
'Privileged'] =
True
176 container = dcx.create_container(
180 host_config=host_config)
181 return container[
'Id']
194 def start(self, host, user, vnf_name, is_privileged=True):
195 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
197 dcx.start(container=vnf_fullname,
199 privileged=is_privileged)
211 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
213 dcx.restart(container=vnf_fullname)
224 def stop(self, host, user, vnf_name):
225 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
227 dcx.stop(container=vnf_fullname)
238 def pause(self, host, user, vnf_name):
239 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
241 dcx.pause(container=vnf_fullname)
252 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
254 dcx.unpause(container=vnf_fullname)
267 def destroy(self, host, user, vnf_name, force=True):
268 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
270 dcx.remove_container(container=vnf_fullname, force=force)
285 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
286 if self.
guest_status(host, user, vnf_name) !=
'running':
289 response = dcx.execute(vnf_fullname,
290 [
"/bin/bash",
"-c", cmd], stdout=
True, stderr=
False)
305 dcx, vnf_fullname, inspect_data = self.
_lookup_vnf(host, user, vnf_name)
306 return inspect_data[
'State'][
'Status'].encode(
'ascii')
def destroy
Destroys a docker container.
def _error_handling
convert docker-py exceptions to nfio exceptions
def get_ip
Returns a container's IP address.
def stop
Stops a docker container.
def pause
Pauses a docker container.
def restart
Restarts a docker container.
def get_id
Returns a container's ID.
def execute_in_guest
Executed commands inside a docker container.
def start
Starts a docker container.
def _is_empty
checks whether a string is empty or None
def unpause
Unpauses a docker container.
def _get_client
Returns a Docker client.
def guest_status
Returns the status of a docker container.
def deploy
Deploys a docker container.