Merge lp:~ralsina/tanuki-agent/ssh-helper into lp:tanuki-agent

Proposed by Roberto Alsina
Status: Work in progress
Proposed branch: lp:~ralsina/tanuki-agent/ssh-helper
Merge into: lp:tanuki-agent
Diff against target: 130 lines (+45/-33)
4 files modified
Makefile (+4/-2)
rpi2-sample-provkit/provision (+2/-31)
scripts/ssh-helper.py (+38/-0)
test_requirements.txt (+1/-0)
To merge this branch: bzr merge lp:~ralsina/tanuki-agent/ssh-helper
Reviewer Review Type Date Requested Status
Tanuki Squad Pending
Review via email: mp+274776@code.launchpad.net

Commit message

A new ssh-helper script to isolate paramiko usage

Description of the change

A new ssh-helper script to isolate paramiko usage

To post a comment you must log in.

Unmerged revisions

113. By Roberto Alsina

added paramiko

112. By Roberto Alsina

New ssh-helper to isolate paramiko usage

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-10-16 19:33:14 +0000
3+++ Makefile 2015-10-16 20:19:59 +0000
4@@ -22,7 +22,7 @@
5 env/bin/flake8 *.py scripts/*.py --max-line-length=99
6
7 cold-install:
8- rm -rf /tmp/pip-cache
9+ rm -rf /tmp/pip-cache
10 bzr branch lp:~tanuki/tanuki-agent/pip-cache /tmp/pip-cache
11 env/bin/pip install --no-index --find-links=/tmp/pip-cache -r requirements.txt
12 env/bin/pip install --no-index --find-links=/tmp/pip-cache -r test_requirements.txt
13@@ -37,11 +37,13 @@
14 env/bin/nuitka scripts/e2e-snap-rev.py --standalone --show-progress --remove-output
15 env/bin/nuitka scripts/e2e-noauth.py --standalone --show-progress --remove-output
16 env/bin/nuitka scripts/api_example.py --standalone --show-progress --remove-output
17+ env/bin/nuitka scripts/ssh-helper.py --standalone --show-progress --remove-output
18 rm -rf tanuki-agent-binaries
19 mkdir tanuki-agent-binaries
20- cp -n agent.dist/* api_example.dist/* e2e-image.dist/* e2e-snap-rev.dist/* e2e-noauth.dist/* tanuki-agent-binaries/
21+ cp -n agent.dist/* ssh-helper.dist/* api_example.dist/* e2e-image.dist/* e2e-snap-rev.dist/* e2e-noauth.dist/* tanuki-agent-binaries/
22 mv tanuki-agent-binaries/agent.exe tanuki-agent-binaries/agent.py
23 mv tanuki-agent-binaries/api_example.exe tanuki-agent-binaries/api_example.py
24+ mv tanuki-agent-binaries/ssh-helper.exe tanuki-agent-binaries/ssh-helper.py
25 cp README.rst tanuki-agent-binaries
26 mkdir tanuki-agent-binaries/requests
27 cp env/lib/python3.4/site-packages/requests/cacert.pem tanuki-agent-binaries/requests/cacert.pem
28
29=== modified file 'rpi2-sample-provkit/provision'
30--- rpi2-sample-provkit/provision 2015-10-16 19:30:35 +0000
31+++ rpi2-sample-provkit/provision 2015-10-16 20:19:59 +0000
32@@ -8,10 +8,6 @@
33 import os
34 import time
35
36-import paramiko
37-
38-MAX_RETRIES = 5
39-
40
41 STEPS = """
42 1. Download the image {image_name} from {image_reference}
43@@ -28,33 +24,8 @@
44 3. Insert the card into the Raspberry Pi 2, and reboot it.
45 """
46
47-
48-def wait_device(device_address, port):
49- """Wait for device to answer SSH."""
50- ssh_identity = os.getenv('SSH_IDENTITY', '~/.ssh/id_rsa.pub')
51- client = paramiko.SSHClient()
52- client.set_missing_host_key_policy(paramiko.client.MissingHostKeyPolicy())
53- for attempt_number in range(1, MAX_RETRIES + 1):
54- try:
55- client.connect(device_address, port=port, username="ubuntu", password="ubuntu",
56- look_for_keys=False, allow_agent=False)
57- except:
58- if attempt_number == MAX_RETRIES:
59- break
60- print(" device still not answering, waiting and retrying #{}...".format(
61- attempt_number))
62- time.sleep(10)
63- else:
64- pubpath = os.path.expanduser(ssh_identity)
65- with open(pubpath, "rb") as fh:
66- pubcontent = fh.read()
67- client.exec_command(b"echo '" + pubcontent + b"' >> ~/.ssh/authorized_keys")
68- return
69-
70- # we never reached the raspi in all attempts
71- print(" device never answered, quitting!")
72- print("\nPlease be sure that the Raspberry Pi 2 is in a functional state and retry.")
73- exit(1)
74+def wait_device(ip, port):
75+ subprocess.check_call(['ssh-helper.py', ip, port])
76
77
78 def main(args):
79
80=== added file 'scripts/ssh-helper.py'
81--- scripts/ssh-helper.py 1970-01-01 00:00:00 +0000
82+++ scripts/ssh-helper.py 2015-10-16 20:19:59 +0000
83@@ -0,0 +1,38 @@
84+#!/usr/bin/env python
85+
86+import sys
87+
88+import paramiko
89+
90+MAX_RETRIES = 5
91+
92+def main(device_address, port):
93+ """Wait for device to answer SSH."""
94+ ssh_identity = os.getenv('SSH_IDENTITY', '~/.ssh/id_rsa.pub')
95+ client = paramiko.SSHClient()
96+ client.set_missing_host_key_policy(paramiko.client.MissingHostKeyPolicy())
97+ for attempt_number in range(1, MAX_RETRIES + 1):
98+ try:
99+ client.connect(device_address, port=port, username="ubuntu", password="ubuntu",
100+ look_for_keys=False, allow_agent=False)
101+ except:
102+ if attempt_number == MAX_RETRIES:
103+ break
104+ print(" device still not answering, waiting and retrying #{}...".format(
105+ attempt_number))
106+ time.sleep(10)
107+ else:
108+ pubpath = os.path.expanduser(ssh_identity)
109+ with open(pubpath, "rb") as fh:
110+ pubcontent = fh.read()
111+ client.exec_command(b"echo '" + pubcontent + b"' >> ~/.ssh/authorized_keys")
112+ return
113+
114+ # we never reached the raspi in all attempts
115+ print(" device never answered, quitting!")
116+ print("\nPlease be sure that the Raspberry Pi 2 is in a functional state and retry.")
117+ exit(1)
118+
119+
120+if __name__ == "__main__":
121+ main(sys.argv[1], sys.argv[2])
122
123=== modified file 'test_requirements.txt'
124--- test_requirements.txt 2015-10-16 19:19:22 +0000
125+++ test_requirements.txt 2015-10-16 20:19:59 +0000
126@@ -2,3 +2,4 @@
127 pytest==2.7.2
128 pytest-capturelog==0.7
129 Markdown==2.6.2
130+paramiko==1.15.3

Subscribers

People subscribed via source and target branches

to all changes: