Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kubespray
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
e44b0727
Commit
e44b0727
authored
5 years ago
by
Matthew Mosesohn
Committed by
Kubernetes Prow Robot
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow inventory_builder to add nodes with hostname (#5398)
Change-Id: Ifd7dd7ce8778f4f1be2016cae8d74452173b5312
parent
18cee65c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contrib/inventory_builder/inventory.py
+22
-5
22 additions, 5 deletions
contrib/inventory_builder/inventory.py
contrib/inventory_builder/tests/test_inventory.py
+1
-1
1 addition, 1 deletion
contrib/inventory_builder/tests/test_inventory.py
with
23 additions
and
6 deletions
contrib/inventory_builder/inventory.py
+
22
−
5
View file @
e44b0727
...
...
@@ -20,6 +20,8 @@
# Add range of hosts: inventory.py 10.10.1.3-10.10.1.5
# Add hosts with different ip and access ip:
# inventory.py 10.0.0.1,192.168.10.1 10.0.0.2,192.168.10.2 10.0.0.3,192.168.1.3
# Add hosts with a specific hostname, ip, and optional access ip:
# inventory.py first,10.0.0.1,192.168.10.1 second,10.0.0.2 last,10.0.0.3
# Delete a host: inventory.py -10.10.1.3
# Delete a host by id: inventory.py -node1
#
...
...
@@ -44,7 +46,8 @@ import sys
ROLES
=
[
'
all
'
,
'
kube-master
'
,
'
kube-node
'
,
'
etcd
'
,
'
k8s-cluster
'
,
'
calico-rr
'
]
PROTECTED_NAMES
=
ROLES
AVAILABLE_COMMANDS
=
[
'
help
'
,
'
print_cfg
'
,
'
print_ips
'
,
'
print_hostnames
'
,
'
load
'
]
AVAILABLE_COMMANDS
=
[
'
help
'
,
'
print_cfg
'
,
'
print_ips
'
,
'
print_hostnames
'
,
'
load
'
]
_boolean_states
=
{
'
1
'
:
True
,
'
yes
'
:
True
,
'
true
'
:
True
,
'
on
'
:
True
,
'
0
'
:
False
,
'
no
'
:
False
,
'
false
'
:
False
,
'
off
'
:
False
}
yaml
=
YAML
()
...
...
@@ -79,7 +82,7 @@ class KubesprayInventory(object):
try
:
self
.
hosts_file
=
open
(
config_file
,
'
r
'
)
self
.
yaml_config
=
yaml
.
load
(
self
.
hosts_file
)
except
FileNotFound
Error
:
except
OS
Error
:
pass
if
changed_hosts
and
changed_hosts
[
0
]
in
AVAILABLE_COMMANDS
:
...
...
@@ -194,8 +197,21 @@ class KubesprayInventory(object):
'
ip
'
:
ip
,
'
access_ip
'
:
access_ip
}
elif
host
[
0
].
isalpha
():
raise
Exception
(
"
Adding hosts by hostname is not supported.
"
)
if
'
,
'
in
host
:
try
:
hostname
,
ip
,
access_ip
=
host
.
split
(
'
,
'
)
except
Exception
:
hostname
,
ip
=
host
.
split
(
'
,
'
)
access_ip
=
ip
if
self
.
exists_hostname
(
all_hosts
,
host
):
self
.
debug
(
"
Skipping existing host {0}.
"
.
format
(
host
))
continue
elif
self
.
exists_ip
(
all_hosts
,
ip
):
self
.
debug
(
"
Skipping existing host {0}.
"
.
format
(
ip
))
continue
all_hosts
[
hostname
]
=
{
'
ansible_host
'
:
access_ip
,
'
ip
'
:
ip
,
'
access_ip
'
:
access_ip
}
return
all_hosts
def
range2ips
(
self
,
hosts
):
...
...
@@ -206,7 +222,7 @@ class KubesprayInventory(object):
# Python 3.x
start
=
int
(
ip_address
(
start_address
))
end
=
int
(
ip_address
(
end_address
))
except
:
except
Exception
:
# Python 2.7
start
=
int
(
ip_address
(
unicode
(
start_address
)))
end
=
int
(
ip_address
(
unicode
(
end_address
)))
...
...
@@ -369,6 +385,7 @@ Advanced usage:
Add another host after initial creation: inventory.py 10.10.1.5
Add range of hosts: inventory.py 10.10.1.3-10.10.1.5
Add hosts with different ip and access ip: inventory.py 10.0.0.1,192.168.10.1 10.0.0.2,192.168.10.2 10.0.0.3,192.168.10.3
Add hosts with a specific hostname, ip, and optional access ip: first,10.0.0.1,192.168.10.1 second,10.0.0.2 last,10.0.0.3
Delete a host: inventory.py -10.10.1.3
Delete a host by id: inventory.py -node1
...
...
This diff is collapsed.
Click to expand it.
contrib/inventory_builder/tests/test_inventory.py
+
1
−
1
View file @
e44b0727
...
...
@@ -22,7 +22,7 @@ path = "./contrib/inventory_builder/"
if
path
not
in
sys
.
path
:
sys
.
path
.
append
(
path
)
import
inventory
import
inventory
# noqa
class
TestInventory
(
unittest
.
TestCase
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment