def reload(self): main.kill_threads() self.parentApp.addForm( "CREATE_LOADBALANCER", CreateSnapshot, name="osc-tui") self.parentApp.switchForm("CREATE_LOADBALANCER")
def sg(): exit() main.kill_threads() main.VM = main.VMs[id] mainForm.CURRENT_GRID_CLASS = securityGroupsGrid.SecurityGroupsGridForOneInstance mainForm.MODE = 'SECURITY-VM' form.reload()
def terminate_vm(): main.kill_threads() if npyscreen.notify_ok_cancel( "Do you really want to terminate this vm:\nName: " + name + "\nID: " + id, "VM Termination", ): main.GATEWAY.DeleteVms(VmIds=[id]) exit()
def terminate_vm(): main.kill_threads() if npyscreen.notify_ok_cancel( "Do you really want to terminate this vm:\nName: " + name + "\nID: " + id, "VM Termination", ): main.GATEWAY.DeleteVms(form=form, VmIds=[id]) form.current_grid.h_refresh(None) exit()
def actionHighlighted(self, act_on_this, key_press): if key_press == 10: if self.vmform: global MODE if MODE == 'INSTANCES': if act_on_this == "CREATE NEW": self.vmform.parentApp.addForm("CREATE_VM", createVm.CreateVm, name="osc-tui") self.vmform.parentApp.switchForm("CREATE_VM") return elif MODE == 'SECURITY': if act_on_this == "CREATE NEW": popup.newSecurityGroup(self.vmform) return elif MODE == 'SECURITY-VM': if act_on_this == "ADD SEC-GROUP": popup.addSecurityGroupToVm(self.vmform) return elif MODE == 'SECURITY-RULES': if act_on_this == "CREATE NEW": popup.newSecurityGroupRule(self.vmform) return elif act_on_this == 'ADD SSH MY IP': main.GATEWAY.CreateSecurityGroupRule( FromPortRange=22, IpProtocol="tcp", IpRange=main.IP + "/32", ToPortRange=22, SecurityGroupId=main.SECURITY_GROUP, Flow="Inbound", ) self.vmform.current_grid.refresh() self.vmform.current_grid.display() return if act_on_this == "EXIT": main.kill_threads() self.vmform.parentApp.switchForm("MAIN") return elif act_on_this == "REFRESH": if hasattr(self.vmform, 'current_grid'): self.vmform.current_grid.refresh() self.vmform.current_grid.display() return MODE = act_on_this global SELECTED_BUTTON if act_on_this == 'INSTANCES' or act_on_this == 'SECURITY': SELECTED_BUTTON = 7 else: SELECTED_BUTTON = self.cursor_line self.vmform.reload()
def reload(self): main.kill_threads() self.parentApp.addForm("Cockpit", MainForm, name="osc-tui") self.parentApp.switchForm("Cockpit")
def reload(self): main.kill_threads() self.parentApp.addForm("CREATE_VM", CreateVm, name="osc-tui") self.parentApp.switchForm("CREATE_VM")
def sg(): exit() main.kill_threads() main.VM = main.VMs[id] mainForm.MODE = 'SECURITY-VM' form.reload()
def reload(self): main.kill_threads() self.parentApp.addForm("CREATE_SNAPSHOT", CreateSnapshot, name="osc-tui") self.parentApp.switchForm("CREATE_SNAPSHOT")
def reload(self): main.kill_threads() self.parentApp.addForm("CREATE_SUBNET", CreateSubnet, name="osc-tui") self.parentApp.switchForm("CREATE_SUBNET")
def reload(self): main.kill_threads() self.parentApp.addForm("CREATE_NET-ACCESS-POINT", CreateNetAccessPoint, name="osc-tui") self.parentApp.switchForm("CREATE_NET-ACCESS-POINT")
def __call__(self): try: global res main.GATEWAY = Gateway(**{"profile": self.name, "user_agent": "osc-tui/" + str(main.VERSION) + " " + authentication.DEFAULT_USER_AGENT}) if hasattr(main.GATEWAY.log, "config"): main.GATEWAY.log.config(type=LOG_MEMORY, what=LOG_KEEP_ONLY_LAST_REQ) # The following code is a little bit completely tricky :) # Here is the idea: # I want to hook all calls to the main.GATEWAY modules to automatically display the pending animation. # (So it's a decorator) # However, for doing such things I need to add a form parameter. # However 2, when performing one call, it will do some "inner calls" so we must not trigger the animation all the time. # One way would be to decorate only the "main functions" but I wanna do it automatically! # Another one is the following one: # If we have the form parameter, we remove it form kwargs and start the pending animation. # So the pending animation won't be started again during "inner # calls". def decorator(func): def wrapped(*args, **kwargs): form = kwargs.get('form') global result result = None def cb(): global result try: result = func(*args, **kwargs) except requests.exceptions.HTTPError as e: npyscreen.notify_confirm( "Error while submitting the request:\n{}\nCode: {}\nReason: {}". format(main.GATEWAY.log.str(), e.response.status_code, e.response.reason), title="ERROR") if form: kwargs.pop('form') popup.startLoading(form, cb) else: cb() return result return wrapped # So now we iterate over all methods of the GATEWAY that are not prefixed by "__" # and basically we decorate them. for method_name in dir(main.GATEWAY): if not method_name.startswith("__"): attr = getattr(main.GATEWAY, method_name) if(callable(attr)): wrapped = decorator(attr) setattr(main.GATEWAY, method_name, wrapped) # now let's check if the profile worked: try: res = main.GATEWAY.ReadClientGateways(form=self.form) if "Errors" not in res: preloader.Preloader.load_async() mainForm.MODE = 'Vms' self.form.parentApp.addForm( "Cockpit", mainForm.MainForm, name="osc-tui") self.form.parentApp.switchForm("Cockpit") else: should_destroy_profile = npyscreen.notify_yes_no( "Credentials are not valids.\nDo you want do delete this profile?", "ERROR", ) if should_destroy_profile: global OAPI_CREDENTIALS del OAPI_CREDENTIALS[self.name] save_credentials(self.form) except Exception as e: npyscreen.notify_confirm("Exeption trow: \"{}\"\nLog in ./osc-tui.log".format(str(e))) traceback.print_exc(file=open("osc-tui.log", "w")) main.kill_threads() exit(1) except requests.ConnectionError: npyscreen.notify_confirm( "Please check your internet connection.", "ERROR")
def quit_key(form, key_val): main.kill_threads() form.parentApp.switchForm("MAIN")
def back(): main.kill_threads() self.parentApp.addForm("CREATE_IMAGE", CreateImage, name="osc-tui") self.parentApp.switchForm("CREATE_IMAGE")
def reload(self): main.kill_threads() self.parentApp.addForm("CREATEIMAGE_FROMINSTANCE", CreateImage_frominstance, name="osc-tui") self.parentApp.switchForm("CREATEIMAGE_FROMINSTANCE")
def reload(self): main.kill_threads() self.parentApp.addForm("CREATEIMAGE_FROMSNAPSHOT", CreateImage_fromsnapshot, name="osc-tui") self.parentApp.switchForm("CREATEIMAGE_FROMSNAPSHOT")
def actionHighlighted(self, act_on_this, key_press): if key_press == 10: if self.form: global MODE if MODE == 'INSTANCES-LBU': if act_on_this == "CREATE NEW": npyscreen.notify_confirm("Not implemented yet :/") return elif MODE == 'INSTANCES': if act_on_this == "CREATE NEW": self.form.parentApp.addForm("CREATE_VM", createVm.CreateVm, name="osc-tui") self.form.parentApp.switchForm("CREATE_VM") return elif MODE == 'SECURITY': if act_on_this == "CREATE NEW": popup.newSecurityGroup(self.form) return elif MODE == 'SECURITY-VM': if act_on_this == "ADD SEC-GROUP": popup.addSecurityGroupToVm(self.form) return elif MODE == 'SECURITY-RULES': if act_on_this == "CREATE NEW": popup.newSecurityGroupRule(self.form) return elif act_on_this == 'ADD SSH MY IP': main.GATEWAY.CreateSecurityGroupRule( form=self.form, FromPortRange=22, IpProtocol="tcp", IpRange=main.IP + "/32", ToPortRange=22, SecurityGroupId=main.SECURITY_GROUP, Flow="Inbound", ) self.form.current_grid.h_refresh(None) self.form.current_grid.display() return elif MODE == 'VOLUMES': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_VOLUME", createVolume.CreateVolume, name="osc-tui") self.form.parentApp.switchForm("CREATE_VOLUME") return elif MODE == 'SNAPSHOT': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_SNAPSHOT", createSnapshot.CreateSnapshot, name="osc-tui") self.form.parentApp.switchForm("CREATE_SNAPSHOT") return elif MODE == 'KEYPAIRS': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_KEYPAIR", createKeyPair.CreateKeyPair, name="osc-tui") self.form.parentApp.switchForm("CREATE_KEYPAIR") return elif MODE == 'LBUs': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_LOADBALANCER", createLoadbalancer.CreateLoadbalancer, name="osc-tui") self.form.parentApp.switchForm("CREATE_LOADBALANCER") return elif MODE == 'VPCs(nets)': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_VPCs", createVpcs.createVpcs, name="osc-tui") self.form.parentApp.switchForm("CREATE_VPCs") return elif MODE == 'SUBNET': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_SUBNET", createVpcs.createSubnet, name="osc-tui") self.form.parentApp.switchForm("CREATE_SUBNET") return elif MODE == 'NET-ACCESS-POINT': if act_on_this == 'CREATE NEW': self.form.parentApp.addForm( "CREATE_NET-ACCESS-POINT", createNetAccessPoint.CreateNetAccessPoint, name="osc-tui") self.form.parentApp.switchForm("CREATE_NET-ACCESS-POINT") return if act_on_this == "EXIT": main.kill_threads() self.form.parentApp.switchForm("MAIN") return elif act_on_this == "REFRESH": if hasattr(self.form, 'current_grid'): self.form.current_grid.h_refresh(None) self.form.current_grid.display() return MODE = act_on_this global SELECTED_BUTTON if act_on_this == 'INSTANCES' or act_on_this == 'SECURITY': SELECTED_BUTTON = 11 else: SELECTED_BUTTON = self.cursor_line self.form.reload()
def back(): main.kill_threads() self.parentApp.switchForm("Cockpit")
def quit(): main.kill_threads() exit()