summaryrefslogtreecommitdiffstats
path: root/docs/release/scenarios/os-odl_l3-ovs-ha/index.rst
blob: fadf8e45a8f510012cdea899349deff3ad4fac78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.. _os-odl_l3-ovs-no:

.. OPNFV - Open Platform for Network Function Virtualization
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0


*******************************************************************************
User Space Accelarated OVS scenario: os-odl_l3-ovs-no Overview and Description
*******************************************************************************

Scenario: "OpenStack - ovs-nfv" (apex-os-odl_l3-ovs-no)
is a scenario developed as part of the ovsnfv
OPNFV project.

.. toctree::
   :numbered:
   :maxdepth: 2

   scenario.description.rst
ff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/usr/bin/env python2.7

##
## Copyright (c) 2019 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## 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.
##

import paramiko
import logging

class SSHClient:
    """Wrapper class for paramiko module to connect via SSH
    """
    _log = None

    _ip = None
    _user = None
    _rsa_private_key = None
    _timeout = None
    _ssh = None
    _connected = False

    _output = None
    _error = None

    def __init__(self, ip=None, user=None, rsa_private_key=None, timeout=15, logger_name=None):
        self._ip = ip
        self._user = user
        self._rsa_private_key = rsa_private_key
        self._timeout = timeout

        if (logger_name is not None):
            self._log = logging.getLogger(logger_name)

        self._connected = False

    def set_credentials(self, ip, user, rsa_private_key):
        self._ip = ip
        self._user = user
        self._rsa_private_key = rsa_private_key

    def connect(self):
        if self._connected:
            if (self._log is not None):
                self._log.debug("Already connected!")
            return

        if ((self._ip is None) or (self._user is None) or
            (self._rsa_private_key is None)):
            if (self._log is not None):
                self._log.error("Wrong parameter! IP %s, user %s, RSA private key %s"
                                % (self._ip, self._user, self._rsa_private_key))
            self._connected = False
            return

        self._ssh = paramiko.SSHClient()
        self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        private_key = paramiko.RSAKey.from_private_key_file(self._rsa_private_key)

        try:
            self._ssh.connect(hostname = self._ip, username = self._user, pkey = private_key)
        except Exception as e:
            if (self._log is not None):
                self._log.error("Failed to connect to the host! IP %s, user %s, RSA private key %s\n%s"
                                % (self._ip, self._user, self._rsa_private_key, e))
            self._connected = False
            self._ssh.close()
            return

        self._connected = True

    def disconnect(self):
        if self._connected:
            self._connected = False
            self._ssh.close()

    def run_cmd(self, cmd):
        self.connect()

        if self._connected is not True:
            return -1

        try:
            ret = 0
            _stdin, stdout, stderr = self._ssh.exec_command(cmd, timeout = self._timeout)
            self._output = stdout.read()
            self._error = stderr.read()
        except Exception as e:
            if (self._log is not None):
                self._log.error("Failed to execute command! IP %s, cmd %s\n%s"
                                % (self._ip, cmd, e))
            ret = -1

        self.disconnect()

        return ret

    def get_output(self):
        return self._output

    def get_error(self):
        return self._error