Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import paramiko |
| 16 | |
| 17 | def onos_command_execute(host, portNum, cmd, user='karaf', passwd='karaf'): |
| 18 | """ |
| 19 | :param host: onos-cord or onos-fabric |
| 20 | :param portNum: 8102 or 8101 |
| 21 | :param cmd: command to execute |
| 22 | :param user: onos/karaf |
| 23 | :param passwd: onos/karaf |
| 24 | :return: output of command executed inside onos karaf (shell) |
| 25 | """ |
| 26 | try: |
| 27 | client = paramiko.SSHClient() |
| 28 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| 29 | client.connect(host, port=int(portNum), username=user, password=passwd) |
| 30 | stdin, stdout, stderr = client.exec_command(cmd) |
| 31 | while not stdout.channel.exit_status_ready(): |
| 32 | if stdout.channel.recv_ready(): |
| 33 | return stdout.read() |
| 34 | finally: |
| 35 | client.close() |
| 36 | |
| 37 | def get_compute_node_ip(compute_node): |
| 38 | """ |
| 39 | :param compute_node: one compute node information from output of 'cordvtn-nodes' |
| 40 | :return: data_ip of that compute node |
| 41 | """ |
| 42 | for line in compute_node.splitlines(): |
| 43 | columns = line.split() |
| 44 | if len(columns) >= 2: |
| 45 | return columns[2].split("/")[0] |