Ejemplo n.º 1
0
 def __init__(self,parent, server=None, instance = None):
     gtk.Frame.__init__(self)
     self.par = parent
     self.serverId = None
     if server is not None:
         self.serverId = server.getLocalId()
     self.instanceId = None
     if instance is not None:
         self.instanceId = instance.getLocalId()
     self.instanceTypes = self.getApplication().getInstanceTypes()
     
     self.set_label(_("Skarphed Admin :: Configure Instance"))
     self.vbox = gtk.VBox()
     self.label = gtk.Label(_("Please configure the Instance"))
     self.vspace = gtk.Label("")
     self.vbox.pack_start(self.label,False)
     self.vbox.pack_start(self.vspace,True)
     
     self.table = gtk.Table(2,4,False)
     self.typeLabel = gtk.Label(_("InstanceType:"))
     
     self.typeStore = gtk.ListStore(str)
     self.typeCombo = gtk.ComboBox(self.typeStore)
     self.typeRenderer = gtk.CellRendererText()
     self.typeCombo.pack_start(self.typeRenderer, True)
     self.typeCombo.add_attribute(self.typeRenderer, 'text', 0)  
     for instanceType in self.instanceTypes:
         self.typeStore.append((instanceType.displayName,))
     self.typeCombo.set_active(0)
     self.urlLabel = gtk.Label(_("URL:"))
     self.urlEntry = DefaultEntry(default_message="http://instance.org")
     self.urlEntry.set_text("http://")
     self.userLabel = gtk.Label(_("Username:"******"username"))
     self.passLabel = gtk.Label(_("Password:"******"●")
     self.table.attach(self.typeLabel,0,1,0,1)
     self.table.attach(self.typeCombo,1,2,0,1)
     self.table.attach(self.urlLabel,0,1,1,2)
     self.table.attach(self.urlEntry,1,2,1,2)
     self.table.attach(self.userLabel,0,1,2,3)
     self.table.attach(self.userEntry,1,2,2,3)
     self.table.attach(self.passLabel,0,1,3,4)
     self.table.attach(self.passEntry,1,2,3,4)
     self.vbox.pack_start(self.table,False)
     
     self.buttonBox = gtk.HBox()
     self.ok = gtk.Button(stock=gtk.STOCK_OK)
     self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
     self.viewpass = ViewPasswordButton()
     self.viewpass.addEntry(self.passEntry)
     self.space = gtk.Label("")
     self.buttonBox.pack_start(self.space,True)
     self.buttonBox.pack_start(self.viewpass,False)
     self.buttonBox.pack_start(self.cancel,False)
     self.buttonBox.pack_start(self.ok,False)
     self.ok.connect("clicked",self.cb_Ok)
     self.cancel.connect("clicked",self.cb_Cancel)
     self.vbox.pack_start(self.buttonBox,False)
     
     self.add(self.vbox)
     self.getApplication().getMainWindow().openDialogPane(self)
     if instance is not None:
         self.urlEntry.set_sensitive(False)
         self.render()
Ejemplo n.º 2
0
    def __init__(self, parent, server=None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is None:
            self.set_label(_("Skarphed Admin Pro :: New Server"))
            self.mode = ServerPropertyPage.MODE_NEW
        else:
            self.serverId = server.getLocalId()
            self.set_label(_("Skarphed Admin Pro :: Server Properties of ")+server.getIp())
            self.mode = ServerPropertyPage.MODE_EDIT
            
        self.vbox = gtk.VBox()
        
        self.instructionlabel = gtk.Label(_("Please enter the Server credentials"))
        self.vbox.pack_start(self.instructionlabel,False)
        
        self.ipFrame = gtk.Frame(_("Common"))
        self.ipFrameT = gtk.Table(2,3,False)
        self.ipFrame_IPLabel = gtk.Label(_("IP:"))
        self.ipFrame_IPEntry = DefaultEntry(default_message="172.16.13.37")
        self.ipFrameT.attach(self.ipFrame_IPLabel, 0,1,0,1)
        self.ipFrameT.attach(self.ipFrame_IPEntry, 1,2,0,1)
        self.ipFrame_NameLabel = gtk.Label(_("Name:"))
        self.ipFrame_NameEntry = DefaultEntry(default_message="Server1")
        self.ipFrameT.attach(self.ipFrame_NameLabel, 0,1,1,2)
        self.ipFrameT.attach(self.ipFrame_NameEntry, 1,2,1,2)
        self.ipFrame_Target_Label = gtk.Label("Target system:")
        self.ipFrame_Target_model = gtk.ListStore(str)
        for target in Server.INSTALLATION_TARGETS:
            self.ipFrame_Target_model.append((target.getName(),))
        self.ipFrame_Target_renderer = gtk.CellRendererText()
        self.ipFrame_Target = gtk.ComboBox(self.ipFrame_Target_model)
        self.ipFrame_Target.pack_start(self.ipFrame_Target_renderer,True)
        self.ipFrame_Target.add_attribute(self.ipFrame_Target_renderer,'text',0)
        self.ipFrameT.attach(self.ipFrame_Target_Label,0,1,2,3)
        self.ipFrameT.attach(self.ipFrame_Target,1,2,2,3)
        self.ipFrame.add(self.ipFrameT)

        self.vbox.pack_start(self.ipFrame,False)
                
        self.sshFrame = gtk.Frame(_("SSH"))
        self.sshFrameT = gtk.Table(2,2,False)
        self.sshFrame_NameLabel = gtk.Label(_("Username:"******"root")
        self.sshFrame_PassLabel = gtk.Label(_("Password:"******"●")
        self.sshFrameT.attach(self.sshFrame_NameLabel, 0,1,0,1)
        self.sshFrameT.attach(self.sshFrame_NameEntry, 1,2,0,1)
        self.sshFrameT.attach(self.sshFrame_PassLabel, 0,1,1,2)
        self.sshFrameT.attach(self.sshFrame_PassEntry, 1,2,1,2)
        self.sshFrame.add(self.sshFrameT)
        self.vbox.pack_start(self.sshFrame,False)
        
        self.instFrame = gtk.Frame(_("Instances"))
        self.instFrameT = gtk.Table(2,4,False)
        self.instList = gtk.TreeView()
        self.instStore = gtk.ListStore(gtk.gdk.Pixbuf,str,int)
        self.instList.set_model(self.instStore)
        self.instCol_Icon = gtk.TreeViewColumn()
        self.instCol_Name = gtk.TreeViewColumn(_('Instance'))
        self.instRen_Icon = gtk.CellRendererPixbuf()
        self.instRen_Name = gtk.CellRendererText()
        self.instCol_Icon.pack_start(self.instRen_Icon,False)
        self.instCol_Name.pack_start(self.instRen_Name,True)            
        self.instCol_Icon.add_attribute(self.instRen_Icon,'pixbuf',0)
        self.instCol_Name.add_attribute(self.instRen_Name,'text',1)
        self.instList.append_column(self.instCol_Icon)
        self.instList.append_column(self.instCol_Name)
        self.instAdd = gtk.Button(stock=gtk.STOCK_ADD)
        self.instRemove = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.instEdit = gtk.Button(stock=gtk.STOCK_EDIT)
        self.instFrameT.attach(self.instList,0,1,0,4)
        self.instFrameT.attach(self.instAdd,1,2,0,1)
        self.instFrameT.attach(self.instRemove,1,2,1,2)
        self.instFrameT.attach(self.instEdit,1,2,2,3)
        self.instAdd.connect("clicked",self.cb_Add)
        self.instRemove.connect("clicked",self.cb_Remove)
        self.instEdit.connect("clicked",self.cb_Edit)
        self.instList.connect("cursor-changed", self.cb_cursorChanged)
        self.instFrame.add(self.instFrameT)
        self.vbox.pack_start(self.instFrame,False)
        
        self.fill = gtk.Label("")
        self.vbox.pack_start(self.fill,True)
        
        self.buttons = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.sshFrame_PassEntry)
        self.ok.connect("clicked", self.cb_OK)
        self.cancel.connect("clicked", self.cb_Cancel)
        self.buttons.pack_end(self.ok,False)
        self.buttons.pack_end(self.cancel,False)
        self.buttons.pack_end(self.viewpass,False)
        self.vbox.pack_start(self.buttons,False)
        
        self.add(self.vbox)
        
        if server is not None:
            self.ipFrame_IPEntry.set_text(server.getIp())
            self.ipFrame_NameEntry.set_text(server.getRawName())
            self.sshFrame_NameEntry.set_text(server.getSSHName())
            self.sshFrame_PassEntry.set_text(server.getSSHPass())
            server.addCallback(self.render)
        self.getApplication().getMainWindow().openDialogPane(self)
        self.render()
Ejemplo n.º 3
0
class InstancePage(gtk.Frame):
    def __init__(self,parent, server=None, instance = None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is not None:
            self.serverId = server.getLocalId()
        self.instanceId = None
        if instance is not None:
            self.instanceId = instance.getLocalId()
        self.instanceTypes = self.getApplication().getInstanceTypes()
        
        self.set_label(_("Skarphed Admin :: Configure Instance"))
        self.vbox = gtk.VBox()
        self.label = gtk.Label(_("Please configure the Instance"))
        self.vspace = gtk.Label("")
        self.vbox.pack_start(self.label,False)
        self.vbox.pack_start(self.vspace,True)
        
        self.table = gtk.Table(2,4,False)
        self.typeLabel = gtk.Label(_("InstanceType:"))
        
        self.typeStore = gtk.ListStore(str)
        self.typeCombo = gtk.ComboBox(self.typeStore)
        self.typeRenderer = gtk.CellRendererText()
        self.typeCombo.pack_start(self.typeRenderer, True)
        self.typeCombo.add_attribute(self.typeRenderer, 'text', 0)  
        for instanceType in self.instanceTypes:
            self.typeStore.append((instanceType.displayName,))
        self.typeCombo.set_active(0)
        self.urlLabel = gtk.Label(_("URL:"))
        self.urlEntry = DefaultEntry(default_message="http://instance.org")
        self.urlEntry.set_text("http://")
        self.userLabel = gtk.Label(_("Username:"******"username"))
        self.passLabel = gtk.Label(_("Password:"******"●")
        self.table.attach(self.typeLabel,0,1,0,1)
        self.table.attach(self.typeCombo,1,2,0,1)
        self.table.attach(self.urlLabel,0,1,1,2)
        self.table.attach(self.urlEntry,1,2,1,2)
        self.table.attach(self.userLabel,0,1,2,3)
        self.table.attach(self.userEntry,1,2,2,3)
        self.table.attach(self.passLabel,0,1,3,4)
        self.table.attach(self.passEntry,1,2,3,4)
        self.vbox.pack_start(self.table,False)
        
        self.buttonBox = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.passEntry)
        self.space = gtk.Label("")
        self.buttonBox.pack_start(self.space,True)
        self.buttonBox.pack_start(self.viewpass,False)
        self.buttonBox.pack_start(self.cancel,False)
        self.buttonBox.pack_start(self.ok,False)
        self.ok.connect("clicked",self.cb_Ok)
        self.cancel.connect("clicked",self.cb_Cancel)
        self.vbox.pack_start(self.buttonBox,False)
        
        self.add(self.vbox)
        self.getApplication().getMainWindow().openDialogPane(self)
        if instance is not None:
            self.urlEntry.set_sensitive(False)
            self.render()
    
    def render(self):
        try:
            instance = self.getApplication().getLocalObjectById(self.instanceId)
        except GenericObjectStoreException:
            self.getApplication().getMainWindow().closeDialogPane(self)
            return
    
        self.urlEntry.set_text(instance.getUrl())
        self.userEntry.set_text(instance.getUsername())
        self.passEntry.set_text(instance.getPassword())
    
    def getInstanceType(self,text):
        for instanceType in self.instanceTypes:
            if instanceType.displayName == text:
                return instanceType
        return None
    
    def cb_Cancel(self, widget=None, data=None):
        self.getApplication().getMainWindow().closeDialogPane()
    
    def cb_Ok (self, widget=None, data=None):
        def errorMessage(msgId):
            msgs = (_("This URL cannot be resolved"),
                    )
            dia = gtk.MessageDialog(parent=self.getPar().getPar(), flags=0, type=gtk.MESSAGE_WARNING, \
                                  buttons=gtk.BUTTONS_OK, message_format=msgs[msgId])
            dia.run()
            dia.destroy()
        
        instance = None
        if self.instanceId is not None:
            instance = self.getApplication().getLocalObjectById(self.instanceId)
        server = self.getApplication().getLocalObjectById(self.serverId)
        
        if instance is not None:
            instance.setUsername(self.userEntry.get_text())
            instance.setPassword(self.passEntry.get_text())
            instance.establishConnections()
        else:
            url = self.urlEntry.get_text()
            if server is None:
                try:
                    server = self.getApplication().createServerFromInstanceUrl(url)
                except DNSError:
                    errorMessage(0)
                    return
            
            selection = self.typeStore[self.typeCombo.get_active()][0]  
            instanceType = self.getInstanceType(selection)
            
            username = self.userEntry.get_text()
            password = self.passEntry.get_text()
            try:
                if not server.createInstance(instanceType, url, username, password):
                    MessagePage(self, _("This URL resolves to another server. You can't add that here."))
                    return
            except None:
                return
        self.getApplication().getMainWindow().closeDialogPane()

        
    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()
Ejemplo n.º 4
0
class ServerPropertyPage(gtk.Frame):
    addWindowOpen=False
    MODE_EDIT = 0
    MODE_NEW = 1

    def __init__(self, parent, server=None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is None:
            self.set_label(_("Skarphed Admin Pro :: New Server"))
            self.mode = ServerPropertyPage.MODE_NEW
        else:
            self.serverId = server.getLocalId()
            self.set_label(_("Skarphed Admin Pro :: Server Properties of ")+server.getIp())
            self.mode = ServerPropertyPage.MODE_EDIT
            
        self.vbox = gtk.VBox()
        
        self.instructionlabel = gtk.Label(_("Please enter the Server credentials"))
        self.vbox.pack_start(self.instructionlabel,False)
        
        self.ipFrame = gtk.Frame(_("Common"))
        self.ipFrameT = gtk.Table(2,3,False)
        self.ipFrame_IPLabel = gtk.Label(_("IP:"))
        self.ipFrame_IPEntry = DefaultEntry(default_message="172.16.13.37")
        self.ipFrameT.attach(self.ipFrame_IPLabel, 0,1,0,1)
        self.ipFrameT.attach(self.ipFrame_IPEntry, 1,2,0,1)
        self.ipFrame_NameLabel = gtk.Label(_("Name:"))
        self.ipFrame_NameEntry = DefaultEntry(default_message="Server1")
        self.ipFrameT.attach(self.ipFrame_NameLabel, 0,1,1,2)
        self.ipFrameT.attach(self.ipFrame_NameEntry, 1,2,1,2)
        self.ipFrame_Target_Label = gtk.Label("Target system:")
        self.ipFrame_Target_model = gtk.ListStore(str)
        for target in Server.INSTALLATION_TARGETS:
            self.ipFrame_Target_model.append((target.getName(),))
        self.ipFrame_Target_renderer = gtk.CellRendererText()
        self.ipFrame_Target = gtk.ComboBox(self.ipFrame_Target_model)
        self.ipFrame_Target.pack_start(self.ipFrame_Target_renderer,True)
        self.ipFrame_Target.add_attribute(self.ipFrame_Target_renderer,'text',0)
        self.ipFrameT.attach(self.ipFrame_Target_Label,0,1,2,3)
        self.ipFrameT.attach(self.ipFrame_Target,1,2,2,3)
        self.ipFrame.add(self.ipFrameT)

        self.vbox.pack_start(self.ipFrame,False)
                
        self.sshFrame = gtk.Frame(_("SSH"))
        self.sshFrameT = gtk.Table(2,2,False)
        self.sshFrame_NameLabel = gtk.Label(_("Username:"******"root")
        self.sshFrame_PassLabel = gtk.Label(_("Password:"******"●")
        self.sshFrameT.attach(self.sshFrame_NameLabel, 0,1,0,1)
        self.sshFrameT.attach(self.sshFrame_NameEntry, 1,2,0,1)
        self.sshFrameT.attach(self.sshFrame_PassLabel, 0,1,1,2)
        self.sshFrameT.attach(self.sshFrame_PassEntry, 1,2,1,2)
        self.sshFrame.add(self.sshFrameT)
        self.vbox.pack_start(self.sshFrame,False)
        
        self.instFrame = gtk.Frame(_("Instances"))
        self.instFrameT = gtk.Table(2,4,False)
        self.instList = gtk.TreeView()
        self.instStore = gtk.ListStore(gtk.gdk.Pixbuf,str,int)
        self.instList.set_model(self.instStore)
        self.instCol_Icon = gtk.TreeViewColumn()
        self.instCol_Name = gtk.TreeViewColumn(_('Instance'))
        self.instRen_Icon = gtk.CellRendererPixbuf()
        self.instRen_Name = gtk.CellRendererText()
        self.instCol_Icon.pack_start(self.instRen_Icon,False)
        self.instCol_Name.pack_start(self.instRen_Name,True)            
        self.instCol_Icon.add_attribute(self.instRen_Icon,'pixbuf',0)
        self.instCol_Name.add_attribute(self.instRen_Name,'text',1)
        self.instList.append_column(self.instCol_Icon)
        self.instList.append_column(self.instCol_Name)
        self.instAdd = gtk.Button(stock=gtk.STOCK_ADD)
        self.instRemove = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.instEdit = gtk.Button(stock=gtk.STOCK_EDIT)
        self.instFrameT.attach(self.instList,0,1,0,4)
        self.instFrameT.attach(self.instAdd,1,2,0,1)
        self.instFrameT.attach(self.instRemove,1,2,1,2)
        self.instFrameT.attach(self.instEdit,1,2,2,3)
        self.instAdd.connect("clicked",self.cb_Add)
        self.instRemove.connect("clicked",self.cb_Remove)
        self.instEdit.connect("clicked",self.cb_Edit)
        self.instList.connect("cursor-changed", self.cb_cursorChanged)
        self.instFrame.add(self.instFrameT)
        self.vbox.pack_start(self.instFrame,False)
        
        self.fill = gtk.Label("")
        self.vbox.pack_start(self.fill,True)
        
        self.buttons = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.sshFrame_PassEntry)
        self.ok.connect("clicked", self.cb_OK)
        self.cancel.connect("clicked", self.cb_Cancel)
        self.buttons.pack_end(self.ok,False)
        self.buttons.pack_end(self.cancel,False)
        self.buttons.pack_end(self.viewpass,False)
        self.vbox.pack_start(self.buttons,False)
        
        self.add(self.vbox)
        
        if server is not None:
            self.ipFrame_IPEntry.set_text(server.getIp())
            self.ipFrame_NameEntry.set_text(server.getRawName())
            self.sshFrame_NameEntry.set_text(server.getSSHName())
            self.sshFrame_PassEntry.set_text(server.getSSHPass())
            server.addCallback(self.render)
        self.getApplication().getMainWindow().openDialogPane(self)
        self.render()
    
    def render(self):
        def search(model, path, rowiter, target):
            text = model.get_value(rowiter,0)
            if text == target.getName():
                self.ipFrame_Target.set_active_iter(rowiter)

        server = None
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            if self.mode == ServerPropertyPage.MODE_EDIT:
                self.getApplication().getMainWindow().closeDialogPane()
                return
        
        self.instFrame.set_visible(self.mode == ServerPropertyPage.MODE_EDIT)

        if server is not None and server.isTargetUsable():
            self.ipFrame_Target_model.foreach(search, server.getTarget())

        self.instStore.clear()
        if server is not None:
            for instance in server.getInstances():
                icon = SKARPHED #TODO: Implement Icon
                self.instStore.append((icon,instance.getName(),instance.getLocalId()))
        self.cb_cursorChanged()

    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()
    
    def cb_Add(self,widget=None,data=None):
        server = self.getApplication().getLocalObjectById(self.serverId)
        InstancePage(self,server)
    
    def cb_Remove(self,widget=None,data=None):
        instance = self.getCurrentInstance()
        if instance is None:
            return
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        server.removeInstance(instance)
        selection = self.instList.get_selection()
        rowiter = selection.get_selected()[1]
        self.instStore.remove(rowiter)
        self.render()
    
    def cb_Edit(self,widget=None,data=None):
        instance = self.getCurrentInstance()
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        if instance is None or server is None:
            return
        InstancePage(self,server,instance)

    def cb_cursorChanged(self, tree=None, path=None, data=None):
        selection = self.instList.get_selection()
        if selection is None:
            state = False
        else:
            rowiter = selection.get_selected()[1]
            state = rowiter is not None
        self.instEdit.set_sensitive(state)
        self.instRemove.set_sensitive(state)
    
    def getCurrentInstance(self, onlyId=True):
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        if server is None:
            return None
        selection = self.instList.get_selection()
        rowiter = selection.get_selected()[1]
        return self.getApplication().getLocalObjectById(self.instStore.get_value(rowiter,2))
         
    
    def cb_OK(self,widget=None,data=None):
        try:
            concernedServer = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            concernedServer = None
        if self.serverId is None:
            server = self.getApplication().getData().createServer()
            self.mode = ServerPropertyPage.MODE_EDIT
        else:
            server = concernedServer
        server.setIp(self.ipFrame_IPEntry.get_text())
        server.setName(self.ipFrame_NameEntry.get_text())
        server.setSSHName(self.sshFrame_NameEntry.get_text())
        server.setSSHPass(self.sshFrame_PassEntry.get_text())
        server.setTarget(self.ipFrame_Target.get_active_text())
        server.load = server.LOADED_PROFILE
        server.establishConnections()
        
        self.getApplication().getMainWindow().closeDialogPane()
    
    def cb_Cancel(self,widget=None,data=None):
        self.getApplication().getMainWindow().closeDialogPane()
Ejemplo n.º 5
0
 def __init__(self,parent, server=None, instance = None):
     gtk.Frame.__init__(self)
     self.par = parent
     self.serverId = None
     if server is not None:
         self.serverId = server.getLocalId()
     self.instanceId = None
     if instance is not None:
         self.instanceId = instance.getLocalId()
     self.instanceTypes = self.getApplication().getInstanceTypes()
     
     self.set_label(_("Skarphed Admin :: Configure Instance"))
     self.vbox = gtk.VBox()
     self.label = gtk.Label(_("Please configure the Instance"))
     self.vspace = gtk.Label("")
     self.vbox.pack_start(self.label,False)
     self.vbox.pack_start(self.vspace,True)
     
     self.table = gtk.Table(2,4,False)
     self.typeLabel = gtk.Label(_("InstanceType:"))
     
     self.typeStore = gtk.ListStore(str)
     self.typeCombo = gtk.ComboBox(self.typeStore)
     self.typeRenderer = gtk.CellRendererText()
     self.typeCombo.pack_start(self.typeRenderer, True)
     self.typeCombo.add_attribute(self.typeRenderer, 'text', 0)  
     for instanceType in self.instanceTypes:
         self.typeStore.append((instanceType.displayName,))
     self.typeCombo.set_active(0)
     self.urlLabel = gtk.Label(_("URL:"))
     self.urlEntry = DefaultEntry(default_message="http://instance.org")
     self.urlEntry.set_text("http://")
     self.userLabel = gtk.Label(_("Username:"******"username"))
     self.passLabel = gtk.Label(_("Password:"******"●")
     self.table.attach(self.typeLabel,0,1,0,1)
     self.table.attach(self.typeCombo,1,2,0,1)
     self.table.attach(self.urlLabel,0,1,1,2)
     self.table.attach(self.urlEntry,1,2,1,2)
     self.table.attach(self.userLabel,0,1,2,3)
     self.table.attach(self.userEntry,1,2,2,3)
     self.table.attach(self.passLabel,0,1,3,4)
     self.table.attach(self.passEntry,1,2,3,4)
     self.vbox.pack_start(self.table,False)
     
     self.buttonBox = gtk.HBox()
     self.ok = gtk.Button(stock=gtk.STOCK_OK)
     self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
     self.viewpass = ViewPasswordButton()
     self.viewpass.addEntry(self.passEntry)
     self.space = gtk.Label("")
     self.buttonBox.pack_start(self.space,True)
     self.buttonBox.pack_start(self.viewpass,False)
     self.buttonBox.pack_start(self.cancel,False)
     self.buttonBox.pack_start(self.ok,False)
     self.ok.connect("clicked",self.cb_Ok)
     self.cancel.connect("clicked",self.cb_Cancel)
     self.vbox.pack_start(self.buttonBox,False)
     
     self.add(self.vbox)
     self.getApplication().getMainWindow().openDialogPane(self)
     if instance is not None:
         self.urlEntry.set_sensitive(False)
         self.render()
Ejemplo n.º 6
0
class InstancePage(gtk.Frame):
    def __init__(self,parent, server=None, instance = None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is not None:
            self.serverId = server.getLocalId()
        self.instanceId = None
        if instance is not None:
            self.instanceId = instance.getLocalId()
        self.instanceTypes = self.getApplication().getInstanceTypes()
        
        self.set_label(_("Skarphed Admin :: Configure Instance"))
        self.vbox = gtk.VBox()
        self.label = gtk.Label(_("Please configure the Instance"))
        self.vspace = gtk.Label("")
        self.vbox.pack_start(self.label,False)
        self.vbox.pack_start(self.vspace,True)
        
        self.table = gtk.Table(2,4,False)
        self.typeLabel = gtk.Label(_("InstanceType:"))
        
        self.typeStore = gtk.ListStore(str)
        self.typeCombo = gtk.ComboBox(self.typeStore)
        self.typeRenderer = gtk.CellRendererText()
        self.typeCombo.pack_start(self.typeRenderer, True)
        self.typeCombo.add_attribute(self.typeRenderer, 'text', 0)  
        for instanceType in self.instanceTypes:
            self.typeStore.append((instanceType.displayName,))
        self.typeCombo.set_active(0)
        self.urlLabel = gtk.Label(_("URL:"))
        self.urlEntry = DefaultEntry(default_message="http://instance.org")
        self.urlEntry.set_text("http://")
        self.userLabel = gtk.Label(_("Username:"******"username"))
        self.passLabel = gtk.Label(_("Password:"******"●")
        self.table.attach(self.typeLabel,0,1,0,1)
        self.table.attach(self.typeCombo,1,2,0,1)
        self.table.attach(self.urlLabel,0,1,1,2)
        self.table.attach(self.urlEntry,1,2,1,2)
        self.table.attach(self.userLabel,0,1,2,3)
        self.table.attach(self.userEntry,1,2,2,3)
        self.table.attach(self.passLabel,0,1,3,4)
        self.table.attach(self.passEntry,1,2,3,4)
        self.vbox.pack_start(self.table,False)
        
        self.buttonBox = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.passEntry)
        self.space = gtk.Label("")
        self.buttonBox.pack_start(self.space,True)
        self.buttonBox.pack_start(self.viewpass,False)
        self.buttonBox.pack_start(self.cancel,False)
        self.buttonBox.pack_start(self.ok,False)
        self.ok.connect("clicked",self.cb_Ok)
        self.cancel.connect("clicked",self.cb_Cancel)
        self.vbox.pack_start(self.buttonBox,False)
        
        self.add(self.vbox)
        self.getApplication().getMainWindow().openDialogPane(self)
        if instance is not None:
            self.urlEntry.set_sensitive(False)
            self.render()
    
    def render(self):
        try:
            instance = self.getApplication().getLocalObjectById(self.instanceId)
        except GenericObjectStoreException:
            self.getApplication().getMainWindow().closeDialogPane(self)
            return
    
        self.urlEntry.set_text(instance.getUrl())
        self.userEntry.set_text(instance.getUsername())
        self.passEntry.set_text(instance.getPassword())
    
    def getInstanceType(self,text):
        for instanceType in self.instanceTypes:
            if instanceType.displayName == text:
                return instanceType
        return None
    
    def cb_Cancel(self, widget=None, data=None):
        self.getApplication().getMainWindow().closeDialogPane()
    
    def cb_Ok (self, widget=None, data=None):
        def errorMessage(msgId):
            msgs = (_("This URL cannot be resolved"),
                    )
            dia = gtk.MessageDialog(parent=self.getPar().getPar(), flags=0, type=gtk.MESSAGE_WARNING, \
                                  buttons=gtk.BUTTONS_OK, message_format=msgs[msgId])
            dia.run()
            dia.destroy()
        
        instance = None
        if self.instanceId is not None:
            instance = self.getApplication().getLocalObjectById(self.instanceId)
        server = self.getApplication().getLocalObjectById(self.serverId)
        
        if instance is not None:
            instance.setUsername(self.userEntry.get_text())
            instance.setPassword(self.passEntry.get_text())
            instance.establishConnections()
        else:
            url = self.urlEntry.get_text()
            if server is None:
                try:
                    server = self.getApplication().createServerFromInstanceUrl(url)
                except DNSError:
                    errorMessage(0)
                    return
            
            selection = self.typeStore[self.typeCombo.get_active()][0]  
            instanceType = self.getInstanceType(selection)
            
            username = self.userEntry.get_text()
            password = self.passEntry.get_text()
            try:
                if not server.createInstance(instanceType, url, username, password):
                    MessagePage(self, _("This URL resolves to another server. You can't add that here."))
                    return
            except None:
                return
        self.getApplication().getMainWindow().closeDialogPane()

        
    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()
Ejemplo n.º 7
0
    def __init__(self, parent, server=None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is None:
            self.set_label(_("Skarphed Admin Pro :: New Server"))
            self.mode = ServerPropertyPage.MODE_NEW
        else:
            self.serverId = server.getLocalId()
            self.set_label(
                _("Skarphed Admin Pro :: Server Properties of ") +
                server.getIp())
            self.mode = ServerPropertyPage.MODE_EDIT

        self.vbox = gtk.VBox()

        self.instructionlabel = gtk.Label(
            _("Please enter the Server credentials"))
        self.vbox.pack_start(self.instructionlabel, False)

        self.ipFrame = gtk.Frame(_("Common"))
        self.ipFrameT = gtk.Table(2, 3, False)
        self.ipFrame_IPLabel = gtk.Label(_("IP:"))
        self.ipFrame_IPEntry = DefaultEntry(default_message="172.16.13.37")
        self.ipFrameT.attach(self.ipFrame_IPLabel, 0, 1, 0, 1)
        self.ipFrameT.attach(self.ipFrame_IPEntry, 1, 2, 0, 1)
        self.ipFrame_NameLabel = gtk.Label(_("Name:"))
        self.ipFrame_NameEntry = DefaultEntry(default_message="Server1")
        self.ipFrameT.attach(self.ipFrame_NameLabel, 0, 1, 1, 2)
        self.ipFrameT.attach(self.ipFrame_NameEntry, 1, 2, 1, 2)
        self.ipFrame_Target_Label = gtk.Label("Target system:")
        self.ipFrame_Target_model = gtk.ListStore(str)
        for target in Server.INSTALLATION_TARGETS:
            self.ipFrame_Target_model.append((target.getName(), ))
        self.ipFrame_Target_renderer = gtk.CellRendererText()
        self.ipFrame_Target = gtk.ComboBox(self.ipFrame_Target_model)
        self.ipFrame_Target.pack_start(self.ipFrame_Target_renderer, True)
        self.ipFrame_Target.add_attribute(self.ipFrame_Target_renderer, 'text',
                                          0)
        self.ipFrameT.attach(self.ipFrame_Target_Label, 0, 1, 2, 3)
        self.ipFrameT.attach(self.ipFrame_Target, 1, 2, 2, 3)
        self.ipFrame.add(self.ipFrameT)

        self.vbox.pack_start(self.ipFrame, False)

        self.sshFrame = gtk.Frame(_("SSH"))
        self.sshFrameT = gtk.Table(2, 2, False)
        self.sshFrame_NameLabel = gtk.Label(_("Username:"******"root")
        self.sshFrame_PassLabel = gtk.Label(_("Password:"******"●")
        self.sshFrameT.attach(self.sshFrame_NameLabel, 0, 1, 0, 1)
        self.sshFrameT.attach(self.sshFrame_NameEntry, 1, 2, 0, 1)
        self.sshFrameT.attach(self.sshFrame_PassLabel, 0, 1, 1, 2)
        self.sshFrameT.attach(self.sshFrame_PassEntry, 1, 2, 1, 2)
        self.sshFrame.add(self.sshFrameT)
        self.vbox.pack_start(self.sshFrame, False)

        self.instFrame = gtk.Frame(_("Instances"))
        self.instFrameT = gtk.Table(2, 4, False)
        self.instList = gtk.TreeView()
        self.instStore = gtk.ListStore(gtk.gdk.Pixbuf, str, int)
        self.instList.set_model(self.instStore)
        self.instCol_Icon = gtk.TreeViewColumn()
        self.instCol_Name = gtk.TreeViewColumn(_('Instance'))
        self.instRen_Icon = gtk.CellRendererPixbuf()
        self.instRen_Name = gtk.CellRendererText()
        self.instCol_Icon.pack_start(self.instRen_Icon, False)
        self.instCol_Name.pack_start(self.instRen_Name, True)
        self.instCol_Icon.add_attribute(self.instRen_Icon, 'pixbuf', 0)
        self.instCol_Name.add_attribute(self.instRen_Name, 'text', 1)
        self.instList.append_column(self.instCol_Icon)
        self.instList.append_column(self.instCol_Name)
        self.instAdd = gtk.Button(stock=gtk.STOCK_ADD)
        self.instRemove = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.instEdit = gtk.Button(stock=gtk.STOCK_EDIT)
        self.instFrameT.attach(self.instList, 0, 1, 0, 4)
        self.instFrameT.attach(self.instAdd, 1, 2, 0, 1)
        self.instFrameT.attach(self.instRemove, 1, 2, 1, 2)
        self.instFrameT.attach(self.instEdit, 1, 2, 2, 3)
        self.instAdd.connect("clicked", self.cb_Add)
        self.instRemove.connect("clicked", self.cb_Remove)
        self.instEdit.connect("clicked", self.cb_Edit)
        self.instList.connect("cursor-changed", self.cb_cursorChanged)
        self.instFrame.add(self.instFrameT)
        self.vbox.pack_start(self.instFrame, False)

        self.fill = gtk.Label("")
        self.vbox.pack_start(self.fill, True)

        self.buttons = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.sshFrame_PassEntry)
        self.ok.connect("clicked", self.cb_OK)
        self.cancel.connect("clicked", self.cb_Cancel)
        self.buttons.pack_end(self.ok, False)
        self.buttons.pack_end(self.cancel, False)
        self.buttons.pack_end(self.viewpass, False)
        self.vbox.pack_start(self.buttons, False)

        self.add(self.vbox)

        if server is not None:
            self.ipFrame_IPEntry.set_text(server.getIp())
            self.ipFrame_NameEntry.set_text(server.getRawName())
            self.sshFrame_NameEntry.set_text(server.getSSHName())
            self.sshFrame_PassEntry.set_text(server.getSSHPass())
            server.addCallback(self.render)
        self.getApplication().getMainWindow().openDialogPane(self)
        self.render()
Ejemplo n.º 8
0
class ServerPropertyPage(gtk.Frame):
    addWindowOpen = False
    MODE_EDIT = 0
    MODE_NEW = 1

    def __init__(self, parent, server=None):
        gtk.Frame.__init__(self)
        self.par = parent
        self.serverId = None
        if server is None:
            self.set_label(_("Skarphed Admin Pro :: New Server"))
            self.mode = ServerPropertyPage.MODE_NEW
        else:
            self.serverId = server.getLocalId()
            self.set_label(
                _("Skarphed Admin Pro :: Server Properties of ") +
                server.getIp())
            self.mode = ServerPropertyPage.MODE_EDIT

        self.vbox = gtk.VBox()

        self.instructionlabel = gtk.Label(
            _("Please enter the Server credentials"))
        self.vbox.pack_start(self.instructionlabel, False)

        self.ipFrame = gtk.Frame(_("Common"))
        self.ipFrameT = gtk.Table(2, 3, False)
        self.ipFrame_IPLabel = gtk.Label(_("IP:"))
        self.ipFrame_IPEntry = DefaultEntry(default_message="172.16.13.37")
        self.ipFrameT.attach(self.ipFrame_IPLabel, 0, 1, 0, 1)
        self.ipFrameT.attach(self.ipFrame_IPEntry, 1, 2, 0, 1)
        self.ipFrame_NameLabel = gtk.Label(_("Name:"))
        self.ipFrame_NameEntry = DefaultEntry(default_message="Server1")
        self.ipFrameT.attach(self.ipFrame_NameLabel, 0, 1, 1, 2)
        self.ipFrameT.attach(self.ipFrame_NameEntry, 1, 2, 1, 2)
        self.ipFrame_Target_Label = gtk.Label("Target system:")
        self.ipFrame_Target_model = gtk.ListStore(str)
        for target in Server.INSTALLATION_TARGETS:
            self.ipFrame_Target_model.append((target.getName(), ))
        self.ipFrame_Target_renderer = gtk.CellRendererText()
        self.ipFrame_Target = gtk.ComboBox(self.ipFrame_Target_model)
        self.ipFrame_Target.pack_start(self.ipFrame_Target_renderer, True)
        self.ipFrame_Target.add_attribute(self.ipFrame_Target_renderer, 'text',
                                          0)
        self.ipFrameT.attach(self.ipFrame_Target_Label, 0, 1, 2, 3)
        self.ipFrameT.attach(self.ipFrame_Target, 1, 2, 2, 3)
        self.ipFrame.add(self.ipFrameT)

        self.vbox.pack_start(self.ipFrame, False)

        self.sshFrame = gtk.Frame(_("SSH"))
        self.sshFrameT = gtk.Table(2, 2, False)
        self.sshFrame_NameLabel = gtk.Label(_("Username:"******"root")
        self.sshFrame_PassLabel = gtk.Label(_("Password:"******"●")
        self.sshFrameT.attach(self.sshFrame_NameLabel, 0, 1, 0, 1)
        self.sshFrameT.attach(self.sshFrame_NameEntry, 1, 2, 0, 1)
        self.sshFrameT.attach(self.sshFrame_PassLabel, 0, 1, 1, 2)
        self.sshFrameT.attach(self.sshFrame_PassEntry, 1, 2, 1, 2)
        self.sshFrame.add(self.sshFrameT)
        self.vbox.pack_start(self.sshFrame, False)

        self.instFrame = gtk.Frame(_("Instances"))
        self.instFrameT = gtk.Table(2, 4, False)
        self.instList = gtk.TreeView()
        self.instStore = gtk.ListStore(gtk.gdk.Pixbuf, str, int)
        self.instList.set_model(self.instStore)
        self.instCol_Icon = gtk.TreeViewColumn()
        self.instCol_Name = gtk.TreeViewColumn(_('Instance'))
        self.instRen_Icon = gtk.CellRendererPixbuf()
        self.instRen_Name = gtk.CellRendererText()
        self.instCol_Icon.pack_start(self.instRen_Icon, False)
        self.instCol_Name.pack_start(self.instRen_Name, True)
        self.instCol_Icon.add_attribute(self.instRen_Icon, 'pixbuf', 0)
        self.instCol_Name.add_attribute(self.instRen_Name, 'text', 1)
        self.instList.append_column(self.instCol_Icon)
        self.instList.append_column(self.instCol_Name)
        self.instAdd = gtk.Button(stock=gtk.STOCK_ADD)
        self.instRemove = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.instEdit = gtk.Button(stock=gtk.STOCK_EDIT)
        self.instFrameT.attach(self.instList, 0, 1, 0, 4)
        self.instFrameT.attach(self.instAdd, 1, 2, 0, 1)
        self.instFrameT.attach(self.instRemove, 1, 2, 1, 2)
        self.instFrameT.attach(self.instEdit, 1, 2, 2, 3)
        self.instAdd.connect("clicked", self.cb_Add)
        self.instRemove.connect("clicked", self.cb_Remove)
        self.instEdit.connect("clicked", self.cb_Edit)
        self.instList.connect("cursor-changed", self.cb_cursorChanged)
        self.instFrame.add(self.instFrameT)
        self.vbox.pack_start(self.instFrame, False)

        self.fill = gtk.Label("")
        self.vbox.pack_start(self.fill, True)

        self.buttons = gtk.HBox()
        self.ok = gtk.Button(stock=gtk.STOCK_OK)
        self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        self.viewpass = ViewPasswordButton()
        self.viewpass.addEntry(self.sshFrame_PassEntry)
        self.ok.connect("clicked", self.cb_OK)
        self.cancel.connect("clicked", self.cb_Cancel)
        self.buttons.pack_end(self.ok, False)
        self.buttons.pack_end(self.cancel, False)
        self.buttons.pack_end(self.viewpass, False)
        self.vbox.pack_start(self.buttons, False)

        self.add(self.vbox)

        if server is not None:
            self.ipFrame_IPEntry.set_text(server.getIp())
            self.ipFrame_NameEntry.set_text(server.getRawName())
            self.sshFrame_NameEntry.set_text(server.getSSHName())
            self.sshFrame_PassEntry.set_text(server.getSSHPass())
            server.addCallback(self.render)
        self.getApplication().getMainWindow().openDialogPane(self)
        self.render()

    def render(self):
        def search(model, path, rowiter, target):
            text = model.get_value(rowiter, 0)
            if text == target.getName():
                self.ipFrame_Target.set_active_iter(rowiter)

        server = None
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            if self.mode == ServerPropertyPage.MODE_EDIT:
                self.getApplication().getMainWindow().closeDialogPane()
                return

        self.instFrame.set_visible(self.mode == ServerPropertyPage.MODE_EDIT)

        if server is not None and server.isTargetUsable():
            self.ipFrame_Target_model.foreach(search, server.getTarget())

        self.instStore.clear()
        if server is not None:
            for instance in server.getInstances():
                icon = SKARPHED  #TODO: Implement Icon
                self.instStore.append(
                    (icon, instance.getName(), instance.getLocalId()))
        self.cb_cursorChanged()

    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()

    def cb_Add(self, widget=None, data=None):
        server = self.getApplication().getLocalObjectById(self.serverId)
        InstancePage(self, server)

    def cb_Remove(self, widget=None, data=None):
        instance = self.getCurrentInstance()
        if instance is None:
            return
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        server.removeInstance(instance)
        selection = self.instList.get_selection()
        rowiter = selection.get_selected()[1]
        self.instStore.remove(rowiter)
        self.render()

    def cb_Edit(self, widget=None, data=None):
        instance = self.getCurrentInstance()
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        if instance is None or server is None:
            return
        InstancePage(self, server, instance)

    def cb_cursorChanged(self, tree=None, path=None, data=None):
        selection = self.instList.get_selection()
        if selection is None:
            state = False
        else:
            rowiter = selection.get_selected()[1]
            state = rowiter is not None
        self.instEdit.set_sensitive(state)
        self.instRemove.set_sensitive(state)

    def getCurrentInstance(self, onlyId=True):
        try:
            server = self.getApplication().getLocalObjectById(self.serverId)
        except GenericObjectStoreException:
            server = None
        if server is None:
            return None
        selection = self.instList.get_selection()
        rowiter = selection.get_selected()[1]
        return self.getApplication().getLocalObjectById(
            self.instStore.get_value(rowiter, 2))

    def cb_OK(self, widget=None, data=None):
        try:
            concernedServer = self.getApplication().getLocalObjectById(
                self.serverId)
        except GenericObjectStoreException:
            concernedServer = None
        if self.serverId is None:
            server = self.getApplication().getData().createServer()
            self.mode = ServerPropertyPage.MODE_EDIT
        else:
            server = concernedServer
        server.setIp(self.ipFrame_IPEntry.get_text())
        server.setName(self.ipFrame_NameEntry.get_text())
        server.setSSHName(self.sshFrame_NameEntry.get_text())
        server.setSSHPass(self.sshFrame_PassEntry.get_text())
        server.setTarget(self.ipFrame_Target.get_active_text())
        server.load = server.LOADED_PROFILE
        server.establishConnections()

        self.getApplication().getMainWindow().closeDialogPane()

    def cb_Cancel(self, widget=None, data=None):
        self.getApplication().getMainWindow().closeDialogPane()