Merge "Add support for custom ssh port" into feature/zuulv3
This commit is contained in:
commit
520703b776
0
nodepool/cmd/nodepoolcmd.py
Normal file → Executable file
0
nodepool/cmd/nodepoolcmd.py
Normal file → Executable file
6
nodepool/nodeutils.py
Normal file → Executable file
6
nodepool/nodeutils.py
Normal file → Executable file
@ -44,7 +44,7 @@ def iterate_timeout(max_seconds, exc, purpose):
|
|||||||
raise exc("Timeout waiting for %s" % 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.
|
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:
|
if ipaddress.ip_address(six.text_type(ip)).version < 6:
|
||||||
family = socket.AF_INET
|
family = socket.AF_INET
|
||||||
sockaddr = (ip, 22)
|
sockaddr = (ip, port)
|
||||||
else:
|
else:
|
||||||
family = socket.AF_INET6
|
family = socket.AF_INET6
|
||||||
sockaddr = (ip, 22, 0, 0)
|
sockaddr = (ip, port, 0, 0)
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
key = None
|
key = None
|
||||||
|
8
nodepool/status.py
Normal file → Executable file
8
nodepool/status.py
Normal file → Executable file
@ -32,7 +32,7 @@ def age(timestamp):
|
|||||||
def node_list(zk, node_id=None):
|
def node_list(zk, node_id=None):
|
||||||
t = PrettyTable(["ID", "Provider", "AZ", "Label",
|
t = PrettyTable(["ID", "Provider", "AZ", "Label",
|
||||||
"Launcher", "Hostname", "Server ID",
|
"Launcher", "Hostname", "Server ID",
|
||||||
"Public IPv4", "Private IPv4", "IPv6",
|
"Public IPv4", "Private IPv4", "IPv6", "SSH Port",
|
||||||
"State", "Age", "Locked", "Comment"])
|
"State", "Age", "Locked", "Comment"])
|
||||||
t.align = 'l'
|
t.align = 'l'
|
||||||
if node_id:
|
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,
|
t.add_row([node.id, node.provider, node.az, node.type,
|
||||||
node.launcher, node.hostname, node.external_id,
|
node.launcher, node.hostname, node.external_id,
|
||||||
node.public_ipv4, node.private_ipv4, node.public_ipv6,
|
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:
|
else:
|
||||||
for node in zk.nodeIterator():
|
for node in zk.nodeIterator():
|
||||||
locked = "unlocked"
|
locked = "unlocked"
|
||||||
@ -62,7 +63,8 @@ def node_list(zk, node_id=None):
|
|||||||
t.add_row([node.id, node.provider, node.az, node.type,
|
t.add_row([node.id, node.provider, node.az, node.type,
|
||||||
node.launcher, node.hostname, node.external_id,
|
node.launcher, node.hostname, node.external_id,
|
||||||
node.public_ipv4, node.private_ipv4, node.public_ipv6,
|
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)
|
return str(t)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class TestNodepoolCMD(tests.DBTestCase):
|
|||||||
self.assert_listed(configfile, ['image-list'], 6, status, image_cnt)
|
self.assert_listed(configfile, ['image-list'], 6, status, image_cnt)
|
||||||
|
|
||||||
def assert_nodes_listed(self, configfile, node_cnt, status="ready"):
|
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):
|
def test_image_list_empty(self):
|
||||||
self.assert_images_listed(self.setup_config("node_cmd.yaml"), 0)
|
self.assert_images_listed(self.setup_config("node_cmd.yaml"), 0)
|
||||||
|
@ -832,6 +832,7 @@ class TestZKModel(tests.BaseTestCase):
|
|||||||
'hostname': 'xyz',
|
'hostname': 'xyz',
|
||||||
'comment': 'comment',
|
'comment': 'comment',
|
||||||
'host_keys': ['key1', 'key2'],
|
'host_keys': ['key1', 'key2'],
|
||||||
|
'ssh_port': 22022,
|
||||||
}
|
}
|
||||||
|
|
||||||
o = zk.Node.fromDict(d, node_id)
|
o = zk.Node.fromDict(d, node_id)
|
||||||
@ -853,3 +854,15 @@ class TestZKModel(tests.BaseTestCase):
|
|||||||
self.assertEqual(o.hostname , d['hostname'])
|
self.assertEqual(o.hostname , d['hostname'])
|
||||||
self.assertEqual(o.comment , d['comment'])
|
self.assertEqual(o.comment , d['comment'])
|
||||||
self.assertEqual(o.host_keys , d['host_keys'])
|
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
3
nodepool/zk.py
Normal file → Executable file
@ -418,6 +418,7 @@ class Node(BaseModel):
|
|||||||
self.private_ipv4 = None
|
self.private_ipv4 = None
|
||||||
self.public_ipv6 = None
|
self.public_ipv6 = None
|
||||||
self.interface_ip = None
|
self.interface_ip = None
|
||||||
|
self.ssh_port = 22
|
||||||
self.image_id = None
|
self.image_id = None
|
||||||
self.launcher = None
|
self.launcher = None
|
||||||
self.created_time = None
|
self.created_time = None
|
||||||
@ -472,6 +473,7 @@ class Node(BaseModel):
|
|||||||
d['private_ipv4'] = self.private_ipv4
|
d['private_ipv4'] = self.private_ipv4
|
||||||
d['public_ipv6'] = self.public_ipv6
|
d['public_ipv6'] = self.public_ipv6
|
||||||
d['interface_ip'] = self.interface_ip
|
d['interface_ip'] = self.interface_ip
|
||||||
|
d['ssh_port'] = self.ssh_port
|
||||||
d['image_id'] = self.image_id
|
d['image_id'] = self.image_id
|
||||||
d['launcher'] = self.launcher
|
d['launcher'] = self.launcher
|
||||||
d['created_time'] = self.created_time
|
d['created_time'] = self.created_time
|
||||||
@ -503,6 +505,7 @@ class Node(BaseModel):
|
|||||||
o.private_ipv4 = d.get('private_ipv4')
|
o.private_ipv4 = d.get('private_ipv4')
|
||||||
o.public_ipv6 = d.get('public_ipv6')
|
o.public_ipv6 = d.get('public_ipv6')
|
||||||
o.interface_ip = d.get('interface_ip')
|
o.interface_ip = d.get('interface_ip')
|
||||||
|
o.ssh_port = d.get('ssh_port', 22)
|
||||||
o.image_id = d.get('image_id')
|
o.image_id = d.get('image_id')
|
||||||
o.launcher = d.get('launcher')
|
o.launcher = d.get('launcher')
|
||||||
o.created_time = d.get('created_time')
|
o.created_time = d.get('created_time')
|
||||||
|
Loading…
Reference in New Issue
Block a user