Ejemplo n.º 1
0
class Distro(M):
    _namespace = "os.distro"
    _vars = [
        var.RowID,
        var.String("tag", 32, mods=[mod.NotNull(), mod.Unique()]),
        var.String("name", 32, mods=[mod.NotNull()]),
        var.Text("description")
    ]
    _acl_rules = dict(add=dict(allow=["admin", "member"]),
                      read=dict(default=True),
                      update=dict(allow=["admin"]),
                      delete=dict(allow=["admin"]),
                      empty=dict(allow=["admin"]))

    @staticmethod
    def defaults():
        dists = {}
        for d in Distro.all():
            dists[d.tag] = d

        if len(dists) == 0:
            dists = {
                "rhel":
                Distro(tag="rhel",
                       name="RHEL",
                       description="RedHat Enterprise Linux").add(),
                "debian":
                Distro(tag="debian", name="Debian",
                       description="Debian Linux").add()
            }

        return dists
Ejemplo n.º 2
0
class AllVars(Model):
    _namespace = "all.vars"
    _vars = [
        var.RowID,
        var.Number("number", mods=[mod.Min(0), mod.Max(100)]),
        var.Boolean("boolean"),
        var.String("string", 32, mods=[mod.NotNull()]),
        var.Character("character", 4),
        var.Binary("binary", 25),
        var.Text("text"),
        var.Float("float"),
        var.Enum("enum", ["one", "two", "three"]),
        var.ForeignKey("cars.make")
    ]
Ejemplo n.º 3
0
class SubCategory(M):
    _namespace = "app.subcategory"
    _vars = [
        var.RowID,
        var.ForeignKey("app.category"),
        var.String("tag", 32, mods=[mod.NotNull(), mod.Unique()]),
        var.String("name", 32, mods=[mod.NotNull()]),
        var.Text("description")
    ]
    _acl_rules = dict(add=dict(allow=["admin", "member"]),
                      read=dict(default=True),
                      update=dict(allow=["admin"]),
                      delete=dict(allow=["admin"]),
                      empty=dict(allow=["admin"]))

    @staticmethod
    def defaults():
        cats = Category.defaults()

        scats = {}
        for c in SubCategory.all():
            scats[c.tag] = c

        if len(scats) == 0:
            scats = {
                "os_rhel":
                SubCategory(app_category_id=cats["os"].id,
                            tag="os_rhel",
                            name="RHEL",
                            description="RedHat Enterprise Linux").add(),
                "os_debian":
                SubCategory(app_category_id=cats["os"].id,
                            tag="os_debian",
                            name="Debian",
                            description="Debian Linux").add(),
                "http_server":
                SubCategory(app_category_id=cats["http"].id,
                            tag="http_server",
                            name="Server",
                            description="HTTP Server").add(),
                "http_client":
                SubCategory(app_category_id=cats["http"].id,
                            tag="http_client",
                            name="Client",
                            description="HTTP Client").add()
            }

        return scats
Ejemplo n.º 4
0
class OS(M):
    _namespace = "os.os"
    _vars = [
        var.RowID,
        var.String("tag", 32, mods=[mod.NotNull()]),
        var.String("name", 32, mods=[mod.NotNull()]),
        var.Text("description"),
        var.ForeignKey("os.distro")
    ]
    _acl_rules = dict(add=dict(allow=["admin", "member"]),
                      read=dict(default=True),
                      update=dict(allow=["admin"]),
                      delete=dict(allow=["admin"]),
                      empty=dict(allow=["admin"]))

    def add_version(self, **kwargs):
        from .Version import Version
        kwargs["os_os_id"] = self.id
        return Version(**kwargs).add()

    @staticmethod
    def defaults():
        dists = Distro.defaults()

        apps = {}
        for a in OS.all():
            apps[a.tag] = a

        if len(apps) == 0:
            apps = {
                "centos":
                OS(tag="centos",
                   name="CentOS",
                   description="Community Enterprise Operating System",
                   os_distro_id=dists["rhel"].id).add(),
                "fedora":
                OS(tag="fedora",
                   name="Fedora",
                   description="Fedora Linux",
                   os_distro_id=dists["rhel"].id).add(),
                "ubuntu":
                OS(tag="ubuntu",
                   name="Ubuntu",
                   description="Canonical Ubuntu",
                   os_distro_id=dists["debian"].id).add()
            }

        return apps
Ejemplo n.º 5
0
class Category(M):
    _namespace = "app.category"
    _vars = [
        var.RowID,
        var.String("tag", 32, mods=[mod.NotNull(), mod.Unique()]),
        var.String("name", 32, mods=[mod.NotNull()]),
        var.Text("description")
    ]
    _acl_rules = dict(add=dict(allow=["admin", "member"]),
                      read=dict(default=True),
                      update=dict(allow=["admin"]),
                      delete=dict(allow=["admin"]),
                      empty=dict(allow=["admin"]))

    @staticmethod
    def defaults():
        cats = {}
        for c in Category.all():
            cats[c.tag] = c

        if len(cats) == 0:
            cats = {
                "os":
                Category(tag="os", name="OS",
                         description="Operating System").add(),
                "http":
                Category(tag="http",
                         name="HTTP",
                         description="Hypertext Transfer Protocol - Internet").
                add(),
                "firewall":
                Category(tag="firewall",
                         name="Firewall",
                         description="Network firewall").add()
            }

        return cats
Ejemplo n.º 6
0
class TestModel( Model ):
    _namespace = "test.model"
    _vars = [
        var.RowID,
        var.String( "tag", 10, mods = [ mod.NotNull(), mod.Unique() ]),
        var.String( "name", 32, mods = [ mod.NotNull() ]),
        var.Text( "description", default = "" ),
    ]

    @staticmethod
    def before_add(event, model, instance ): pass

    @staticmethod
    def after_add( event, model, instance ): pass

    @staticmethod
    def before_delete( event, model, instance ): pass

    @staticmethod
    def after_delete( event, model, instance ): pass

    @staticmethod
    def before_update( event, model, instance ): pass

    @staticmethod
    def after_update( event, model, instance ): pass

    @staticmethod
    def before_validate( event, model, instance ): pass

    @staticmethod
    def after_validate( event, model, instance ): pass

    @staticmethod
    def before_all( event, model ): pass

    @staticmethod
    def after_all( event, model, instances ): pass

    @staticmethod
    def before_get( event, model, row_id ): pass

    @staticmethod
    def after_get( event, model, instance ): pass

    @staticmethod
    def before_empty( event, model ): pass

    @staticmethod
    def after_empty( event, model ): pass

    @staticmethod
    def before_create( event, model ): pass

    @staticmethod
    def after_create( event, model ): pass

    @staticmethod
    def before_destroy( event, model ): pass

    @staticmethod
    def after_destroy( event, model ): pass

    @staticmethod
    def before_filter( event, model, params ): pass

    @staticmethod
    def after_filter( event, model, instances, params ): pass
Ejemplo n.º 7
0
class App(M):
    _namespace = "app.app"
    _vars = [
        var.RowID,
        var.String("tag", 32, mods=[mod.NotNull()]),
        var.String("name", 32, mods=[mod.NotNull()]),
        var.Text("description"),
        var.ForeignKey("apps.subcategory")
    ]
    _acl_rules = dict(add=dict(allow=["admin", "member"]),
                      read=dict(default=True),
                      update=dict(allow=["admin"]),
                      delete=dict(allow=["admin"]),
                      empty=dict(allow=["admin"]))

    def add_version(self, **kwargs):
        from .Version import Version
        kwargs["app_app_id"] = self.id
        return Version(**kwargs).add()

    @staticmethod
    def defaults():
        scats = SubCategory.defaults()

        apps = {}
        for a in App.all():
            apps[a.tag] = a

        if len(apps) == 0:
            apps = {
                "centos":
                App(tag="centos",
                    name="CentOS",
                    description="Community Enterprise Operating System",
                    app_subcategory_id=scats["os_rhel"].id).add(),
                "ubuntu":
                App(tag="ubuntu",
                    name="Ubuntu",
                    description="Canonical Ubuntu",
                    app_subcategory_id=scats["os_debian"].id).add(),
                "nginx":
                App(tag="nginx",
                    name="Nginx",
                    description="Nginx Web Server",
                    app_subcategory_id=scats["http_server"].id).add(),
                "httpd":
                App(tag="httpd",
                    name="Apache",
                    description="Apache Web Server",
                    app_subcategory_id=scats["http_server"].id).add(),
                "curl":
                App(tag="curl",
                    name="Curl",
                    description="Curl Web Client",
                    app_subcategory_id=scats["http_client"].id).add(),
                "wget":
                App(tag="wget",
                    name="Wget",
                    description="Wget Web Client",
                    app_subcategory_id=scats["http_client"].id).add()
            }

        return apps