Example #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
Example #2
0
class Car(Model):
    _namespace = "cars.make"
    _vars = [
        var.RowID,
        var.String("manufacturer", 32, mods=[mod.NotNull()]),
        var.String("make", 32, mods=[mod.NotNull()]),
        var.Number("year", mods=[mod.NotNull(),
                                 mod.Min(1950),
                                 mod.Max(2017)]),
    ]
Example #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
Example #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
Example #5
0
class Version(M):
    _namespace = "app.version"
    _vars = [
        var.RowID,
        var.ForeignKey("app.app"),
        var.Number("major", default=0, mods=[mod.NotNull()]),
        var.Number("minor", default=0, mods=[mod.NotNull()]),
        var.Number("bugfix", default=0, mods=[]),
        var.Number("build", default=0, mods=[]),
        var.String("name", 32, mods=[]),
        var.Date("release_date")
    ]
    _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():
        from .App import App
        from datetime import date
        apps = App.defaults()

        app = apps["nginx"]
        app.add_version(major=1,
                        minor=6,
                        bugfix=1,
                        name="v1.6.1",
                        release_date=date(2017, 01, 27))
        app.add_version(major=1,
                        minor=5,
                        bugfix=1,
                        name="v1.5.1",
                        release_date=date(2016, 06, 27))

        app = apps["centos"]
        app.add_version(major=7,
                        minor=0,
                        build=1511,
                        name="v7.0",
                        release_date=date(2015, 11, 01))
        app.add_version(major=6,
                        minor=8,
                        name="v6.8",
                        release_date=date(2015, 10, 01))
Example #6
0
class Version( M ):
    _namespace = "os.version"
    _vars = [
        var.RowID,
        var.ForeignKey( "os.os" ),
        var.Number( "major",  default = 0, mods = [ mod.NotNull() ]),
        var.Number( "minor",  default = 0, mods = [ mod.NotNull() ]),
        var.Number( "bugfix", default = 0, mods = [] ),
        var.Number( "build",  default = 0, mods = [] ),
        var.String( "name", 32, mods = [] ),
        var.Date( "release_date" )
    ]
    _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():
        from .OS import OS
        from datetime import date
        os = OS.defaults()

        o = os["centos"]
        o.add_version( major = 7, minor = 3, build = 1611, name = "v7.3", release_date = date( 2016, 11, 01 ))
        o.add_version( major = 7, minor = 2, build = 1511, name = "v7.2", release_date = date( 2015, 11, 01 ))
        o.add_version( major = 7, minor = 1, build = 1503, name = "v7.1", release_date = date( 2015, 03, 01 ))
        o.add_version( major = 7, minor = 0, build = 1406, name = "v7.0", release_date = date( 2014, 06, 01 ))
        o.add_version( major = 6, minor = 8,               name = "v6.8", release_date = date( 2015, 10, 01 ))

        o = os["ubuntu"]
        o.add_version( major = 17, minor = 04, release_date = date(2017, 04, 01), name = "Zesty Zapus"      )
        o.add_version( major = 16, minor = 10, release_date = date(2016, 10, 13), name = "Yakkety Yak"      )
        o.add_version( major = 16, minor = 04, release_date = date(2016, 04, 21), name = "Xenial Xerus"     )
        o.add_version( major = 15, minor = 10, release_date = date(2015, 10, 22), name = "Wily Werewolf"    )
        o.add_version( major = 15, minor = 04, release_date = date(2015, 04, 23), name = "Vivid Vervet"     )
        o.add_version( major = 14, minor = 10, release_date = date(2014, 10, 23), name = "Utopic Unicorn"   )
        o.add_version( major = 14, minor = 04, release_date = date(2014, 04, 17), name = "Trusty Tahr"      )
        o.add_version( major = 13, minor = 10, release_date = date(2013, 10, 17), name = "Saucy Salamander" )
        o.add_version( major = 13, minor = 04, release_date = date(2013, 04, 25), name = "Raring Ringtail"  )
        o.add_version( major = 12, minor = 10, release_date = date(2012, 10, 18), name = "Quantal Quetzal"  )
        o.add_version( major = 12, minor = 04, release_date = date(2012, 04, 26), name = "Precise Pangolin" )
Example #7
0
class Chapter(M):
    _namespace = "chapter.chapter"
    _vars = [var.RowID, var.String("name", 32, mods=[mod.NotNull()])]
    _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 add_defaults():
        pass
Example #8
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")
    ]
Example #9
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
Example #10
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
Example #11
0
class TestModel(Model):
    _namespace = "test.model"
    _vars = [var.RowID, var.Number("test", default=0, mods=[mod.NotNull()])]
Example #12
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