diff --git a/osc_tui/createImage.py b/osc_tui/createImage.py index 284675b..a430e6a 100644 --- a/osc_tui/createImage.py +++ b/osc_tui/createImage.py @@ -1,6 +1,4 @@ -from time import sleep import oscscreen -from osc_tui import createImage from osc_tui import main # All images combo box. diff --git a/osc_tui/createKeyPair.py b/osc_tui/createKeyPair.py index ada3432..bf43cc5 100644 --- a/osc_tui/createKeyPair.py +++ b/osc_tui/createKeyPair.py @@ -1,6 +1,5 @@ import oscscreen from osc_tui import main -from osc_tui import popup import os from os.path import expanduser @@ -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()): diff --git a/osc_tui/createLoadbalancer.py b/osc_tui/createLoadbalancer.py index ab24d88..06447a2 100644 --- a/osc_tui/createLoadbalancer.py +++ b/osc_tui/createLoadbalancer.py @@ -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. diff --git a/osc_tui/createSnapshot.py b/osc_tui/createSnapshot.py index 58a2792..7661098 100644 --- a/osc_tui/createSnapshot.py +++ b/osc_tui/createSnapshot.py @@ -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, diff --git a/osc_tui/createVpcs.py b/osc_tui/createVpcs.py index e42b84b..476dd9f 100644 --- a/osc_tui/createVpcs.py +++ b/osc_tui/createVpcs.py @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/osc_tui/flexibleGPU.py b/osc_tui/flexibleGPU.py index 22167ac..761755c 100644 --- a/osc_tui/flexibleGPU.py +++ b/osc_tui/flexibleGPU.py @@ -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): diff --git a/osc_tui/guiRules.py b/osc_tui/guiRules.py index 036dbc7..6139128 100644 --- a/osc_tui/guiRules.py +++ b/osc_tui/guiRules.py @@ -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(): diff --git a/osc_tui/imageGrid.py b/osc_tui/imageGrid.py index 192018b..af36788 100644 --- a/osc_tui/imageGrid.py +++ b/osc_tui/imageGrid.py @@ -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): diff --git a/osc_tui/instancesGrid.py b/osc_tui/instancesGrid.py index ef626a1..48d650f 100644 --- a/osc_tui/instancesGrid.py +++ b/osc_tui/instancesGrid.py @@ -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 diff --git a/osc_tui/keyPairsGrid.py b/osc_tui/keyPairsGrid.py index 0617740..5ba1009 100644 --- a/osc_tui/keyPairsGrid.py +++ b/osc_tui/keyPairsGrid.py @@ -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): diff --git a/osc_tui/loadbalancerGrid.py b/osc_tui/loadbalancerGrid.py index 18f869e..7f21b06 100644 --- a/osc_tui/loadbalancerGrid.py +++ b/osc_tui/loadbalancerGrid.py @@ -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): diff --git a/osc_tui/main.py b/osc_tui/main.py index 85314e8..c1e6c24 100644 --- a/osc_tui/main.py +++ b/osc_tui/main.py @@ -14,8 +14,6 @@ from osc_tui import profileSelector from osc_tui import guiRules -import time - # GLOBALS ATTRIBUTES APP = None GATEWAY = None diff --git a/osc_tui/mainForm.py b/osc_tui/mainForm.py index 7cf3ad4..d91127b 100644 --- a/osc_tui/mainForm.py +++ b/osc_tui/mainForm.py @@ -2,7 +2,6 @@ import ipaddress import oscscreen -import pyperclip import graphviz @@ -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 @@ -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): @@ -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 @@ -348,12 +345,12 @@ def reload(self): self.parentApp.addForm("Cockpit", MainForm, name="osc-tui") self.parentApp.switchForm("Cockpit") - def quit_key(form, key_val): + def quit_key(self, key_val): main.kill_threads() - form.parentApp.switchForm("MAIN") + self.parentApp.switchForm("MAIN") - def key_reload(form, _): - form.reload() + def key_reload(self, _): + self.reload() def set_up_handlers(self): super().set_up_handlers() diff --git a/osc_tui/netAccesssPoint.py b/osc_tui/netAccesssPoint.py index 7821bdd..71b3edb 100644 --- a/osc_tui/netAccesssPoint.py +++ b/osc_tui/netAccesssPoint.py @@ -1,6 +1,3 @@ -import oscscreen -import pyperclip - from osc_tui import main from osc_tui import popup from osc_tui import selectableGrid diff --git a/osc_tui/netPeering.py b/osc_tui/netPeering.py index cde0f02..63dff7f 100644 --- a/osc_tui/netPeering.py +++ b/osc_tui/netPeering.py @@ -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): diff --git a/osc_tui/popup.py b/osc_tui/popup.py index 578717c..f16c3ca 100644 --- a/osc_tui/popup.py +++ b/osc_tui/popup.py @@ -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"] @@ -674,7 +673,6 @@ def instances_registered(): ) def delete_cb(): - val = main.GATEWAY.DeleteLoadBalancer(LoadBalancerName=name) form.current_grid.h_refresh(None) exit() @@ -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 diff --git a/osc_tui/profileSelector.py b/osc_tui/profileSelector.py index 45a3489..d4803b7 100644 --- a/osc_tui/profileSelector.py +++ b/osc_tui/profileSelector.py @@ -3,7 +3,6 @@ import json import os from pathlib import Path -import threading from osc_tui import preloader import oscscreen diff --git a/osc_tui/securityGroupsGrid.py b/osc_tui/securityGroupsGrid.py index a7e1f12..584f641 100644 --- a/osc_tui/securityGroupsGrid.py +++ b/osc_tui/securityGroupsGrid.py @@ -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): diff --git a/osc_tui/securityRulesGrid.py b/osc_tui/securityRulesGrid.py index 2a61980..d96032a 100644 --- a/osc_tui/securityRulesGrid.py +++ b/osc_tui/securityRulesGrid.py @@ -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): diff --git a/osc_tui/selectableGrid.py b/osc_tui/selectableGrid.py index 76cced9..b93c016 100644 --- a/osc_tui/selectableGrid.py +++ b/osc_tui/selectableGrid.py @@ -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. diff --git a/osc_tui/snapshotGrid.py b/osc_tui/snapshotGrid.py index c5bd541..3b5c217 100644 --- a/osc_tui/snapshotGrid.py +++ b/osc_tui/snapshotGrid.py @@ -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 SnapshotGrid(selectableGrid.SelectableGrid): diff --git a/osc_tui/volumesGrid.py b/osc_tui/volumesGrid.py index 60073c3..ca31e9b 100644 --- a/osc_tui/volumesGrid.py +++ b/osc_tui/volumesGrid.py @@ -1,12 +1,8 @@ - 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 VolumeGrid(selectableGrid.SelectableGrid): def __init__(self, screen, *args, **keywords): @@ -180,7 +176,6 @@ def on_selection(line): self.on_selection = on_selection def refresh_call(self, name_filter=None): - id = main.VM["VmId"] groups = main.GATEWAY.ReadVolumes( form=self.form, Filters={ 'LinkVolumeVmIds': [id]}) @@ -190,7 +185,6 @@ def refresh_call(self, name_filter=None): def refresh(self): - id = main.VM["VmId"] groups = main.do_search(self.data.copy(), ['VolumeId', 'VolumeType', 'Size', 'SubregionName']) values = list() diff --git a/osc_tui/vpcsGrid.py b/osc_tui/vpcsGrid.py index df271df..a61c8be 100644 --- a/osc_tui/vpcsGrid.py +++ b/osc_tui/vpcsGrid.py @@ -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 vpcsGrid(selectableGrid.SelectableGrid): diff --git a/setup.py b/setup.py index 6c3074a..680101d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ # -*- coding:utf-8 -*- from setuptools import find_packages, setup -import os setup( name='osc-tui',