将SALT_STACK的JOB-CACHE放到数据库中,而建库用DJANGO的ORM完成

时间:2020-12-17 11:45:29

下面包括了SALT_MASTER的配置,及DJANGO的ORM里更改默认表名称,更改默认字段名称(里面有个RETURN),更改默认ID索引。。。

一个下午有和它磨来磨去。。。

感谢鹏龙,感谢高远。。:)

参考:

http://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html#module-salt.returners.mysql

原表SQL语句:

CREATE DATABASE  `salt`
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;

USE `salt`;

--
-- Table structure for table `jids`
--

DROP TABLE IF EXISTS `jids`;
CREATE TABLE `jids` (
  `jid` ) NOT NULL,
  `load` mediumtext NOT NULL,
  UNIQUE KEY `jid` (`jid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `salt_returns`
--

DROP TABLE IF EXISTS `salt_returns`;
CREATE TABLE `salt_returns` (
  `fun` ) NOT NULL,
  `jid` ) NOT NULL,
  `return` mediumtext NOT NULL,
  `id` ) NOT NULL,
  `success` ) NOT NULL,
  `full_ret` mediumtext NOT NULL,
  `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  KEY `id` (`id`),
  KEY `jid` (`jid`),
  KEY `fun` (`fun`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `salt_events`
--

DROP TABLE IF EXISTS `salt_events`;
CREATE TABLE `salt_events` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`tag` ) NOT NULL,
`data` ) NOT NULL,
`alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`master_id` ) NOT NULL,
PRIMARY KEY (`id`),
KEY `tag` (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DJANGO的ORM的样子:


from django.db import models

# Create your models here.class jids(models.Model):    jid = models.CharField(max_length=255, unique=True)    load = models.TextField(max_length=1024)

    def __unicode__(self):        return self.jid

    class Meta:        db_table = 'jids'        ordering = ('-jid',)

class salt_events(models.Model):    tag = models.CharField(max_length=255)    data = models.CharField(max_length=1024)    alter_time = models.DateTimeField(auto_now_add=True)    master_id = models.CharField(max_length=255)

    def __unicode__(self):        return self.id

    class Meta:        db_table = 'salt_events'        ordering = ('-id',)

class salt_returns(models.Model):    custom_id = models.AutoField(primary_key=True)    fun = models.CharField(max_length=50)    jid = models.CharField(max_length=255)    return_char = models.TextField(max_length=1024, db_column='return')    id = models.CharField(max_length=50)    success = models.CharField(max_length=10)    full_ret = models.TextField(max_length=1024)    alter_time = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):        return self.custom_id

    class Meta:        db_table = 'salt_returns'        ordering = ('-custom_id',)
 

SALT_MASTER配置更改:

#add by chengang
#--
#
#
event_return: mysql
master_job_cache: mysql
mysql.host: '1.1.1.1'
mysql.user: 'xxx'
mysql.pass: 'yyyy'
mysql.db: 'AAAA'
mysql.port: 

DJANGO更新ORM的语句:

python manage.py makemigrations

#python manage.py syncdb(听说快放弃不用)

python manage.py migrate

测试效果:

将SALT_STACK的JOB-CACHE放到数据库中,而建库用DJANGO的ORM完成