Add support for custom ssh port

This change adds 'ssh_port' to the Node class.

Change-Id: I5e6d3969ae04f90abd1a3fd908c160cda4791bad
This commit is contained in:
Tristan Cacqueray 2017-05-29 00:29:47 +00:00
parent ccc488ab54
commit a5077fc344
6 changed files with 25 additions and 7 deletions

0
nodepool/cmd/nodepoolcmd.py Normal file → Executable file
View File

6
nodepool/nodeutils.py Normal file → Executable file
View File

@ -44,7 +44,7 @@ def iterate_timeout(max_seconds, exc, purpose):
raise exc("Timeout waiting for %s" % purpose)
def keyscan(ip, timeout=60):
def keyscan(ip, port=22, timeout=60):
'''
Scan the IP address for public SSH keys.
@ -55,10 +55,10 @@ def keyscan(ip, timeout=60):
if ipaddress.ip_address(six.text_type(ip)).version < 6:
family = socket.AF_INET
sockaddr = (ip, 22)
sockaddr = (ip, port)
else:
family = socket.AF_INET6
sockaddr = (ip, 22, 0, 0)
sockaddr = (ip, port, 0, 0)
keys = []
key = None

8
nodepool/status.py Normal file → Executable file
View File

@ -32,7 +32,7 @@ def age(timestamp):
def node_list(zk, node_id=None):
t = PrettyTable(["ID", "Provider", "AZ", "Label",
"Launcher", "Hostname", "Server ID",
"Public IPv4", "Private IPv4", "IPv6",
"Public IPv4", "Private IPv4", "IPv6", "SSH Port",
"State", "Age", "Locked", "Comment"])
t.align = 'l'
if node_id:
@ -49,7 +49,8 @@ def node_list(zk, node_id=None):
t.add_row([node.id, node.provider, node.az, node.type,
node.launcher, node.hostname, node.external_id,
node.public_ipv4, node.private_ipv4, node.public_ipv6,
node.state, age(node.state_time), locked, node.comment])
node.ssh_port, node.state, age(node.state_time), locked,
node.comment])
else:
for node in zk.nodeIterator():
locked = "unlocked"
@ -62,7 +63,8 @@ def node_list(zk, node_id=None):
t.add_row([node.id, node.provider, node.az, node.type,
node.launcher, node.hostname, node.external_id,
node.public_ipv4, node.private_ipv4, node.public_ipv6,
node.state, age(node.state_time), locked, node.comment])
node.ssh_port, node.state, age(node.state_time), locked,
node.comment])
return str(t)

View File

@ -59,7 +59,7 @@ class TestNodepoolCMD(tests.DBTestCase):
self.assert_listed(configfile, ['image-list'], 6, status, image_cnt)
def assert_nodes_listed(self, configfile, node_cnt, status="ready"):
self.assert_listed(configfile, ['list'], 10, status, node_cnt)
self.assert_listed(configfile, ['list'], 11, status, node_cnt)
def test_image_list_empty(self):
self.assert_images_listed(self.setup_config("node_cmd.yaml"), 0)

View File

@ -832,6 +832,7 @@ class TestZKModel(tests.BaseTestCase):
'hostname': 'xyz',
'comment': 'comment',
'host_keys': ['key1', 'key2'],
'ssh_port': 22022,
}
o = zk.Node.fromDict(d, node_id)
@ -853,3 +854,15 @@ class TestZKModel(tests.BaseTestCase):
self.assertEqual(o.hostname , d['hostname'])
self.assertEqual(o.comment , d['comment'])
self.assertEqual(o.host_keys , d['host_keys'])
self.assertEqual(o.ssh_port , d['ssh_port'])
def test_custom_ssh_port(self):
n = zk.Node('0001')
n.state = zk.BUILDING
d = n.toDict()
self.assertEqual(d["ssh_port"], 22, "Default port not 22")
n = zk.Node.fromDict(d, '0001')
self.assertEqual(n.ssh_port, 22, "Default port not 22")
n.ssh_port = 22022
d = n.toDict()
self.assertEqual(d["ssh_port"], 22022, "Custom ssh port not set")

3
nodepool/zk.py Normal file → Executable file
View File

@ -418,6 +418,7 @@ class Node(BaseModel):
self.private_ipv4 = None
self.public_ipv6 = None
self.interface_ip = None
self.ssh_port = 22
self.image_id = None
self.launcher = None
self.created_time = None
@ -472,6 +473,7 @@ class Node(BaseModel):
d['private_ipv4'] = self.private_ipv4
d['public_ipv6'] = self.public_ipv6
d['interface_ip'] = self.interface_ip
d['ssh_port'] = self.ssh_port
d['image_id'] = self.image_id
d['launcher'] = self.launcher
d['created_time'] = self.created_time
@ -503,6 +505,7 @@ class Node(BaseModel):
o.private_ipv4 = d.get('private_ipv4')
o.public_ipv6 = d.get('public_ipv6')
o.interface_ip = d.get('interface_ip')
o.ssh_port = d.get('ssh_port', 22)
o.image_id = d.get('image_id')
o.launcher = d.get('launcher')
o.created_time = d.get('created_time')