This commit is contained in:
2023-03-17 01:50:20 +02:00
parent 1c86f4301c
commit 696062ad3a

View File

@@ -975,6 +975,11 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
# Any input other than yes does not continue the node creation
assert confirm == "yes", "User did not confirm"
if provider == "gce":
gceNodes = driver.list_nodes()
for gceNode in gceNodes:
if gceNode.name == name:
print("A node with that name already exists under this project, please choose another one")
exit(0)
node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata)
elif provider == "azure":
sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP)
@@ -1036,6 +1041,11 @@ def create_node(provider, name=None, location=None, size=None, image=None, confi
else:
# When the -y or --yes parameter is passed we go straight to the node creation
if provider == "gce":
gceNodes = driver.list_nodes()
for gceNode in gceNodes:
if gceNode.name == name:
print("A node with that name already exists under this project, please choose another one")
exit(0)
node = driver.create_node(name=name, image=image, size=size, location=location, ex_service_accounts=sa_scopes, ex_metadata=metadata)
elif provider == "azure":
sec_groups = driver.ex_list_network_security_groups(SECDEP_AZURE_RESOURCE_GROUP)
@@ -1140,16 +1150,16 @@ def list_all_nodes(filterIn=None):
# available states: running, rebooting, terminated, pending, stopped, suspended, paused, erro, unknown
# for delete
if filterIn == "delete":
nodes = list(filter(lambda x: 'running' in x.state.lower() and 'rebooting' in x.state.lower() and 'stopped' in x.state.lower() and 'suspended' in x.state.lower() and 'paused' in x.state.lower(), nodes))
nodes = list(filter(lambda x: 'running' in x.state.lower() or 'rebooting' in x.state.lower() or 'stopped' in x.state.lower() or 'suspended' in x.state.lower() or 'paused' in x.state.lower(), nodes))
# for start
if filterIn == "start":
nodes = list(filter(lambda x: 'stopped' in x.state.lower() and 'suspended' in x.state.lower() and 'paused' in x.state.lower(), nodes))
nodes = list(filter(lambda x: 'stopped' in x.state.lower() or 'suspended' in x.state.lower() or 'paused' in x.state.lower(), nodes))
# for stop
if filterIn == "stop":
nodes = list(filter(lambda x: 'running' in x.state.lower() and 'rebooting' in x.state.lower(), nodes))
nodes = list(filter(lambda x: 'running' in x.state.lower() or 'rebooting' in x.state.lower(), nodes))
# for reboot
if filterIn == "reboot":
nodes = list(filter(lambda x: 'running' in x.state.lower() and 'stopped' in x.state.lower() and 'suspended' in x.state.lower() and 'paused' in x.state.lower(), nodes))
nodes = list(filter(lambda x: 'running' in x.state.lower() or 'suspended' in x.state.lower() or 'paused' in x.state.lower(), nodes))
for node in nodes:
count += 1
print("{}) {}\n\nState: {}\nPublic IPs: {}\nPrivate IPs: {}\nDriver: {}\nSize: {}\nImage: {}\nCreation Date: {}\nExtra: {}\n".format(count, node.name, node.state, node.public_ips, node.private_ips, node.driver, node.size, node.image, node.created_at, node.extra))
@@ -1182,14 +1192,14 @@ def node_action(action):
case "start":
succeded = driver.start_node(node)
case "delete":
succeded = driver.delete_node(node)
succeded = driver.destroy_node(node)
case _:
print("Invalid action command")
exit(0)
if(succeded):
print("%s node %s was successful" % (providerName.upper(), action))
print("%s node %s -> successful" % (providerName.upper(), action))
else:
print("%s node could not %s" % (providerName.upper(), action))
print("%s node %s -> failed" % (providerName.upper(), action))
if providerName == "azure" and action == "delete":
driver = get_corresponding_driver("azure")
node_location = node.extra['location']
@@ -1228,14 +1238,15 @@ def node_action_all(action):
case "startall":
succeded = driver.start_node(node)
case "deleteall":
succeded = driver.delete_node(node)
succeded = driver.destroy_node(node)
case _:
print("Invalid action command")
exit(0)
string = action[:-3]
if(succeded):
print("%s node %s was successful" % (node.name, action))
print("%s node %s -> successful" % (node.name, string))
else:
print("%s node could not %s" % (node.name, action))
print("%s node %s -> failed" % (node.name, string))
if providerName == "azure" and action == "delete":
driver = get_corresponding_driver("azure")
node_location = node.extra['location']