Merge "docs: Update install and release docs for DPDK migration support"
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / remotesystem.py
1 #!/bin/env python
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 import os
20 import time
21 import socket
22
23 def ssh(user, ip, cmd):
24     # print cmd;
25     ssh_options = ""
26     ssh_options += "-o StrictHostKeyChecking=no "
27     ssh_options += "-o UserKnownHostsFile=/dev/null "
28     ssh_options += "-o LogLevel=quiet "
29     running = os.popen("ssh " + ssh_options + " " + user + "@" + ip + " \"" + cmd + "\"");
30     ret = {};
31     ret['out'] = running.read().strip();
32     ret['ret'] = running.close();
33     if (ret['ret'] == None):
34         ret['ret'] = 0;
35
36     return ret;
37
38 def ssh_check_quit(obj, user, ip, cmd):
39     ret = ssh(user, ip, cmd);
40     if (ret['ret'] != 0):
41         obj._err = True;
42         obj._err_str = ret['out'];
43         exit(-1);
44
45 class remoteSystem:
46     def __init__(self, user, ip):
47         self._ip          = ip;
48         self._user        = user;
49
50     def run(self, cmd):
51         return ssh(self._user, self._ip, cmd);
52
53     def scp(self, src, dst):
54         running = os.popen("scp " + self._user + "@" + self._ip + ":" + src + " " + dst);
55         return running.close();
56
57     def getIP(self):
58         return self._ip