Skip to content

Commit

Permalink
Merge branch 'master' into add-shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-mal authored Sep 25, 2023
2 parents 274665c + df9c618 commit b58da49
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 133 deletions.
2 changes: 0 additions & 2 deletions osc_tui/createImage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from time import sleep
import oscscreen
from osc_tui import createImage
from osc_tui import main

# All images combo box.
Expand Down
6 changes: 2 additions & 4 deletions osc_tui/createKeyPair.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import oscscreen
from osc_tui import main
from osc_tui import popup
import os

from os.path import expanduser
Expand Down Expand Up @@ -35,9 +34,8 @@ def back():
self.inspector = None

def write_key(path, private_key):
key_file = open(os.path.expanduser(path), 'w')
key_file.write(private_key)
key_file.close()
with open(os.path.expanduser(path), 'w') as key_file :
key_file.write(private_key)

def create():
if(NAME.get_value()):
Expand Down
2 changes: 0 additions & 2 deletions osc_tui/createLoadbalancer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import oscscreen
from osc_tui import main
from osc_tui import popup
import os
from osc_tui import preloader

# NAME input.
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/createSnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def create():
return
else:
id = ID_LIST[VOLUME_COMBO.get_value()]
volume = VOLUME_COMBO.get_values()[
VOLUME_COMBO.get_value()
]
res = main.GATEWAY.CreateSnapshot(
form=self,
VolumeId=id,
Expand Down
40 changes: 21 additions & 19 deletions osc_tui/createVpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# List of all Subregions
SUBREGION = None


class createVpcs(oscscreen.FormBaseNew):
class CreateVpcs(oscscreen.FormBaseNew):
def __init__(self, *args, **keywords):
super().__init__(*args, **keywords)

Expand All @@ -30,14 +29,15 @@ def back():
main.kill_threads()
self.parentApp.switchForm("Cockpit")

self.inspector = None

def create():
cidr = CIDR.get_value()
res = main.GATEWAY.CreateNet(
form=self,
IpRange=cidr,
)
cidr_value = CIDR.get_value()
if cidr_value:
main.GATEWAY.CreateNet(
form=self,
IpRange=cidr_value,
)
else:
popup.errorPopup("CIDR is missing.")
back()

global CIDR
Expand All @@ -52,7 +52,7 @@ def create():
self.add_widget(oscscreen.ButtonPress, name="EXIT").whenPressed = back


class createSubnet(oscscreen.FormBaseNew):
class CreateSubnet(oscscreen.FormBaseNew):
def __init__(self, *args, **keywords):
super().__init__(*args, **keywords)

Expand All @@ -70,16 +70,18 @@ def back():
main.kill_threads()
self.parentApp.switchForm("Cockpit")

self.inspector = None

def create():
cidr = CIDRSUBNET.get_value()
res = main.GATEWAY.CreateSubnet(
form=self,
IpRange=cidr,
NetId=popup.SUBNETID,
SubregionName=SUBREGION.get_values()[SUBREGION.get_value()],
)
cidr_value = CIDRSUBNET.get_value()
subregion_value = SUBREGION.get_values()[SUBREGION.get_value()]
if cidr_value and subregion_value:
main.GATEWAY.CreateSubnet(
form=self,
IpRange=cidr_value,
NetId=popup.SUBNETID,
SubregionName=subregion_value,
)
else:
popup.errorPopup("CIDR is missing.")
back()

global CIDR
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/flexibleGPU.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine

class Grid(selectableGrid.SelectableGrid):
def __init__(self, screen, *args, **keywords):
Expand Down
30 changes: 15 additions & 15 deletions osc_tui/guiRules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def objectify():
ret = None
if os.path.isfile(PATH):
ret = {}
configFile = open(PATH)
j = json.loads(configFile.read())
for rule_name in j:
rule=j[rule_name]
if "mode" not in rule:
print('"mode" is a requirre argument of costum rule',
file=sys.stderr)
if rule["mode"] not in ret:
ret[rule["mode"]] = {}
ret[rule["mode"]][rule_name] = {
"ports": rule["ports"],
"protocols": rule["protocols"]
}
if "ips" in rule:
ret[rule["mode"]][rule_name]["ips"] = rule["ips"]
with open(PATH) as configFile :
j = json.loads(configFile.read())
for rule_name in j:
rule=j[rule_name]
if "mode" not in rule:
print('"mode" is a requirre argument of costum rule',
file=sys.stderr)
if rule["mode"] not in ret:
ret[rule["mode"]] = {}
ret[rule["mode"]][rule_name] = {
"ports": rule["ports"],
"protocols": rule["protocols"]
}
if "ips" in rule:
ret[rule["mode"]][rule_name]["ips"] = rule["ips"]
return ret

def parse():
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/imageGrid.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import oscscreen
import pyperclip
import time

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class ImageGrid(selectableGrid.SelectableGrid):
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/instancesGrid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import time

import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/keyPairsGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class KeyPairsGrid(selectableGrid.SelectableGrid):
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/loadbalancerGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class loadbalancerGrid(selectableGrid.SelectableGrid):
Expand Down
12 changes: 5 additions & 7 deletions osc_tui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from osc_tui import profileSelector
from osc_tui import guiRules

import time

# GLOBALS ATTRIBUTES
APP = None
GATEWAY = None
Expand Down Expand Up @@ -144,11 +142,11 @@ def main():
i += 1
if i == argc:
if os.path.isfile(profileSelector.dst_file):
configFile = open(profileSelector.dst_file)
OAPI_CREDENTIALS = json.loads(configFile.read())
print("Profiles:")
for c in OAPI_CREDENTIALS:
print(str(c))
with open(profileSelector.dst_file, 'r') as configFile:
OAPI_CREDENTIALS = json.loads(configFile.read())
print("Profiles:")
for c in OAPI_CREDENTIALS:
print(str(c))
else:
print("{} not found, can't read profile !!!".
format(profileSelector.dst_file),
Expand Down
20 changes: 8 additions & 12 deletions osc_tui/mainForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ipaddress

import oscscreen
import pyperclip

import graphviz

Expand All @@ -27,10 +26,8 @@
from osc_tui import popup
from osc_tui import securityGroupsGrid
from osc_tui import securityRulesGrid
from osc_tui import selectableGrid
from osc_tui import snapshotGrid
from osc_tui import loadbalancerGrid
from osc_tui import virtualMachine
from osc_tui import volumesGrid
from osc_tui import guiRules

Expand All @@ -44,19 +41,19 @@
LINE_SEPARATOR_COL = MENU_WIDTH + 1
GRID_START_COL = MENU_WIDTH +3

def swicthToVolumeEdit(form, id, volume):
form.parentApp.addForm("Volume-Edit",
def swicthToVolumeEdit(self, id, volume):
self.parentApp.addForm("Volume-Edit",
volumesGrid.VolumeEdit,
volume=volume,
name="osc-tui Volume-Edit {}".format(id))
form.parentApp.switchForm("Volume-Edit")
self.parentApp.switchForm("Volume-Edit")

def swicthToVolumeLink(form, id, volume):
form.parentApp.addForm("Volume-Link",
def swicthToVolumeLink(self, id, volume):
self.parentApp.addForm("Volume-Link",
volumesGrid.VolumeLink,
volume=volume,
name="osc-tui Volume-Link {}".format(id))
form.parentApp.switchForm("Volume-Link")
self.parentApp.switchForm("Volume-Link")


class mainMenu(oscscreen.MultiLineAction):
Expand Down Expand Up @@ -199,7 +196,7 @@ def actionHighlighted(self, act_on_this, key_press):
if act_on_this == 'Create new':
self.form.parentApp.addForm(
"CREATE_SUBNET",
createVpcs.createSubnet,
createVpcs.CreateSubnet,
name="osc-tui")
self.form.parentApp.switchForm("CREATE_SUBNET")
return
Expand Down Expand Up @@ -414,7 +411,7 @@ def switch_to_keypairs(self, _):
global MODE
MODE = "Keypairs"
self.reload()

def set_up_handlers(self):
super().set_up_handlers()
self.add_handlers({"q": self.quit_key})
Expand All @@ -432,4 +429,3 @@ def set_up_handlers(self):
"r" : self.key_reload,
curses.KEY_F5 : self.key_reload
})

3 changes: 0 additions & 3 deletions osc_tui/netAccesssPoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import oscscreen
import pyperclip

from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/netPeering.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine

class Grid(selectableGrid.SelectableGrid):
def __init__(self, screen, *args, **keywords):
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def remove_cb():


def addSecurityGroupToVm(form, form_color='STANDOUT'):
main.SECURITY_GROUP
F = ConfirmCancelPopup(name='Add New Security Group', color=form_color)
F.preserve_selected_widget = True
groups = main.VM["SecurityGroups"]
Expand Down Expand Up @@ -674,7 +673,6 @@ def instances_registered():
)

def delete_cb():
val = main.GATEWAY.DeleteLoadBalancer(LoadBalancerName=name)
form.current_grid.h_refresh(None)
exit()

Expand Down Expand Up @@ -778,7 +776,6 @@ def associateRoutetable():
exit()

def delete_cb():
val = main.GATEWAY.DeleteSubnet(SubnetId=name)
form.current_grid.h_refresh(None)
exit()
delete.whenPressed = delete_cb
Expand Down
1 change: 0 additions & 1 deletion osc_tui/profileSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
from pathlib import Path
import threading
from osc_tui import preloader

import oscscreen
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/securityGroupsGrid.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class SecurityGroupsGrid(selectableGrid.SelectableGrid):
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/securityRulesGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

from osc_tui import createVm
from osc_tui import main
import oscscreen
from osc_tui import popup
import pyperclip
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class SecurityRulesGrid(selectableGrid.SelectableGrid):
Expand Down
2 changes: 0 additions & 2 deletions osc_tui/selectableGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import curses
import threading
import time

import oscscreen

from osc_tui import main
from osc_tui import popup
from osc_tui import mainForm

# Initially it was designed to have a thread that auto refresh... However, even if it worked fine, if too many people does it, it looks like a DDOS attack.
Expand Down
Loading

0 comments on commit b58da49

Please sign in to comment.