python--第二十四天总结
CMDB介绍
CMDB --Configuration Management Database 配置管理数据库, CMDB存储与管理企业IT架构中设备的各种配置信息,它与所有服务支持和服务交付流程都紧密相联,支持这些流程的运转、发挥配置信息 的价值,同时依赖于相关流程保证数据的准确性。
- 整合是指能够充分利用来自其他数据源的信息,对CMDB中包含的记录源属性进行存取,将多个数据源合并至一个视图中,生成连同来自CMDB和其他数据源信息在内的报告;
- 调和能力是指通过对来自每个数据源的匹配字段进行对比,保证CMDB中的记录在多个数据源中没有重复现象,维持CMDB中每个配置项目数据源的完整性;自动调整流程使得初始实施、数据库管理员的手动运作和现场维护支持工作降至最低;
- 同步指确保CMDB中的信息能够反映联合数据源的更新情况,在联合数据源更新频率的基础上确定CMDB更新日程,按照经过批准的变更来更新 CMDB,找出未被批准的变更;
- 应用映射与可视化,说明应用间的关系并反应应用和其他组件之间的依存关系,了解变更造成的影响并帮助诊断问题。
CMDB 资产管理部分实现
需求
- •存储所有IT资产信息
- •数据可手动添加
- •硬件信息可自动收集
- •硬件信息可自动变更
- •可对其它系统灵活开放API
- •API接口安全认证
立业之本:定义表结构
- 各种硬件都能存
- 资产变更有纪录
- 资产ID永不变
- 资产要有状态机
重中之重:接口设计好
- 可对内外灵活开放接口
- 接口定义要标准化
- 一定要提供排错依据
- 数据返回要标准
- 要能增删改查
- 所有异常要抓住
- 接口安全要注意
CMDB资产数据自动汇报及更新流程图
https://www.processon.com/view/link/571b4b2ce4b049474cc87feb
自定义用户认证
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#django.contrib.auth.models.PermissionsMixin.has_perms
- user_models.py
- #!/usr/bin/env python
- #_*_ coding:utf-8 _*_
- from django.db import models
- from django.contrib.auth.models import (
- BaseUserManager, AbstractBaseUser
- )
- class UserProfileManager(BaseUserManager):
- def create_user(self, email, name, password=None):
- """
- Creates and saves a User with the given email, date of
- birth and password.
- """
- if not email:
- raise ValueError('Users must have an email address')
- user = self.model(
- email=self.normalize_email(email),
- name=name,
- )
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_superuser(self, email, name, password):
- """
- Creates and saves a superuser with the given email, date of
- birth and password.
- """
- user = self.create_user(email,
- password=password,
- name=name
- )
- user.is_admin = True
- user.save(using=self._db)
- return user
- class UserProfile(AbstractBaseUser):
- email = models.EmailField(
- verbose_name='email address',
- max_length=255,
- unique=True,
- )
- name = models.CharField(u'名字',max_length=32)
- is_active = models.BooleanField(default=True)
- is_admin = models.BooleanField(default=False)
- objects = UserProfileManager()
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = ['name']
- def get_full_name(self):
- # The user is identified by their email address
- return self.email
- def get_short_name(self):
- # The user is identified by their email address
- return self.email
- def __str__(self): # __unicode__ on Python 2
- return self.email
- def has_perm(self, perm, obj=None):
- "Does the user have a specific permission?"
- # Simplest possible answer: Yes, always
- return True
- def has_module_perms(self, app_label):
- "Does the user have permissions to view the app `app_label`?"
- # Simplest possible answer: Yes, always
- return True
- @property
- def is_staff(self):
- "Is the user a member of staff?"
- # Simplest possible answer: All admins are staff
- return self.is_admin
- class Meta:
- verbose_name = u'用户信息'
- verbose_name_plural = u"用户信息"
- def __unicode__(self):
- return self.name
- ----------------------------------
- user_admin_models.py
- #!/usr/bin/env python
- #_*_ coding:utf-8 _*_
- from django import forms
- from django.contrib import admin
- from django.contrib.auth.models import Group
- from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
- from django.contrib.auth.forms import ReadOnlyPasswordHashField
- from assets.user_models import UserProfile
- class UserCreationForm(forms.ModelForm):
- """A form for creating new users. Includes all the required
- fields, plus a repeated password."""
- password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
- password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
- class Meta:
- model = UserProfile
- fields = ('email', 'name')
- def clean_password2(self):
- # Check that the two password entries match
- password1 = self.cleaned_data.get("password1")
- password2 = self.cleaned_data.get("password2")
- if password1 and password2 and password1 != password2:
- raise forms.ValidationError("Passwords don't match")
- return password2
- def save(self, commit=True):
- # Save the provided password in hashed format
- user = super(UserCreationForm, self).save(commit=False)
- user.set_password(self.cleaned_data["password1"])
- if commit:
- user.save()
- return user
- class UserChangeForm(forms.ModelForm):
- """A form for updating users. Includes all the fields on
- the user, but replaces the password field with admin's
- password hash display field.
- """
- password = ReadOnlyPasswordHashField()
- class Meta:
- model = UserProfile
- fields = ('email', 'password', 'name', 'is_active', 'is_admin')
- def clean_password(self):
- # Regardless of what the user provides, return the initial value.
- # This is done here, rather than on the field, because the
- # field does not have access to the initial value
- return self.initial["password"]
- class UserAdmin(BaseUserAdmin):
- # The forms to add and change user instances
- form = UserChangeForm
- add_form = UserCreationForm
- # The fields to be used in displaying the User model.
- # These override the definitions on the base UserAdmin
- # that reference specific fields on auth.User.
- list_display = ('email', 'name', 'is_admin')
- list_filter = ('is_admin',)
- fieldsets = (
- (None, {'fields': ('email', 'password')}),
- ('Personal info', {'fields': ('name',)}),
- ('Permissions', {'fields': ('is_admin',)}),
- )
- # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
- # overrides get_fieldsets to use this attribute when creating a user.
- add_fieldsets = (
- (None, {
- 'classes': ('wide',),
- 'fields': ('email', 'name', 'password1', 'password2')}
- ),
- )
- search_fields = ('email',)
- ordering = ('email',)
- filter_horizontal = ()
浅谈Restful API
理解RESTful架构 :http://www.ruanyifeng.com/blog/2011/09/restful
RESTful API 设计指南:http://www.ruanyifeng.com/blog/2014/05/restful_api.html
如何实现安全的WEB API 接口认证?
MadKing开源CMDB源码
https://github.com/triaquae/MadKing
python--第二十四天总结的更多相关文章
- Python第二十四天 binascii模块
Python第二十四天 binascii模块 binascii用来进行进制和字符串之间的转换 import binascii s = 'abcde' h = binascii.b2a_hex(s) # ...
- 孤荷凌寒自学python第二十四天python类中隐藏的私有方法探秘
孤荷凌寒自学python第二十四天python类中隐藏的私有方法探秘 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天发现了python的类中隐藏着一些特殊的私有方法. 这些私有方法不管我 ...
- python第二十四天-----作业终于完成啦
作业 1, ATM:模拟实现一个ATM + 购物商城程序 额度 15000或自定义实现购物商城,买东西加入 购物车,调用信用卡接口结账可以提现,手续费5%支持多账户登录支持账户间转账记录每月日常消费流 ...
- python第二十四课——set中的函数
集合中常用的一些函数: 1.add(obj):追加一个obj元素到集合中 pop():从集合中随机弹出一个元素 remove(obj):删除集合中和obj匹配的元素 clear():清空集合 s1={ ...
- 初学 Python(十四)——生成器
初学 Python(十四)--生成器 初学 Python,主要整理一些学习到的知识点,这次是生成器. # -*- coding:utf-8 -*- ''''' 生成式的作用: 减少内存占有,不用一次性 ...
- Python第十四天 序列化 pickle模块 cPickle模块 JSON模块 API的两种格式
Python第十四天 序列化 pickle模块 cPickle模块 JSON模块 API的两种格式 目录 Pycharm使用技巧(转载) Python第一天 安装 shell 文件 Py ...
- 孤荷凌寒自学python第二十五天初识python的time模块
孤荷凌寒自学python第二十五天python的time模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 通过对time模块添加引用,就可以使用python的time模块来进行相关的时间操 ...
- 孤荷凌寒自学python第十四天python代码的书写规范与条件语句及判断条件式
孤荷凌寒自学python第十四天python代码的书写规范与条件语句及判断条件式 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 在我学习过的所有语言中,对VB系的语言比较喜欢,而对C系和J系 ...
- NeHe OpenGL教程 第二十四课:扩展
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- javaSE第二十四天
第二十四天 363 1:多线程(理解) 363 (1)JDK5以后的Lock锁 363 A:定义 363 B:方法: 364 C:具体应用(以售票程序为例) 364 ...
随机推荐
- python32模拟鼠标和键盘操作
前言Windows pywin32允许你像vc一样的形式来使用python开发win32应用.代码风格可以类似win32 sdk,也可以类似MFC,由你选择.如果你仍不放弃vc一样的代码过程在pyth ...
- 使用阿里云Java SDK 实现 DDNS
本代码的实现前提: 1.拥有阿里云域名,且获取了Access Key 及 Access Secret 2.能获取外网IP的页面地址(注意:ip138.com的实际包含ip地址为http://2018. ...
- English 翻译到Vyeshal的软件
我或许可以做一个从英语到Vyeshal的翻译软件2333
- 极速认识RSS!
在解释RSS是什么之前,让我先来举个栗子. 大家都能在街道看到许多海报栏.在那里,会贴出各种各样最新的消息,比如哪个系要开讲座了.星期二晚上的电影放什么.二手货转让等 等.只要看一下海报栏,就会对学校 ...
- flink入门:01 构建简单运行程序
1. mac平台安装flink(默认最新版) brew install apache-flink 安装结果: Version 1.7.1, commit ID: 89eafb4 2. jdk版本,我尝 ...
- pycharm移动项目文件后,运行报错
pycharm移动项目文件后,运行报错: ModuleNotFoundError: No module named 'D:/my_project/my_cases/email139cases/tes ...
- 值得推荐的五大敏捷PHP开发框架
各位开发者,对于在HTML中混乱使用PHP的人来说,我们给大家推荐几款PHP敏捷开发的框架,以及它们为什么能够流行. 在我们开始之前,先了解敏捷开发是个什么东东. 敏捷是一种软件开发方法,每次开发计划 ...
- STS临时授权访问OSS
STS临时授权访问OSS OSS 可以通过阿里云 STS (Security Token Service) 进行临时授权访问.阿里云 STS 是为云计算用户提供临时访问令牌的Web服务.通过 STS, ...
- 爬虫之requests
一.基本用法 1.GET请求 ①r=requests.get(url) --返回Response对象 def get(url, params=None, **kwargs): params={... ...
- 嵌入式文件IO实验
实验步骤: 1.arm-linux-gcc 交叉编译环境的安装.参考网站:https://jingyan.baidu.com/article/9c69d48f80282013c9024e20.html ...