blob: ac07dc20e12e9857b6ea5c5ebb79bd8dc835ed95 [file] [log] [blame]
Kailash Khalasi2f567a42017-09-27 13:50:05 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Zack Williamsc6722d52020-01-13 16:34:33 -070015from __future__ import absolute_import
16
Kailash Khalasi2f567a42017-09-27 13:50:05 -070017import paramiko
18
Zack Williamsc6722d52020-01-13 16:34:33 -070019
20def onos_command_execute(host, portNum, cmd, user="karaf", passwd="karaf"):
Kailash Khalasi2f567a42017-09-27 13:50:05 -070021 """
22 :param host: onos-cord or onos-fabric
23 :param portNum: 8102 or 8101
24 :param cmd: command to execute
25 :param user: onos/karaf
26 :param passwd: onos/karaf
27 :return: output of command executed inside onos karaf (shell)
28 """
29 try:
30 client = paramiko.SSHClient()
31 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
32 client.connect(host, port=int(portNum), username=user, password=passwd)
33 stdin, stdout, stderr = client.exec_command(cmd)
34 while not stdout.channel.exit_status_ready():
35 if stdout.channel.recv_ready():
36 return stdout.read()
37 finally:
38 client.close()
39
Zack Williamsc6722d52020-01-13 16:34:33 -070040
Kailash Khalasi2f567a42017-09-27 13:50:05 -070041def get_compute_node_ip(compute_node):
42 """
43 :param compute_node: one compute node information from output of 'cordvtn-nodes'
44 :return: data_ip of that compute node
45 """
46 for line in compute_node.splitlines():
47 columns = line.split()
48 if len(columns) >= 2:
Zack Williamsc6722d52020-01-13 16:34:33 -070049 return columns[2].split("/")[0]