Ok
This commit is contained in:
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
apache_libcloud==3.7.0
|
||||||
|
paramiko==2.11.1
|
||||||
|
python-dotenv==1.0.0
|
||||||
31
secdep.py
31
secdep.py
@@ -14,7 +14,8 @@
|
|||||||
# 7) list images available
|
# 7) list images available
|
||||||
# 8) list sizes available
|
# 8) list sizes available
|
||||||
# 9) list locations available
|
# 9) list locations available
|
||||||
# 10) run a script on during the creation of a new instance
|
# 10) run a script during the creation of a new instance
|
||||||
|
# 11) ssh to an instance
|
||||||
# from the command line using flags
|
# from the command line using flags
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -70,6 +71,7 @@ parser.add_argument('-n', '--name', help='Name of instance')
|
|||||||
parser.add_argument('-g', '--region', help='Region to use')
|
parser.add_argument('-g', '--region', help='Region to use')
|
||||||
parser.add_argument('-y', '--yes', help='Do not ask for confirmation', action='store_true')
|
parser.add_argument('-y', '--yes', help='Do not ask for confirmation', action='store_true')
|
||||||
parser.add_argument('-p', '--print', help='Also print node, image, location or size', action='store_true')
|
parser.add_argument('-p', '--print', help='Also print node, image, location or size', action='store_true')
|
||||||
|
parser.add_argument('-ssh', '--ssh', help='Connect to an instance using ssh', action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not os.path.exists(SECDEP_SSH_PUBLIC_KEY) or not os.path.exists(SECDEP_SSH_PRIVATE_KEY):
|
if not os.path.exists(SECDEP_SSH_PUBLIC_KEY) or not os.path.exists(SECDEP_SSH_PRIVATE_KEY):
|
||||||
@@ -1434,7 +1436,29 @@ def delete_all_nodes():
|
|||||||
# for ip in ips:
|
# for ip in ips:
|
||||||
# if ip.name == node.name+"-ip":
|
# if ip.name == node.name+"-ip":
|
||||||
# driver.ex_delete_public_ip(ip)
|
# driver.ex_delete_public_ip(ip)
|
||||||
|
|
||||||
|
def ssh():
|
||||||
|
node = choose_from_list(list_all_nodes(), "node")
|
||||||
|
ip = node.public_ip
|
||||||
|
port = 22
|
||||||
|
username = "secdep"
|
||||||
|
sshkey = SECDEP_SSH_PRIVATE_KEY
|
||||||
|
try:
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
ssh.load_system_host_keys()
|
||||||
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
ssh.connect(ip, port=port, username=username, key_filename=sshkey)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
prompt = input("$> ")
|
||||||
|
if prompt == "exit": break
|
||||||
|
stdin, stdout, stderr = ssh.exec_command(prompt)
|
||||||
|
print(stdout.read().decode())
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
break
|
||||||
|
ssh.close()
|
||||||
|
except Exception as err:
|
||||||
|
print(str(err))
|
||||||
|
|
||||||
# If -I -S or -G is passed, provider must be passed as well
|
# If -I -S or -G is passed, provider must be passed as well
|
||||||
if args.listimages or args.listsizes or args.listlocations:
|
if args.listimages or args.listsizes or args.listlocations:
|
||||||
@@ -1481,6 +1505,9 @@ if args.action:
|
|||||||
else:
|
else:
|
||||||
node_action(args.action)
|
node_action(args.action)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
if args.ssh:
|
||||||
|
ssh()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
if args.delete:
|
if args.delete:
|
||||||
delete_node()
|
delete_node()
|
||||||
|
|||||||
Reference in New Issue
Block a user