Created
April 10, 2017 18:01
-
-
Save dav1x/a4d74773d415bfbd0cd29f4d92d7723c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_inventory_file(self): | |
total_nodes=int(self.master_nodes)+int(self.app_nodes)+int(self.infra_nodes)+int(self.support_nodes)+int(self.args.node_number) | |
nodes_remove=int(self.master_nodes)+int(self.app_nodes)+int(self.infra_nodes)+int(self.support_nodes) | |
ip4addr = [] | |
for i in range(total_nodes): | |
p = iptools.ipv4.ip2long(self.vm_ipaddr_start) + i | |
ip4addr.append(iptools.ipv4.long2ip(p)) | |
unusedip4addr = [] | |
for i in range(0, int(self.args.node_number)): | |
unusedip4addr.insert(0, ip4addr.pop()) | |
d = {} | |
d['host_inventory'] = {} | |
for i in range(0, int(self.args.node_number)): | |
#determine node_number increment on the number of nodes | |
if self.args.node_type == 'app': | |
node_ip = int(self.app_nodes) + i | |
guest_name = self.args.node_type + '-' + str(node_ip) | |
if self.args.node_type == 'infra': | |
node_ip = int(self.infra_nodes) + i | |
guest_name = self.args.node_type + '-' + str(node_ip) | |
if self.ocp_hostname_prefix: | |
guest_name = self.ocp_hostname_prefix + guest_name | |
d['host_inventory'][guest_name] = {} | |
d['host_inventory'][guest_name]['guestname'] = guest_name | |
d['host_inventory'][guest_name]['ip4addr'] = unusedip4addr[0] | |
d['host_inventory'][guest_name]['tag'] = self.args.node_type | |
del unusedip4addr[0] | |
with open(self.inventory_file, 'w') as outfile: | |
json.dump(d, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment