From aa005317f75ea9d8454f8decb619a6e8a4c75bd5 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 11:11:43 +0800 Subject: [PATCH 001/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0vim=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_19.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/c04/c04_19.md b/source/c04/c04_19.md index c5b184b..6c505d6 100644 --- a/source/c04/c04_19.md +++ b/source/c04/c04_19.md @@ -14,6 +14,9 @@ 正常模式(按Esc或Ctrl+[进入) 左下角显示文件名或为空 插入模式(按i进入) 左下角显示--INSERT-- 可视模式(按v进入) 左下角显示--VISUAL-- +替换模式(按r或R开始) 左下角显示 --REPLACE-- +命令行模式(按:或者/或者?开始) +ex模式 没用过,有兴趣的同学可以自行了解 ``` ## 2. 打开文件 From 6b56ae929418fc5df1987dea38cecdb02ccef0a1 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:52:59 +0800 Subject: [PATCH 002/227] update bookmark --- source/bookmark.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/bookmark.rst b/source/bookmark.rst index 37b61e1..c76b807 100755 --- a/source/bookmark.rst +++ b/source/bookmark.rst @@ -12,6 +12,8 @@ Python电子教程 - `RUNNOOB的Python教程 `__ - `w3school&runoob教程合集-1:囊括世面各种语言 `__ - `w3school&runoob教程合集-2:囊括世面各种语言 `__ +- `现代魔法学院:Python教室 `__ +- `Python中文学习大本营 `__ Linux入门 ~~~~~~~~~~~ @@ -150,3 +152,4 @@ Python参考文档 - `Iconfont-阿里巴巴矢量图标库 `__ - `Icons for everything - Noun Project `__ - `Font Awesome,一套绝佳的图标字体库和CSS框架 `__ +- `iSlide:制作高大上的PPT`__ From 5c056e9089976f45d4d98abb2368d760cb1e9e30 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:53:22 +0800 Subject: [PATCH 003/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20mac=20=E6=8A=80?= =?UTF-8?q?=E5=B7=A7=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_18.md | 109 ++++++++++++++++++++++++++++++++++--- source/c04/c04_18.rst | 121 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 217 insertions(+), 13 deletions(-) diff --git a/source/c04/c04_18.md b/source/c04/c04_18.md index 2cc9082..d2c1a9b 100644 --- a/source/c04/c04_18.md +++ b/source/c04/c04_18.md @@ -21,22 +21,117 @@ command + / option + command + e ``` -## 4.18.2 Finder +## 4.18.2 截图工具 + +1. Xnip:取色+丰富的标注功能+滚动截屏; +2. Snip:小巧轻量+滚动截屏:; +3. QQ:截屏+录屏+OCR文字识别; +4. Snipaste:贴屏功能; +5. ScreenShot PSD:psd 文件,每种元素都有单独的图层。 + +## 4.18.3 快捷操作 ``` +# 返回桌面 +fn + f11 + +# finder 后退与前进 command + up # 文件夹后退 command + down # 文件夹前进 ``` -## 4.18.3 截图工具 -1.Xnip:取色+丰富的标注功能+滚动截屏; -2.Snip:小巧轻量+滚动截屏:; -3.QQ:截屏+录屏+OCR文字识别; -4.Snipaste:贴屏功能; -5.ScreenShot PSD:psd 文件,每种元素都有单独的图层。 +## 4.18.4 系统设置 + +关闭仪表盘 + +``` +点击系统偏好设置 -> 调度中心 -> 仪表盘 -> 关闭 +``` + +finder的显示 + +![](http://image.python-online.cn/20190810161513.png) + + + +**[防止电脑温度过高](https://mp.weixin.qq.com/s/qKQO616vxADFp1cVtA62Cw)** + +1. 不使用 Adobe Flash 播放器(改用 HTML5播放器),因为其效能极低,会耗费大量的系统资源,导致电脑温度快速上升。 + +2. 不将电脑放在软的地方,如沙发,枕头等,可以买个散热支架。 + + ![来自Mac派](http://image.python-online.cn/20190810162000.png) + + 3. 打开「活动监视器」(Alfred就可以打开),杀掉暂没用且cpu使用率最高的程序 + + ![](http://image.python-online.cn/20190810162315.png) + + 4. MacBook Pro CPU 温度在 5、60℃ 的时候,风扇会转到两三千转每分钟,只有 CPU 温度达到 70 多度或更高时,才会高速运转降温。但这时 Mac 已经很热了。 + + 我们可以借用软件,手动让散热风扇全速运转,这样就能更快的散热。常用的软件有 Macs Fan Control、TG Pro、smcFanControl,三个用下来我比较推荐 Macs Fan Control。 + + Macs Fan Control 可以查看各 CPU 核心的温度、主板、电池、内存温度等。可以分别调节两个风扇的转速,也可以设定条件自动调整转速。安装后就可以在系统状态栏看到电脑目前的温度和转速。 + + 风扇转得快了,散热自然也快了,但是风扇声音也更大了。建议只在非常烫(超过60℃?)的时候开启。 + + + +## 4.18.5 软件推荐 + +Alfred 3:快捷神器 + +iTerm2:终端神器 + +New File Menu:右键新建特定格式的文件。 + +Caffenie:讲PPT时,控制不息屏。 + +Tickeys:键盘模拟音效。 + +Magnet/Moon:窗口控制 + +Bartender 3:状态栏管理 + +SourceTree:Git可视化管理 + +FreeDownloadManagger:下载管理 + +PicGo:图床上传 + +Typora/Bear:Markdown写作工具 + +滴答清单:待办事项管理 + +Capture Gif:Gif 录制(不推荐) + +Kap Beta:录屏开源免费软件,支持GIF导出,快捷键:`Command Shift 5` + +TeamViewer:远程控制工具 + +iStat Menus:系统指标仪表盘 + +CheatSheet:快捷键帮助菜单 + +CCleaner:系统清理、软件卸载 + +印象笔记:笔记 + +WPS:Office套件 + +Snipaste:截图工具 + +Macs Fan Control:控制风扇转速,加快散热 + +ShortCat:在系统栏也可以搜索聚焦 + + + +## 参考文章 +1. [Mac 上值得推荐的录屏软件](https://mp.weixin.qq.com/s/cvS6BLI53JFQY2P3rvg9Xw) +2. [Mac 连显示器或电视需要买什么线?](https://mp.weixin.qq.com/s/V8A_1GBxtlN2WZrcTsi-YQ) --- diff --git a/source/c04/c04_18.rst b/source/c04/c04_18.rst index 953960c..26adcec 100644 --- a/source/c04/c04_18.rst +++ b/source/c04/c04_18.rst @@ -23,23 +23,132 @@ # Expose Tabs: option + command + e -4.18.2 Finder -------------- +4.18.2 截图工具 +--------------- + +1. Xnip:取色+丰富的标注功能+滚动截屏; +2. Snip:小巧轻量+滚动截屏:; +3. QQ:截屏+录屏+OCR文字识别; +4. Snipaste:贴屏功能; +5. ScreenShot PSD:psd 文件,每种元素都有单独的图层。 + +4.18.3 快捷操作 +--------------- :: + # 返回桌面 + fn + f11 + + # finder 后退与前进 command + up # 文件夹后退 command + down # 文件夹前进 -4.18.3 截图工具 +4.18.4 系统设置 +--------------- + +关闭仪表盘 + +:: + + 点击系统偏好设置 -> 调度中心 -> 仪表盘 -> 关闭 + +finder的显示 + +|image0| + +`防止电脑温度过高 `__ + +1. 不使用 Adobe Flash 播放器(改用 + HTML5播放器),因为其效能极低,会耗费大量的系统资源,导致电脑温度快速上升。 + +2. 不将电脑放在软的地方,如沙发,枕头等,可以买个散热支架。 + + .. figure:: http://image.python-online.cn/20190810162000.png + :alt: 来自Mac派 + + 来自Mac派 + + 3. 打开「活动监视器」(Alfred就可以打开),杀掉暂没用且cpu使用率最高的程序 + + |image1| + + 4. MacBook Pro CPU 温度在 5、60℃ + 的时候,风扇会转到两三千转每分钟,只有 CPU 温度达到 70 + 多度或更高时,才会高速运转降温。但这时 Mac 已经很热了。 + + 我们可以借用软件,手动让散热风扇全速运转,这样就能更快的散热。常用的软件有 + Macs Fan Control、TG Pro、smcFanControl,三个用下来我比较推荐 Macs + Fan Control。 + + Macs Fan Control 可以查看各 CPU + 核心的温度、主板、电池、内存温度等。可以分别调节两个风扇的转速,也可以设定条件自动调整转速。安装后就可以在系统状态栏看到电脑目前的温度和转速。 + + 风扇转得快了,散热自然也快了,但是风扇声音也更大了。建议只在非常烫(超过60℃?)的时候开启。 + +4.18.5 软件推荐 --------------- -1.Xnip:取色+丰富的标注功能+滚动截屏; 2.Snip:小巧轻量+滚动截屏:; -3.QQ:截屏+录屏+OCR文字识别; 4.Snipaste:贴屏功能; 5.ScreenShot -PSD:psd 文件,每种元素都有单独的图层。 +Alfred 3:快捷神器 + +iTerm2:终端神器 + +New File Menu:右键新建特定格式的文件。 + +Caffenie:讲PPT时,控制不息屏。 + +Tickeys:键盘模拟音效。 + +Magnet/Moon:窗口控制 + +Bartender 3:状态栏管理 + +SourceTree:Git可视化管理 + +FreeDownloadManagger:下载管理 + +PicGo:图床上传 + +Typora/Bear:Markdown写作工具 + +滴答清单:待办事项管理 + +Capture Gif:Gif 录制(不推荐) + +Kap Beta:录屏开源免费软件,支持GIF导出,快捷键:\ ``Command Shift 5`` + +TeamViewer:远程控制工具 + +iStat Menus:系统指标仪表盘 + +CheatSheet:快捷键帮助菜单 + +CCleaner:系统清理、软件卸载 + +印象笔记:笔记 + +WPS:Office套件 + +Snipaste:截图工具 + +Macs Fan Control:控制风扇转速,加快散热 + +ShortCat:在系统栏也可以搜索聚焦 + +参考文章 +-------- + +1. `Mac + 上值得推荐的录屏软件 `__ +2. `Mac + 连显示器或电视需要买什么线? `__ -------------- .. figure:: http://image.python-online.cn/20190511161447.png :alt: 关注公众号,获取最新干货! + +.. |image0| image:: http://image.python-online.cn/20190810161513.png +.. |image1| image:: http://image.python-online.cn/20190810162315.png + From 9a6841f583e2f64b237346e78bb065874243cf7e Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:53:46 +0800 Subject: [PATCH 004/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20vim=20=E6=96=87?= =?UTF-8?q?=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_19.md | 10 ++++++++-- source/c04/c04_19.rst | 13 +++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/c04/c04_19.md b/source/c04/c04_19.md index 6c505d6..bdc995a 100644 --- a/source/c04/c04_19.md +++ b/source/c04/c04_19.md @@ -122,6 +122,10 @@ cc 替换整行(就是删除当前行,并在下一行插入) cw 替换一个单词(就是删除一个单词,就进入插入模式),前提是游标处于单词第一个字母(可用b定位) C (大写C)替换至行尾(和D有所区别,D是删除(剪切)至行尾,C是删除至行位并进入插入模式) +# % 就表示所有行,不加就表求当前行 +# 加g表示对每一行的所有匹配到的进行替换,不加就是第一个 +# 如果不加g,而改成c,就会让你再进行确认,选择a进行全部替换,选择y替换,选择n不替换 + :s/old/new/ 用old替换new,替换当前行的第一个匹配 :s/old/new/g 用old替换new,替换当前行的所有匹配 @@ -249,8 +253,7 @@ ZZ 保存并退出 :q! 强制退出并忽略所有更改 :e! 放弃所有修改,并打开原来文件。 - -ZZ 保存并退出 +:open! 放弃所有修改,并打开原来文件。 :sav(eas) new.txt 另存为一个新文件,退出原文件的编辑且不会保存 :f(ile) new.txt 新开一个文件,并不保存,退出原文件的编辑且不会保存 @@ -582,6 +585,9 @@ vim -x file_name :!perl script.pl 执行perl脚本,可以不用退出vim,非常方便。 :suspend或Ctrl - Z 挂起vim,回到shell,按fg可以返回vim。 + +# 执行完当前命令后,自动回到vim环境,但不知为何文件内容变成空了 +:silent !command ``` ## 20. 帮助命令 diff --git a/source/c04/c04_19.rst b/source/c04/c04_19.rst index 68ca0c1..c54989c 100644 --- a/source/c04/c04_19.rst +++ b/source/c04/c04_19.rst @@ -23,6 +23,9 @@ Vim。 正常模式(按Esc或Ctrl+[进入) 左下角显示文件名或为空 插入模式(按i进入) 左下角显示--INSERT-- 可视模式(按v进入) 左下角显示--VISUAL-- + 替换模式(按r或R开始) 左下角显示 --REPLACE-- + 命令行模式(按:或者/或者?开始) + ex模式 没用过,有兴趣的同学可以自行了解 2. 打开文件 ----------- @@ -130,6 +133,10 @@ Vim。 cw 替换一个单词(就是删除一个单词,就进入插入模式),前提是游标处于单词第一个字母(可用b定位) C (大写C)替换至行尾(和D有所区别,D是删除(剪切)至行尾,C是删除至行位并进入插入模式) + # % 就表示所有行,不加就表求当前行 + # 加g表示对每一行的所有匹配到的进行替换,不加就是第一个 + # 如果不加g,而改成c,就会让你再进行确认,选择a进行全部替换,选择y替换,选择n不替换 + :s/old/new/ 用old替换new,替换当前行的第一个匹配 :s/old/new/g 用old替换new,替换当前行的所有匹配 @@ -260,8 +267,7 @@ Vim。 :q! 强制退出并忽略所有更改 :e! 放弃所有修改,并打开原来文件。 - - ZZ 保存并退出 + :open! 放弃所有修改,并打开原来文件。 :sav(eas) new.txt 另存为一个新文件,退出原文件的编辑且不会保存 :f(ile) new.txt 新开一个文件,并不保存,退出原文件的编辑且不会保存 @@ -612,6 +618,9 @@ n\ ``==``\ ,这种方式要求你所编辑的文件的扩展名是被vim所识 :suspend或Ctrl - Z 挂起vim,回到shell,按fg可以返回vim。 + # 执行完当前命令后,自动回到vim环境,但不知为何文件内容变成空了 + :silent !command + 20. 帮助命令 ------------ From 5a46b31592fe0d457db31abeea715231eb0b4ebd Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:54:04 +0800 Subject: [PATCH 005/227] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20gooble=20=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8A=80=E5=B7=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_20.md | 38 ++++++++++++++++++++++++++++++++++++++ source/c04/c04_20.rst | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 source/c04/c04_20.md create mode 100644 source/c04/c04_20.rst diff --git a/source/c04/c04_20.md b/source/c04/c04_20.md new file mode 100644 index 0000000..8edd8ca --- /dev/null +++ b/source/c04/c04_20.md @@ -0,0 +1,38 @@ +# 4.20 学会使用谷歌搜索引擎 + +1、按文件类型搜索 加filetype + +``` +流畅的python filetype:pdf +``` + +2、过滤关键字 用减号 + +``` +Python协程 -CSDN +``` + +3、必须包含某关键字 用加号 + +``` +linux常用命令 +centos +``` + +4、搜索指定网站 加site + +``` +Python冷知识 site:python-online.cn +``` + +5、链接中包含字符串 加inurl + +``` +Python冷知识 inurl:python-online +``` + +6、完全匹配搜索结果 加双绰号包裹 + +``` +"装饰器进阶用法详解" +``` + diff --git a/source/c04/c04_20.rst b/source/c04/c04_20.rst new file mode 100644 index 0000000..9e31f91 --- /dev/null +++ b/source/c04/c04_20.rst @@ -0,0 +1,38 @@ +4.20 学会使用谷歌搜索引擎 +========================= + +1、按文件类型搜索 加filetype + +:: + + 流畅的python filetype:pdf + +2、过滤关键字 用减号 + +:: + + Python协程 -CSDN + +3、必须包含某关键字 用加号 + +:: + + linux常用命令 +centos + +4、搜索指定网站 加site + +:: + + Python冷知识 site:python-online.cn + +5、链接中包含字符串 加inurl + +:: + + Python冷知识 inurl:python-online + +6、完全匹配搜索结果 加双绰号包裹 + +:: + + "装饰器进阶用法详解" From c11fa64cea7f42f8a2d765b14c75aa3f35d01f87 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:54:46 +0800 Subject: [PATCH 006/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0linux=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=EF=BC=88=E5=88=AB=E5=90=8D=E6=8A=80=E5=B7=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c07/c07_01.md | 61 ++++++++++++++++++++++++++++++++++ source/c07/c07_01.rst | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/source/c07/c07_01.md b/source/c07/c07_01.md index f522c1e..5bc4404 100644 --- a/source/c07/c07_01.md +++ b/source/c07/c07_01.md @@ -1548,8 +1548,69 @@ $ alias catgra='cat /var/lib/mysql/grastate.dat' # 比如我们的ll,系统默认给我们加了别名,ll='ls -l --color=auto',也就是加上颜色效果 # 如果我们不要颜色效果,可以这样使用转义符,使用原生的命令 $ \ll somedir +``` +这里转几条来自 「**良许Linux**」的总结,非常实用,你可以跟着设置一下 + +1、压缩包文件,特别是 tar 文件在 Linux 下使用非常广泛,但是 tar 命令的选项又非常多,也不好记住。所以我们可以将常用的几个选项定义为一个别名 **untar** ,这样我们需要解压 tar 文件时,直接 **untar filename** 即可。 + +``` +alias untar='tar -zxvf ' +``` + +2、我们下载一个很大的文件时,突然网络异常中断了,我们重新下载是不是很抓狂?别担心,我们的 wget 命令有个 -c 选项,支持断点下载,我们也可以将它设置为别名: + +``` +alias wget='wget -c ' +``` + +3、有时我们需要生成一个 20 个字符的随机数密码,我们可以使用 openssl 命令,但完整的命令又很长很不方便,我们可以设置别名: + +``` +alias getpass="openssl rand -base64 20" +``` + +4、下载一个文件之后,我们想要校验一下它的 checksum 值,可以将这个命令封装为一个别名 **sha** ,之后我们 **sha filename** 就可以校验文件的 checksum 值。 + +``` +alias sha='shasum -a 256 ' +``` + +5、正常情况下,ping 命令将无限次输出,但其实没多大意义。我们可以使用 -c 命令将其限制为 5 次输出,然后设置为别名 **ping** ,使用时,**ping url** 即可。 + +``` +alias ping='ping -c 5' +``` + +6、如果我们想随时随地启动一个 web 服务器,我们可以使用这个别名: + +``` +alias www='python -m SimpleHTTPServer 8000' +``` + +7、网速的测试在工作中也经常用到,但 Linux 没有自带命令可用,我们可以借助第三方工具 **speedtest-cli** 。这个工具可以直接从 Github 上下载,使用方法里面也有详细介绍。我们需要先使用 **speedtest-cli** 命令来选择离我们最近的服务器,然后设置如下别名: + +``` +alias speed='speedtest-cli --server 2406 --simple' +``` + +8、你的公网 IP 是多少?记性好的可以直接背下来,但如果你有 10 台上百台服务器呢?也可以背下来,然后参加最强大脑。其实有个命令可以直接查询,但那个命令太变态,不好记,果断设置为别名。 ``` +alias ipe='curl ipinfo.io/ip' +``` + +9、如何知道自己的局域网 IP ?这个命令同样变态,果断设置别名。 + +``` +alias ipi='ipconfig getifaddr en0' +``` + +10、最后,清屏,我们可以使用 **ctrl + l** 快捷键,也可以将 **clear** 命令定义得更短,这样使用起来更直接,更粗暴。 + +``` +alias c='clear' +``` + 【column】 一个很好用的命令,经常用于管道符后,进行文本展示 diff --git a/source/c07/c07_01.rst b/source/c07/c07_01.rst index df51905..a93b219 100755 --- a/source/c07/c07_01.rst +++ b/source/c07/c07_01.rst @@ -1682,6 +1682,82 @@ CentOS # 如果我们不要颜色效果,可以这样使用转义符,使用原生的命令 $ \ll somedir +这里转几条来自 「\ **良许Linux**\ 」的总结,非常实用,你可以跟着设置一下 + +1、压缩包文件,特别是 tar 文件在 Linux 下使用非常广泛,但是 tar +命令的选项又非常多,也不好记住。所以我们可以将常用的几个选项定义为一个别名 +**untar** ,这样我们需要解压 tar 文件时,直接 **untar filename** 即可。 + +:: + + alias untar='tar -zxvf ' + +2、我们下载一个很大的文件时,突然网络异常中断了,我们重新下载是不是很抓狂?别担心,我们的 +wget 命令有个 -c 选项,支持断点下载,我们也可以将它设置为别名: + +:: + + alias wget='wget -c ' + +3、有时我们需要生成一个 20 个字符的随机数密码,我们可以使用 openssl +命令,但完整的命令又很长很不方便,我们可以设置别名: + +:: + + alias getpass="openssl rand -base64 20" + +4、下载一个文件之后,我们想要校验一下它的 checksum +值,可以将这个命令封装为一个别名 **sha** ,之后我们 **sha filename** +就可以校验文件的 checksum 值。 + +:: + + alias sha='shasum -a 256 ' + +5、正常情况下,ping 命令将无限次输出,但其实没多大意义。我们可以使用 -c +命令将其限制为 5 次输出,然后设置为别名 **ping** ,使用时,\ **ping +url** 即可。 + +:: + + alias ping='ping -c 5' + +6、如果我们想随时随地启动一个 web 服务器,我们可以使用这个别名: + +:: + + alias www='python -m SimpleHTTPServer 8000' + +7、网速的测试在工作中也经常用到,但 Linux +没有自带命令可用,我们可以借助第三方工具 **speedtest-cli** +。这个工具可以直接从 Github +上下载,使用方法里面也有详细介绍。我们需要先使用 **speedtest-cli** +命令来选择离我们最近的服务器,然后设置如下别名: + +:: + + alias speed='speedtest-cli --server 2406 --simple' + +8、你的公网 IP 是多少?记性好的可以直接背下来,但如果你有 10 +台上百台服务器呢?也可以背下来,然后参加最强大脑。其实有个命令可以直接查询,但那个命令太变态,不好记,果断设置为别名。 + +:: + + alias ipe='curl ipinfo.io/ip' + +9、如何知道自己的局域网 IP ?这个命令同样变态,果断设置别名。 + +:: + + alias ipi='ipconfig getifaddr en0' + +10、最后,清屏,我们可以使用 **ctrl + l** 快捷键,也可以将 **clear** +命令定义得更短,这样使用起来更直接,更粗暴。 + +:: + + alias c='clear' + 【column】 一个很好用的命令,经常用于管道符后,进行文本展示 From 302e34e56667c40fe5966df9a9a564d351d82aa7 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 10 Aug 2019 22:55:00 +0800 Subject: [PATCH 007/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20docker=20=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E7=9F=A5=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c07/c07_05.md | 147 +++++++++++++++++++++++++-------- source/c07/c07_05.rst | 184 +++++++++++++++++++++++++++++++----------- 2 files changed, 251 insertions(+), 80 deletions(-) diff --git a/source/c07/c07_05.md b/source/c07/c07_05.md index 52010b1..7e685cc 100644 --- a/source/c07/c07_05.md +++ b/source/c07/c07_05.md @@ -2,21 +2,24 @@ --- -## 一、三种基础网络 +## 7.5.1 三种local网络 在docker安装的时候会自动创建三种网络可供使用。 ```shell $ docker network ls -【none】 :没有网络,与外界完全隔离。这个只能用在容器业务不需要联网,不需要集群,而只在本机运行业务时使用。目的就是隔绝网络。 +1.【none】 :没有网络,与外界完全隔离。这个只能用在容器业务不需要联网,不需要集群,而只在本机运行业务时使用。目的就是隔绝网络。 --> 指定: $ docker run -it --network=none busybox - -【host】 :使用 host 网络,容器的网络配置和 host 完全一样。连 hostname 也是一样。最大的好处就是性能,如果容器对网络传输效率有较高要求,则可以选择 host 网络。当然不便之处就是牺牲一些灵活性,比如要考虑端口冲突问题,Docker host 上已经使用的端口就不能再用了。 + + +2. 【host】 :使用 host 网络,容器的网络配置和 host 完全一样。 --> 指定: $ docker run -it --network=host busybox -【bridge】: docker安装的时候默认会创建一个 “docker0” 的linux bridge,若不指定网络,就会都挂在这个网桥下。若宿主机可上网,用这个网络创建的容器也可以上网。 + + +3. 【bridge】: docker安装的时候默认会创建一个 “docker0” 的linux bridge,若不指定网络,就会都挂在这个网桥下。若宿主机可上网,用这个网络创建的容器也可以上网。 --> 1. 无需指定,就使用这个网络 2. $ docker run -it --network=bridge busybox @@ -29,47 +32,53 @@ $ docker network inspect bridge 说明一下,host 网络: 直接使用 Docker host 的网络最大的好处就是性能,如果容器对网络传输效率有较高要求,则可以选择 host 网络。当然不便之处就是牺牲一些灵活性,比如要考虑端口冲突问题,Docker host 上已经使用的端口就不能再用了。 -## 二、自定义网络 -### 2.1 跨主机网络 +## 7.5.2 自定义网络 +### 7.5.2.1 跨主机网络 上面几种网络都是自带的,同时我们也可以自定义网络(通常是网桥)。 ``` # 指定driver=bridge $ docker network create --driver bridge my_net1 -# 这种无法指定ip,subnet创建的网络才能指定,会报如下错误 -docker: Error response from daemon: user specified IP address is supported only when connecting to networks with user configured subnets. # 如果不指定网络段,会自己生成 172.x.0.1/16 ,x 从17开始,每创建一个递增。 -# 就是第一次创建是,172.17.0.1/16 -# 第二次创建是,172.18.0.1/16 - - $ docker network create --driver bridge --subnet 192.168.7.0/24 --gatewat 192.168.7.1 my_net2 $ ``` 1. 同一网络(网桥)下的容器,可以通信 2. 不同网络(网桥)下的容器,docker 默认不允许通信(当然可以通过路由转发来实现),可以用命令将容器挂到另一网桥上 +特别说明: + +>不指定subnet创建的网络,在创建容器时无法指定ip创建,会报如下错误 +> +>docker: Error response from daemon: user specified IP address is supported only when connecting to networks with user configured subnets. + + + 命令:docker network connect my_net2 -上面不管是 `none` , `host`, `bridge` 都是 `local` 类型的网络,仅能在本机上进行通信。 +上面 `7.5.1节` 里的三种网络,不管是 `none` , `host`, `bridge` 都是 `local` 类型的网络,它们仅能在本机上进行通信。 -而如果如实现集群通信,基础网络是不能满足要求的。这就需要我们自定义网络。这些网络也同样也是有三种(主要是根据 `driver` 不同): +而如果如实现集群通信,这三种基础的local网络是不能满足要求的。这就需要我们使用自定义网络。自定义网络,同样也分为三种(主要是根据 `driver` 不同): + +- bridge +- overlay +- macvlan ### 2.2 bridge -``` -# 只要指定driver为bridge 就可以创建一个网桥 -# driver 有三种,一种是bridge、overlay、macvlan +先来看看 bridge的。 +``` # 创建网络:bridge - $ docker network create --driver bridge my_net $ docker network create --driver bridge --subnet 192.168.7.0/24 --gatewat 192.168.7.1 my_net2 + # 该网络没有指定子网,使用的是dhcp分配ip -$ docker run -it --network my_net +$ docker run -it --network my_net1 + # 该网络创建时有指定子网,所以可以指定ip创建 $ docker run -it --network my_net2 --ip 192.168.7.10 @@ -156,28 +165,25 @@ docker exec bbox2 ip r `br0` 除了连接所有的 `endpoint`,还会连接一个 `vxlan` 设备,用于与其他 `host` 建立 `vxlan tunnel`。容器之间的数据就是通过这个 `tunnel` 通信的。 -## 三、容器之间通信 +## 7.5.3 容器之间通信 -``` 1. 同一网络(网桥)下的容器,可以通信 2. 不同网络(网桥)下的容器,docker 默认不允许通信(当然可以通过路由转发来实现),可以通过在容器挂一个和另一容器在同一网桥下的网卡 - 命令:docker network connect my_net2 + 命令:`docker network connect my_net2 ` +3. 共享网络 + 两个容器是可以共享一个网络的。共享网卡和配置信息。 + 命令:`docker run -it --network:container: busy` + +检测容器间的通信,都是用 ping ip 来判断的。 +在我们不知道其他容器的ip时,其实是可以通过 ping 容器名,**前提是这些容器都处于自定义的网络中,必须是自定义的。** -以上是通用类型,都是用ping ip来检测能否通信,或者说通过ip来通信。 -下面介绍,在我们不知道其他容器的ip时,可以通过容器名来通信,前提是这些容器都处于自定义的网络中,必须是自定义的。 如:现有两个容器,bbox1和bbox2,都用的my_net2,在bbox1里可以通过 ping bbox2来与bbox2通信。 但若现有bbox3,是使用bridge的网络,则无法使用这样的方式 -3. 共享网络 -两个容器是可以共享一个网络的。共享网卡和配置信息。 - 命令:docker run -it --network:container: busy -``` - -## 四、容器与外部通信 +## 7.5.4 容器与外部通信 包括 `容器访问外部`和`外部访问容器`。 -``` 1. 容器访问外部 是通过 NAT 网络地址转换,来使用host的ip给外部发送数据包。 这个只要配置下iptales就可以。 @@ -186,10 +192,85 @@ docker exec bbox2 ip r 2. 外部访问容器 容器对外暴露一个端口,这个port和host的port,要映射起来,这个是由docker proxy来做的。docker proxy会时时监控host的端口,若有请求访问这个host port就重定向给容器的port -命令:docker run -it -p 8080:80 httpd # 将hostr的8080映射给httpd容器的80端口 +命令:`docker run -it -p 8080:80 httpd ` + +是将 host 的8080映射给httpd容器的80端口。 + +## 7.5.5 容器的通信原理 + +Docker 的网络是基于 `namespace` 和 `cgroup` 实现的。 + +这里来讲讲的 namespace。 + +在Linux下,我们一般用ip命令创建 Network Namespace,而在Docker的源码中,它并没有用ip命令,而是自己实现了ip命令内的一些功能——是用了Raw Socket发些“奇怪”的数据。 + +这里,我通过 ip命令的演示来重现这个过程。 + +```shell +## 首先,我们先增加一个网桥lxcbr0,模仿docker0 +brctl addbr lxcbr0 +brctl stp lxcbr0 off +ifconfig lxcbr0 192.168.10.1/24 up #为网桥设置IP地址 + +## 接下来,我们要创建一个network namespace - ns1 + +# 增加一个namesapce 命令为 ns1 (使用ip netns add命令) +ip netns add ns1 + +# 激活namespace中的loopback,即127.0.0.1(使用ip netns exec ns1来操作ns1中的命令) +ip netns exec ns1 ip link set dev lo up + +## 然后,我们需要增加一对虚拟网卡 + +# 增加一个pair虚拟网卡,注意其中的veth类型,其中一个网卡要按进容器中 +ip link add veth-ns1 type veth peer name lxcbr0.1 + +# 把 veth-ns1 按到namespace ns1中,这样容器中就会有一个新的网卡了 +ip link set veth-ns1 netns ns1 + +# 把容器里的 veth-ns1改名为 eth0 (容器外会冲突,容器内就不会了) +ip netns exec ns1 ip link set dev veth-ns1 name eth0 + +# 为容器中的网卡分配一个IP地址,并激活它 +ip netns exec ns1 ifconfig eth0 192.168.10.11/24 up + + +# 上面我们把veth-ns1这个网卡按到了容器中,然后我们要把lxcbr0.1添加上网桥上 +brctl addif lxcbr0 lxcbr0.1 + +# 为容器增加一个路由规则,让容器可以访问外面的网络 +ip netns exec ns1 ip route add default via 192.168.10.1 + +# 在/etc/netns下创建network namespce名称为ns1的目录, +# 然后为这个namespace设置resolv.conf,这样,容器内就可以访问域名了 +mkdir -p /etc/netns/ns1 +echo "nameserver 8.8.8.8" > /etc/netns/ns1/resolv.conf +``` + +上面基本上就是docker网络的原理了,只不过, + +- Docker的resolv.conf没有用这样的方式,而是用了[上篇中的Mount Namesapce的那种方式](https://coolshell.cn/articles/17010.html) +- 另外,docker是用进程的PID来做Network Namespace的名称的。 + +了解了这些后,你甚至可以为正在运行的docker容器增加一个新的网卡: + +```shell +`ip link add peerA ``type` `veth peer name peerB ``brctl addif docker0 peerA ``ip link ``set` `peerA up ``ip link ``set` `peerB netns ${container-pid} ``ip netns ``exec` `${container-pid} ip link ``set` `dev peerB name eth1 ``ip netns ``exec` `${container-pid} ip link ``set` `eth1 up ; ``ip netns ``exec` `${container-pid} ip addr add ${ROUTEABLE_IP} dev eth1 ;` ``` +上面的示例是我们为正在运行的docker容器,增加一个eth1的网卡,并给了一个静态的可被外部访问到的IP地址。 + +这个需要把外部的“物理网卡”配置成混杂模式,这样这个eth1网卡就会向外通过ARP协议发送自己的Mac地址,然后外部的交换机就会把到这个IP地址的包转到“物理网卡”上,因为是混杂模式,所以eth1就能收到相关的数据,一看,是自己的,那么就收到。这样,Docker容器的网络就和外部通了。 + +当然,无论是Docker的NAT方式,还是混杂模式都会有性能上的问题,NAT不用说了,存在一个转发的开销,混杂模式呢,网卡上收到的负载都会完全交给所有的虚拟网卡上,于是就算一个网卡上没有数据,但也会被其它网卡上的数据所影响。 + +这两种方式都不够完美,我们知道,真正解决这种网络问题需要使用VLAN技术,于是Google的同学们为Linux内核实现了一个[IPVLAN的驱动](https://lwn.net/Articles/620087/),这基本上就是为Docker量身定制的。 + + + +## 参考文章 +- 7.5.5 摘自:[DOCKER基础技术:LINUX NAMESPACE(下)](https://coolshell.cn/articles/17029.html) --- diff --git a/source/c07/c07_05.rst b/source/c07/c07_05.rst index 734fdaf..a474517 100755 --- a/source/c07/c07_05.rst +++ b/source/c07/c07_05.rst @@ -3,8 +3,8 @@ -------------- -一、三种基础网络 ----------------- +7.5.1 三种local网络 +------------------- 在docker安装的时候会自动创建三种网络可供使用。 @@ -12,15 +12,18 @@ $ docker network ls - 【none】 :没有网络,与外界完全隔离。这个只能用在容器业务不需要联网,不需要集群,而只在本机运行业务时使用。目的就是隔绝网络。 + 1.【none】 :没有网络,与外界完全隔离。这个只能用在容器业务不需要联网,不需要集群,而只在本机运行业务时使用。目的就是隔绝网络。 --> 指定: $ docker run -it --network=none busybox - - 【host】 :使用 host 网络,容器的网络配置和 host 完全一样。连 hostname 也是一样。最大的好处就是性能,如果容器对网络传输效率有较高要求,则可以选择 host 网络。当然不便之处就是牺牲一些灵活性,比如要考虑端口冲突问题,Docker host 上已经使用的端口就不能再用了。 + + + 2. 【host】 :使用 host 网络,容器的网络配置和 host 完全一样。 --> 指定: $ docker run -it --network=host busybox - 【bridge】: docker安装的时候默认会创建一个 “docker0” 的linux bridge,若不指定网络,就会都挂在这个网桥下。若宿主机可上网,用这个网络创建的容器也可以上网。 + + + 3. 【bridge】: docker安装的时候默认会创建一个 “docker0” 的linux bridge,若不指定网络,就会都挂在这个网桥下。若宿主机可上网,用这个网络创建的容器也可以上网。 --> 1. 无需指定,就使用这个网络 2. $ docker run -it --network=bridge busybox @@ -37,11 +40,11 @@ host 网络。当然不便之处就是牺牲一些灵活性,比如要考虑端口冲突问题,Docker host 上已经使用的端口就不能再用了。 -二、自定义网络 --------------- +7.5.2 自定义网络 +---------------- -2.1 跨主机网络 -~~~~~~~~~~~~~~ +7.5.2.1 跨主机网络 +~~~~~~~~~~~~~~~~~~ 上面几种网络都是自带的,同时我们也可以自定义网络(通常是网桥)。 @@ -49,15 +52,9 @@ host 上已经使用的端口就不能再用了。 # 指定driver=bridge $ docker network create --driver bridge my_net1 - # 这种无法指定ip,subnet创建的网络才能指定,会报如下错误 - docker: Error response from daemon: user specified IP address is supported only when connecting to networks with user configured subnets. # 如果不指定网络段,会自己生成 172.x.0.1/16 ,x 从17开始,每创建一个递增。 - # 就是第一次创建是,172.17.0.1/16 - # 第二次创建是,172.18.0.1/16 - - $ docker network create --driver bridge --subnet 192.168.7.0/24 --gatewat 192.168.7.1 my_net2 $ @@ -65,29 +62,41 @@ host 上已经使用的端口就不能再用了。 2. 不同网络(网桥)下的容器,docker 默认不允许通信(当然可以通过路由转发来实现),可以用命令将容器挂到另一网桥上 +特别说明: + + 不指定subnet创建的网络,在创建容器时无法指定ip创建,会报如下错误 + + docker: Error response from daemon: user specified IP address is + supported only when connecting to networks with user configured + subnets. + 命令:docker network connect my_net2 -上面不管是 ``none`` , ``host``, ``bridge`` 都是 ``local`` -类型的网络,仅能在本机上进行通信。 +上面 ``7.5.1节`` 里的三种网络,不管是 ``none`` , ``host``, ``bridge`` +都是 ``local`` 类型的网络,它们仅能在本机上进行通信。 -而如果如实现集群通信,基础网络是不能满足要求的。这就需要我们自定义网络。这些网络也同样也是有三种(主要是根据 +而如果如实现集群通信,这三种基础的local网络是不能满足要求的。这就需要我们使用自定义网络。自定义网络,同样也分为三种(主要是根据 ``driver`` 不同): +- bridge +- overlay +- macvlan + 2.2 bridge ~~~~~~~~~~ -:: +先来看看 bridge的。 - # 只要指定driver为bridge 就可以创建一个网桥 - # driver 有三种,一种是bridge、overlay、macvlan +:: # 创建网络:bridge - $ docker network create --driver bridge my_net $ docker network create --driver bridge --subnet 192.168.7.0/24 --gatewat 192.168.7.1 my_net2 + # 该网络没有指定子网,使用的是dhcp分配ip - $ docker run -it --network my_net + $ docker run -it --network my_net1 + # 该网络创建时有指定子网,所以可以指定ip创建 $ docker run -it --network my_net2 --ip 192.168.7.10 @@ -190,40 +199,121 @@ br0 上。 设备,用于与其他 ``host`` 建立 ``vxlan tunnel``\ 。容器之间的数据就是通过这个 ``tunnel`` 通信的。 -三、容器之间通信 ----------------- - -:: +7.5.3 容器之间通信 +------------------ - 1. 同一网络(网桥)下的容器,可以通信 - 2. 不同网络(网桥)下的容器,docker 默认不允许通信(当然可以通过路由转发来实现),可以通过在容器挂一个和另一容器在同一网桥下的网卡 - 命令:docker network connect my_net2 +1. 同一网络(网桥)下的容器,可以通信 +2. 不同网络(网桥)下的容器,docker + 默认不允许通信(当然可以通过路由转发来实现),可以通过在容器挂一个和另一容器在同一网桥下的网卡 + 命令:\ ``docker network connect my_net2 `` +3. 共享网络 两个容器是可以共享一个网络的。共享网卡和配置信息。 + 命令:\ ``docker run -it --network:container: busy`` - 以上是通用类型,都是用ping ip来检测能否通信,或者说通过ip来通信。 - 下面介绍,在我们不知道其他容器的ip时,可以通过容器名来通信,前提是这些容器都处于自定义的网络中,必须是自定义的。 - 如:现有两个容器,bbox1和bbox2,都用的my_net2,在bbox1里可以通过 ping bbox2来与bbox2通信。 - 但若现有bbox3,是使用bridge的网络,则无法使用这样的方式 +检测容器间的通信,都是用 ping ip 来判断的。 +在我们不知道其他容器的ip时,其实是可以通过 ping +容器名,\ **前提是这些容器都处于自定义的网络中,必须是自定义的。** - 3. 共享网络 - 两个容器是可以共享一个网络的。共享网卡和配置信息。 - 命令:docker run -it --network:container: busy +如:现有两个容器,bbox1和bbox2,都用的my_net2,在bbox1里可以通过 ping +bbox2来与bbox2通信。 +但若现有bbox3,是使用bridge的网络,则无法使用这样的方式 -四、容器与外部通信 ------------------- +7.5.4 容器与外部通信 +-------------------- 包括 ``容器访问外部``\ 和\ ``外部访问容器``\ 。 -:: - - 1. 容器访问外部 - 是通过 NAT 网络地址转换,来使用host的ip给外部发送数据包。 +1. 容器访问外部 是通过 NAT + 网络地址转换,来使用host的ip给外部发送数据包。 这个只要配置下iptales就可以。 +2. 外部访问容器 + 容器对外暴露一个端口,这个port和host的port,要映射起来,这个是由docker + proxy来做的。docker proxy会时时监控host的端口,若有请求访问这个host + port就重定向给容器的port + +命令:\ ``docker run -it -p 8080:80 httpd`` + +是将 host 的8080映射给httpd容器的80端口。 + +7.5.5 容器的通信原理 +-------------------- + +Docker 的网络是基于 ``namespace`` 和 ``cgroup`` 实现的。 + +这里来讲讲的 namespace。 + +在Linux下,我们一般用ip命令创建 Network +Namespace,而在Docker的源码中,它并没有用ip命令,而是自己实现了ip命令内的一些功能——是用了Raw +Socket发些“奇怪”的数据。 + +这里,我通过 ip命令的演示来重现这个过程。 + +.. code:: shell + + ## 首先,我们先增加一个网桥lxcbr0,模仿docker0 + brctl addbr lxcbr0 + brctl stp lxcbr0 off + ifconfig lxcbr0 192.168.10.1/24 up #为网桥设置IP地址 + + ## 接下来,我们要创建一个network namespace - ns1 + + # 增加一个namesapce 命令为 ns1 (使用ip netns add命令) + ip netns add ns1 + + # 激活namespace中的loopback,即127.0.0.1(使用ip netns exec ns1来操作ns1中的命令) + ip netns exec ns1 ip link set dev lo up + + ## 然后,我们需要增加一对虚拟网卡 + + # 增加一个pair虚拟网卡,注意其中的veth类型,其中一个网卡要按进容器中 + ip link add veth-ns1 type veth peer name lxcbr0.1 + + # 把 veth-ns1 按到namespace ns1中,这样容器中就会有一个新的网卡了 + ip link set veth-ns1 netns ns1 + + # 把容器里的 veth-ns1改名为 eth0 (容器外会冲突,容器内就不会了) + ip netns exec ns1 ip link set dev veth-ns1 name eth0 + + # 为容器中的网卡分配一个IP地址,并激活它 + ip netns exec ns1 ifconfig eth0 192.168.10.11/24 up + + + # 上面我们把veth-ns1这个网卡按到了容器中,然后我们要把lxcbr0.1添加上网桥上 + brctl addif lxcbr0 lxcbr0.1 + + # 为容器增加一个路由规则,让容器可以访问外面的网络 + ip netns exec ns1 ip route add default via 192.168.10.1 + + # 在/etc/netns下创建network namespce名称为ns1的目录, + # 然后为这个namespace设置resolv.conf,这样,容器内就可以访问域名了 + mkdir -p /etc/netns/ns1 + echo "nameserver 8.8.8.8" > /etc/netns/ns1/resolv.conf + +上面基本上就是docker网络的原理了,只不过, + +- Docker的resolv.conf没有用这样的方式,而是用了\ `上篇中的Mount + Namesapce的那种方式 `__ +- 另外,docker是用进程的PID来做Network Namespace的名称的。 + +了解了这些后,你甚至可以为正在运行的docker容器增加一个新的网卡: + +.. code:: shell + + `ip link add peerA ``type` `veth peer name peerB ``brctl addif docker0 peerA ``ip link ``set` `peerA up ``ip link ``set` `peerB netns ${container-pid} ``ip netns ``exec` `${container-pid} ip link ``set` `dev peerB name eth1 ``ip netns ``exec` `${container-pid} ip link ``set` `eth1 up ; ``ip netns ``exec` `${container-pid} ip addr add ${ROUTEABLE_IP} dev eth1 ;` + +上面的示例是我们为正在运行的docker容器,增加一个eth1的网卡,并给了一个静态的可被外部访问到的IP地址。 + +这个需要把外部的“物理网卡”配置成混杂模式,这样这个eth1网卡就会向外通过ARP协议发送自己的Mac地址,然后外部的交换机就会把到这个IP地址的包转到“物理网卡”上,因为是混杂模式,所以eth1就能收到相关的数据,一看,是自己的,那么就收到。这样,Docker容器的网络就和外部通了。 + +当然,无论是Docker的NAT方式,还是混杂模式都会有性能上的问题,NAT不用说了,存在一个转发的开销,混杂模式呢,网卡上收到的负载都会完全交给所有的虚拟网卡上,于是就算一个网卡上没有数据,但也会被其它网卡上的数据所影响。 + +这两种方式都不够完美,我们知道,真正解决这种网络问题需要使用VLAN技术,于是Google的同学们为Linux内核实现了一个\ `IPVLAN的驱动 `__\ ,这基本上就是为Docker量身定制的。 - 2. 外部访问容器 - 容器对外暴露一个端口,这个port和host的port,要映射起来,这个是由docker proxy来做的。docker proxy会时时监控host的端口,若有请求访问这个host port就重定向给容器的port +参考文章 +-------- - 命令:docker run -it -p 8080:80 httpd # 将hostr的8080映射给httpd容器的80端口 +- 7.5.5 摘自:\ `DOCKER基础技术:LINUX + NAMESPACE(下) `__ -------------- From bd04a2aa75f16a2381db2614ea0d92fbd7c49a73 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 11 Aug 2019 10:26:34 +0800 Subject: [PATCH 008/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A3=85=E9=A5=B0?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c01/c01_19.md | 47 +++++++++++++++++++++++++++++++++++++++++++ source/c01/c01_19.rst | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 source/c01/c01_19.md create mode 100644 source/c01/c01_19.rst diff --git a/source/c01/c01_19.md b/source/c01/c01_19.md new file mode 100644 index 0000000..1f084ab --- /dev/null +++ b/source/c01/c01_19.md @@ -0,0 +1,47 @@ +# 1.19 Django Blog笔记 + +```shell +# 运行项目 +python manager.py runserver 127.0.0.1:8080 + +# 登陆 xadmin 后台 +127.0.0.1:8080/xadmin + +# 帐号密码 +MING:wbm54378 + +# 更新表结构 +python manage.py makemigrations +python manage.py migrate +``` + + + +配置文件 + +```shell +https://www.cnblogs.com/yangxiaolan/p/5826661.html + +# 开发环境中 static 可以这样 +STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'static'), +] + +# 生产环境 +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') +``` + +数据库密码 + +```shell +root:Wangbm@123 +wangbm:VfgiCtc42tpu +``` + + + +Django 中使用上传图片,显示图片 + +- [Django Media URL的配置](https://www.jianshu.com/p/7979d3e32495) \ No newline at end of file diff --git a/source/c01/c01_19.rst b/source/c01/c01_19.rst new file mode 100644 index 0000000..fc0d271 --- /dev/null +++ b/source/c01/c01_19.rst @@ -0,0 +1,44 @@ +1.19 Django Blog笔记 +==================== + +.. code:: shell + + # 运行项目 + python manager.py runserver 127.0.0.1:8080 + + # 登陆 xadmin 后台 + 127.0.0.1:8080/xadmin + + # 帐号密码 + MING:wbm54378 + + # 更新表结构 + python manage.py makemigrations + python manage.py migrate + +配置文件 + +.. code:: shell + + https://www.cnblogs.com/yangxiaolan/p/5826661.html + + # 开发环境中 static 可以这样 + STATIC_URL = '/static/' + STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'static'), + ] + + # 生产环境 + STATIC_URL = '/static/' + STATIC_ROOT = os.path.join(BASE_DIR, 'static') + +数据库密码 + +.. code:: shell + + root:Wangbm@123 + wangbm:VfgiCtc42tpu + +Django 中使用上传图片,显示图片 + +- `Django Media URL的配置 `__ From dfdc04de42dea8c6fcf30d0ed06635414413d0e0 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Tue, 27 Aug 2019 20:33:16 +0800 Subject: [PATCH 009/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0git=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=8A=80=E5=B7=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_06.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/c04/c04_06.md b/source/c04/c04_06.md index 1f89981..be02abf 100644 --- a/source/c04/c04_06.md +++ b/source/c04/c04_06.md @@ -65,6 +65,9 @@ $ git push -u learn_git master #learn_git是之前命名的远程仓库名,mas $ git clone [github url] # 举例 $ git clone git@github.com:BingmingWong/test.git + +# 更改远程仓库地址 +git remote set-url origin git@:you_repo.git ``` ### 1.5 GitHub合并至本地 @@ -360,6 +363,8 @@ Git 的使用全都是命令行的,由于没有那么直观,所以很容易 +如果想要用户名和密码登陆,可以将上面的 OpenSSH 改成 PuTTY/Plink就行了。 + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file From 914ebcd9344642ec13c9ca64baf6b2b375485bee Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Tue, 27 Aug 2019 20:42:11 +0800 Subject: [PATCH 010/227] =?UTF-8?q?=E6=B7=BB=E5=8A=A0fallocate=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c07/c07_01.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/c07/c07_01.md b/source/c07/c07_01.md index 5bc4404..1ae5b36 100644 --- a/source/c07/c07_01.md +++ b/source/c07/c07_01.md @@ -1127,6 +1127,12 @@ $ losetup -a $ losetup -d /dev/loop0 ``` +使用dd拷贝磁盘可以,但是如果想要快速生成大文件,速度就相当慢了,可以试试fallocate命令 + +```shell +fallocate -l 100G test_file +``` + ### 2.6 任务管理 #### 一次性任务(at) From 19d6da6c5898dc6533dda6b48fc50323f8073ce0 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Tue, 27 Aug 2019 20:43:59 +0800 Subject: [PATCH 011/227] update --- source/c08/c08_01.md | 10 +++++++++- source/c08/c08_03.md | 13 ++++++++----- source/c08/c08_06.md | 2 +- source/c08/c08_08.md | 4 ++++ source/c08/c08_14.md | 8 ++++++++ source/c08/c08_15.md | 22 +++++++++++++++++++++- 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/source/c08/c08_01.md b/source/c08/c08_01.md index 2c11b0b..fdd7618 100644 --- a/source/c08/c08_01.md +++ b/source/c08/c08_01.md @@ -128,7 +128,7 @@ $neutron subnet-create --name public\ --allocation-pool start=172.20.20.100,end=172.20.20.199 \ --gateway 172.20.20.200 \ --enable_dhcp=False \ - --dns_nameserver 114.114.114.114 \ + --dns-nameserver 114.114.114.114 \ public 172.20.20.0/24 # 创建子网,更多选项可以查看 neutron subnet-create -h @@ -384,6 +384,14 @@ rabbitmqctl set_user_tags openstack administrator # 指定节点执行命令 rabbitmq -n rabbit@ws_controller02 [command] ``` +## 3.3 pacemaker + +``` +pkill -9 pacemaker;service pacemaker restart +``` + + + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/c08/c08_03.md b/source/c08/c08_03.md index ad2f274..be0a6de 100644 --- a/source/c08/c08_03.md +++ b/source/c08/c08_03.md @@ -444,16 +444,19 @@ service firewalld stop sudo update-rc.d -f firewalld remove ``` -设置cloud-init参数 -```shell - -``` - 若有其他要修改的地方,可自行修改。然后关机虚拟机 ``` shutdown -h now ``` + + +## 8.3.3 修改镜像的文件 + +通过 guestfish 工具可以实现不用创建虚拟机就可以修改镜像里的文件内容。 + +![](http://image.python-online.cn/20190827200522.png) + ## 附录:参考文档 * [OpenStack社区:CentOS 镜像制作示例](http://docs.ocselected.org/openstack-manuals/kilo/image-guide/content/centos-image.html) diff --git a/source/c08/c08_06.md b/source/c08/c08_06.md index 1ed2d23..5129988 100644 --- a/source/c08/c08_06.md +++ b/source/c08/c08_06.md @@ -52,7 +52,7 @@ cloud-init 是 linux 的一个工具,当系统启动时,cloud-init 可从 no 3. cloud-init modules -m config 4. cloud-init modules -m final -除了这几个命令之外,还有几个 +除了这几个命令之外,还有几个: - cloud-init query -n [name] - cloud-init single -n [name] --frequency diff --git a/source/c08/c08_08.md b/source/c08/c08_08.md index 719b586..a654981 100644 --- a/source/c08/c08_08.md +++ b/source/c08/c08_08.md @@ -137,6 +137,10 @@ systemctl restart neutron-openvswitch-agent 9. 使用 dhcp 的模式,cloudinit 从 configure drive 中知道是dhcp后就不会去刷新配置文件将static 改为dhcp(使用的是NetworkManager自动获取ip,这在开机启动时 NetworkManager就会先于cloudinit 去做),所以如果这个镜像原网卡配置文件里是静态ip,那么使用这个镜像创建dhcp 的虚拟机,就会暴露旧ip,但是这对于配置ip没有影响,NetworkManager 配置ip的顺序是先dhcp,获取不到再从配置文件读。 10. 如果一个子网只有dhcp port,子网可以被删除,如果有其他port,则子网不能删除。 +11. 一个network一个ns,一个ns下面会有多个dhcp server的ip,正常情况下每个subnet一个dhcp server,若一个network下有多个开启了dhcp server 的子网,只关闭其中一个子网的dhcp,并不会立马删除这个dhcp port,因为这个port还有其他人占用(感觉这块neutron处理不好,应该更新一个port的fixed_ip,把关闭dhcp 的子网的ip给删除掉),当一个network里没有开启dhcp的子网且没有虚拟机使用dhcp的情况下,neutron才会删除这个dhcp port。 + + + ## 8.8.5 镜像问题排查 diff --git a/source/c08/c08_14.md b/source/c08/c08_14.md index aa8eead..5c728d7 100644 --- a/source/c08/c08_14.md +++ b/source/c08/c08_14.md @@ -247,6 +247,14 @@ neutron port-create --fixed-ip \ +重装 `openvswith.ko` 过程 + +```shell +ovs-dpctl del-dp ovs-system && rmmod openvswitch && insmod ./openvswitch.ko && service openvswitch restart && service network restart +``` + + + --- diff --git a/source/c08/c08_15.md b/source/c08/c08_15.md index efc5f60..1e13ac6 100644 --- a/source/c08/c08_15.md +++ b/source/c08/c08_15.md @@ -30,4 +30,24 @@ neutron api 的入口是在这里![](http://image.python-online.cn/2019080411184 ![](http://image.python-online.cn/20190804092214.png) -![](http://image.python-online.cn/20190804091911.png) \ No newline at end of file +![](http://image.python-online.cn/20190804091911.png) + + + + + +--- + +当不指定子网、也不指定ip时(也就是不传fixed_ip),而且 cluster 里 即 有ipv4 的子网也有ipv6的子网,这时候 neutron 会去创建一个既有ipv4也有ipv6的port,只要有一个version的子网里没有可用ip,都会失败。 + +![](http://image.python-online.cn/20190809213209.png) + +这里是遍历一个version的所有的子网列表,只要能找到一个子网有可用ip,就返回,如果遍历完都没有找到ip,那就要抛出异常了。 + +![](http://image.python-online.cn/20190809213223.png) + +```python +class IpAddressGenerationFailureAllSubnets(IpAddressGenerationFailure): + message = _("No more IP addresses available.") +``` + From 74818e918b1a2aa3404498dc5936cfacd833208f Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Tue, 27 Aug 2019 20:44:33 +0800 Subject: [PATCH 012/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0openstack=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_05.md | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index eb3f479..21b6010 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -485,6 +485,31 @@ nova api 的接口参数是在 nova/api/openstack/compute/schemas/ 目录下, ![](http://image.python-online.cn/20190730140551.png) +装饰器里会传入一个参数,就是 schema 的内容,通过它可以约束一个请求内的参数合法性。 + +schemas 的文件都统一放在 `nova\api\openstack\compute\schemas` 目录下。 + +对于创建虚拟机来说,它的 schemas 文件是在上面目录下的 `servers.py` + +但并不是说,创建虚拟机的所有参数校验规则只在这里,nova 这边引入了 stevedore,它是 oslo 项目中为OpenStack其他项目提供动态加载功能的公共组件库(详细可以看这篇文章:https://blog.csdn.net/bill_xiang_/article/details/78852717)。通过它可以用添加扩展的方式,给 servers 更新 schemas。 + +![](http://image.python-online.cn/20190826210813.png) + +关键在于这个 map 函数,它会循环所有的扩展() + +![](http://image.python-online.cn/20190826211542.png) + +将调用传进去的 `self._create_extension_schema` 将已加载到的扩展schemas 更新到主schemas里去。 + +``` +# [ext.obj.name for ext in self.create_schema_manager.extensions] +['MultipleCreate', 'BlockDeviceMapping', 'BlockDeviceMappingV1', 'AvailabilityZone', 'UserData', 'Keypairs', 'SchedulerHints', 'SecurityGroups', 'ConfigDrive'] +``` + + + +![](http://image.python-online.cn/20190826211737.png) + 装饰器 schemas 的定义如下: ![](http://image.python-online.cn/20190730142527.png) @@ -493,6 +518,38 @@ nova api 的接口参数是在 nova/api/openstack/compute/schemas/ 目录下, ![](http://image.python-online.cn/20190730143003.png) + + +## 8.5.20 往数据库中加字段 + +先先定义好migrate 文件 + +```python +from sqlalchemy import MetaData, Text, Table, Column + + +def upgrade(migrate_engine): + meta = MetaData(bind=migrate_engine) + instances = Table('instances', meta, autoload=True) + + if not hasattr(instances.c, 'host_routes'): + instances.create_column(Column('host_routes', Text(), default=[])) +``` + +然后在 nova/objects/instances.py 中的fields加入相应的字段。 + +然后在 nova/db/sqlalchemy/models.py 也要加相应的 Column + +最后再执行这个命令,同步数据库 + +``` +nova-manage db sync +``` + + + + + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file From 7a6f61d772c2797b0f9a4d8b26a8e7b5baef41ec Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Wed, 28 Aug 2019 12:48:50 +0800 Subject: [PATCH 013/227] update --- source/c03/c03_01.md | 175 ++++++++++++++++++++++---------------- source/c03/c03_01.rst | 192 +++++++++++++++++++++++++----------------- source/c04/c04_09.md | 8 +- 3 files changed, 222 insertions(+), 153 deletions(-) diff --git a/source/c03/c03_01.md b/source/c03/c03_01.md index 4ff1316..7ebf962 100644 --- a/source/c03/c03_01.md +++ b/source/c03/c03_01.md @@ -2,24 +2,50 @@ --- -## 3.1.1 装饰器语法糖 +对于每一个学习 Python 的同学,想必对 `@` 符号一定不陌生了,正如你所知, @ 符号是装饰器的语法糖,@符号后面的函数就是我们本文的主角:**装饰器**。 -如果你接触 Python 有一段时间了的话,想必你对 `@` 符号一定不陌生了,没错 `@` 符号就是装饰器的语法糖。 +装饰器放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上。和这个函数绑定在一起。在我们调用这个函数的时候,第一件事并不是执行这个函数,而是将这个函数做为参数传入它头顶上这顶帽子,这顶帽子我们称之为 `装饰器` 。 -它放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上。和这个函数绑定在一起。在我们调用这个函数的时候,第一件事并不是执行这个函数,而是将这个函数做为参数传入它头顶上这顶帽子,这顶帽子我们称之为`装饰函数` 或 `装饰器`。 +曾经我在刚转行做程序员时的一次的面试中,被面试官问过这样的两个问题: -你要问我装饰器可以实现什么功能?我只能说你的脑洞有多大,装饰器就有多强大。 +> 1、你都用过装饰器实现过什么样的功能? +> +> 2、如何写一个可以传参的装饰器? -装饰器的使用方法很固定: -- 先定义一个装饰函数(帽子)(也可以用类、偏函数实现) -- 再定义你的业务函数、或者类(人) -- 最后把这顶帽子带在这个人头上 +对于当时实战经验非常有限的我,第一个问题只能回答一些非常简单的用法,而第二个问题却没能回答上来。 -装饰器的简单的用法有很多,这里举两个常见的。 -- 日志打印器 -- 时间计时器 +当时带着这两个问题,我就开始系统的学习装饰器的所有内容。这些一直整理在自己的博客中,今天对其进行了大量的补充和勘误,发表在这里分享给大家。希望对刚入门以及进阶的朋友可以提供一些参考。 -## 3.1.2 入门用法:日志打印器 +![](http://image.python-online.cn/20190811100737.png) + +## 3.1.1 Hello,装饰器 + +装饰器的使用方法很固定 +- 先定义一个装饰器(帽子) +- 再定义你的业务函数或者类(人) +- 最后把这装饰器(帽子)扣在这个函数(人)头上 + +就像下面这样子 + +```python +def decorator(func): + def wrapper(*args, **kw): + return func() + return wrapper + +@decorator +def function(): + print("hello, decorator") +``` + +实际上,装饰器并不是编码必须性,意思就是说,你不使用装饰器完全可以,它的出现,应该是使我们的代码 + +- 更加优雅,代码结构更加清晰 +- 将实现特定的功能代码封装成装饰器,提高代码复用率,增强代码可读性 + +接下来,我将以实例讲解,如何编写出各种简单及复杂的装饰器。 + +## 3.1.2 入门:日志打印器 首先是**日志打印器**。 实现的功能: @@ -27,15 +53,15 @@ - 在函数执行完,也不能拍拍屁股就走人了,咱可是有礼貌的代码,再打印一行日志告知下主人,我执行完啦。 ```python -# 这是装饰函数 +# 这是装饰器函数,参数 func 是被装饰的函数 def logger(func): def wrapper(*args, **kw): - print('我准备开始计算:{} 函数了:'.format(func.__name__)) + print('主人,我准备开始执行:{} 函数了:'.format(func.__name__)) # 真正执行的是这行。 func(*args, **kw) - print('啊哈,我计算完啦。给自己加个鸡腿!!') + print('主人,我执行完啦。') return wrapper ``` 假如,我的业务函数是,计算两个数之和。写好后,直接给它带上帽子。 @@ -44,18 +70,18 @@ def logger(func): def add(x, y): print('{} + {} = {}'.format(x, y, x+y)) ``` -然后我们来计算一下。 +然后执行一下 add 函数。 ```python add(200, 50) ``` -快来看看输出了什么,神奇不? +来看看输出了什么? ```python -我准备开始计算:add 函数了: +主人,我准备开始执行:add 函数了: 200 + 50 = 250 -啊哈,我计算完啦。给自己加个鸡腿! +主人,我执行完啦。 ``` -## 3.1.3 入门用法:时间计时器 +## 3.1.3 入门:时间计时器 再来看看 **时间计时器** 实现功能:顾名思义,就是计算一个函数的执行时长。 @@ -84,50 +110,54 @@ def want_sleep(sleep_time): want_sleep(10) ``` -来看看,输出。真的是2秒. +来看看输出,如预期一样,输出10秒。 ``` -花费时间:2.0073800086975098秒 +花费时间:10.0073800086975098秒 ``` -## 3.1.4 进阶用法:带参数的函数装饰器 - -通过上面简单的入门,你大概已经感受到了装饰的神奇魅力了。 +## 3.1.4 进阶:带参数的函数装饰器 -不过,装饰器的用法远不止如此。我们今天就要把这个知识点讲透。 +通过上面两个简单的入门示例,你应该能体会到装饰器的工作原理了。 -上面的例子,装饰器是不能接收参数的。其用法,只能适用于一些简单的场景。不传参的装饰器,只能对被装饰函数,执行固定逻辑。 +不过,装饰器的用法还远不止如此,深究下去,还大有文章。今天就一起来把这个知识点学透。 -如果你有经验,你一定经常在项目中,看到有的装饰器是带有参数的。 +回过头去看看上面的例子,装饰器是不能接收参数的。其用法,只能适用于一些简单的场景。不传参的装饰器,只能对被装饰函数,执行固定逻辑。 -装饰器本身是一个函数,既然做为一个函数都不能携带函数,那这个函数的功能就很受限。只能执行固定的逻辑。这无疑是非常不合理的。而如果我们要用到两个内容大体一致,只是某些地方不同的逻辑。不传参的话,我们就要写两个装饰器。小明觉得这不能忍。 +装饰器本身是一个函数,做为一个函数,如果不能传参,那这个函数的功能就会很受限,只能执行固定的逻辑。这意味着,如果装饰器的逻辑代码的执行需要根据不同场景进行调整,若不能传参的话,我们就要写两个装饰器,这显然是不合理的。 -那么装饰器如何实现`传参`呢,会比较复杂,需要两层嵌套。 +比如我们要实现一个可以定时发送邮件的任务(一分钟发送一封),定时进行时间同步的任务(一天同步一次),就可以自己实现一个 periodic_task (定时任务)的装饰器,这个装饰器可以接收一个时间间隔的参数,间隔多长时间执行一次任务。 -同样,我们也来举个例子。 +可以这样像下面这样写,由于这个功能代码比较复杂,不利于学习,这里就不贴了。 -我们要在这两个函数的执行的时候,分别根据其国籍,来说出一段打招呼的话。 ```python -def chinese(): - print("我来自中国。") - -def american(): - print("I am from America.") +@periodic_task(spacing=60) +def send_mail(): + pass + +@periodic_task(spacing=86400) +def ntp() + pass ``` -在给他们俩戴上装饰器的时候,就要跟装饰器说,这个人是哪国人,然后装饰器就会做出判断,打出对应的招呼。 -戴上帽子后,是这样的。 +那我们来自己创造一个伪场景,可以在装饰器里传入一个参数,指明国籍,并在函数执行前,用自己国家的母语打一个招呼。 + ```python +# 小明,中国人 @say_hello("china") -def chinese(): - print("我来自中国。") +def xiaoming(): + pass +# jack,美国人 @say_hello("america") -def american(): - print("I am from America.") +def jack(): + pass ``` -万事俱备,只差帽子了。来定义一下,这里需要两层嵌套。 +那我们如果实现这个装饰器,让其可以实现 `传参` 呢? + +会比较复杂,需要两层嵌套。 + ```python def say_hello(contry): def wrapper(func): @@ -144,23 +174,19 @@ def say_hello(contry): return deco return wrapper ``` -执行一下 +来执行一下 ```python -american() +xiaoming() print("------------") -chinese() +jack() ``` 看看输出结果。 ```python 你好! -我来自中国。 ------------ hello. -I am from America ``` -emmmm,这很NB。。。 - -## 3.1.5 高阶用法:不带参数的类装饰器 +## 3.1.5 高阶:不带参数的类装饰器 以上都是基于函数实现的装饰器,在阅读别人代码时,还可以时常发现还有基于类实现的装饰器。 @@ -168,6 +194,8 @@ emmmm,这很NB。。。 `__init__` :接收被装饰函数 `__call__` :实现装饰逻辑。 +还是以日志打印这个简单的例子为例 + ```python class logger(object): def __init__(self, func): @@ -190,9 +218,7 @@ say("hello") say hello! ``` - - -## 3.1.6 高阶用法:带参数的类装饰器 +## 3.1.6 高阶:带参数的类装饰器 上面不带参数的例子,你发现没有,只能打印`INFO`级别的日志,正常情况下,我们还需要打印`DEBUG` `WARNING`等级别的日志。 这就需要给类装饰器传入参数,给这个函数指定级别了。 @@ -233,7 +259,9 @@ say hello! 对于这个 callable 对象,我们最熟悉的就是函数了。 -除函数之外,类也可以是 callable 对象,只要实现了`__call__` 函数(上面几个盒子已经接触过了),还有比较少人使用的偏函数也是 callable 对象。 +除函数之外,类也可以是 callable 对象,只要实现了`__call__` 函数(上面几个例子已经接触过了)。 + +还有容易被人忽略的偏函数其实也是 callable 对象。 接下来就来说说,如何使用 类和偏函数结合实现一个与众不同的装饰器。 @@ -430,16 +458,16 @@ class Student(object): self.age = age # 实例化 -XiaoMing = Student("小明") +xiaoming = Student("小明") # 添加属性 -XiaoMing.age=25 +xiaoming.age=25 # 查询属性 -XiaoMing.age +xiaoming.age # 删除属性 -del XiaoMing.age +del xiaoming.age ``` 但是稍有经验的开发人员,一下就可以看出,这样直接把属性暴露出去,虽然写起来很简单,但是并不能对属性的值做合法性限制。为了实现这个功能,我们可以这样写。 ```python @@ -462,25 +490,25 @@ class Student(object): self._age = None -XiaoMing = Student("小明") +xiaoming = Student("小明") # 添加属性 -XiaoMing.set_age(25) +xiaoming.set_age(25) # 查询属性 -XiaoMing.get_age() +xiaoming.get_age() # 删除属性 -XiaoMing.del_age() +xiaoming.del_age() ``` 上面的代码设计虽然可以变量的定义,但是可以发现不管是获取还是赋值(通过函数)都和我们平时见到的不一样。 按照我们思维习惯应该是这样的。 ``` # 赋值 -XiaoMing.age = 25 +xiaoming.age = 25 # 获取 -XiaoMing.age +xiaoming.age ``` 那么这样的方式我们如何实现呢。请看下面的代码。 ```python @@ -505,16 +533,16 @@ class Student(object): def age(self): del self._age -XiaoMing = Student("小明") +xiaoming = Student("小明") # 设置属性 -XiaoMing.age = 25 +xiaoming.age = 25 # 查询属性 -XiaoMing.age +xiaoming.age # 删除属性 -del XiaoMing.age +del xiaoming.age ``` 用`@property`装饰过的函数,会将一个函数定义成一个属性,属性的值就是该函数return的内容。**同时**,会将这个函数变成另外一个装饰器。就像后面我们使用的`@age.setter`和`@age.deleter`。 @@ -644,7 +672,6 @@ in __get__ - 使代码可读性更高,逼格更高; - 代码结构更加清晰,代码冗余度更低; - 刚好我在最近也有一个场景,可以用装饰器很好的实现,暂且放上来看看。 这是一个实现控制函数运行超时的装饰器。如果超时,则会抛出超时异常。 @@ -673,4 +700,8 @@ def timeout_limit(timeout_time): ``` ---- -![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) +非常感谢你能阅读到这里,这篇文章我写了很久,算是比较干货的那种,文章有些长,但还是希望花点时间把这些知识点都搞明白,而不要只是收藏。 + +我的文章更新频率是远低于其他 Python 技术号,但我仍然坚持自己,坚持原创,每周虽然只有一篇,但我能保证我的每一篇文章都是诚意之作。希望那些对你有帮助的文章能够多多帮忙转发分享。这也是我更新的一大动力。非常感谢。 + +![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/c03/c03_01.rst b/source/c03/c03_01.rst index a89d41a..0f01f88 100755 --- a/source/c03/c03_01.rst +++ b/source/c03/c03_01.rst @@ -3,25 +3,54 @@ -------------- -3.1.1 装饰器语法糖 ------------------- +对于每一个学习 Python 的同学,想必对 ``@`` +符号一定不陌生了,正如你所知, @ +符号是装饰器的语法糖,@符号后面的函数就是我们本文的主角:\ **装饰器**\ 。 -如果你接触 Python 有一段时间了的话,想必你对 ``@`` -符号一定不陌生了,没错 ``@`` 符号就是装饰器的语法糖。 +装饰器放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上。和这个函数绑定在一起。在我们调用这个函数的时候,第一件事并不是执行这个函数,而是将这个函数做为参数传入它头顶上这顶帽子,这顶帽子我们称之为 +``装饰器`` 。 -它放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上。和这个函数绑定在一起。在我们调用这个函数的时候,第一件事并不是执行这个函数,而是将这个函数做为参数传入它头顶上这顶帽子,这顶帽子我们称之为\ ``装饰函数`` -或 ``装饰器``\ 。 +曾经我在刚转行做程序员时的一次的面试中,被面试官问过这样的两个问题: -你要问我装饰器可以实现什么功能?我只能说你的脑洞有多大,装饰器就有多强大。 + 1、你都用过装饰器实现过什么样的功能? -装饰器的使用方法很固定: - -先定义一个装饰函数(帽子)(也可以用类、偏函数实现) - -再定义你的业务函数、或者类(人) - 最后把这顶帽子带在这个人头上 + 2、如何写一个可以传参的装饰器? -装饰器的简单的用法有很多,这里举两个常见的。 - 日志打印器 - 时间计时器 +对于当时实战经验非常有限的我,第一个问题只能回答一些非常简单的用法,而第二个问题却没能回答上来。 -3.1.2 入门用法:日志打印器 --------------------------- +当时带着这两个问题,我就开始系统的学习装饰器的所有内容。这些一直整理在自己的博客中,今天对其进行了大量的补充和勘误,发表在这里分享给大家。希望对刚入门以及进阶的朋友可以提供一些参考。 + +|image0| + +3.1.1 Hello,装饰器 +------------------- + +装饰器的使用方法很固定 - 先定义一个装饰器(帽子) - +再定义你的业务函数或者类(人) - +最后把这装饰器(帽子)扣在这个函数(人)头上 + +就像下面这样子 + +.. code:: python + + def decorator(func): + def wrapper(*args, **kw): + return func() + return wrapper + + @decorator + def function(): + print("hello, decorator") + +实际上,装饰器并不是编码必须性,意思就是说,你不使用装饰器完全可以,它的出现,应该是使我们的代码 + +- 更加优雅,代码结构更加清晰 +- 将实现特定的功能代码封装成装饰器,提高代码复用率,增强代码可读性 + +接下来,我将以实例讲解,如何编写出各种简单及复杂的装饰器。 + +3.1.2 入门:日志打印器 +---------------------- 首先是\ **日志打印器**\ 。 实现的功能: - 在函数执行前,先打印一行日志告知一下主人,我要执行函数了。 - @@ -29,15 +58,15 @@ .. code:: python - # 这是装饰函数 + # 这是装饰器函数,参数 func 是被装饰的函数 def logger(func): def wrapper(*args, **kw): - print('我准备开始计算:{} 函数了:'.format(func.__name__)) + print('主人,我准备开始执行:{} 函数了:'.format(func.__name__)) # 真正执行的是这行。 func(*args, **kw) - print('啊哈,我计算完啦。给自己加个鸡腿!!') + print('主人,我执行完啦。') return wrapper 假如,我的业务函数是,计算两个数之和。写好后,直接给它带上帽子。 @@ -48,22 +77,22 @@ def add(x, y): print('{} + {} = {}'.format(x, y, x+y)) -然后我们来计算一下。 +然后执行一下 add 函数。 .. code:: python add(200, 50) -快来看看输出了什么,神奇不? +来看看输出了什么? .. code:: python - 我准备开始计算:add 函数了: + 主人,我准备开始执行:add 函数了: 200 + 50 = 250 - 啊哈,我计算完啦。给自己加个鸡腿! + 主人,我执行完啦。 -3.1.3 入门用法:时间计时器 --------------------------- +3.1.3 入门:时间计时器 +---------------------- 再来看看 **时间计时器** 实现功能:顾名思义,就是计算一个函数的执行时长。 @@ -94,54 +123,56 @@ want_sleep(10) -来看看,输出。真的是2秒. +来看看输出,如预期一样,输出10秒。 :: - 花费时间:2.0073800086975098秒 - -3.1.4 进阶用法:带参数的函数装饰器 ----------------------------------- + 花费时间:10.0073800086975098秒 -通过上面简单的入门,你大概已经感受到了装饰的神奇魅力了。 - -不过,装饰器的用法远不止如此。我们今天就要把这个知识点讲透。 +3.1.4 进阶:带参数的函数装饰器 +------------------------------ -上面的例子,装饰器是不能接收参数的。其用法,只能适用于一些简单的场景。不传参的装饰器,只能对被装饰函数,执行固定逻辑。 +通过上面两个简单的入门示例,你应该能体会到装饰器的工作原理了。 -如果你有经验,你一定经常在项目中,看到有的装饰器是带有参数的。 +不过,装饰器的用法还远不止如此,深究下去,还大有文章。今天就一起来把这个知识点学透。 -装饰器本身是一个函数,既然做为一个函数都不能携带函数,那这个函数的功能就很受限。只能执行固定的逻辑。这无疑是非常不合理的。而如果我们要用到两个内容大体一致,只是某些地方不同的逻辑。不传参的话,我们就要写两个装饰器。小明觉得这不能忍。 +回过头去看看上面的例子,装饰器是不能接收参数的。其用法,只能适用于一些简单的场景。不传参的装饰器,只能对被装饰函数,执行固定逻辑。 -那么装饰器如何实现\ ``传参``\ 呢,会比较复杂,需要两层嵌套。 +装饰器本身是一个函数,做为一个函数,如果不能传参,那这个函数的功能就会很受限,只能执行固定的逻辑。这意味着,如果装饰器的逻辑代码的执行需要根据不同场景进行调整,若不能传参的话,我们就要写两个装饰器,这显然是不合理的。 -同样,我们也来举个例子。 +比如我们要实现一个可以定时发送邮件的任务(一分钟发送一封),定时进行时间同步的任务(一天同步一次),就可以自己实现一个 +periodic_task +(定时任务)的装饰器,这个装饰器可以接收一个时间间隔的参数,间隔多长时间执行一次任务。 -我们要在这两个函数的执行的时候,分别根据其国籍,来说出一段打招呼的话。 +可以这样像下面这样写,由于这个功能代码比较复杂,不利于学习,这里就不贴了。 .. code:: python - def chinese(): - print("我来自中国。") + @periodic_task(spacing=60) + def send_mail(): + pass + + @periodic_task(spacing=86400) + def ntp() + pass - def american(): - print("I am from America.") - -在给他们俩戴上装饰器的时候,就要跟装饰器说,这个人是哪国人,然后装饰器就会做出判断,打出对应的招呼。 - -戴上帽子后,是这样的。 +那我们来自己创造一个伪场景,可以在装饰器里传入一个参数,指明国籍,并在函数执行前,用自己国家的母语打一个招呼。 .. code:: python + # 小明,中国人 @say_hello("china") - def chinese(): - print("我来自中国。") + def xiaoming(): + pass + # jack,美国人 @say_hello("america") - def american(): - print("I am from America.") + def jack(): + pass -万事俱备,只差帽子了。来定义一下,这里需要两层嵌套。 +那我们如果实现这个装饰器,让其可以实现 ``传参`` 呢? + +会比较复杂,需要两层嵌套。 .. code:: python @@ -160,28 +191,24 @@ return deco return wrapper -执行一下 +来执行一下 .. code:: python - american() + xiaoming() print("------------") - chinese() + jack() 看看输出结果。 .. code:: python 你好! - 我来自中国。 ------------ hello. - I am from America - -emmmm,这很NB。。。 -3.1.5 高阶用法:不带参数的类装饰器 ----------------------------------- +3.1.5 高阶:不带参数的类装饰器 +------------------------------ 以上都是基于函数实现的装饰器,在阅读别人代码时,还可以时常发现还有基于类实现的装饰器。 @@ -189,6 +216,8 @@ emmmm,这很NB。。。 ``__init__``\ 两个内置函数。 ``__init__`` :接收被装饰函数 ``__call__`` :实现装饰逻辑。 +还是以日志打印这个简单的例子为例 + .. code:: python class logger(object): @@ -213,8 +242,8 @@ emmmm,这很NB。。。 [INFO]: the function say() is running... say hello! -3.1.6 高阶用法:带参数的类装饰器 --------------------------------- +3.1.6 高阶:带参数的类装饰器 +---------------------------- 上面不带参数的例子,你发现没有,只能打印\ ``INFO``\ 级别的日志,正常情况下,我们还需要打印\ ``DEBUG`` ``WARNING``\ 等级别的日志。 @@ -263,8 +292,9 @@ emmmm,这很NB。。。 对于这个 callable 对象,我们最熟悉的就是函数了。 除函数之外,类也可以是 callable 对象,只要实现了\ ``__call__`` -函数(上面几个盒子已经接触过了),还有比较少人使用的偏函数也是 callable -对象。 +函数(上面几个例子已经接触过了)。 + +还有容易被人忽略的偏函数其实也是 callable 对象。 接下来就来说说,如何使用 类和偏函数结合实现一个与众不同的装饰器。 @@ -358,7 +388,7 @@ Python工匠:使用装饰器的小技巧) 其实例化的过程,你可以参考我这里的调试过程,加以理解。 -|image0| +|image1| 3.1.9 wraps 装饰器有啥用? -------------------------- @@ -475,16 +505,16 @@ wraps的情况下,也可以让 ``wrapped.__name__`` 打印出 wrapped,代码 self.age = age # 实例化 - XiaoMing = Student("小明") + xiaoming = Student("小明") # 添加属性 - XiaoMing.age=25 + xiaoming.age=25 # 查询属性 - XiaoMing.age + xiaoming.age # 删除属性 - del XiaoMing.age + del xiaoming.age 但是稍有经验的开发人员,一下就可以看出,这样直接把属性暴露出去,虽然写起来很简单,但是并不能对属性的值做合法性限制。为了实现这个功能,我们可以这样写。 @@ -509,16 +539,16 @@ wraps的情况下,也可以让 ``wrapped.__name__`` 打印出 wrapped,代码 self._age = None - XiaoMing = Student("小明") + xiaoming = Student("小明") # 添加属性 - XiaoMing.set_age(25) + xiaoming.set_age(25) # 查询属性 - XiaoMing.get_age() + xiaoming.get_age() # 删除属性 - XiaoMing.del_age() + xiaoming.del_age() 上面的代码设计虽然可以变量的定义,但是可以发现不管是获取还是赋值(通过函数)都和我们平时见到的不一样。 按照我们思维习惯应该是这样的。 @@ -526,10 +556,10 @@ wraps的情况下,也可以让 ``wrapped.__name__`` 打印出 wrapped,代码 :: # 赋值 - XiaoMing.age = 25 + xiaoming.age = 25 # 获取 - XiaoMing.age + xiaoming.age 那么这样的方式我们如何实现呢。请看下面的代码。 @@ -556,16 +586,16 @@ wraps的情况下,也可以让 ``wrapped.__name__`` 打印出 wrapped,代码 def age(self): del self._age - XiaoMing = Student("小明") + xiaoming = Student("小明") # 设置属性 - XiaoMing.age = 25 + xiaoming.age = 25 # 查询属性 - XiaoMing.age + xiaoming.age # 删除属性 - del XiaoMing.age + del xiaoming.age 用\ ``@property``\ 装饰过的函数,会将一个函数定义成一个属性,属性的值就是该函数return的内容。\ **同时**\ ,会将这个函数变成另外一个装饰器。就像后面我们使用的\ ``@age.setter``\ 和\ ``@age.deleter``\ 。 @@ -738,9 +768,15 @@ property -------------- +非常感谢你能阅读到这里,这篇文章我写了很久,算是比较干货的那种,文章有些长,但还是希望花点时间把这些知识点都搞明白,而不要只是收藏。 + +我的文章更新频率是远低于其他 Python +技术号,但我仍然坚持自己,坚持原创,每周虽然只有一篇,但我能保证我的每一篇文章都是诚意之作。希望那些对你有帮助的文章能够多多帮忙转发分享。这也是我更新的一大动力。非常感谢。 + .. figure:: http://image.python-online.cn/20190511161447.png :alt: 关注公众号,获取最新干货! -.. |image0| image:: http://image.python-online.cn/20190512113917.png +.. |image0| image:: http://image.python-online.cn/20190811100737.png +.. |image1| image:: http://image.python-online.cn/20190512113917.png diff --git a/source/c04/c04_09.md b/source/c04/c04_09.md index bec495b..d00bb5d 100644 --- a/source/c04/c04_09.md +++ b/source/c04/c04_09.md @@ -2,7 +2,9 @@ --- -本文是数据库学习笔记系列-第一篇。仅介绍了MySQL的基本概念和使用。 +数据库是每个后端程序员都必须扎实掌握的一项基本技能,而做为最主流的关系型数据库 MySQL,上手也极为容易,这里是我几年前自学 MySQL 时做下的笔记,现整理出来,一共两篇,这是第一篇。 + +在这篇文章里,我就介绍了一些 MySQL 的基本操作(增删改查)及表结构的解析。 ## 一、库操作 @@ -312,11 +314,11 @@ timestamp默认是自动更新当前时间的(在记录创建或更新时更 插入数据 ![](https://i.loli.net/2017/08/26/59a0cebd074ab.png) -`**作用之一`** +**作用之一** 规范数据格式: 数据只能是规定的数据中的其中一个 -`**作用之二`** +**作用之二** 节省存储空间:枚举实际存储的是数值而不是字符串本身. From 22d5a56ce7512ae61c858ed8c75947e2a7c7bf9f Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Wed, 28 Aug 2019 12:49:28 +0800 Subject: [PATCH 014/227] =?UTF-8?q?=E7=94=9F=E6=88=90rst=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_06.rst | 5 ++++ source/c04/c04_09.rst | 11 ++++++-- source/c07/c07_01.rst | 6 ++++ source/c08/c08_01.rst | 9 +++++- source/c08/c08_03.rst | 12 +++++--- source/c08/c08_05.rst | 66 ++++++++++++++++++++++++++++++++++++++++--- source/c08/c08_06.rst | 2 +- source/c08/c08_08.rst | 8 ++++++ source/c08/c08_14.rst | 6 ++++ source/c08/c08_15.rst | 19 +++++++++++++ 10 files changed, 131 insertions(+), 13 deletions(-) diff --git a/source/c04/c04_06.rst b/source/c04/c04_06.rst index 8dcce2f..b13493a 100755 --- a/source/c04/c04_06.rst +++ b/source/c04/c04_06.rst @@ -75,6 +75,9 @@ add/commit 前撤销对文件的修改 # 举例 $ git clone git@github.com:BingmingWong/test.git + # 更改远程仓库地址 + git remote set-url origin git@:you_repo.git + 1.5 GitHub合并至本地 ~~~~~~~~~~~~~~~~~~~~ @@ -398,6 +401,8 @@ Desktop真心觉得不好用)。 |image3| +如果想要用户名和密码登陆,可以将上面的 OpenSSH 改成 PuTTY/Plink就行了。 + -------------- .. figure:: http://image.python-online.cn/20190511161447.png diff --git a/source/c04/c04_09.rst b/source/c04/c04_09.rst index a7744e8..b0830b1 100755 --- a/source/c04/c04_09.rst +++ b/source/c04/c04_09.rst @@ -3,7 +3,12 @@ -------------- -本文是数据库学习笔记系列-第一篇。仅介绍了MySQL的基本概念和使用。 +数据库是每个后端程序员都必须扎实掌握的一项基本技能,而做为最主流的关系型数据库 +MySQL,上手也极为容易,这里是我几年前自学 MySQL +时做下的笔记,现整理出来,一共两篇,这是第一篇。 + +在这篇文章里,我就介绍了一些 MySQL +的基本操作(增删改查)及表结构的解析。 一、库操作 ---------- @@ -360,11 +365,11 @@ timestamp默认是自动更新当前时间的(在记录创建或更新时更 | 插入数据 | |image10| -``**作用之一``\ \*\* +**作用之一** 规范数据格式: 数据只能是规定的数据中的其中一个 -``**作用之二``\ \*\* +**作用之二** 节省存储空间:枚举实际存储的是数值而不是字符串本身. diff --git a/source/c07/c07_01.rst b/source/c07/c07_01.rst index a93b219..12ea6b1 100755 --- a/source/c07/c07_01.rst +++ b/source/c07/c07_01.rst @@ -1227,6 +1227,12 @@ Linux上,硬件的设备驱动(如硬盘)和特殊设备文件(如\ ``/d # 卸载 $ losetup -d /dev/loop0 +使用dd拷贝磁盘可以,但是如果想要快速生成大文件,速度就相当慢了,可以试试fallocate命令 + +.. code:: shell + + fallocate -l 100G test_file + 2.6 任务管理 ~~~~~~~~~~~~ diff --git a/source/c08/c08_01.rst b/source/c08/c08_01.rst index f725f9a..481da0a 100755 --- a/source/c08/c08_01.rst +++ b/source/c08/c08_01.rst @@ -137,7 +137,7 @@ aggregate管理 --allocation-pool start=172.20.20.100,end=172.20.20.199 \ --gateway 172.20.20.200 \ --enable_dhcp=False \ - --dns_nameserver 114.114.114.114 \ + --dns-nameserver 114.114.114.114 \ public 172.20.20.0/24 # 创建子网,更多选项可以查看 neutron subnet-create -h @@ -399,6 +399,13 @@ aggregate管理 # 指定节点执行命令 rabbitmq -n rabbit@ws_controller02 [command] +3.3 pacemaker +------------- + +:: + + pkill -9 pacemaker;service pacemaker restart + -------------- .. figure:: http://image.python-online.cn/20190511161447.png diff --git a/source/c08/c08_03.rst b/source/c08/c08_03.rst index 24a184c..049fb4a 100755 --- a/source/c08/c08_03.rst +++ b/source/c08/c08_03.rst @@ -485,16 +485,19 @@ CentOS6 创建快照前需要先删除\ ``75-persistent-net-generator.rules`` service firewalld stop sudo update-rc.d -f firewalld remove -设置cloud-init参数 - -.. code:: shell - 若有其他要修改的地方,可自行修改。然后关机虚拟机 :: shutdown -h now +8.3.3 修改镜像的文件 +-------------------- + +通过 guestfish 工具可以实现不用创建虚拟机就可以修改镜像里的文件内容。 + +|image2| + 附录:参考文档 -------------- @@ -517,4 +520,5 @@ CentOS6 创建快照前需要先删除\ ``75-persistent-net-generator.rules`` .. |image0| image:: https://i.loli.net/2018/01/27/5a6c34714685d.png .. |image1| image:: https://i.loli.net/2018/01/27/5a6c34b14c6ec.png +.. |image2| image:: http://image.python-online.cn/20190827200522.png diff --git a/source/c08/c08_05.rst b/source/c08/c08_05.rst index d9ece4d..982051e 100644 --- a/source/c08/c08_05.rst +++ b/source/c08/c08_05.rst @@ -534,15 +534,70 @@ nova api 的接口参数是在 nova/api/openstack/compute/schemas/ |image40| -装饰器 schemas 的定义如下: +装饰器里会传入一个参数,就是 schema +的内容,通过它可以约束一个请求内的参数合法性。 + +schemas 的文件都统一放在 ``nova\api\openstack\compute\schemas`` 目录下。 + +对于创建虚拟机来说,它的 schemas 文件是在上面目录下的 ``servers.py`` + +但并不是说,创建虚拟机的所有参数校验规则只在这里,nova 这边引入了 +stevedore,它是 oslo +项目中为OpenStack其他项目提供动态加载功能的公共组件库(详细可以看这篇文章:https://blog.csdn.net/bill_xiang_/article/details/78852717)。通过它可以用添加扩展的方式,给 +servers 更新 schemas。 |image41| +关键在于这个 map 函数,它会循环所有的扩展() + +|image42| + +将调用传进去的 ``self._create_extension_schema`` 将已加载到的扩展schemas +更新到主schemas里去。 + +:: + + # [ext.obj.name for ext in self.create_schema_manager.extensions] + ['MultipleCreate', 'BlockDeviceMapping', 'BlockDeviceMappingV1', 'AvailabilityZone', 'UserData', 'Keypairs', 'SchedulerHints', 'SecurityGroups', 'ConfigDrive'] + +|image43| + +装饰器 schemas 的定义如下: + +|image44| + 比如我们使用的 novaclient 发出的请求,是 v2.3.7的,所以 create() 顶部的五个schema 装饰器,上面四个都会空跑,不会进行校验,只有最后一个才会进入检验逻辑。 -|image42| +|image45| + +8.5.20 往数据库中加字段 +----------------------- + +先先定义好migrate 文件 + +.. code:: python + + from sqlalchemy import MetaData, Text, Table, Column + + + def upgrade(migrate_engine): + meta = MetaData(bind=migrate_engine) + instances = Table('instances', meta, autoload=True) + + if not hasattr(instances.c, 'host_routes'): + instances.create_column(Column('host_routes', Text(), default=[])) + +然后在 nova/objects/instances.py 中的fields加入相应的字段。 + +然后在 nova/db/sqlalchemy/models.py 也要加相应的 Column + +最后再执行这个命令,同步数据库 + +:: + + nova-manage db sync -------------- @@ -591,6 +646,9 @@ nova api 的接口参数是在 nova/api/openstack/compute/schemas/ .. |image38| image:: http://image.python-online.cn/20190708103119.png .. |image39| image:: http://image.python-online.cn/20190719170825.png .. |image40| image:: http://image.python-online.cn/20190730140551.png -.. |image41| image:: http://image.python-online.cn/20190730142527.png -.. |image42| image:: http://image.python-online.cn/20190730143003.png +.. |image41| image:: http://image.python-online.cn/20190826210813.png +.. |image42| image:: http://image.python-online.cn/20190826211542.png +.. |image43| image:: http://image.python-online.cn/20190826211737.png +.. |image44| image:: http://image.python-online.cn/20190730142527.png +.. |image45| image:: http://image.python-online.cn/20190730143003.png diff --git a/source/c08/c08_06.rst b/source/c08/c08_06.rst index 8912b08..792eb81 100644 --- a/source/c08/c08_06.rst +++ b/source/c08/c08_06.rst @@ -79,7 +79,7 @@ NetworkManager后,默认情况下它的启动顺序是会在 cloudinit-local 3. cloud-init modules -m config 4. cloud-init modules -m final -除了这几个命令之外,还有几个 +除了这几个命令之外,还有几个: - cloud-init query -n [name] - cloud-init single -n [name] –frequency diff --git a/source/c08/c08_08.rst b/source/c08/c08_08.rst index 60ff8dd..c95f770 100644 --- a/source/c08/c08_08.rst +++ b/source/c08/c08_08.rst @@ -175,6 +175,14 @@ NetworkManager, ubuntu 是network-manager)才负责获取ip。 10. 如果一个子网只有dhcp port,子网可以被删除,如果有其他port,则子网不能删除。 +11. 一个network一个ns,一个ns下面会有多个dhcp + server的ip,正常情况下每个subnet一个dhcp + server,若一个network下有多个开启了dhcp server + 的子网,只关闭其中一个子网的dhcp,并不会立马删除这个dhcp + port,因为这个port还有其他人占用(感觉这块neutron处理不好,应该更新一个port的fixed_ip,把关闭dhcp + 的子网的ip给删除掉),当一个network里没有开启dhcp的子网且没有虚拟机使用dhcp的情况下,neutron才会删除这个dhcp + port。 + 8.8.5 镜像问题排查 ------------------ diff --git a/source/c08/c08_14.rst b/source/c08/c08_14.rst index d6fb0fa..c2bac3a 100644 --- a/source/c08/c08_14.rst +++ b/source/c08/c08_14.rst @@ -245,6 +245,12 @@ Port 去创建虚拟机,二是,修改 nova-api 的接口,使之支持。 |image4| +重装 ``openvswith.ko`` 过程 + +.. code:: shell + + ovs-dpctl del-dp ovs-system && rmmod openvswitch && insmod ./openvswitch.ko && service openvswitch restart && service network restart + -------------- .. figure:: http://image.python-online.cn/20190511161447.png diff --git a/source/c08/c08_15.rst b/source/c08/c08_15.rst index e4aec06..a063773 100644 --- a/source/c08/c08_15.rst +++ b/source/c08/c08_15.rst @@ -37,6 +37,23 @@ subnet_id。 |image9| +-------------- + +当不指定子网、也不指定ip时(也就是不传fixed_ip),而且 cluster 里 即 +有ipv4 的子网也有ipv6的子网,这时候 neutron +会去创建一个既有ipv4也有ipv6的port,只要有一个version的子网里没有可用ip,都会失败。 + +|image10| + +这里是遍历一个version的所有的子网列表,只要能找到一个子网有可用ip,就返回,如果遍历完都没有找到ip,那就要抛出异常了。 + +|image11| + +.. code:: python + + class IpAddressGenerationFailureAllSubnets(IpAddressGenerationFailure): + message = _("No more IP addresses available.") + .. |image0| image:: http://image.python-online.cn/20190804111844.png .. |image1| image:: http://image.python-online.cn/20190804111715.png .. |image2| image:: http://image.python-online.cn/20190803181706.png @@ -47,4 +64,6 @@ subnet_id。 .. |image7| image:: http://image.python-online.cn/20190804094131.png .. |image8| image:: http://image.python-online.cn/20190804092214.png .. |image9| image:: http://image.python-online.cn/20190804091911.png +.. |image10| image:: http://image.python-online.cn/20190809213209.png +.. |image11| image:: http://image.python-online.cn/20190809213223.png From ce094443ae01a25db0efe90bfcbf99f7317199c1 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sat, 31 Aug 2019 18:10:34 +0800 Subject: [PATCH 015/227] =?UTF-8?q?=E6=96=B0=E5=A2=83=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c01/c01_22.md | 191 +++++++++++++++++++++++++++++++++++++++++++ source/c04/c04_15.md | 16 ++++ source/c07/c07_01.md | 3 + source/c08/c08_05.md | 20 +++++ source/c08/c08_06.md | 38 ++++++++- source/c08/c08_14.md | 40 +++++++++ 6 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 source/c01/c01_22.md diff --git a/source/c01/c01_22.md b/source/c01/c01_22.md new file mode 100644 index 0000000..5e94dc9 --- /dev/null +++ b/source/c01/c01_22.md @@ -0,0 +1,191 @@ +# 1.22 如何修改 CentOS 6.x 上默认Python + +最近在工作中遇到一个问题,就是有一个功能希望在各种服务器上实现,而服务器上的系统版本可能都不一样,有的是 CentOS 6.x,有的是 CentOS 7.x 。 + +需要说明的一点是,CentOS 6.x 上的 Python 版本是 2.6.x 的,而 CentOS 7.x 上的 Python 版本是 2.7.x 的,这意味着我要实现的功能要适配这两种版本的系统。 + +你可能会说,这有什么的,自己写的时候,注意一下就好了。 + +事情其实没有那么容易,我要实现的功能是基于一个框架进行定制,需要修改不少的框架代码。这个框架在不同的 Linux 版本上,是有不同的版本的,而且差异巨大,曾经想过在 CentOS 6.x 和 CentOS 7.x 将这个框架安装成同一个版本,最后还是失败了,无法安装,原因就是高版本需要 Python2.7,而 CentOS 6.x 上只有 Python2.6。 + +这个历史问题一直遗留到现在,由于这次的功能影响到的代码较多,如果要对两个版本的框架分别进行定制的话,需要花不少的时间,为了不维护两套版本,避免浪费多余的精力去做适配,我决定将 CentOS 6.x 上默认的 Python2.6 升级成 Python2.7。 + +下面是整个升级过程,别看步骤简单,这些精简步骤的背后可是有不少的坑,被我踩过后,你可以直接使用了。 + + + + +1. 首先确认下你机器上的默认的 Python 版本 + +```shell +$ python -V +Python 2.6.6 + +$ whereis python +python: /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz +``` + + + +2. 由于我们将使用编译安装的方式,所以要安装下 gcc,及一些工具包。 + +注意一定要全部安装,不然后面会发现有不少 python 的工具用不了。 + +比如不安装 zlib 会无法安装 setuptools,不装 openssl 和 openssl-devel,会无法使用 pip 工具等 + +``` +$ yum install gcc -y +$ yum groupinstall "Development tools" +$ yum install zlib-devel bzip2-devel openssl openssl-devel ncurses-devel sqlite-devel -y +``` + + 如果你这里未按照我的步骤来安装,你后面使用的时候出现了各种各样的问题,不要慌,只要再回来这里,把没安装的包装上,安装完成后,你需要进入第四步重新编译安装Python。 + + + +3. 下载最新的 Python2.7.x 安装包,解压并进入指定目录 + +``` +$ wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz +$ tar zxvf Python-2.7.14.tgz +$ cd Python-2.7.14 +``` + + + +4. 配置,编译,安装 + +```shell +# --prefix 指定 python 安装的路径 +$ ./configure --prefix=/usr/local/python/python2.7 +$ make +$ make install +``` + +`./configure` 命令执行完毕之后创建一个文件creating Makefile,供下面的make命令使用 执行 `make install` 之后就会把程序安装到我们指定的目录中去。 + +Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –help输出详细的选项列表。其中 `--prefix` 选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,库文件默认放在 `/usr/local/lib` ,配置文件默认放在 `/usr/local/etc` ,其它的资源文件放在 `/usr /local/share`。如果配置 `--prefix`,如:`./configure --prefix=/usr/local/test` 可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。 + +用了 `--prefix` 选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。当然要卸载程序,也可以在原来的make目录下用一次 `make uninstall`,但前提是make文件指定过uninstall。 + + + +5. 查看系统的 Python 版本 + +```shell +$ python -V +Python 2.6.6 +``` + + 如果你查看还是 Python 2.6.6 版本,请继续看第六步。 + + + +6. 修改系统默认的 Python 版本 + +查看新安装的Python版本,当前系统的Python版本,并将系统指向的Python从2.6.x修改为2.7.x,再次查看当前系统的Python版本,已经变更为2.7.x + +```shell +# 这是我们刚安装的 Python +$/usr/local/bin/python2.7 -V +Python 2.7.14 + +# 这是系统默认 Python +$ /usr/bin/python -V +Python 2.6.6 + +# 备份原来的 Python 文件 +$ mv /usr/bin/python /usr/bin/python.bak + +# 建立软链接,将我们刚安装的 python2.7 做为系统默认版本 +ln -s /usr/local/bin/python2.7 /usr/bin/python + +# 再次查看 Python 版本,已经成功切换过来 +$ python -V +Python 2.7.14 +``` + +7. 重新指定 yum 的Python版本 + +上面我们改了系统的默认 Python 版本,由于CentOS 6.x 的 yum 是基于Python2.6 的,为了不影响 yum 的使用,需单独将yum指向python2.6版本。 + +编辑: vim /usr/bin/yum ,将` /usr/bin/python` 改成 `/usr/bin/python2.6` + +```python +#!/usr/bin/python2.6 +``` + + + +8. 安装 setuptools 及 pip + +pip是python的安装工具,很多python的常用工具,都可以通过pip进行安装。要安装pip,首先要安装setuptools。从这个链接,你可以得到相关信息:https://pypi.python.org/pypi/setuptools + +```shell +# 下载 setuptools +$ wget https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4 +``` + +同样的,进行安装: + +```shell +$ tar vxf setuptools-21.0.0.tar.gz +$ cd setuptools-21.0.0 +$ python setup.py install +``` + +安装完成后,下载pip。其信息在如下网站:https://pypi.python.org/pypi/pip + +```shell +# 下载 pip +wget https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7 +``` + +同样的,进行安装 + +```shell +$ tar vxf pip-8.1.1.tar.gz +$ cd pip-8.1.1 +$ python setup.py install +``` + +安装完成后,执行 `pip list` 查看一下安装的包,若无异常,则一切顺利。或者你也可以试着安装一下第三方包 `pip install requests` 。 + + + +8. 转移cloudinit + +上面说的项目,其实就是 cloudinit。接下来就要将 centos 7.2 上的cloudinit 的目录整体拷贝到 centos 6.5 的/usr/local/lib/python2.7/site-packages/ 目录下 + +![](http://image.python-online.cn/20190831160317.png) + +然后安装一些 cloudinit 的依赖包。 + +```shell +$ pip install six requests prettytable jsonpatch configobj + +# 默认还是安装在 python2.6 下 +$ yum install PyYAML -y + +# 将这些文件拷贝到 python2.7 目录下 +# 如果你不知道 python2.7 的目录,使用 import sys;print sys.path 就可以打印 +$ cd /usr/lib64/python2.6/site-packages +$ cp -r yaml/ /usr/local/lib/python2.7/site-packages/ +$ cp -p _yaml.so /usr/local/lib/python2.7/site-packages/ +$ cp -p PyYAML-3.10-py2.6.egg-info /usr/local/lib/python2.7/site-packages/ +``` + +执行一下 cloudinit 的几个命令,没有问题,任务就完成了。 + +```shell +$ cloud-init init -l +$ cloud-init init +``` + + + +**参考文章** + +- https://www.cnblogs.com/stonehe/p/7944366.html + +![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/c04/c04_15.md b/source/c04/c04_15.md index 6ee7ec6..6a91021 100644 --- a/source/c04/c04_15.md +++ b/source/c04/c04_15.md @@ -771,6 +771,22 @@ PyCharm 打开一个文件,就占用一个标签面。 而这些配置步骤还挺多的,我专门写了一篇文章介绍设置过程,你可以点此查看:[图文教程|不能不会的远程调试技巧](https://mp.weixin.qq.com/s/ECWCJMQ6oEDaY1x1JfGfkg) + + +## 4.15.31 专属剪切板 + + + +ctrl + shift + c + + + +## 4.15.32 json 格式化 + + + + + ## 附录 - [PyCharm 快捷键 Mac 版 ](https://resources.jetbrains.com/storage/products/pycharm/docs/PyCharm_ReferenceCard_mac.pdf) diff --git a/source/c07/c07_01.md b/source/c07/c07_01.md index 1ae5b36..1be73a9 100644 --- a/source/c07/c07_01.md +++ b/source/c07/c07_01.md @@ -1637,7 +1637,10 @@ securityfs on /sys/kernel/security type secur ## 六、业务相关 + + 查看虚机的CPU是否支持虚拟化 + ``` egrep '(vmx|svm)' /proc/cpuinfo # 如果有标红的vmx(Intel)、svm(AMD)说明就支持,virtualbox不支持(坑) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index 21b6010..5404d92 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -520,6 +520,26 @@ schemas 的文件都统一放在 `nova\api\openstack\compute\schemas` 目录下 +是不是很呐闷,为什么创建server 的接口,会知道关联上面那9个 schemas,其实那各自代表一种资源,属于扩展资源(它们的中心是核心资源)。 + +那这些扩展资源是如何关联到核心资源的,这是在哪定义的呢? + +其实就是 nova 的 setup.cfg 里定义好的。 + +就像下面指明了 server 的 create 接口会去加载这9个扩展资源。 + +![](http://image.python-online.cn/20190830091540.png) + +搜索一下 server_create 方法 + +还真的只有这 9 个资源里才会定义。 + +![](http://image.python-online.cn/20190830092203.png) + +这就神奇了,servers 这个核心资源是如何加载到这些资源的,看了下代码是使用 stevedore 这个模块去动态加载,然后还会校验这些资源是否都有 `server_create` ,只有有这个函数,才会被正常加载进来。 + +![](http://image.python-online.cn/20190830093613.png) + ## 8.5.20 往数据库中加字段 先先定义好migrate 文件 diff --git a/source/c08/c08_06.md b/source/c08/c08_06.md index 5129988..dfeb939 100644 --- a/source/c08/c08_06.md +++ b/source/c08/c08_06.md @@ -80,6 +80,12 @@ cloud-init 是 linux 的一个工具,当系统启动时,cloud-init 可从 no ![](http://image.python-online.cn/20190430213729.png) +如果你在调试 single,而且你把 /var/lib/cloud 目录删除过,请务必要执行一下 cloud-init init ,不然会取不到 user_data + +centos 6.5 的cloudinit 使用的是 python2.6,没有 format 语法,请注意不要使用。这是和 centos7的一点区别。 + + + ## 8.6.3 数据源是如何读取的? 数据源的读取入口是在 入口文件(CentOS6.x 是在 `/usr/bin/cloud-init`,CentOS7.x 是在 `/usr/lib/python2.7/site-packages/cloudinit/cmd/main.py`)的 main_init 函数中,会调用 `stages.py:fetch()` 函数。 @@ -120,9 +126,21 @@ find_source 是通过一个一个去执行 对应source模块的 get_data(), ![](http://image.python-online.cn/20190429104357.png) -而在 CentOS7.x (cloud-init 0.7.9)中 或者 Ubuntu 16.04(cloud-init 17.1)中,并没有限定需要在 local 阶段时才可进入。所以如果你使用调试工具直接执行 init 阶段,也是可以配置网络的。 +而在 CentOS7.x (cloud-init 0.7.9)中 或者 Ubuntu 16.04(cloud-init 17.1)中,配置网络不是在 on_first_boot 函数里,而是在 stages.py:apply_network_config() 里。 + +![](http://image.python-online.cn/20190829141059.png) + +并且新版的cloudinit ,local 和 init 阶段都会去配置网络,区别在于,local阶段只写配置文件,而init阶段不仅写配置文件,还会启动网卡,将ip配置上。 -![](http://image.python-online.cn/20190429104307.png) +centos 7.x ,因为会跳过,它是在 stages.py:apply_network_config 函数里,这是在 local 阶段写入配置文件,而在 init 阶段 启动网卡。 + +![](http://image.python-online.cn/20190829113537.png) + +所以如果要调试的话可以直接执行 init 阶段。 + +而如果是虚拟机重启的话,是在stages.py 这边判断是否为新虚拟机的,这也和旧版本有所区别。 + +![](http://image.python-online.cn/20190829141059.png) 为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 @@ -350,6 +368,22 @@ myjob.cfg:text/upstart-job ![](http://image.python-online.cn/20190708175813.png) + + + + +查看机器里有哪几张网卡 + +ls -l /sys/class/net + + + +只查看 ipv4 或 ipv6的网卡ip + +ip -6 addr show + +ip -4 addr show + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/c08/c08_14.md b/source/c08/c08_14.md index 5c728d7..e5d03aa 100644 --- a/source/c08/c08_14.md +++ b/source/c08/c08_14.md @@ -253,9 +253,49 @@ neutron port-create --fixed-ip \ ovs-dpctl del-dp ovs-system && rmmod openvswitch && insmod ./openvswitch.ko && service openvswitch restart && service network restart ``` +## 8.14.4 cloudinit支持 +CentOS 6.x 在使用 ipv6 方面有问题 +![](http://image.python-online.cn/20190829103805.png) +导致在网卡配置文件里的配置的ip 都为none + + + + + +![](http://image.python-online.cn/20190829104544.png) + +上面的 callbak 是 这个函数 + +![](http://image.python-online.cn/20190829104806.png) + + + +centos6.x 的网络信息不是从 latest 里的 network_data.json 里读取的,而是从 content/0000 里读取 + +![](http://image.python-online.cn/20190829110541.png) + +这是因为 centos 6.x 配置网络是在 local 阶段做的,而local阶段做的话,就会从 content/0000 + +![](http://image.python-online.cn/20190829105558.png) + +而 centos7.x 其实也会走 on_first_boot 去配置网络,但是cloudinit 在centos7.x 里 sources.DSMODE_PASS + +![](http://image.python-online.cn/20190829112446.png) + +导致在 local 阶段,这里配置网络被pass掉,自然也就不会从 content/0000 读取了。 + +![](http://image.python-online.cn/20190829111917.png) + + + +centos 6.x 配置网络是在 on_first_boot 函数里,这是 local 阶段就会执行的。 + + + +![](http://image.python-online.cn/20190829161243.png) --- From 697ce448983779bf20f7de222d6d398f101f127b Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 1 Sep 2019 12:01:37 +0800 Subject: [PATCH 016/227] update rst files --- source/c01/c01_22.rst | 205 ++++++++++++++++++++++++++++++++++++++++++ source/c04/c04_15.rst | 8 ++ source/c08/c08_05.rst | 26 ++++++ source/c08/c08_06.rst | 72 ++++++++++----- source/c08/c08_14.rst | 48 ++++++++++ 5 files changed, 339 insertions(+), 20 deletions(-) create mode 100644 source/c01/c01_22.rst diff --git a/source/c01/c01_22.rst b/source/c01/c01_22.rst new file mode 100644 index 0000000..09a37f7 --- /dev/null +++ b/source/c01/c01_22.rst @@ -0,0 +1,205 @@ +1.22 如何修改 CentOS 6.x 上默认Python +===================================== + +最近在工作中遇到一个问题,就是有一个功能希望在各种服务器上实现,而服务器上的系统版本可能都不一样,有的是 +CentOS 6.x,有的是 CentOS 7.x 。 + +需要说明的一点是,CentOS 6.x 上的 Python 版本是 2.6.x 的,而 CentOS 7.x +上的 Python 版本是 2.7.x +的,这意味着我要实现的功能要适配这两种版本的系统。 + +你可能会说,这有什么的,自己写的时候,注意一下就好了。 + +事情其实没有那么容易,我要实现的功能是基于一个框架进行定制,需要修改不少的框架代码。这个框架在不同的 +Linux 版本上,是有不同的版本的,而且差异巨大,曾经想过在 CentOS 6.x 和 +CentOS 7.x +将这个框架安装成同一个版本,最后还是失败了,无法安装,原因就是高版本需要 +Python2.7,而 CentOS 6.x 上只有 Python2.6。 + +这个历史问题一直遗留到现在,由于这次的功能影响到的代码较多,如果要对两个版本的框架分别进行定制的话,需要花不少的时间,为了不维护两套版本,避免浪费多余的精力去做适配,我决定将 +CentOS 6.x 上默认的 Python2.6 升级成 Python2.7。 + +下面是整个升级过程,别看步骤简单,这些精简步骤的背后可是有不少的坑,被我踩过后,你可以直接使用了。 + +1. 首先确认下你机器上的默认的 Python 版本 + +.. code:: shell + + $ python -V + Python 2.6.6 + + $ whereis python + python: /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz + +2. 由于我们将使用编译安装的方式,所以要安装下 gcc,及一些工具包。 + +注意一定要全部安装,不然后面会发现有不少 python 的工具用不了。 + +比如不安装 zlib 会无法安装 setuptools,不装 openssl 和 +openssl-devel,会无法使用 pip 工具等 + +:: + + $ yum install gcc -y + $ yum groupinstall "Development tools" + $ yum install zlib-devel bzip2-devel openssl openssl-devel ncurses-devel sqlite-devel -y + +如果你这里未按照我的步骤来安装,你后面使用的时候出现了各种各样的问题,不要慌,只要再回来这里,把没安装的包装上,安装完成后,你需要进入第四步重新编译安装Python。 + +3. 下载最新的 Python2.7.x 安装包,解压并进入指定目录 + +:: + + $ wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz + $ tar zxvf Python-2.7.14.tgz + $ cd Python-2.7.14 + +4. 配置,编译,安装 + +.. code:: shell + + # --prefix 指定 python 安装的路径 + $ ./configure --prefix=/usr/local/python/python2.7 + $ make + $ make install + +``./configure`` 命令执行完毕之后创建一个文件creating +Makefile,供下面的make命令使用 执行 ``make install`` +之后就会把程序安装到我们指定的目录中去。 + +Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure +–help输出详细的选项列表。其中 ``--prefix`` +选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr +/local/bin,库文件默认放在 ``/usr/local/lib`` ,配置文件默认放在 +``/usr/local/etc`` ,其它的资源文件放在 +``/usr /local/share``\ 。如果配置 +``--prefix``\ ,如:\ ``./configure --prefix=/usr/local/test`` +可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。 + +用了 ``--prefix`` +选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。当然要卸载程序,也可以在原来的make目录下用一次 +``make uninstall``\ ,但前提是make文件指定过uninstall。 + +5. 查看系统的 Python 版本 + +.. code:: shell + + $ python -V + Python 2.6.6 + +如果你查看还是 Python 2.6.6 版本,请继续看第六步。 + +6. 修改系统默认的 Python 版本 + +查看新安装的Python版本,当前系统的Python版本,并将系统指向的Python从2.6.x修改为2.7.x,再次查看当前系统的Python版本,已经变更为2.7.x + +.. code:: shell + + # 这是我们刚安装的 Python + $/usr/local/bin/python2.7 -V + Python 2.7.14 + + # 这是系统默认 Python + $ /usr/bin/python -V + Python 2.6.6 + + # 备份原来的 Python 文件 + $ mv /usr/bin/python /usr/bin/python.bak + + # 建立软链接,将我们刚安装的 python2.7 做为系统默认版本 + ln -s /usr/local/bin/python2.7 /usr/bin/python + + # 再次查看 Python 版本,已经成功切换过来 + $ python -V + Python 2.7.14 + +7. 重新指定 yum 的Python版本 + +上面我们改了系统的默认 Python 版本,由于CentOS 6.x 的 yum +是基于Python2.6 的,为了不影响 yum +的使用,需单独将yum指向python2.6版本。 + +编辑: vim /usr/bin/yum ,将\ ``/usr/bin/python`` 改成 +``/usr/bin/python2.6`` + +.. code:: python + + #!/usr/bin/python2.6 + +8. 安装 setuptools 及 pip + +pip是python的安装工具,很多python的常用工具,都可以通过pip进行安装。要安装pip,首先要安装setuptools。从这个链接,你可以得到相关信息:https://pypi.python.org/pypi/setuptools + +.. code:: shell + + # 下载 setuptools + $ wget https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4 + +同样的,进行安装: + +.. code:: shell + + $ tar vxf setuptools-21.0.0.tar.gz + $ cd setuptools-21.0.0 + $ python setup.py install + +安装完成后,下载pip。其信息在如下网站:https://pypi.python.org/pypi/pip + +.. code:: shell + + # 下载 pip + wget https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7 + +同样的,进行安装 + +.. code:: shell + + $ tar vxf pip-8.1.1.tar.gz + $ cd pip-8.1.1 + $ python setup.py install + +安装完成后,执行 ``pip list`` +查看一下安装的包,若无异常,则一切顺利。或者你也可以试着安装一下第三方包 +``pip install requests`` 。 + +8. 转移cloudinit + +上面说的项目,其实就是 cloudinit。接下来就要将 centos 7.2 上的cloudinit +的目录整体拷贝到 centos 6.5 的/usr/local/lib/python2.7/site-packages/ +目录下 + +|image0| + +然后安装一些 cloudinit 的依赖包。 + +.. code:: shell + + $ pip install six requests prettytable jsonpatch configobj + + # 默认还是安装在 python2.6 下 + $ yum install PyYAML -y + + # 将这些文件拷贝到 python2.7 目录下 + # 如果你不知道 python2.7 的目录,使用 import sys;print sys.path 就可以打印 + $ cd /usr/lib64/python2.6/site-packages + $ cp -r yaml/ /usr/local/lib/python2.7/site-packages/ + $ cp -p _yaml.so /usr/local/lib/python2.7/site-packages/ + $ cp -p PyYAML-3.10-py2.6.egg-info /usr/local/lib/python2.7/site-packages/ + +执行一下 cloudinit 的几个命令,没有问题,任务就完成了。 + +.. code:: shell + + $ cloud-init init -l + $ cloud-init init + +**参考文章** + +- https://www.cnblogs.com/stonehe/p/7944366.html + +.. figure:: http://image.python-online.cn/20190511161447.png + :alt: 关注公众号,获取最新干货! + + +.. |image0| image:: http://image.python-online.cn/20190831160317.png + diff --git a/source/c04/c04_15.rst b/source/c04/c04_15.rst index 94a6088..d2584d4 100644 --- a/source/c04/c04_15.rst +++ b/source/c04/c04_15.rst @@ -917,6 +917,14 @@ Debug ,而远程调试需要不少前置步骤。 而这些配置步骤还挺多的,我专门写了一篇文章介绍设置过程,你可以点此查看:\ `图文教程|不能不会的远程调试技巧 `__ +4.15.31 专属剪切板 +------------------ + +ctrl + shift + c + +4.15.32 json 格式化 +------------------- + 附录 ---- diff --git a/source/c08/c08_05.rst b/source/c08/c08_05.rst index 982051e..f7e2e71 100644 --- a/source/c08/c08_05.rst +++ b/source/c08/c08_05.rst @@ -572,6 +572,29 @@ servers 更新 schemas。 |image45| +是不是很呐闷,为什么创建server 的接口,会知道关联上面那9个 +schemas,其实那各自代表一种资源,属于扩展资源(它们的中心是核心资源)。 + +那这些扩展资源是如何关联到核心资源的,这是在哪定义的呢? + +其实就是 nova 的 setup.cfg 里定义好的。 + +就像下面指明了 server 的 create 接口会去加载这9个扩展资源。 + +|image46| + +搜索一下 server_create 方法 + +还真的只有这 9 个资源里才会定义。 + +|image47| + +这就神奇了,servers 这个核心资源是如何加载到这些资源的,看了下代码是使用 +stevedore 这个模块去动态加载,然后还会校验这些资源是否都有 +``server_create`` ,只有有这个函数,才会被正常加载进来。 + +|image48| + 8.5.20 往数据库中加字段 ----------------------- @@ -651,4 +674,7 @@ servers 更新 schemas。 .. |image43| image:: http://image.python-online.cn/20190826211737.png .. |image44| image:: http://image.python-online.cn/20190730142527.png .. |image45| image:: http://image.python-online.cn/20190730143003.png +.. |image46| image:: http://image.python-online.cn/20190830091540.png +.. |image47| image:: http://image.python-online.cn/20190830092203.png +.. |image48| image:: http://image.python-online.cn/20190830093613.png diff --git a/source/c08/c08_06.rst b/source/c08/c08_06.rst index 792eb81..09d9335 100644 --- a/source/c08/c08_06.rst +++ b/source/c08/c08_06.rst @@ -110,6 +110,12 @@ NetworkManager后,默认情况下它的启动顺序是会在 cloudinit-local |image7| +如果你在调试 single,而且你把 /var/lib/cloud +目录删除过,请务必要执行一下 cloud-init init ,不然会取不到 user_data + +centos 6.5 的cloudinit 使用的是 python2.6,没有 format +语法,请注意不要使用。这是和 centos7的一点区别。 + 8.6.3 数据源是如何读取的? -------------------------- @@ -161,12 +167,26 @@ on_first_boot。 |image14| 而在 CentOS7.x (cloud-init 0.7.9)中 或者 Ubuntu 16.04(cloud-init -17.1)中,并没有限定需要在 local -阶段时才可进入。所以如果你使用调试工具直接执行 init -阶段,也是可以配置网络的。 +17.1)中,配置网络不是在 on_first_boot 函数里,而是在 +stages.py:apply_network_config() 里。 |image15| +并且新版的cloudinit ,local 和 init +阶段都会去配置网络,区别在于,local阶段只写配置文件,而init阶段不仅写配置文件,还会启动网卡,将ip配置上。 + +centos 7.x ,因为会跳过,它是在 stages.py:apply_network_config +函数里,这是在 local 阶段写入配置文件,而在 init 阶段 启动网卡。 + +|image16| + +所以如果要调试的话可以直接执行 init 阶段。 + +而如果是虚拟机重启的话,是在stages.py +这边判断是否为新虚拟机的,这也和旧版本有所区别。 + +|image17| + 为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 在 cloud-init 的比较重要的几个文件有: @@ -182,12 +202,12 @@ on_first_boot。 如果是按照旧虚拟机创建新的快照镜像,然后使用这个镜像创建新的虚拟机,有可能会在同一块网卡上出现新旧两个ip,这是因为虚拟机在启动过程中,会先读取原网络配置配置ip,然后才会运行 cloud-init 进行新ip的配置,而新ip的配置是使用 ``ifup`` -这个命令\ |image16| +这个命令\ |image18| -使用这种方式并不会将第一次配置的旧ip给清除掉。\ |image17| +使用这种方式并不会将第一次配置的旧ip给清除掉。\ |image19| 这个问题,目前我只在CentOS6 中遇到过。可以通过修改代码让其先 ``ifdown`` -再 ``ifup`` 就可以解决这个问题。\ |image18| +再 ``ifup`` 就可以解决这个问题。\ |image20| **坑二** @@ -197,7 +217,7 @@ NetworkManager 具体的创建逻辑是在这 -|image19| +|image21| **坑三** @@ -218,12 +238,12 @@ NetworkManager 一个是会自动DHCP获取到一个以ip命名的hostname,并将原来的覆盖掉。 -|image20| +|image22| 为了避免出现这些情况,请务必保证这些包都安装完整(左为 CentOS 7.2,右为 CentOS 6.5)。 -|image21| +|image23| 8.6.5 userdata 使用说明 ----------------------- @@ -396,7 +416,7 @@ cirename0 的网卡。 这就是cloudinit搞的鬼,在cloudinit的local阶段,好像会记录之前的mac地址,如果发现不一致,就会触发rename_interface。 -|image22| +|image24| 8.6.7 虚拟机启动卡住 -------------------- @@ -409,7 +429,17 @@ ephemeral0 拿到对应的 /dev/vdb,并将其写入 /etc/fstab 中。在下次重启时,会根据 fstab 挂载磁盘,如果挂载不上,就会导致虚拟机启动卡住。 -|image23| +|image25| + +查看机器里有哪几张网卡 + +ls -l /sys/class/net + +只查看 ipv4 或 ipv6的网卡ip + +ip -6 addr show + +ip -4 addr show -------------- @@ -432,13 +462,15 @@ ephemeral0 拿到对应的 /dev/vdb,并将其写入 /etc/fstab .. |image12| image:: http://image.python-online.cn/20190430230839.png .. |image13| image:: http://image.python-online.cn/20190430231108.png .. |image14| image:: http://image.python-online.cn/20190429104357.png -.. |image15| image:: http://image.python-online.cn/20190429104307.png -.. |image16| image:: http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d -.. |image17| image:: http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c -.. |image18| image:: http://image.python-online.cn/20190430231812.png -.. |image19| image:: http://image.python-online.cn/20190430232309.png -.. |image20| image:: http://image.python-online.cn/20190429205735.png -.. |image21| image:: http://image.python-online.cn/20190430232911.png -.. |image22| image:: http://image.python-online.cn/20190623091911.png -.. |image23| image:: http://image.python-online.cn/20190708175813.png +.. |image15| image:: http://image.python-online.cn/20190829141059.png +.. |image16| image:: http://image.python-online.cn/20190829113537.png +.. |image17| image:: http://image.python-online.cn/20190829141059.png +.. |image18| image:: http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d +.. |image19| image:: http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c +.. |image20| image:: http://image.python-online.cn/20190430231812.png +.. |image21| image:: http://image.python-online.cn/20190430232309.png +.. |image22| image:: http://image.python-online.cn/20190429205735.png +.. |image23| image:: http://image.python-online.cn/20190430232911.png +.. |image24| image:: http://image.python-online.cn/20190623091911.png +.. |image25| image:: http://image.python-online.cn/20190708175813.png diff --git a/source/c08/c08_14.rst b/source/c08/c08_14.rst index c2bac3a..ab5fea7 100644 --- a/source/c08/c08_14.rst +++ b/source/c08/c08_14.rst @@ -251,6 +251,46 @@ Port 去创建虚拟机,二是,修改 nova-api 的接口,使之支持。 ovs-dpctl del-dp ovs-system && rmmod openvswitch && insmod ./openvswitch.ko && service openvswitch restart && service network restart +8.14.4 cloudinit支持 +-------------------- + +CentOS 6.x 在使用 ipv6 方面有问题 + +|image5| + +导致在网卡配置文件里的配置的ip 都为none + +|image6| + +上面的 callbak 是 这个函数 + +|image7| + +centos6.x 的网络信息不是从 latest 里的 network_data.json +里读取的,而是从 content/0000 里读取 + +|image8| + +这是因为 centos 6.x 配置网络是在 local +阶段做的,而local阶段做的话,就会从 content/0000 + +|image9| + +而 centos7.x 其实也会走 on_first_boot 去配置网络,但是cloudinit +在centos7.x 里 sources.DSMODE_PASS + +|image10| + +导致在 local 阶段,这里配置网络被pass掉,自然也就不会从 content/0000 +读取了。 + +|image11| + +centos 6.x 配置网络是在 on_first_boot 函数里,这是 local +阶段就会执行的。 + +|image12| + -------------- .. figure:: http://image.python-online.cn/20190511161447.png @@ -262,4 +302,12 @@ Port 去创建虚拟机,二是,修改 nova-api 的接口,使之支持。 .. |image2| image:: http://image.python-online.cn/20190716180952.png .. |image3| image:: http://image.python-online.cn/20190804110647.png .. |image4| image:: http://image.python-online.cn/20190716180726.png +.. |image5| image:: http://image.python-online.cn/20190829103805.png +.. |image6| image:: http://image.python-online.cn/20190829104544.png +.. |image7| image:: http://image.python-online.cn/20190829104806.png +.. |image8| image:: http://image.python-online.cn/20190829110541.png +.. |image9| image:: http://image.python-online.cn/20190829105558.png +.. |image10| image:: http://image.python-online.cn/20190829112446.png +.. |image11| image:: http://image.python-online.cn/20190829111917.png +.. |image12| image:: http://image.python-online.cn/20190829161243.png From adc336bd5181dbab0c068f380893d6621e2f010a Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Wed, 4 Sep 2019 20:54:08 +0800 Subject: [PATCH 017/227] update file --- source/c08/c08_01.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/c08/c08_01.md b/source/c08/c08_01.md index fdd7618..5d6a469 100644 --- a/source/c08/c08_01.md +++ b/source/c08/c08_01.md @@ -150,6 +150,9 @@ $ neutron port-list neutron port-create --tenant-id 100001 --fixed-ip ip_address=192.168.0.22 --mac-address fa:16:3e:3a:e8:1b nova interface-attach b0cc47bc-25c3-48ca-a4fd-5523326b515a --port-id 8bcba4eb-ade0-403d-8f13-45ed70936f03 + +# 关闭port安全组 +neutron port-update --no-security-groups --port-security-enabled=False ``` ### 1.3 Glance From d1284e3eaa7de1511ef660e90b29ada963846c87 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Fri, 6 Sep 2019 21:56:09 +0800 Subject: [PATCH 018/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0cloudinit=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_14.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source/c08/c08_14.md b/source/c08/c08_14.md index e5d03aa..aa705b3 100644 --- a/source/c08/c08_14.md +++ b/source/c08/c08_14.md @@ -261,10 +261,6 @@ CentOS 6.x 在使用 ipv6 方面有问题 导致在网卡配置文件里的配置的ip 都为none - - - - ![](http://image.python-online.cn/20190829104544.png) 上面的 callbak 是 这个函数 @@ -293,9 +289,29 @@ centos6.x 的网络信息不是从 latest 里的 network_data.json 里读取的 centos 6.x 配置网络是在 on_first_boot 函数里,这是 local 阶段就会执行的。 +![](http://image.python-online.cn/20190829161243.png) + + + +ubuntu 解析网卡配置 + +```python +from cloudinit.net import eni +config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') +``` + +![](http://image.python-online.cn/20190906091102.png) + +## 8.14.5 其他命令记录 + + + +``` +# 网络启动不来,先 flush 试一下 +ip addr flush dev ens3 +``` -![](http://image.python-online.cn/20190829161243.png) --- From fb26e3f2104ac07a54ff6228456c83c6f78d5989 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Fri, 6 Sep 2019 21:56:35 +0800 Subject: [PATCH 019/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=8C=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E6=9C=BA=E6=98=AF=E5=A6=82=E4=BD=95=E5=88=86=E9=85=8D?= =?UTF-8?q?ip=E7=9A=84=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_05.md | 49 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index 5404d92..f491897 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -162,8 +162,6 @@ grep -E "Start executing commands|End executing commands" /var/log/nova/nova-com 下次修改方法:一个是最开始获取`source_type`时判断为isolate,一个是后面 `isolate`的`extract_snapshot` 也要和lvm一样实现一下。 - - ## 8.5.6 宿主机资源采集上报 compute的资源上报,是在 `nova/compute/resource_tracker.py:_init_compute_node` 里。 @@ -177,6 +175,53 @@ compute的资源上报,是在 `nova/compute/resource_tracker.py:_init_compute_ +## 8.5.7 虚拟机的ip是如何分配的? + +这一节主要讲两个点: + +1. Port 是如何创建的? +2. network_info 是如何组装的? + + + +虚拟机配置网络可以cloudinit从 ConfigDrive 里取得网络信息,然后配置。而这里的网络信息是怎么来的呢,这就是本节要讲的内容,它就是 `network_info` 信息,它的最终去向是 ConfigDrive。 + +在创建虚拟机时,需要的资源有很多,而网络就是其中一种(`network_info`),其他的还有 `block_device_info` 。 + +当你看完本节后,你会发现,network_info 其实是创建完 port 后,根据port的信息组装成一个对象。 + +虚拟机创建资源的代码是在 `nova/compute/manager.py` 里的 `_build_resource()` 里 + +![](http://image.python-online.cn/20190906093751.png) + +这里只讲一下 `network_info`,其他的我都忽略了。 + +![](http://image.python-online.cn/20190906094703.png) + +在这个函数`_allocate_network()` ,主要做如下两件事。 + +![](http://image.python-online.cn/20190906214536.png) + +继续进入这个函数,如果不指定重试次数,默认是一次。 + +![](http://image.python-online.cn/20190906100119.png) + +接下来就是调用我们非常熟悉的 `_create_port_minimal` 函数去创建port + +![](http://image.python-online.cn/20190906213038.png) + +如果你全局搜索,你会发现,在 network/rpc.py 下也有这个函数,这个是通过 nova interface-attach 为虚拟机添加网卡,从 nova-api 那边发起的 rpc 请求,才会走到这里 + +![](http://image.python-online.cn/20190906210825.png) + +上面创建完port了,后面最后一个函数,我已经标出来了,开始组装获取 network_info 对象。 + +![](http://image.python-online.cn/20190906213823.png) + + + + + ## 8.5.8 手动引入上下文环境 有两种方式可以生成context From 8ad10e8703aed99d00767813e590fea4696a578c Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Fri, 6 Sep 2019 21:57:23 +0800 Subject: [PATCH 020/227] =?UTF-8?q?=E4=BF=AE=E6=AD=A3keepalived=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c07/C07_08.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/c07/C07_08.md b/source/c07/C07_08.md index 884acb3..6fd3a16 100644 --- a/source/c07/C07_08.md +++ b/source/c07/C07_08.md @@ -64,6 +64,10 @@ vrrp_instance VI_1 { #vrrp实例定义部分 virtual_ipaddress { #设置虚拟ip地址,可以设置多个,每行一个 219.157.114.206/24 dev eth1 label eth1:0 } + track_interface { + eth1 + } + track_script { chk_zabbix } From e717e613fbecd344de5533c7a26956c7bd7de5c8 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Fri, 6 Sep 2019 23:20:47 +0800 Subject: [PATCH 021/227] update rst --- source/c01/c01_19.md | 5 +- source/c01/c01_19.rst | 5 +- source/c07/c07_08.rst | 4 + source/c08/c08_01.rst | 3 + source/c08/c08_05.rst | 197 +++++++++++++++++++++++++++--------------- source/c08/c08_14.rst | 18 ++++ 6 files changed, 158 insertions(+), 74 deletions(-) diff --git a/source/c01/c01_19.md b/source/c01/c01_19.md index 1f084ab..a43af06 100644 --- a/source/c01/c01_19.md +++ b/source/c01/c01_19.md @@ -7,8 +7,8 @@ python manager.py runserver 127.0.0.1:8080 # 登陆 xadmin 后台 127.0.0.1:8080/xadmin -# 帐号密码 -MING:wbm54378 +# 测试帐号密码 +wbm@54378@# # 更新表结构 python manage.py makemigrations @@ -36,6 +36,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') 数据库密码 ```shell +# 测试帐号密码 root:Wangbm@123 wangbm:VfgiCtc42tpu ``` diff --git a/source/c01/c01_19.rst b/source/c01/c01_19.rst index fc0d271..68d30f8 100644 --- a/source/c01/c01_19.rst +++ b/source/c01/c01_19.rst @@ -9,8 +9,8 @@ # 登陆 xadmin 后台 127.0.0.1:8080/xadmin - # 帐号密码 - MING:wbm54378 + # 测试帐号密码 + wbm@54378@# # 更新表结构 python manage.py makemigrations @@ -36,6 +36,7 @@ .. code:: shell + # 测试帐号密码 root:Wangbm@123 wangbm:VfgiCtc42tpu diff --git a/source/c07/c07_08.rst b/source/c07/c07_08.rst index e177ced..7dc9bd9 100644 --- a/source/c07/c07_08.rst +++ b/source/c07/c07_08.rst @@ -68,6 +68,10 @@ server双机高可用 `__ virtual_ipaddress { #设置虚拟ip地址,可以设置多个,每行一个 219.157.114.206/24 dev eth1 label eth1:0 } + track_interface { + eth1 + } + track_script { chk_zabbix } diff --git a/source/c08/c08_01.rst b/source/c08/c08_01.rst index 481da0a..3d3ef5f 100755 --- a/source/c08/c08_01.rst +++ b/source/c08/c08_01.rst @@ -160,6 +160,9 @@ aggregate管理 nova interface-attach b0cc47bc-25c3-48ca-a4fd-5523326b515a --port-id 8bcba4eb-ade0-403d-8f13-45ed70936f03 + # 关闭port安全组 + neutron port-update --no-security-groups --port-security-enabled=False + 1.3 Glance ~~~~~~~~~~ diff --git a/source/c08/c08_05.rst b/source/c08/c08_05.rst index f7e2e71..b6850d0 100644 --- a/source/c08/c08_05.rst +++ b/source/c08/c08_05.rst @@ -200,6 +200,56 @@ compute的资源上报,是在 从数据库获取旧数据 ``self.compute_node = self._get_compute_node(context)`` +8.5.7 虚拟机的ip是如何分配的? +------------------------------ + +这一节主要讲两个点: + +1. Port 是如何创建的? +2. network_info 是如何组装的? + +虚拟机配置网络可以cloudinit从 ConfigDrive +里取得网络信息,然后配置。而这里的网络信息是怎么来的呢,这就是本节要讲的内容,它就是 +``network_info`` 信息,它的最终去向是 ConfigDrive。 + +在创建虚拟机时,需要的资源有很多,而网络就是其中一种(\ ``network_info``\ ),其他的还有 +``block_device_info`` 。 + +当你看完本节后,你会发现,network_info 其实是创建完 port +后,根据port的信息组装成一个对象。 + +虚拟机创建资源的代码是在 ``nova/compute/manager.py`` 里的 +``_build_resource()`` 里 + +|image14| + +这里只讲一下 ``network_info``\ ,其他的我都忽略了。 + +|image15| + +在这个函数\ ``_allocate_network()`` ,主要做如下两件事。 + +|image16| + +继续进入这个函数,如果不指定重试次数,默认是一次。 + +|image17| + +接下来就是调用我们非常熟悉的 ``_create_port_minimal`` 函数去创建port + +|image18| + +如果你全局搜索,你会发现,在 network/rpc.py 下也有这个函数,这个是通过 +nova interface-attach 为虚拟机添加网卡,从 nova-api 那边发起的 rpc +请求,才会走到这里 + +|image19| + +上面创建完port了,后面最后一个函数,我已经标出来了,开始组装获取 +network_info 对象。 + +|image20| + 8.5.8 手动引入上下文环境 ------------------------ @@ -207,11 +257,11 @@ compute的资源上报,是在 1. 如果有请求req(在nova-api里),可以使用这种 -|image14| +|image21| 2. 其他地方可以使用这种 -|image15| +|image22| 8.5.9 指定ip时检查allocation_pools ---------------------------------- @@ -223,16 +273,16 @@ compute的资源上报,是在 先来看看,port 是如何创建的 -|image16| +|image23| 若要解决这个问题,可以参考原生代码中,在为子网添加allocation_pool时,验证是否合法的的逻辑,代码如下 -|image17| +|image24| 然后在 ``neutron\neutron\db\ipam_pluggable_backend.py`` 文件中添加我们检查 ip是否在 allocation_pools 中的逻辑代码。 -|image18| +|image25| .. code:: python @@ -255,17 +305,17 @@ compute的资源上报,是在 然后还要定义一个异常类型 -|image19| +|image26| 若指定的ip在allocation pool 里,则正常创建,若不在allocation 里,就会在 nova-compute 日志中报错。 -|image20| +|image27| 可以发现我们的ip 172.20.22.64 并不在子网的allocation pool,理所当然在nova的日志中可以看到相应的报错。 -|image21| +|image28| 8.5.10 attach port时ip占用提示 ------------------------------ @@ -285,7 +335,7 @@ IpAddressAlreadyAllocated,而在 neutronclient 只有 IpAddressInUseClient 的异常,并不匹配,在neutronclient 端与neutron 对应的异常应该为 IpAddressAlreadyAllocatedClient 。 -|image22| +|image29| 如何让nova-api能够返回具体的错误信息呢? @@ -296,26 +346,26 @@ IpAddressAlreadyAllocatedClient 异常。 并且在nova 创建port的代码处,捕获这个异常 -|image23| +|image30| 这种要改两个组件,而且要将neutronclient 的代码也管理起来,较为麻烦 一种是,只改neutron,在neutron/ipam/exceptions.py 添加一个与 neutronclient 相对应的异常。 -|image24| +|image31| 然后修改 neutron/ipam/drivers/neutrondb_ipam/drivers.py 修改异常类型 -|image25| +|image32| 通过 postman 进行模拟,已经可以返回具体的信息 -|image26| +|image33| 另附:neutron 是如何判断ip是否已经占用?代码如下 -|image27| +|image34| 8.5.11 nova-compute 如何启动的? -------------------------------- @@ -323,11 +373,11 @@ neutronclient 相对应的异常。 从 /usr/bin/nova-compute 这个文件可以了解到nova-compute的入口是 ``nova.cmd.compute:main()`` -|image28| +|image35| 从这个入口进去,会开启一个 ``nova-compute`` 的服务。 -|image29| +|image36| 当调用 service.Service.create 时(create 是一个工厂函数),实际是返回实例化的 service.Service 对象。当没有传入 @@ -335,20 +385,20 @@ manager 时,就会以binary 里的为准。比如binary 是\ ``nova-compute``\ ,那manager_cls 就是 ``compute_manager``\ ,对应的manager 导入路径,会从配置里读取。 -|image30| +|image37| 8.5.13 支持指定子网和指定ip --------------------------- 在 nova-api 接收请求处。 -|image31| +|image38| -|image32| +|image39| 对 network_info 进行解析,然后塞给 request 对象返回。 -|image33| +|image40| 8.5.14 HTTP 状态码 ------------------ @@ -468,7 +518,7 @@ isolate 一个目录下。这个目录下有一个名为 disk 的qcow2文件,而这个qcow2 文件的backing file 是指向一个 base 镜像文件(raw格式)。 -|image34| +|image41| 8.5.16 独立磁盘与LVM -------------------- @@ -480,7 +530,7 @@ isolate 缺点:无法像 LVM 存储池那样,做到精准而灵活的资源分配,有可能造成资源浪费或资源不足。 -|image35| +|image42| **LVM** @@ -499,14 +549,14 @@ isolate 只要在主机组上设置的metadata 的 key-value 和 extra_spec 的key-value一样就可以实现宿主机的过滤。 -|image36| +|image43| 8.5.18 生成config drive ----------------------- -|image37| +|image44| -|image38| +|image45| :: @@ -526,13 +576,13 @@ isolate nova api 的接口参数是在 nova/api/openstack/compute/schemas/ 目录下,如创建虚拟机的接口如下: -|image39| +|image46| 这些参数字段后面的类型是用来做参数类型的校验的。 在application 函数的头部,可以发现有如下这几种装饰器, -|image40| +|image47| 装饰器里会传入一个参数,就是 schema 的内容,通过它可以约束一个请求内的参数合法性。 @@ -546,11 +596,11 @@ stevedore,它是 oslo 项目中为OpenStack其他项目提供动态加载功能的公共组件库(详细可以看这篇文章:https://blog.csdn.net/bill_xiang_/article/details/78852717)。通过它可以用添加扩展的方式,给 servers 更新 schemas。 -|image41| +|image48| 关键在于这个 map 函数,它会循环所有的扩展() -|image42| +|image49| 将调用传进去的 ``self._create_extension_schema`` 将已加载到的扩展schemas 更新到主schemas里去。 @@ -560,17 +610,17 @@ servers 更新 schemas。 # [ext.obj.name for ext in self.create_schema_manager.extensions] ['MultipleCreate', 'BlockDeviceMapping', 'BlockDeviceMappingV1', 'AvailabilityZone', 'UserData', 'Keypairs', 'SchedulerHints', 'SecurityGroups', 'ConfigDrive'] -|image43| +|image50| 装饰器 schemas 的定义如下: -|image44| +|image51| 比如我们使用的 novaclient 发出的请求,是 v2.3.7的,所以 create() 顶部的五个schema 装饰器,上面四个都会空跑,不会进行校验,只有最后一个才会进入检验逻辑。 -|image45| +|image52| 是不是很呐闷,为什么创建server 的接口,会知道关联上面那9个 schemas,其实那各自代表一种资源,属于扩展资源(它们的中心是核心资源)。 @@ -581,19 +631,19 @@ schemas,其实那各自代表一种资源,属于扩展资源(它们的中 就像下面指明了 server 的 create 接口会去加载这9个扩展资源。 -|image46| +|image53| 搜索一下 server_create 方法 还真的只有这 9 个资源里才会定义。 -|image47| +|image54| 这就神奇了,servers 这个核心资源是如何加载到这些资源的,看了下代码是使用 stevedore 这个模块去动态加载,然后还会校验这些资源是否都有 ``server_create`` ,只有有这个函数,才会被正常加载进来。 -|image48| +|image55| 8.5.20 往数据库中加字段 ----------------------- @@ -642,39 +692,46 @@ stevedore 这个模块去动态加载,然后还会校验这些资源是否都 .. |image11| image:: http://image.python-online.cn/FnJA8RNIvJN2lAEXbKtJDpOLg1vg .. |image12| image:: http://image.python-online.cn/FnGyI8jCQFLCGi0pGVmI3SV6pDrv .. |image13| image:: http://image.python-online.cn/FrbE6oEZ3vtTWwDfMNQ16MGi6SWr -.. |image14| image:: http://image.python-online.cn/20190426153322.png -.. |image15| image:: http://image.python-online.cn/20190426152148.png -.. |image16| image:: http://image.python-online.cn/20190526141815.png -.. |image17| image:: http://image.python-online.cn/20190526142453.png -.. |image18| image:: http://image.python-online.cn/20190526134519.png -.. |image19| image:: http://image.python-online.cn/20190526141226.png -.. |image20| image:: http://image.python-online.cn/20190526134543.png -.. |image21| image:: http://image.python-online.cn/20190526134618.png -.. |image22| image:: http://image.python-online.cn/20190526140213.png -.. |image23| image:: http://image.python-online.cn/20190526140301.png -.. |image24| image:: http://image.python-online.cn/20190526140315.png -.. |image25| image:: http://image.python-online.cn/20190526140336.png -.. |image26| image:: http://image.python-online.cn/20190526140410.png -.. |image27| image:: http://image.python-online.cn/20190526143235.png -.. |image28| image:: http://image.python-online.cn/20190526205152.png -.. |image29| image:: http://image.python-online.cn/20190526165007.png -.. |image30| image:: http://image.python-online.cn/20190526204328.png -.. |image31| image:: http://image.python-online.cn/20190529203441.png -.. |image32| image:: http://image.python-online.cn/20190529215953.png -.. |image33| image:: http://image.python-online.cn/20190529215825.png -.. |image34| image:: http://image.python-online.cn/20190627213044.png -.. |image35| image:: http://image.python-online.cn/20190627213609.png -.. |image36| image:: http://image.python-online.cn/20190627215038.png -.. |image37| image:: http://image.python-online.cn/20190708100902.png -.. |image38| image:: http://image.python-online.cn/20190708103119.png -.. |image39| image:: http://image.python-online.cn/20190719170825.png -.. |image40| image:: http://image.python-online.cn/20190730140551.png -.. |image41| image:: http://image.python-online.cn/20190826210813.png -.. |image42| image:: http://image.python-online.cn/20190826211542.png -.. |image43| image:: http://image.python-online.cn/20190826211737.png -.. |image44| image:: http://image.python-online.cn/20190730142527.png -.. |image45| image:: http://image.python-online.cn/20190730143003.png -.. |image46| image:: http://image.python-online.cn/20190830091540.png -.. |image47| image:: http://image.python-online.cn/20190830092203.png -.. |image48| image:: http://image.python-online.cn/20190830093613.png +.. |image14| image:: http://image.python-online.cn/20190906093751.png +.. |image15| image:: http://image.python-online.cn/20190906094703.png +.. |image16| image:: http://image.python-online.cn/20190906214536.png +.. |image17| image:: http://image.python-online.cn/20190906100119.png +.. |image18| image:: http://image.python-online.cn/20190906213038.png +.. |image19| image:: http://image.python-online.cn/20190906210825.png +.. |image20| image:: http://image.python-online.cn/20190906213823.png +.. |image21| image:: http://image.python-online.cn/20190426153322.png +.. |image22| image:: http://image.python-online.cn/20190426152148.png +.. |image23| image:: http://image.python-online.cn/20190526141815.png +.. |image24| image:: http://image.python-online.cn/20190526142453.png +.. |image25| image:: http://image.python-online.cn/20190526134519.png +.. |image26| image:: http://image.python-online.cn/20190526141226.png +.. |image27| image:: http://image.python-online.cn/20190526134543.png +.. |image28| image:: http://image.python-online.cn/20190526134618.png +.. |image29| image:: http://image.python-online.cn/20190526140213.png +.. |image30| image:: http://image.python-online.cn/20190526140301.png +.. |image31| image:: http://image.python-online.cn/20190526140315.png +.. |image32| image:: http://image.python-online.cn/20190526140336.png +.. |image33| image:: http://image.python-online.cn/20190526140410.png +.. |image34| image:: http://image.python-online.cn/20190526143235.png +.. |image35| image:: http://image.python-online.cn/20190526205152.png +.. |image36| image:: http://image.python-online.cn/20190526165007.png +.. |image37| image:: http://image.python-online.cn/20190526204328.png +.. |image38| image:: http://image.python-online.cn/20190529203441.png +.. |image39| image:: http://image.python-online.cn/20190529215953.png +.. |image40| image:: http://image.python-online.cn/20190529215825.png +.. |image41| image:: http://image.python-online.cn/20190627213044.png +.. |image42| image:: http://image.python-online.cn/20190627213609.png +.. |image43| image:: http://image.python-online.cn/20190627215038.png +.. |image44| image:: http://image.python-online.cn/20190708100902.png +.. |image45| image:: http://image.python-online.cn/20190708103119.png +.. |image46| image:: http://image.python-online.cn/20190719170825.png +.. |image47| image:: http://image.python-online.cn/20190730140551.png +.. |image48| image:: http://image.python-online.cn/20190826210813.png +.. |image49| image:: http://image.python-online.cn/20190826211542.png +.. |image50| image:: http://image.python-online.cn/20190826211737.png +.. |image51| image:: http://image.python-online.cn/20190730142527.png +.. |image52| image:: http://image.python-online.cn/20190730143003.png +.. |image53| image:: http://image.python-online.cn/20190830091540.png +.. |image54| image:: http://image.python-online.cn/20190830092203.png +.. |image55| image:: http://image.python-online.cn/20190830093613.png diff --git a/source/c08/c08_14.rst b/source/c08/c08_14.rst index ab5fea7..d0bd8d2 100644 --- a/source/c08/c08_14.rst +++ b/source/c08/c08_14.rst @@ -291,6 +291,23 @@ centos 6.x 配置网络是在 on_first_boot 函数里,这是 local |image12| +ubuntu 解析网卡配置 + +.. code:: python + + from cloudinit.net import eni + config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') + +|image13| + +8.14.5 其他命令记录 +------------------- + +:: + + # 网络启动不来,先 flush 试一下 + ip addr flush dev ens3 + -------------- .. figure:: http://image.python-online.cn/20190511161447.png @@ -310,4 +327,5 @@ centos 6.x 配置网络是在 on_first_boot 函数里,这是 local .. |image10| image:: http://image.python-online.cn/20190829112446.png .. |image11| image:: http://image.python-online.cn/20190829111917.png .. |image12| image:: http://image.python-online.cn/20190829161243.png +.. |image13| image:: http://image.python-online.cn/20190906091102.png From 95507dacdf032fc1ed18f5a186e96d54d85f80a7 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Wed, 11 Sep 2019 08:18:35 +0800 Subject: [PATCH 022/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20cloudinit=20?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_06.md | 155 +++++++++++++++++++++++++++++++++++++++++-- source/c08/c08_13.md | 19 ++++++ source/c08/c08_14.md | 18 ----- 3 files changed, 170 insertions(+), 22 deletions(-) diff --git a/source/c08/c08_06.md b/source/c08/c08_06.md index dfeb939..3d16f5a 100644 --- a/source/c08/c08_06.md +++ b/source/c08/c08_06.md @@ -370,20 +370,167 @@ myjob.cfg:text/upstart-job +## 8.6.8 模块是怎么执行的 +核心代码在 `_run_modules` 函数里: -查看机器里有哪几张网卡 +```python +# stages.py +def _run_modules(self, mostly_mods): + cc = self.init.cloudify() + # Return which ones ran + # and which ones failed + the exception of why it failed + failures = [] + which_ran = [] + for (mod, name, freq, args) in mostly_mods: + try: + # Try the modules frequency, otherwise fallback to a known one + if not freq: + freq = mod.frequency + if freq not in FREQUENCIES: + freq = PER_INSTANCE + LOG.debug("Running module %s (%s) with frequency %s", + name, mod, freq) + + # Use the configs logger and not our own + # TODO(harlowja): possibly check the module + # for having a LOG attr and just give it back + # its own logger? + func_args = [name, self.cfg, + cc, config.LOG, args] + # Mark it as having started running + which_ran.append(name) + # This name will affect the semaphore name created + run_name = "config-%s" % (name) + + desc = "running %s with frequency %s" % (run_name, freq) + myrep = events.ReportEventStack( + name=run_name, description=desc, parent=self.reporter) + + with myrep: + # 执行模块 + ran, _r = cc.run(run_name, mod.handle, func_args, + freq=freq) + if ran: + myrep.message = "%s ran successfully" % run_name + else: + myrep.message = "%s previously ran" % run_name +``` -ls -l /sys/class/net +上面的 cc.run(),代码如下: +```python +# helpers.py +def run(self, name, functor, args, freq=None, clear_on_fail=False): + + # 获取 sem 文件。 + sem = self._get_sem(freq) + if not sem: + sem = DummySemaphores() + if not args: + args = [] + + # 判断是否已经执行过(准确说是,是否需要执行),具体逻辑可以参考上面 8.6.8 章节的逻辑。 + if sem.has_run(name, freq): + LOG.debug("%s already ran (freq=%s)", name, freq) + return (False, None) + + # 如果需要执行,就在对应的 sem 目录下生成一个文件(锁) + with sem.lock(name, freq, clear_on_fail) as lk: + if not lk: + raise LockFailure("Failed to acquire lock for %s" % name) + else: + LOG.debug("Running %s using lock (%s)", name, lk) + if isinstance(args, (dict)): + # 然后去执行这个模块 + results = functor(**args) + else: + results = functor(*args) + return (True, results) +``` -只查看 ipv4 或 ipv6的网卡ip -ip -6 addr show +## 8.6.9 模块执行的频率 + +在 cloudinit 里的各个模块里,都可以配置执行频率。 + +- PER_ALWAYS:总是执行 +- PER_INSTANCE:每个虚拟机实例一次 +- PER_ONCE:每个镜像只执行一次 + +对于 `PER_INSTANCE` 和 `PER_ONCE` 和区别,从名字和代码实现上看,似乎没有区别,继续看 cloudinit 里的代码,只有一个模块使用了 PER_ONCE ,那就是 `cc_scripts_per_once.py`。 + +![](http://image.python-online.cn/20190910160035.png) + +其实他们还是有区别的,由下面的代码来看 + +- `PER_ONCE` 获取的 sem 文件是从 `/var/lib/cloud/` 下的文件获取的,这个目录一个镜像只会生成一次(若你不删除的话)。 +- `PER_INSTANCE` 获取 sem 文件是从 `/var/lib/cloud/instances/` 下的文件获取的,这个目录每个虚拟机一个。 + +![](http://image.python-online.cn/20190910150305.png) + +如果你的模块里已经配置了频率,则以此为准。若没有配置,则默认为 `PER_INSTANCE`。 + +具体函数:`_run_modules` + +![](http://image.python-online.cn/20190910142222.png) + + + +那么cloudinit 是如何控制模块的执行频率呢? + +通过代码可以发现,其在运行时,会先调用 `has_run` 函数,在这里会去取对应目录下(上面的 sem_path)的sem文件,如果有存在 sem 文件,说明已经执行过(返回 False ),如果不存在 sem 文件(返回 True) 说明未执行过。 + +![](http://image.python-online.cn/20190910153637.png) + +sem 文件是怎样的? + +这是 `PER_ONCE` 的 sem 文件: + +![](http://image.python-online.cn/20190910171359.png) +这是 `PER_INSTANCE` 的 sem 文件![](http://image.python-online.cn/20190910171538.png) + + + +## 8.6.10 如何解析网卡配置 + +ubuntu 的网卡配置不是正常我们常见的 json 或者 yaml 格式,若要将其转化成python的字典对象。这在cloudinit是怎么做的呢? + +将这个功能拿出来 ,你可以这样用。 + +```python +from cloudinit.net import eni +config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') +``` + +![](http://image.python-online.cn/20190906091102.png) + +## 8.6.11 低版本的日志输出 + +如果你用过 centos6.x 的 cloudinit,你会发现其根本不会将日志输出到 `/var/log/cloud-init.log `中。 + +经过排查,你可以在 `cloudinit/log.py` 中按下面的改法修改解决 + +![](http://image.python-online.cn/20190909172153.png) + +## 8.6.11 相关命令 + +```shell +# 查看机器里有哪几张网卡 +ls -l /sys/class/net + +# 只查看 ipv4 或 ipv6的网卡ip +ip -6 addr show ip -4 addr show +# 网络启动不来,先 flush 试一下 +ip addr flush dev ens3 +``` + + + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/c08/c08_13.md b/source/c08/c08_13.md index d86ee9b..d585fca 100644 --- a/source/c08/c08_13.md +++ b/source/c08/c08_13.md @@ -243,6 +243,25 @@ arp -e -i eth1 arp -f /etc/ethers ``` +## 8.13.3 ovs 流表 + +使用 `ovs-ofctl dump-flows br-int` 可以查看从 br-int 到 br0-ovs 的流表。 + +查看 `0x0000/0x1fff` 这一行后的 `actions=mod_vlan_vid:4` ,其中的 `4` 是vlan id,意思是从虚拟机的网卡出来的包如果tag=4,在经过 br0-ovs 的时候,就会把 tag 去掉,不会被过滤掉,使其能把包发向公网。 + +假如不设置tag,br-int 上的包就不会流往 br0-ovs。 + +假如你的虚拟机是连在 br-int 上,而且没有tag,那么需要你手动加tag + +``` +virsh domiflist vm_domain +ovs-vsctl set port vnet0 tag=4 +``` + + + + + --- diff --git a/source/c08/c08_14.md b/source/c08/c08_14.md index aa705b3..c0ee5e7 100644 --- a/source/c08/c08_14.md +++ b/source/c08/c08_14.md @@ -293,24 +293,6 @@ centos 6.x 配置网络是在 on_first_boot 函数里,这是 local 阶段就 -ubuntu 解析网卡配置 - -```python -from cloudinit.net import eni -config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') -``` - -![](http://image.python-online.cn/20190906091102.png) - -## 8.14.5 其他命令记录 - - - -``` -# 网络启动不来,先 flush 试一下 -ip addr flush dev ens3 -``` - --- From c1dc74269925d2302a2c5c85f77b4f74b9af6a4b Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Wed, 11 Sep 2019 21:19:55 +0800 Subject: [PATCH 023/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20cloudinit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_06.md | 229 ++++++++++++++++++++++++++++--------------- 1 file changed, 151 insertions(+), 78 deletions(-) diff --git a/source/c08/c08_06.md b/source/c08/c08_06.md index 3d16f5a..656ff4c 100644 --- a/source/c08/c08_06.md +++ b/source/c08/c08_06.md @@ -116,84 +116,6 @@ find_source 是通过一个一个去执行 对应source模块的 get_data(), -## 8.6.4 网络是如何配置的? - -在不同的 cloudinit 版本中,网络配置部分的代码是不同的。 - -首先要知道,配置网络是在 `on_first_boot` 函数里配置的。它是在cloudinit 判断该机器为新虚拟机时才会执行。也就是说,这个网络配置在一个虚拟机生命周期里,只会执行一次,如果要二次执行,需要执行 `rm -rf /var/lib/cloud` ,将缓存数据删除,这边才会重新认定为新虚拟机。 - -在 CentOS6.x (cloud-init 0.7.5)中,网络信息的读取与配置都是在且仅能在 local 阶段进行的,代码如下,只在 dsmode 为 local 时才会执行 on_first_boot。 - -![](http://image.python-online.cn/20190429104357.png) - -而在 CentOS7.x (cloud-init 0.7.9)中 或者 Ubuntu 16.04(cloud-init 17.1)中,配置网络不是在 on_first_boot 函数里,而是在 stages.py:apply_network_config() 里。 - -![](http://image.python-online.cn/20190829141059.png) - -并且新版的cloudinit ,local 和 init 阶段都会去配置网络,区别在于,local阶段只写配置文件,而init阶段不仅写配置文件,还会启动网卡,将ip配置上。 - -centos 7.x ,因为会跳过,它是在 stages.py:apply_network_config 函数里,这是在 local 阶段写入配置文件,而在 init 阶段 启动网卡。 - -![](http://image.python-online.cn/20190829113537.png) - -所以如果要调试的话可以直接执行 init 阶段。 - -而如果是虚拟机重启的话,是在stages.py 这边判断是否为新虚拟机的,这也和旧版本有所区别。 - -![](http://image.python-online.cn/20190829141059.png) - -为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 - -在 cloud-init 的比较重要的几个文件有: - -- 入口文件(上面已经说明过了) -- stages.py -- distros/rhel.py -- sources/DataSourceConfigDrive.py - -在网络配置这块,有几个大坑。 - -**坑一** - -如果是按照旧虚拟机创建新的快照镜像,然后使用这个镜像创建新的虚拟机,有可能会在同一块网卡上出现新旧两个ip,这是因为虚拟机在启动过程中,会先读取原网络配置配置ip,然后才会运行 cloud-init 进行新ip的配置,而新ip的配置是使用 `ifup` 这个命令![](http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d) - -使用这种方式并不会将第一次配置的旧ip给清除掉。![](http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c) - -这个问题,目前我只在CentOS6 中遇到过。可以通过修改代码让其先 `ifdown` 再 `ifup` 就可以解决这个问题。![](http://image.python-online.cn/20190430231812.png) - -**坑二** - -如果使用dhcp,cloudinit不会创建或者刷新网卡配置文件,而把配置ip交由 NetworkManager ,让它自动获取。这是很重要。所以如果你用旧虚拟机创建快照的方式做镜像,然后用这个镜像创建的虚拟机会有旧虚拟机的配置文件会暴露原机器的ip地址。 - -具体的创建逻辑是在这 - -![](http://image.python-online.cn/20190430232309.png) - -**坑三** - -在 CentOS 6 上,安装NetworkManager 时不会安装完整。 - -会导致两个问题,一个是在启动时,会提示无法加载插件,导致启动失败。 - -``` -Apr 29 11:13:29 localhost NetworkManager[1365]: Loaded plugin keyfile: (cc -) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailinn -g list. -Apr 29 11:13:29 localhost NetworkManager[1365]: [1556507609.466522] [maii -n.c:708] main(): failed to initialize the network manager: Could not load pluginn - 'ibft': /usr/lib64/NetworkManager/libnm-settings-plugin-ibft.so: undefined symbb -ol: g_slist_free_full -Apr 29 11:13:29 localhost NetworkManager[1365]: exiting (error) -``` - -一个是会自动DHCP获取到一个以ip命名的hostname,并将原来的覆盖掉。 - -![](http://image.python-online.cn/20190429205735.png) - -为了避免出现这些情况,请务必保证这些包都安装完整(左为 CentOS 7.2,右为 CentOS 6.5)。 - -![](http://image.python-online.cn/20190430232911.png) - ## 8.6.5 userdata 使用说明 现在 Userdate 可以支持如下三种格式 @@ -515,6 +437,157 @@ config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') ![](http://image.python-online.cn/20190909172153.png) +## 8.6.12 旧版本网络配置的三个巨坑 + +在不同的 cloudinit 版本中,网络配置部分的代码是不同的。 + +首先要知道,配置网络是在 `on_first_boot` 函数里配置的。它是在cloudinit 判断该机器为新虚拟机时才会执行。也就是说,这个网络配置在一个虚拟机生命周期里,只会执行一次,如果要二次执行,需要执行 `rm -rf /var/lib/cloud` ,将缓存数据删除,这边才会重新认定为新虚拟机。 + +这里仅以 cloudinit 0.7.5 ( CentOS6.x)的版本为例。 + +在 cloud-init 0.7.5中,网络信息的读取与配置都是在且仅能在 local 阶段进行的,代码如下,只在 dsmode 为 local 时才会执行 on_first_boot。 + +![](http://image.python-online.cn/20190429104357.png) + +而如果是虚拟机重启的话,是在stages.py 这边判断是否为新虚拟机的,这也和旧版本有所区别。 + +![](http://image.python-online.cn/20190829141059.png) + +为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 + +在 cloud-init 的比较重要的几个文件有: + +- 入口文件(上面已经说明过了) +- stages.py +- distros/rhel.py +- sources/DataSourceConfigDrive.py + +在网络配置这块,有几个大坑。 + +**坑一** + +如果是按照旧虚拟机创建新的快照镜像,然后使用这个镜像创建新的虚拟机,有可能会在同一块网卡上出现新旧两个ip,这是因为虚拟机在启动过程中,会先读取原网络配置配置ip,然后才会运行 cloud-init 进行新ip的配置,而新ip的配置是使用 `ifup` 这个命令![](http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d) + +使用这种方式并不会将第一次配置的旧ip给清除掉。![](http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c) + +这个问题,目前我只在CentOS6 中遇到过。可以通过修改代码让其先 `ifdown` 再 `ifup` 就可以解决这个问题。![](http://image.python-online.cn/20190430231812.png) + +**坑二** + +如果使用dhcp,cloudinit不会创建或者刷新网卡配置文件,而把配置ip交由 NetworkManager ,让它自动获取。这是很重要。所以如果你用旧虚拟机创建快照的方式做镜像,然后用这个镜像创建的虚拟机会有旧虚拟机的配置文件会暴露原机器的ip地址。 + +具体的创建逻辑是在这 + +![](http://image.python-online.cn/20190430232309.png) + +**坑三** + +在 CentOS 6 上,安装NetworkManager 时不会安装完整。 + +会导致两个问题,一个是在启动时,会提示无法加载插件,导致启动失败。 + +``` +Apr 29 11:13:29 localhost NetworkManager[1365]: Loaded plugin keyfile: (cc +) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailinn +g list. +Apr 29 11:13:29 localhost NetworkManager[1365]: [1556507609.466522] [maii +n.c:708] main(): failed to initialize the network manager: Could not load pluginn + 'ibft': /usr/lib64/NetworkManager/libnm-settings-plugin-ibft.so: undefined symbb +ol: g_slist_free_full +Apr 29 11:13:29 localhost NetworkManager[1365]: exiting (error) +``` + +一个是会自动DHCP获取到一个以ip命名的hostname,并将原来的覆盖掉。 + +![](http://image.python-online.cn/20190429205735.png) + +为了避免出现这些情况,请务必保证这些包都安装完整(左为 CentOS 7.2,右为 CentOS 6.5)。 + +![](http://image.python-online.cn/20190430232911.png) + +## + +## 8.6.13 网络是如何启动的?(新版本) + +这里仅以 cloudinit 18.5 的版本为例。 + +通过查看代码主流程时,获取ds的时候,有一个参数是 existing,它有两个值: + +- trust:说明 ds 的缓存是可以相信的,不用再去校验 instance_uuid +- check:说明会去校验 instance_uuid,如果相同直接返回 ds 的缓存,如果不同则返回None,让后的步骤再去从 CD-ROM 读取最新的。 + +在 local 阶段的时候,`existing` 是 `check` ,这是合理的。 + +![](http://image.python-online.cn/20190911175423.png) + +![](http://image.python-online.cn/20190911174648.png) + +在local阶段,on_first_boot 的函数 network 是 False ,所以这里也不会写网卡配置文件,自然也不会配置。 + +![](http://image.python-online.cn/20190911173615.png) + +![](http://image.python-online.cn/20190911195024.png) + + + +再往后面看,就可以发现,原来写配置文件的地方是在 `cmd/main.py` 里。 + +```python +# cmd/main.py +mode = sources.DSMODE_LOCAL if args.local else sources.DSMODE_NETWORK + +# 中间省略多行代码 ... +init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL)) +``` + +第一行,如果是 local 阶段,mode 为 local,bring_up 为 False,意思是只写配置文件,而不启用网卡。 + +等到 init 阶段时,mode 为 net (`sources.DSMODE_NETWORK`)时,bring_up 为 True,意思是会启用网卡,配置ip。 + +网卡网卡的主要函数在下面 `apply_network_config` 这个函数里,这个函数主要做三个事情: + +1. 获取网卡配置 +2. 校正网卡名,以 ConfigDrive 的配置为准 +3. 将ip信息写入配置文件,并启动网卡 + +![](http://image.python-online.cn/20190911202425.png) + +那它是如何对网卡进行重命令的呢?看了代码,其实是用ip命令实现的。 + +![](http://image.python-online.cn/20190911202551.png) + +提取出来其实就三条命令,要注意的是,这三条命令执行是有顺序的 + +``` +1. ip link set ens3 down +2. ip link set ens3 name eth0 +3. ip link set eth0 up +``` + +还有一点要说的是,cloudinit 是如何取到本机真实的网卡信息的呢?他是从 `/sys/class/net/` 目录下获取的。每个网卡一个目录,每个目录下都有相应的文件记录相应的信息,比如 `/sys/class/net/ens3/address` 记录的是网卡的 mac 地址。 + +![](http://image.python-online.cn/20190911203953.png) + +接下来就要开始配置网络了,先写网络配置文件,再根据参数选择是否启用网络。 + +![](http://image.python-online.cn/20190911204805.png) + +如果是重启虚拟机或者 init 阶段进入这里呢,会不会又重复配置网络了呢? + +答案是:不会的。 + +cloudinit 会根据缓存中的虚拟机的uuid来与ConfigDrive 的对比,如果不一样,则认为这台虚拟机是新创建的虚拟机,只有新的虚拟机才会走入这里去配置网络。 + +![](http://image.python-online.cn/20190911205518.png) + +那问题又来了,虽然上面有个 bring_up 的参数,实际上,通过代码可以发现,在 local 阶段,bring_up 为 False 不会去启用网卡,而在 init 阶段呢,虽然 bring_up 为 True,但是此时,经过 local 阶段后,代码逻辑会认为这是台旧虚拟机,不会再走后面配置网络的函数,那就很奇怪了,网卡的ip是如何配置上的呢? + +这是个好问题,也是个很难察觉的点。 + +大多数人,可能不知道linux内部的服务是有启动顺序的。在这种情况下,我们必须保证,cloudinit 写入配置的服务(cloud-init-local)必须在 network 或者 Network-Manager 的服务之前。 + +这样在 cloud-init-local 执行完后,就会自动配置上网络了。 + ## 8.6.11 相关命令 ```shell From 02099c852ac80112b5eea193fe02306c013d8219 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Mon, 30 Sep 2019 08:59:21 +0800 Subject: [PATCH 024/227] =?UTF-8?q?ubuntu=20=E4=BD=BF=E7=94=A8=20ipv6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_14.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/source/c08/c08_14.md b/source/c08/c08_14.md index c0ee5e7..7e4d2f4 100644 --- a/source/c08/c08_14.md +++ b/source/c08/c08_14.md @@ -293,6 +293,38 @@ centos 6.x 配置网络是在 on_first_boot 函数里,这是 local 阶段就 +## 8.14.5 ubuntu禁用ipv6 + +如果你给你的ubuntu配置上了ipv6的ip,那当你使用 apt-get install 软件包的时候,会使用ipv6去源安装,这将会使你的安装过程卡住: + +![](http://image.python-online.cn/20190926171038.png) + +如何解决这个问题呢? + +参考文章:https://ubuntuqa.com/article/1577.html + +我使用的方法是 + +在终端中运行以下命令禁用IPv6,`0`表示已启用,而`1`表示已禁用。 + +``` +echo 1>/proc/sys/net/ipv6/conf/all/disable_ipv6 +``` + +然后在终端内禁用IPv6,需要再输入以下内容: + +``` +echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf +echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf +echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf +echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf +sudo sysctl -p +``` + + + + + --- From 2b3d07a8cbb7042d229f608d9d60533acf357520 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Mon, 30 Sep 2019 09:00:01 +0800 Subject: [PATCH 025/227] =?UTF-8?q?cloudinit=20=E5=A6=82=E4=BD=95=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=AE=A2=E6=88=B7=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_06.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/source/c08/c08_06.md b/source/c08/c08_06.md index 656ff4c..b77036e 100644 --- a/source/c08/c08_06.md +++ b/source/c08/c08_06.md @@ -192,7 +192,8 @@ ws_virt_network_dep: netmask: 255.255.255.0 gateway: 192.168.3.254 - +# 会将这些命令写入如下文件,但是并没有执行 +# /var/lib/cloud/instances/25be4404-4665-4b64-91cc-3289cf2a0af0/scripts/runcmd runcmd: - [ sed, -i, -e, '%s/x/y/g', some_file] - echo "modified some_file" @@ -505,8 +506,6 @@ Apr 29 11:13:29 localhost NetworkManager[1365]: exiting (error) ![](http://image.python-online.cn/20190430232911.png) -## - ## 8.6.13 网络是如何启动的?(新版本) 这里仅以 cloudinit 18.5 的版本为例。 @@ -588,7 +587,26 @@ cloudinit 会根据缓存中的虚拟机的uuid来与ConfigDrive 的对比,如 这样在 cloud-init-local 执行完后,就会自动配置上网络了。 -## 8.6.11 相关命令 +## 8.6.14 在虚拟机启动时执行命令 + +cloudinit 允许通过 user_data 指定你想在虚拟机启动时,执行的命令。 + +``` +# 会将这些命令写入如下文件,但是并没有执行 +# +runcmd: + - [ sed, -i, -e, '%s/x/y/g', some_file] + - echo "modified some_file" + - [cat, some_file] +``` + +当你进行了如此配置后,cloudinit 会通过 runcmd 模块,将这些命令组合起来写入 `/var/lib/cloud/instances//scripts/runcmd`。 + +但这仅仅只是写入,若要执行这些命令,还需要你在 /etc/cloud/cloud.cfg 中配置 `scripts_user`,这样 cloud-init 才会去执行它。 + + + +## 8.6.15 相关命令 ```shell # 查看机器里有哪几张网卡 From 80c8d2dceaaa3dfe635fbba9b9d1966fed258834 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Mon, 30 Sep 2019 09:00:18 +0800 Subject: [PATCH 026/227] =?UTF-8?q?openstack=20=E5=A6=82=E4=BD=95=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c08/c08_05.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index f491897..8e6eea4 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -613,7 +613,15 @@ nova-manage db sync +## 8.5.21 如何加action +``` +self._record_action_start(context, instance, instance_actions.REBOOT) +``` + +## 8.5.22 如何生成ConfigDrive + +![](http://image.python-online.cn/20190912135302.png) --- From 8010473e3ff763c5bb6ecbc20f22304b4d3a5db9 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 6 Oct 2019 19:24:25 +0800 Subject: [PATCH 027/227] update --- source/c01/c01_10.md | 23 ++++++++++++++--------- source/c01/c01_21.md | 6 ++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/c01/c01_10.md b/source/c01/c01_10.md index bc0811d..1056def 100644 --- a/source/c01/c01_10.md +++ b/source/c01/c01_10.md @@ -972,7 +972,7 @@ hello hello ``` -如果你用单`\`结尾是会报语法错误。 +但是如果你用单`\`结尾是会报语法错误的 ```python >>> str3="\" @@ -980,8 +980,11 @@ hello str3="\" ^ SyntaxError: EOL while scanning string literal ->>> ->>> +``` + +就算你指定它是个 raw 字符串,也不行。 + +```python >>> str3=r"\" File "", line 1 str3=r"\" @@ -1006,10 +1009,6 @@ b ['a', 'b'] ``` - - - - ## 33. 更新字典 通常我们更新字典的方式是这样的 @@ -1031,8 +1030,6 @@ b {'namne': 'jane', 'gender': 'male', 'age': 24} ``` - - ## 34. 嵌套上下文管理的另类写法 当我们要写一个嵌套的上下文管理器时,可能会这样写 @@ -1099,6 +1096,14 @@ with test_context('aaa'), test_context('bbb'): +## 36. Python 里也可以有 end + +有不少编程语言,循环、判断代码块需要用 end 标明结束,这样一定程序上会使代码逻辑更加清晰一点,其实这种语法在 Python 里并没有必要,但如果你想用,也不是没有办法,具体你看下面这个例子。 + +![](http://image.python-online.cn/20190915213412.png) + + + ## 附录:参考文章 - [wtfpython](https://github.com/satwikkansal/wtfpython) diff --git a/source/c01/c01_21.md b/source/c01/c01_21.md index 9b1893f..d35190f 100644 --- a/source/c01/c01_21.md +++ b/source/c01/c01_21.md @@ -8,3 +8,9 @@ 解决网页不能右键,在console中输入:document.oncontextmenu=true ``` +在 linux 上看 json 文件 + +``` +cat test.json | python -m json.tool +``` + From 7142b6b8d3d705819cef874d9aa45fa79a3b18cf Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 6 Oct 2019 19:24:36 +0800 Subject: [PATCH 028/227] =?UTF-8?q?=E5=AD=A6=E4=B9=A0js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c01/c01_23.md | 125 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 source/c01/c01_23.md diff --git a/source/c01/c01_23.md b/source/c01/c01_23.md new file mode 100644 index 0000000..495309a --- /dev/null +++ b/source/c01/c01_23.md @@ -0,0 +1,125 @@ +# 1.23 Pythonista 学习 Js + +1. JavaScript的设计者希望用`null`表示一个空的值,而`undefined`表示值未定义。事实证明,这并没有什么卵用,区分两者的意义不大。大多数情况下,我们都应该用`null`。`undefined`仅仅在判断函数参数是否传递的情况下有用。 + + + +2. 在JavaScript中,使用等号`=`对变量进行赋值。可以把任意数据类型赋值给变量,同一个变量可以反复赋值,而且可以是不同类型的变量,但是要注意只能用`var`申明一次。 + + + +3. var 申明的变量不是全局变量,如果不使用 var 申明变量,就会变成全局变量,多个js文件会共享这个变量,互相影响。这个语言设计弊端,在 ECMA 推出 strict 模式后得到解决,不使用 var 申明变量的会运行出错。 + + + +4. 直接操作数组的长度,或者对超出数组长度的索引赋值,可以扩容和压缩数组的大小。 + + + +5. 对象之间的比较和Python差异巨大,`=` 表示值的比较,`===` 表示对象类型的比较,主要分为下面三种情况: + + ```javascript + // 1. 对于string,number等【基础类型】,==和===是有区别的。 + // 如果是不同类型,== 会将两边转化成同一类型再看值是否相等 + // 如果是相同类型,直接对值进行比较。 + alert('1'==1);//结果是true + alert('1'===1);//结果是false + + + // 2. 如果是 Array,Object等高级类型,==和===是没有区别的。 + // 直接比较指针地址。,跟 Python 里的 is 等同。 + + + // 3. 基础类型与高级类型,==和===是有区别的。 + // 对于==,将高级转化为基础类型,进行“值”比较。 + // 因为类型不同,===结果为false。 + var a = new String('1');//定义一个string的高级类型 + var b = '1';//定一个基础类型字符串 + alert(b==a);//为true + alert(b===a);//为false + ``` + +6. 定义一个函数,其参数个数可以少于传入的参数个数,基于可以不定义参数,还可以传入参数。那传入的多余的参数如何获取呢?可以使用 arguments 这个变量取得所有的参数,但这个变量仅在参数内起作用。 + + ```python + function foo(a, b, ...rest) { + console.log('a = ' + a); + console.log('b = ' + b); + console.log(rest); + } + ``` + +7. JavaScript的函数定义有个特点,它会先扫描整个函数体的语句,把所有申明的变量“提升”到函数顶部,但是并不会提前为变量赋值。 + + ```javascript + 'use strict'; + + function foo() { + var x = 'Hello, ' + y; + console.log(x); + var y = 'Bob'; + } + + foo(); + + // 对于 javascript 引擎,看到代码相当于 + function foo() { + var y; // 提升变量y的申明,此时y为undefined + var x = 'Hello, ' + y; + console.log(x); + y = 'Bob'; + } + ``` + + + +8. This有个巨坑,需要新手注意。 + + 如下,当没有 `var that = this;` 这句时,函数内部的函数里的this指向的是 window 对象。 + + ```javascript + 'use strict'; + + var xiaoming = { + name: '小明', + birth: 1990, + age: function () { + var that = this; // 在方法内部一开始就捕获this + function getAgeFromBirth() { + var y = new Date().getFullYear(); + return y - that.birth; // 用that而不是this + } + return getAgeFromBirth(); + } + }; + + xiaoming.age(); // 25 + ``` + + 或者,可以用 apply 的方法来解决这个问题,apply 的第一个参数是人该函数要绑定的对象,第二个参数是一个列表,装的是要传递给这个函数据参数。 + + ```javascript + function getAge() { + var y = new Date().getFullYear(); + return y - this.birth; + } + + var xiaoming = { + name: '小明', + birth: 1990, + age: getAge + }; + + xiaoming.age(); // 29 + getAge.apply(xiaoming, []); // 29, this指向xiaoming, 参数为空 + ``` + + 假如,不想绑定给任何对象,第一个参数可以用 null。如 + + ```javascript + Math.max.apply(null, [3, 5, 4]); // 5 + Math.max.call(null, 3, 5, 4); // 5 + ``` + + + From 2047786af0de93c75ed821df1e7e0762b508c005 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 6 Oct 2019 19:26:09 +0800 Subject: [PATCH 029/227] =?UTF-8?q?=E6=B7=BB=E5=8A=A0k8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c07/c07_11.md | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 source/c07/c07_11.md diff --git a/source/c07/c07_11.md b/source/c07/c07_11.md new file mode 100644 index 0000000..678bebb --- /dev/null +++ b/source/c07/c07_11.md @@ -0,0 +1,88 @@ +# 7.11 K8S:基础入门 + +一些基础命令 + +``` +# 启动cluster +minikube start + +# 查看集群信息 +kubectl cluster-info + +# 部署应用 +kubectl run kubernetes-bootcamp \ + --image=docker.io/jocatalin/kubernetes-bootcamp:v1 \ + --port=8080 + +# 查看所有的 deployments,在这里可以看到应用副本数 +kubectl get deployments + + +# 增加副本数 +kubectl scale deployments/kubernetes-bootcamp --replicas=3 +# 若要 scale down,就将 replicas 数值减小 +kubectl scale deployments/kubernetes-bootcamp --replicas=2 + +# 查看所有的副本 +kubectl get pods + +# 查看集群下的节点 +kubectl get nodes + +# 查看集群下的服务 +kubectl get services +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +kubernetes ClusterIP 10.96.0.1 443/TCP 19m +kubernetes-bootcamp NodePort 10.100.191.46 8080:30141/TCP 12s + +# 添加端口映射,主机上的端口是随机分配的 +kubectl expose deployment/kubernetes-bootcamp \ + --type="NodePort" \ + --port 8080 + +# 上面的 bootcamp 有两个副本,当我们curl访问应用时,请求会随机发到三个pod里 +# 其中 minikube 是该主机的 hostname,30141 是上面随机分配的端口号 +curl minikube:30141 + + +# 升级应用,从上面的 v1 升级到 v2,使用 get pods 可以发现这是一个删除再创建的过程。 +kubectl set image deployments/kubernetes-bootcamp \ + kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2 + +# 回退,升级后后悔了,可以再回退到 之前的 v1 版本。 +kubectl rollout undo deployments/kubernetes-bootcamp + +# 查看 namespace,kubernetes 默认创建了两个 +# default -- 创建资源时如果不指定,将被放到这个 Namespace 中。 +# kube-system -- Kubernetes 自己创建的系统资源将放到这个 Namespace 中。 +kubectl get namespace + + +``` + + + +K8s 角色详解 + +![](http://image.python-online.cn/20190907162015.png) + +其中 Controller 还分为几种: + +1. Deployment:最常用的 Controller +2. ReplicaSet:实现 Pod 的多副本管理,一般不会直接使用 +3. Daemonset:用于运行 Daemon +4. StatefuleSet:保证每个副本的名称不变及启动/更新/删除顺序 +5. Job:用于运行完即删除的应用。 + +一个 Pod 里可以运行一个容器(最常用),也可以运行多个容器,若运行多个容器,那这几个容器的工作必定有着紧密的联系,而且需要直接 **共享资源**。 + + + + + + + + + + + From cb6fa5a967b76a51f45cec0eeafd6d2484c6e4aa Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Sun, 6 Oct 2019 19:27:48 +0800 Subject: [PATCH 030/227] make rst --- source/c01/c01_10.rst | 19 +- source/c01/c01_21.rst | 6 + source/c01/c01_23.rst | 119 ++++++++++ source/c07/c07_11.rst | 79 +++++++ source/c08/c08_05.rst | 13 ++ source/c08/c08_06.rst | 503 ++++++++++++++++++++++++++++++++---------- source/c08/c08_13.rst | 19 ++ source/c08/c08_14.rst | 33 ++- 8 files changed, 665 insertions(+), 126 deletions(-) create mode 100644 source/c01/c01_23.rst create mode 100644 source/c07/c07_11.rst diff --git a/source/c01/c01_10.rst b/source/c01/c01_10.rst index 141a60e..960bb93 100755 --- a/source/c01/c01_10.rst +++ b/source/c01/c01_10.rst @@ -1080,7 +1080,7 @@ import 是 Python 导包的方式。 >>> print(str2) hello -如果你用单\ ``\``\ 结尾是会报语法错误。 +但是如果你用单\ ``\``\ 结尾是会报语法错误的 .. code:: python @@ -1089,8 +1089,11 @@ import 是 Python 导包的方式。 str3="\" ^ SyntaxError: EOL while scanning string literal - >>> - >>> + +就算你指定它是个 raw 字符串,也不行。 + +.. code:: python + >>> str3=r"\" File "", line 1 str3=r"\" @@ -1204,6 +1207,15 @@ import 是 Python 导包的方式。 >>> b [1, 2, 3, 4, 5, 6, 7, 8] +36. Python 里也可以有 end +------------------------- + +有不少编程语言,循环、判断代码块需要用 end +标明结束,这样一定程序上会使代码逻辑更加清晰一点,其实这种语法在 Python +里并没有必要,但如果你想用,也不是没有办法,具体你看下面这个例子。 + +|image3| + 附录:参考文章 -------------- @@ -1218,4 +1230,5 @@ import 是 Python 导包的方式。 .. |image0| image:: http://image.python-online.cn/20190511165650.png .. |image1| image:: http://image.python-online.cn/20190511165716.png .. |image2| image:: http://image.python-online.cn/20190511165735.png +.. |image3| image:: http://image.python-online.cn/20190915213412.png diff --git a/source/c01/c01_21.rst b/source/c01/c01_21.rst index 5f99c9f..f76a2f6 100644 --- a/source/c01/c01_21.rst +++ b/source/c01/c01_21.rst @@ -8,3 +8,9 @@ 解决网页不能选中,在console中输入:document.onselectstart=true 解决网页不能复制,在console中输入:document.oncopy=true 解决网页不能右键,在console中输入:document.oncontextmenu=true + +在 linux 上看 json 文件 + +:: + + cat test.json | python -m json.tool diff --git a/source/c01/c01_23.rst b/source/c01/c01_23.rst new file mode 100644 index 0000000..4174cbd --- /dev/null +++ b/source/c01/c01_23.rst @@ -0,0 +1,119 @@ +1.23 Pythonista 学习 Js +======================= + +1. JavaScript的设计者希望用\ ``null``\ 表示一个空的值,而\ ``undefined``\ 表示值未定义。事实证明,这并没有什么卵用,区分两者的意义不大。大多数情况下,我们都应该用\ ``null``\ 。\ ``undefined``\ 仅仅在判断函数参数是否传递的情况下有用。 + +2. 在JavaScript中,使用等号\ ``=``\ 对变量进行赋值。可以把任意数据类型赋值给变量,同一个变量可以反复赋值,而且可以是不同类型的变量,但是要注意只能用\ ``var``\ 申明一次。 + +3. var 申明的变量不是全局变量,如果不使用 var + 申明变量,就会变成全局变量,多个js文件会共享这个变量,互相影响。这个语言设计弊端,在 + ECMA 推出 strict 模式后得到解决,不使用 var 申明变量的会运行出错。 + +4. 直接操作数组的长度,或者对超出数组长度的索引赋值,可以扩容和压缩数组的大小。 + +5. 对象之间的比较和Python差异巨大,\ ``=`` 表示值的比较,\ ``===`` + 表示对象类型的比较,主要分为下面三种情况: + + .. code:: javascript + + // 1. 对于string,number等【基础类型】,==和===是有区别的。 + // 如果是不同类型,== 会将两边转化成同一类型再看值是否相等 + // 如果是相同类型,直接对值进行比较。 + alert('1'==1);//结果是true + alert('1'===1);//结果是false + + + // 2. 如果是 Array,Object等高级类型,==和===是没有区别的。 + // 直接比较指针地址。,跟 Python 里的 is 等同。 + + + // 3. 基础类型与高级类型,==和===是有区别的。 + // 对于==,将高级转化为基础类型,进行“值”比较。 + // 因为类型不同,===结果为false。 + var a = new String('1');//定义一个string的高级类型 + var b = '1';//定一个基础类型字符串 + alert(b==a);//为true + alert(b===a);//为false + +6. 定义一个函数,其参数个数可以少于传入的参数个数,基于可以不定义参数,还可以传入参数。那传入的多余的参数如何获取呢?可以使用 + arguments 这个变量取得所有的参数,但这个变量仅在参数内起作用。 + + .. code:: python + + function foo(a, b, ...rest) { + console.log('a = ' + a); + console.log('b = ' + b); + console.log(rest); + } + +7. JavaScript的函数定义有个特点,它会先扫描整个函数体的语句,把所有申明的变量“提升”到函数顶部,但是并不会提前为变量赋值。 + + .. code:: javascript + + 'use strict'; + + function foo() { + var x = 'Hello, ' + y; + console.log(x); + var y = 'Bob'; + } + + foo(); + + // 对于 javascript 引擎,看到代码相当于 + function foo() { + var y; // 提升变量y的申明,此时y为undefined + var x = 'Hello, ' + y; + console.log(x); + y = 'Bob'; + } + +8. This有个巨坑,需要新手注意。 + + 如下,当没有 ``var that = this;`` + 这句时,函数内部的函数里的this指向的是 window 对象。 + + .. code:: javascript + + 'use strict'; + + var xiaoming = { + name: '小明', + birth: 1990, + age: function () { + var that = this; // 在方法内部一开始就捕获this + function getAgeFromBirth() { + var y = new Date().getFullYear(); + return y - that.birth; // 用that而不是this + } + return getAgeFromBirth(); + } + }; + + xiaoming.age(); // 25 + + 或者,可以用 apply 的方法来解决这个问题,apply + 的第一个参数是人该函数要绑定的对象,第二个参数是一个列表,装的是要传递给这个函数据参数。 + + .. code:: javascript + + function getAge() { + var y = new Date().getFullYear(); + return y - this.birth; + } + + var xiaoming = { + name: '小明', + birth: 1990, + age: getAge + }; + + xiaoming.age(); // 29 + getAge.apply(xiaoming, []); // 29, this指向xiaoming, 参数为空 + + 假如,不想绑定给任何对象,第一个参数可以用 null。如 + + .. code:: javascript + + Math.max.apply(null, [3, 5, 4]); // 5 + Math.max.call(null, 3, 5, 4); // 5 diff --git a/source/c07/c07_11.rst b/source/c07/c07_11.rst new file mode 100644 index 0000000..19b278b --- /dev/null +++ b/source/c07/c07_11.rst @@ -0,0 +1,79 @@ +7.11 K8S:基础入门 +================== + +一些基础命令 + +:: + + # 启动cluster + minikube start + + # 查看集群信息 + kubectl cluster-info + + # 部署应用 + kubectl run kubernetes-bootcamp \ + --image=docker.io/jocatalin/kubernetes-bootcamp:v1 \ + --port=8080 + + # 查看所有的 deployments,在这里可以看到应用副本数 + kubectl get deployments + + + # 增加副本数 + kubectl scale deployments/kubernetes-bootcamp --replicas=3 + # 若要 scale down,就将 replicas 数值减小 + kubectl scale deployments/kubernetes-bootcamp --replicas=2 + + # 查看所有的副本 + kubectl get pods + + # 查看集群下的节点 + kubectl get nodes + + # 查看集群下的服务 + kubectl get services + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + kubernetes ClusterIP 10.96.0.1 443/TCP 19m + kubernetes-bootcamp NodePort 10.100.191.46 8080:30141/TCP 12s + + # 添加端口映射,主机上的端口是随机分配的 + kubectl expose deployment/kubernetes-bootcamp \ + --type="NodePort" \ + --port 8080 + + # 上面的 bootcamp 有两个副本,当我们curl访问应用时,请求会随机发到三个pod里 + # 其中 minikube 是该主机的 hostname,30141 是上面随机分配的端口号 + curl minikube:30141 + + + # 升级应用,从上面的 v1 升级到 v2,使用 get pods 可以发现这是一个删除再创建的过程。 + kubectl set image deployments/kubernetes-bootcamp \ + kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2 + + # 回退,升级后后悔了,可以再回退到 之前的 v1 版本。 + kubectl rollout undo deployments/kubernetes-bootcamp + + # 查看 namespace,kubernetes 默认创建了两个 + # default -- 创建资源时如果不指定,将被放到这个 Namespace 中。 + # kube-system -- Kubernetes 自己创建的系统资源将放到这个 Namespace 中。 + kubectl get namespace + +K8s 角色详解 + +|image0| + +其中 Controller 还分为几种: + +1. Deployment:最常用的 Controller +2. ReplicaSet:实现 Pod 的多副本管理,一般不会直接使用 +3. Daemonset:用于运行 Daemon +4. StatefuleSet:保证每个副本的名称不变及启动/更新/删除顺序 +5. Job:用于运行完即删除的应用。 + +一个 Pod +里可以运行一个容器(最常用),也可以运行多个容器,若运行多个容器,那这几个容器的工作必定有着紧密的联系,而且需要直接 +**共享资源**\ 。 + +.. |image0| image:: http://image.python-online.cn/20190907162015.png + diff --git a/source/c08/c08_05.rst b/source/c08/c08_05.rst index b6850d0..9fc2619 100644 --- a/source/c08/c08_05.rst +++ b/source/c08/c08_05.rst @@ -672,6 +672,18 @@ stevedore 这个模块去动态加载,然后还会校验这些资源是否都 nova-manage db sync +8.5.21 如何加action +------------------- + +:: + + self._record_action_start(context, instance, instance_actions.REBOOT) + +8.5.22 如何生成ConfigDrive +-------------------------- + +|image56| + -------------- .. figure:: http://image.python-online.cn/20190511161447.png @@ -734,4 +746,5 @@ stevedore 这个模块去动态加载,然后还会校验这些资源是否都 .. |image53| image:: http://image.python-online.cn/20190830091540.png .. |image54| image:: http://image.python-online.cn/20190830092203.png .. |image55| image:: http://image.python-online.cn/20190830093613.png +.. |image56| image:: http://image.python-online.cn/20190912135302.png diff --git a/source/c08/c08_06.rst b/source/c08/c08_06.rst index 09d9335..2dfb575 100644 --- a/source/c08/c08_06.rst +++ b/source/c08/c08_06.rst @@ -151,100 +151,6 @@ get_data(),如果获取到了数据就直接返回。 |image13| -8.6.4 网络是如何配置的? ------------------------- - -在不同的 cloudinit 版本中,网络配置部分的代码是不同的。 - -首先要知道,配置网络是在 ``on_first_boot`` 函数里配置的。它是在cloudinit -判断该机器为新虚拟机时才会执行。也就是说,这个网络配置在一个虚拟机生命周期里,只会执行一次,如果要二次执行,需要执行 -``rm -rf /var/lib/cloud`` ,将缓存数据删除,这边才会重新认定为新虚拟机。 - -在 CentOS6.x (cloud-init 0.7.5)中,网络信息的读取与配置都是在且仅能在 -local 阶段进行的,代码如下,只在 dsmode 为 local 时才会执行 -on_first_boot。 - -|image14| - -而在 CentOS7.x (cloud-init 0.7.9)中 或者 Ubuntu 16.04(cloud-init -17.1)中,配置网络不是在 on_first_boot 函数里,而是在 -stages.py:apply_network_config() 里。 - -|image15| - -并且新版的cloudinit ,local 和 init -阶段都会去配置网络,区别在于,local阶段只写配置文件,而init阶段不仅写配置文件,还会启动网卡,将ip配置上。 - -centos 7.x ,因为会跳过,它是在 stages.py:apply_network_config -函数里,这是在 local 阶段写入配置文件,而在 init 阶段 启动网卡。 - -|image16| - -所以如果要调试的话可以直接执行 init 阶段。 - -而如果是虚拟机重启的话,是在stages.py -这边判断是否为新虚拟机的,这也和旧版本有所区别。 - -|image17| - -为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 - -在 cloud-init 的比较重要的几个文件有: - -- 入口文件(上面已经说明过了) -- stages.py -- distros/rhel.py -- sources/DataSourceConfigDrive.py - -在网络配置这块,有几个大坑。 - -**坑一** - -如果是按照旧虚拟机创建新的快照镜像,然后使用这个镜像创建新的虚拟机,有可能会在同一块网卡上出现新旧两个ip,这是因为虚拟机在启动过程中,会先读取原网络配置配置ip,然后才会运行 -cloud-init 进行新ip的配置,而新ip的配置是使用 ``ifup`` -这个命令\ |image18| - -使用这种方式并不会将第一次配置的旧ip给清除掉。\ |image19| - -这个问题,目前我只在CentOS6 中遇到过。可以通过修改代码让其先 ``ifdown`` -再 ``ifup`` 就可以解决这个问题。\ |image20| - -**坑二** - -如果使用dhcp,cloudinit不会创建或者刷新网卡配置文件,而把配置ip交由 -NetworkManager -,让它自动获取。这是很重要。所以如果你用旧虚拟机创建快照的方式做镜像,然后用这个镜像创建的虚拟机会有旧虚拟机的配置文件会暴露原机器的ip地址。 - -具体的创建逻辑是在这 - -|image21| - -**坑三** - -在 CentOS 6 上,安装NetworkManager 时不会安装完整。 - -会导致两个问题,一个是在启动时,会提示无法加载插件,导致启动失败。 - -:: - - Apr 29 11:13:29 localhost NetworkManager[1365]: Loaded plugin keyfile: (cc - ) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailinn - g list. - Apr 29 11:13:29 localhost NetworkManager[1365]: [1556507609.466522] [maii - n.c:708] main(): failed to initialize the network manager: Could not load pluginn - 'ibft': /usr/lib64/NetworkManager/libnm-settings-plugin-ibft.so: undefined symbb - ol: g_slist_free_full - Apr 29 11:13:29 localhost NetworkManager[1365]: exiting (error) - -一个是会自动DHCP获取到一个以ip命名的hostname,并将原来的覆盖掉。 - -|image22| - -为了避免出现这些情况,请务必保证这些包都安装完整(左为 CentOS 7.2,右为 -CentOS 6.5)。 - -|image23| - 8.6.5 userdata 使用说明 ----------------------- @@ -324,7 +230,8 @@ content-types:text/cloud-config netmask: 255.255.255.0 gateway: 192.168.3.254 - + # 会将这些命令写入如下文件,但是并没有执行 + # /var/lib/cloud/instances/25be4404-4665-4b64-91cc-3289cf2a0af0/scripts/runcmd runcmd: - [ sed, -i, -e, '%s/x/y/g', some_file] - echo "modified some_file" @@ -416,7 +323,7 @@ cirename0 的网卡。 这就是cloudinit搞的鬼,在cloudinit的local阶段,好像会记录之前的mac地址,如果发现不一致,就会触发rename_interface。 -|image24| +|image14| 8.6.7 虚拟机启动卡住 -------------------- @@ -429,17 +336,372 @@ ephemeral0 拿到对应的 /dev/vdb,并将其写入 /etc/fstab 中。在下次重启时,会根据 fstab 挂载磁盘,如果挂载不上,就会导致虚拟机启动卡住。 +|image15| + +8.6.8 模块是怎么执行的 +---------------------- + +核心代码在 ``_run_modules`` 函数里: + +.. code:: python + + # stages.py + def _run_modules(self, mostly_mods): + cc = self.init.cloudify() + # Return which ones ran + # and which ones failed + the exception of why it failed + failures = [] + which_ran = [] + for (mod, name, freq, args) in mostly_mods: + try: + # Try the modules frequency, otherwise fallback to a known one + if not freq: + freq = mod.frequency + if freq not in FREQUENCIES: + freq = PER_INSTANCE + LOG.debug("Running module %s (%s) with frequency %s", + name, mod, freq) + + # Use the configs logger and not our own + # TODO(harlowja): possibly check the module + # for having a LOG attr and just give it back + # its own logger? + func_args = [name, self.cfg, + cc, config.LOG, args] + # Mark it as having started running + which_ran.append(name) + # This name will affect the semaphore name created + run_name = "config-%s" % (name) + + desc = "running %s with frequency %s" % (run_name, freq) + myrep = events.ReportEventStack( + name=run_name, description=desc, parent=self.reporter) + + with myrep: + # 执行模块 + ran, _r = cc.run(run_name, mod.handle, func_args, + freq=freq) + if ran: + myrep.message = "%s ran successfully" % run_name + else: + myrep.message = "%s previously ran" % run_name + +上面的 cc.run(),代码如下: + +.. code:: python + + # helpers.py + def run(self, name, functor, args, freq=None, clear_on_fail=False): + + # 获取 sem 文件。 + sem = self._get_sem(freq) + if not sem: + sem = DummySemaphores() + if not args: + args = [] + + # 判断是否已经执行过(准确说是,是否需要执行),具体逻辑可以参考上面 8.6.8 章节的逻辑。 + if sem.has_run(name, freq): + LOG.debug("%s already ran (freq=%s)", name, freq) + return (False, None) + + # 如果需要执行,就在对应的 sem 目录下生成一个文件(锁) + with sem.lock(name, freq, clear_on_fail) as lk: + if not lk: + raise LockFailure("Failed to acquire lock for %s" % name) + else: + LOG.debug("Running %s using lock (%s)", name, lk) + if isinstance(args, (dict)): + # 然后去执行这个模块 + results = functor(**args) + else: + results = functor(*args) + return (True, results) + +8.6.9 模块执行的频率 +-------------------- + +在 cloudinit 里的各个模块里,都可以配置执行频率。 + +- PER_ALWAYS:总是执行 +- PER_INSTANCE:每个虚拟机实例一次 +- PER_ONCE:每个镜像只执行一次 + +对于 ``PER_INSTANCE`` 和 ``PER_ONCE`` +和区别,从名字和代码实现上看,似乎没有区别,继续看 cloudinit +里的代码,只有一个模块使用了 PER_ONCE ,那就是 +``cc_scripts_per_once.py``\ 。 + +|image16| + +其实他们还是有区别的,由下面的代码来看 + +- ``PER_ONCE`` 获取的 sem 文件是从 ``/var/lib/cloud/`` + 下的文件获取的,这个目录一个镜像只会生成一次(若你不删除的话)。 +- ``PER_INSTANCE`` 获取 sem 文件是从 + ``/var/lib/cloud/instances/`` + 下的文件获取的,这个目录每个虚拟机一个。 + +|image17| + +如果你的模块里已经配置了频率,则以此为准。若没有配置,则默认为 +``PER_INSTANCE``\ 。 + +具体函数:\ ``_run_modules`` + +|image18| + +那么cloudinit 是如何控制模块的执行频率呢? + +通过代码可以发现,其在运行时,会先调用 ``has_run`` +函数,在这里会去取对应目录下(上面的 sem_path)的sem文件,如果有存在 sem +文件,说明已经执行过(返回 False ),如果不存在 sem 文件(返回 True) +说明未执行过。 + +|image19| + +sem 文件是怎样的? + +这是 ``PER_ONCE`` 的 sem 文件: + +|image20| + +这是 ``PER_INSTANCE`` 的 sem 文件\ |image21| + +8.6.10 如何解析网卡配置 +----------------------- + +ubuntu 的网卡配置不是正常我们常见的 json 或者 yaml +格式,若要将其转化成python的字典对象。这在cloudinit是怎么做的呢? + +将这个功能拿出来 ,你可以这样用。 + +.. code:: python + + from cloudinit.net import eni + config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') + +|image22| + +8.6.11 低版本的日志输出 +----------------------- + +如果你用过 centos6.x 的 cloudinit,你会发现其根本不会将日志输出到 +``/var/log/cloud-init.log``\ 中。 + +经过排查,你可以在 ``cloudinit/log.py`` 中按下面的改法修改解决 + +|image23| + +8.6.12 旧版本网络配置的三个巨坑 +------------------------------- + +在不同的 cloudinit 版本中,网络配置部分的代码是不同的。 + +首先要知道,配置网络是在 ``on_first_boot`` 函数里配置的。它是在cloudinit +判断该机器为新虚拟机时才会执行。也就是说,这个网络配置在一个虚拟机生命周期里,只会执行一次,如果要二次执行,需要执行 +``rm -rf /var/lib/cloud`` ,将缓存数据删除,这边才会重新认定为新虚拟机。 + +这里仅以 cloudinit 0.7.5 ( CentOS6.x)的版本为例。 + +在 cloud-init 0.7.5中,网络信息的读取与配置都是在且仅能在 local +阶段进行的,代码如下,只在 dsmode 为 local 时才会执行 on_first_boot。 + +|image24| + +而如果是虚拟机重启的话,是在stages.py +这边判断是否为新虚拟机的,这也和旧版本有所区别。 + |image25| -查看机器里有哪几张网卡 +为了让你能更加清晰的了解这个网络配置过程,我阅读了这块的源代码。 + +在 cloud-init 的比较重要的几个文件有: + +- 入口文件(上面已经说明过了) +- stages.py +- distros/rhel.py +- sources/DataSourceConfigDrive.py + +在网络配置这块,有几个大坑。 + +**坑一** -ls -l /sys/class/net +如果是按照旧虚拟机创建新的快照镜像,然后使用这个镜像创建新的虚拟机,有可能会在同一块网卡上出现新旧两个ip,这是因为虚拟机在启动过程中,会先读取原网络配置配置ip,然后才会运行 +cloud-init 进行新ip的配置,而新ip的配置是使用 ``ifup`` +这个命令\ |image26| + +使用这种方式并不会将第一次配置的旧ip给清除掉。\ |image27| + +这个问题,目前我只在CentOS6 中遇到过。可以通过修改代码让其先 ``ifdown`` +再 ``ifup`` 就可以解决这个问题。\ |image28| + +**坑二** + +如果使用dhcp,cloudinit不会创建或者刷新网卡配置文件,而把配置ip交由 +NetworkManager +,让它自动获取。这是很重要。所以如果你用旧虚拟机创建快照的方式做镜像,然后用这个镜像创建的虚拟机会有旧虚拟机的配置文件会暴露原机器的ip地址。 + +具体的创建逻辑是在这 + +|image29| + +**坑三** + +在 CentOS 6 上,安装NetworkManager 时不会安装完整。 + +会导致两个问题,一个是在启动时,会提示无法加载插件,导致启动失败。 + +:: + + Apr 29 11:13:29 localhost NetworkManager[1365]: Loaded plugin keyfile: (cc + ) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailinn + g list. + Apr 29 11:13:29 localhost NetworkManager[1365]: [1556507609.466522] [maii + n.c:708] main(): failed to initialize the network manager: Could not load pluginn + 'ibft': /usr/lib64/NetworkManager/libnm-settings-plugin-ibft.so: undefined symbb + ol: g_slist_free_full + Apr 29 11:13:29 localhost NetworkManager[1365]: exiting (error) + +一个是会自动DHCP获取到一个以ip命名的hostname,并将原来的覆盖掉。 + +|image30| + +为了避免出现这些情况,请务必保证这些包都安装完整(左为 CentOS 7.2,右为 +CentOS 6.5)。 + +|image31| + +8.6.13 网络是如何启动的?(新版本) +----------------------------------- + +这里仅以 cloudinit 18.5 的版本为例。 + +通过查看代码主流程时,获取ds的时候,有一个参数是 existing,它有两个值: + +- trust:说明 ds 的缓存是可以相信的,不用再去校验 instance_uuid +- check:说明会去校验 instance_uuid,如果相同直接返回 ds + 的缓存,如果不同则返回None,让后的步骤再去从 CD-ROM 读取最新的。 + +在 local 阶段的时候,\ ``existing`` 是 ``check`` ,这是合理的。 + +|image32| + +|image33| + +在local阶段,on_first_boot 的函数 network 是 False +,所以这里也不会写网卡配置文件,自然也不会配置。 + +|image34| + +|image35| + +再往后面看,就可以发现,原来写配置文件的地方是在 ``cmd/main.py`` 里。 + +.. code:: python + + # cmd/main.py + mode = sources.DSMODE_LOCAL if args.local else sources.DSMODE_NETWORK + + # 中间省略多行代码 ... + init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL)) + +第一行,如果是 local 阶段,mode 为 local,bring_up 为 +False,意思是只写配置文件,而不启用网卡。 + +等到 init 阶段时,mode 为 net +(\ ``sources.DSMODE_NETWORK``\ )时,bring_up 为 +True,意思是会启用网卡,配置ip。 + +网卡网卡的主要函数在下面 ``apply_network_config`` +这个函数里,这个函数主要做三个事情: + +1. 获取网卡配置 +2. 校正网卡名,以 ConfigDrive 的配置为准 +3. 将ip信息写入配置文件,并启动网卡 + +|image36| + +那它是如何对网卡进行重命令的呢?看了代码,其实是用ip命令实现的。 + +|image37| + +提取出来其实就三条命令,要注意的是,这三条命令执行是有顺序的 + +:: + + 1. ip link set ens3 down + 2. ip link set ens3 name eth0 + 3. ip link set eth0 up + +还有一点要说的是,cloudinit 是如何取到本机真实的网卡信息的呢?他是从 +``/sys/class/net/`` +目录下获取的。每个网卡一个目录,每个目录下都有相应的文件记录相应的信息,比如 +``/sys/class/net/ens3/address`` 记录的是网卡的 mac 地址。 + +|image38| + +接下来就要开始配置网络了,先写网络配置文件,再根据参数选择是否启用网络。 + +|image39| + +如果是重启虚拟机或者 init 阶段进入这里呢,会不会又重复配置网络了呢? + +答案是:不会的。 + +cloudinit 会根据缓存中的虚拟机的uuid来与ConfigDrive +的对比,如果不一样,则认为这台虚拟机是新创建的虚拟机,只有新的虚拟机才会走入这里去配置网络。 + +|image40| + +那问题又来了,虽然上面有个 bring_up 的参数,实际上,通过代码可以发现,在 +local 阶段,bring_up 为 False 不会去启用网卡,而在 init 阶段呢,虽然 +bring_up 为 True,但是此时,经过 local +阶段后,代码逻辑会认为这是台旧虚拟机,不会再走后面配置网络的函数,那就很奇怪了,网卡的ip是如何配置上的呢? + +这是个好问题,也是个很难察觉的点。 + +大多数人,可能不知道linux内部的服务是有启动顺序的。在这种情况下,我们必须保证,cloudinit +写入配置的服务(cloud-init-local)必须在 network 或者 Network-Manager +的服务之前。 + +这样在 cloud-init-local 执行完后,就会自动配置上网络了。 + +8.6.14 在虚拟机启动时执行命令 +----------------------------- + +cloudinit 允许通过 user_data 指定你想在虚拟机启动时,执行的命令。 + +:: + + # 会将这些命令写入如下文件,但是并没有执行 + # + runcmd: + - [ sed, -i, -e, '%s/x/y/g', some_file] + - echo "modified some_file" + - [cat, some_file] + +当你进行了如此配置后,cloudinit 会通过 runcmd +模块,将这些命令组合起来写入 +``/var/lib/cloud/instances//scripts/runcmd``\ 。 + +但这仅仅只是写入,若要执行这些命令,还需要你在 /etc/cloud/cloud.cfg +中配置 ``scripts_user``\ ,这样 cloud-init 才会去执行它。 + +8.6.15 相关命令 +--------------- + +.. code:: shell -只查看 ipv4 或 ipv6的网卡ip + # 查看机器里有哪几张网卡 + ls -l /sys/class/net -ip -6 addr show + # 只查看 ipv4 或 ipv6的网卡ip + ip -6 addr show + ip -4 addr show -ip -4 addr show + # 网络启动不来,先 flush 试一下 + ip addr flush dev ens3 -------------- @@ -461,16 +723,31 @@ ip -4 addr show .. |image11| image:: http://image.python-online.cn/FpqcyL4hWwpaAGzsdreQwXvH4Rx8 .. |image12| image:: http://image.python-online.cn/20190430230839.png .. |image13| image:: http://image.python-online.cn/20190430231108.png -.. |image14| image:: http://image.python-online.cn/20190429104357.png -.. |image15| image:: http://image.python-online.cn/20190829141059.png -.. |image16| image:: http://image.python-online.cn/20190829113537.png -.. |image17| image:: http://image.python-online.cn/20190829141059.png -.. |image18| image:: http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d -.. |image19| image:: http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c -.. |image20| image:: http://image.python-online.cn/20190430231812.png -.. |image21| image:: http://image.python-online.cn/20190430232309.png -.. |image22| image:: http://image.python-online.cn/20190429205735.png -.. |image23| image:: http://image.python-online.cn/20190430232911.png -.. |image24| image:: http://image.python-online.cn/20190623091911.png -.. |image25| image:: http://image.python-online.cn/20190708175813.png +.. |image14| image:: http://image.python-online.cn/20190623091911.png +.. |image15| image:: http://image.python-online.cn/20190708175813.png +.. |image16| image:: http://image.python-online.cn/20190910160035.png +.. |image17| image:: http://image.python-online.cn/20190910150305.png +.. |image18| image:: http://image.python-online.cn/20190910142222.png +.. |image19| image:: http://image.python-online.cn/20190910153637.png +.. |image20| image:: http://image.python-online.cn/20190910171359.png +.. |image21| image:: http://image.python-online.cn/20190910171538.png +.. |image22| image:: http://image.python-online.cn/20190906091102.png +.. |image23| image:: http://image.python-online.cn/20190909172153.png +.. |image24| image:: http://image.python-online.cn/20190429104357.png +.. |image25| image:: http://image.python-online.cn/20190829141059.png +.. |image26| image:: http://image.python-online.cn/Fp1TeHSiIMIQoZygbW9VSfAagB_d +.. |image27| image:: http://image.python-online.cn/Fh-5SQ8qYjhJEKovI6LmIpabSy2c +.. |image28| image:: http://image.python-online.cn/20190430231812.png +.. |image29| image:: http://image.python-online.cn/20190430232309.png +.. |image30| image:: http://image.python-online.cn/20190429205735.png +.. |image31| image:: http://image.python-online.cn/20190430232911.png +.. |image32| image:: http://image.python-online.cn/20190911175423.png +.. |image33| image:: http://image.python-online.cn/20190911174648.png +.. |image34| image:: http://image.python-online.cn/20190911173615.png +.. |image35| image:: http://image.python-online.cn/20190911195024.png +.. |image36| image:: http://image.python-online.cn/20190911202425.png +.. |image37| image:: http://image.python-online.cn/20190911202551.png +.. |image38| image:: http://image.python-online.cn/20190911203953.png +.. |image39| image:: http://image.python-online.cn/20190911204805.png +.. |image40| image:: http://image.python-online.cn/20190911205518.png diff --git a/source/c08/c08_13.rst b/source/c08/c08_13.rst index f770980..c882955 100644 --- a/source/c08/c08_13.rst +++ b/source/c08/c08_13.rst @@ -257,6 +257,25 @@ cache里没有这个ip,就会重新发送arp广播,获取到正确的mac地 # 指定文件设置多个arp条目 arp -f /etc/ethers +8.13.3 ovs 流表 +--------------- + +使用 ``ovs-ofctl dump-flows br-int`` 可以查看从 br-int 到 br0-ovs +的流表。 + +查看 ``0x0000/0x1fff`` 这一行后的 ``actions=mod_vlan_vid:4`` ,其中的 +``4`` 是vlan id,意思是从虚拟机的网卡出来的包如果tag=4,在经过 br0-ovs +的时候,就会把 tag 去掉,不会被过滤掉,使其能把包发向公网。 + +假如不设置tag,br-int 上的包就不会流往 br0-ovs。 + +假如你的虚拟机是连在 br-int 上,而且没有tag,那么需要你手动加tag + +:: + + virsh domiflist vm_domain + ovs-vsctl set port vnet0 tag=4 + -------------- .. figure:: http://image.python-online.cn/20190511161447.png diff --git a/source/c08/c08_14.rst b/source/c08/c08_14.rst index d0bd8d2..1094051 100644 --- a/source/c08/c08_14.rst +++ b/source/c08/c08_14.rst @@ -291,22 +291,35 @@ centos 6.x 配置网络是在 on_first_boot 函数里,这是 local |image12| -ubuntu 解析网卡配置 +8.14.5 ubuntu禁用ipv6 +--------------------- -.. code:: python - - from cloudinit.net import eni - config=eni.parse_deb_config('/etc/network/interfaces.d/50-cloud-init.cfg') +如果你给你的ubuntu配置上了ipv6的ip,那当你使用 apt-get install +软件包的时候,会使用ipv6去源安装,这将会使你的安装过程卡住: |image13| -8.14.5 其他命令记录 -------------------- +如何解决这个问题呢? + +参考文章:https://ubuntuqa.com/article/1577.html + +我使用的方法是 + +在终端中运行以下命令禁用IPv6,\ ``0``\ 表示已启用,而\ ``1``\ 表示已禁用。 + +:: + + echo 1>/proc/sys/net/ipv6/conf/all/disable_ipv6 + +然后在终端内禁用IPv6,需要再输入以下内容: :: - # 网络启动不来,先 flush 试一下 - ip addr flush dev ens3 + echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf + echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf + echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf + echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf + sudo sysctl -p -------------- @@ -327,5 +340,5 @@ ubuntu 解析网卡配置 .. |image10| image:: http://image.python-online.cn/20190829112446.png .. |image11| image:: http://image.python-online.cn/20190829111917.png .. |image12| image:: http://image.python-online.cn/20190829161243.png -.. |image13| image:: http://image.python-online.cn/20190906091102.png +.. |image13| image:: http://image.python-online.cn/20190926171038.png From ba017c6769e2a36b31298d5c5cd2e3583f2330a7 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Tue, 8 Oct 2019 21:07:28 +0800 Subject: [PATCH 031/227] update --- source/c08/c08_05.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index 8e6eea4..5196f37 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -339,6 +339,39 @@ nova-api 返回的结果令人无法理解: ![](http://image.python-online.cn/20190526204328.png) +## 8.5.12 往 spec_obj 里添加对象 + +在 nova-scheduler 里的 过滤器里,有俩非常重要的对象。 + +- host_state:包含每台 host 的所有信息 +- spec_obj:包含创建虚拟机请求的所有信息 + +![](http://image.python-online.cn/20191008173211.png) + +有时候,spec_obj 里并没有我们想要的信息(比如虚拟机的 metadata),这时候,我们就要手动添加。 + +这里我以 metadata 为例,来讲一下这个添加过程。 + +首先第一点要清楚的是,spec_obj 其实是 RequestSpec 对象:nova/objects/request_spec.py,所以下面的修改都是在这个文件里进行。 + +要往这个对象加属性,第一步是要定义这个字段。 + +![](http://image.python-online.cn/20191008174046.png) + +往 instance_fields 追加属性名 + +![](http://image.python-online.cn/20191008210127.png) + +最后在 `from_primitives` 这个函数里,把这个新属性赋值一下。 + +```python +spec.metadata = request_spec['instance_properties'].get('metadata', {}) +``` + + + + + ## 8.5.13 支持指定子网和指定ip 在 nova-api 接收请求处。 From 2f57552ebc8bb251a7db3cb000e159c12d9e359f Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Thu, 10 Oct 2019 09:04:38 +0800 Subject: [PATCH 032/227] update --- source/c08/c08_05.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/c08/c08_05.md b/source/c08/c08_05.md index 5196f37..5666422 100644 --- a/source/c08/c08_05.md +++ b/source/c08/c08_05.md @@ -358,11 +358,11 @@ nova-api 返回的结果令人无法理解: ![](http://image.python-online.cn/20191008174046.png) -往 instance_fields 追加属性名 +往 instance_fields 追加属性名,完了后,这个属性会出现在 `request_spec['instance_properties']` 里 ![](http://image.python-online.cn/20191008210127.png) -最后在 `from_primitives` 这个函数里,把这个新属性赋值一下。 +最后在 `from_primitives` 这个函数里,把这个新属性赋值给 request_spec 对象。 ```python spec.metadata = request_spec['instance_properties'].get('metadata', {}) From 48526cc15ca4321c6e5179083b163541032d741e Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Thu, 10 Oct 2019 23:53:59 +0800 Subject: [PATCH 033/227] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=86=B7=E7=9F=A5?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c01/c01_10.md | 128 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 24 deletions(-) diff --git a/source/c01/c01_10.md b/source/c01/c01_10.md index 1056def..6c6a4a0 100644 --- a/source/c01/c01_10.md +++ b/source/c01/c01_10.md @@ -1009,28 +1009,7 @@ b ['a', 'b'] ``` -## 33. 更新字典 - -通常我们更新字典的方式是这样的 - -```python ->>> dict1 = {'age':24} ->>> dict1.update({'age':30}) ->>> dict1 -{'age': 30} -``` - -除此之外还有另外一种方式,你可能比较陌生 - -``` ->>> dict1 = {'namne':'ming', 'gender':'male', 'age':24} ->>> dict2 = {'namne':'jane', 'gender':'male'} ->>> dict3 = {**dict1, **dict2} ->>> dict3 -{'namne': 'jane', 'gender': 'male', 'age': 24} -``` - -## 34. 嵌套上下文管理的另类写法 +## 33. 嵌套上下文管理的另类写法 当我们要写一个嵌套的上下文管理器时,可能会这样写 @@ -1067,7 +1046,7 @@ with test_context('aaa'), test_context('bbb'): print('========== in main ============') ``` -## 35. += 不等同于=+ +## 34. += 不等同于=+ 对列表 进行`+=` 操作相当于 extend,而使用 `=+` 操作是新增了一个列表。 @@ -1096,7 +1075,7 @@ with test_context('aaa'), test_context('bbb'): -## 36. Python 里也可以有 end +## 35. Python 里也可以有 end 有不少编程语言,循环、判断代码块需要用 end 标明结束,这样一定程序上会使代码逻辑更加清晰一点,其实这种语法在 Python 里并没有必要,但如果你想用,也不是没有办法,具体你看下面这个例子。 @@ -1104,6 +1083,107 @@ with test_context('aaa'), test_context('bbb'): +## 36. 花样更新字典的技巧 + +常规的更新字典的方式是这样的 + +```python +>>> profile={'name': 'wangbm'} +>>> extra={'age': 25, 'gender': 'male'} +>>> profile.update(extra) +>>> profile +{'gender': 'male', 'age': 25, 'name': 'wangbm'} +``` + +今天明哥来集中讲下字典的更新方式 + +```python +>>> profile={'name': 'wangbm'} +>>> extra=[('age', 25), ('gender', 'male')] +>>> profile.update(extra) +>>> profile +{'gender': 'male', 'age': 25, 'name': 'wangbm'} +``` + +如果你见过上面这种,那接下来这种我保证大部分人都没用过 + +```python +>>> profile={'name': 'wangbm'} +>>> profile.update(age=25, gender='male') +>>> profile +{'gender': 'male', 'age': 25, 'name': 'wangbm'} +``` + +## 37. 被低估的 print + +print 很多人只用来执行简单的打印功能。 + +print 作为一个函数,本身也附有各种各样的参数,只是很多人不知道。 + +你一定知道 join 这种很高效的字符串拼接方式。 + +```python +>>> alist = ['a', 'b', 'c'] +>>> ','.join(alist) +'a,b,c' +``` + +当如果 alist 里有非字符串的元素时,join 就会抛错。 + +```python +>>> alist = ['a', 'b', 3] +>>> ','.join(alist) +Traceback (most recent call last): + File "", line 1, in +TypeError: sequence item 2: expected str instance, int found +``` + +如果要解决这个问题,可能要提前将数值转化成字符串类型。 + +```python +>>> alist = ['a', 'b', 3] +>>> blist = [str(i) for i in alist] +>>> blist +['a', 'b', '3'] +>>> ','.join(blist) +'a,b,3' +``` + +这里再介绍一种更简洁的方法,就是使用 print 来实现,但这种有局限,好像只能在命令行模式下使用,毕竟 print 标准输出,无法进行赋值。 + +下面我使用 `_` 来获取上一次的返回值,再赋值给 blist。 + +```python +>>> print(*alist, sep=',') +a,b,3 +>>> blist = _ +>>> blist +'a,b,3' +``` + +既然说到了 print,那么再说一点print 的神技巧。 + +很多初学者,喜欢使用 print 来进行调试追踪。 + +一点不好的地方是,普通的 print 是输出到终端屏幕,而不能将保持在文件中。 + +其实 print 是支持将输出重定向到文件中的,不过说实话,个人感觉还不如使用 logging 模块呢,或者直接 f.write()。 + +```python +>>> with open('test.log', mode='w') as f: +... print('hello, python', file=f, flush=True) +>>> exit() + +$ cat test.log +hello, python +``` + + + +以上两点,学习自董伟明的文章:[一些你不知道的Python Tips](https://mp.weixin.qq.com/s/KTLRwzCM7lOvBF4IEGuBPg) + + + ## 附录:参考文章 - [wtfpython](https://github.com/satwikkansal/wtfpython) From 2c31e101823067c18900f30c67a04af078b685b2 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Mon, 14 Oct 2019 22:34:32 +0800 Subject: [PATCH 034/227] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/c04/c04_03.md | 22 ++++++++++++++++++++++ source/c08/c08_12.md | 8 ++++++++ source/conf.py | 6 +++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/source/c04/c04_03.md b/source/c04/c04_03.md index 1b1e6a3..9189725 100644 --- a/source/c04/c04_03.md +++ b/source/c04/c04_03.md @@ -266,6 +266,28 @@ pandoc -V mainfont="SimSun" -f markdown -t rst hello.md -o hello.rst 到这里,属于你的个人博客就搭建好了,快去试一下吧。 最后,整个项目的源码和模块包我都放在公众号(`Python编程时光`)后台,请关注后,回复「`Sphinx`」领取。 + + +## 4.3.7 自定义js + +将js文件放在 `source/_static/js/` 目录下,然后修改 conf.py + +```python +html_static_path = ['_static'] + +html_js_files = [ + 'css/readmore.js', +] +``` + +由于这个功能只在 sphinx 1.8 + 版本中才支持,所以你要确定你的版本。若低于这个版本,可以用Python 3.5(Python 2.7 不支持了)中新建一个虚拟环境,然后安装最新的 sphinx 包。 + +```shell +pip install Sphinx sphinx-rtd-theme -i https://pypi.douban.com/simple +``` + +但是这个功能添加的 js 都在header里,并不能添加到最后面。 + ## 附录:参考文档 - [Sphinx配置MarkDown解析](http://www.sphinx-doc.org/en/master/usage/markdown.html) diff --git a/source/c08/c08_12.md b/source/c08/c08_12.md index 2f25dfc..cab287c 100644 --- a/source/c08/c08_12.md +++ b/source/c08/c08_12.md @@ -10,6 +10,8 @@ 经过以上两个过程后,nova-scheduler 会将选到的主机返回给 nova-conductor,这时候 nova-conductor 才会去调用 nova-compute 去进行真正的创建过程。 +## 8.12.1 过滤器和称重器 + 接下来,我会从源码的角度来分析一下这个过程。 从源代码中看,最开始是 nova-conductor (nova/conductor/manager.py)在给 nova-compute 发创建请求前,会先让 nova-scheduler 选出一台资源充足的计算节点。 @@ -58,6 +60,12 @@ LOG.debug("Weighed %(hosts)s", {'hosts': weighed_hosts}) LOG.debug("Selected host: %(host)s", {'host': chosen_host}) ``` +## 8.12.2 指定宿主机创建 + +当指定宿主机进行虚拟机的创建后,以上所有的过滤器都会无效(不会走代码)。 + +![](http://image.python-online.cn/20191011103832.png) + --- ![关注公众号,获取最新干货!](http://image.python-online.cn/20190511161447.png) \ No newline at end of file diff --git a/source/conf.py b/source/conf.py index 64e5361..40ebc20 100755 --- a/source/conf.py +++ b/source/conf.py @@ -62,7 +62,7 @@ html_theme = 'default' -#html_static_path = ['_static'] +html_static_path = ['_static'] # Output file base name for HTML help builder. htmlhelp_basename = 'Python-Time BLOG' @@ -137,3 +137,7 @@ _exts = "../exts" sys.path.append(os.path.abspath(_exts)) + +html_js_files = [ + 'js/readmore.js', +] \ No newline at end of file From facd1c694aba1b0c57133748ec78633d3d3a7812 Mon Sep 17 00:00:00 2001 From: BingmingWong Date: Mon, 14 Oct 2019 22:35:02 +0800 Subject: [PATCH 035/227] =?UTF-8?q?=E6=B7=BB=E5=8A=A0readmore.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_static/js/readmore.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 source/_static/js/readmore.js diff --git a/source/_static/js/readmore.js b/source/_static/js/readmore.js new file mode 100644 index 0000000..1168735 --- /dev/null +++ b/source/_static/js/readmore.js @@ -0,0 +1,12 @@ +!function (e, t) { "use strict"; "object" == typeof module && "object" == typeof module.exports ? module.exports = e.document ? t(e, !0) : function (e) { if (!e.document) throw new Error("jQuery requires a window with a document"); return t(e) } : t(e) }("undefined" != typeof window ? window : this, function (C, e) { "use strict"; var t = [], E = C.document, r = Object.getPrototypeOf, s = t.slice, g = t.concat, u = t.push, i = t.indexOf, n = {}, o = n.toString, v = n.hasOwnProperty, a = v.toString, l = a.call(Object), y = {}, m = function (e) { return "function" == typeof e && "number" != typeof e.nodeType }, x = function (e) { return null != e && e === e.window }, c = { type: !0, src: !0, nonce: !0, noModule: !0 }; function b(e, t, n) { var r, i, o = (n = n || E).createElement("script"); if (o.text = e, t) for (r in c) (i = t[r] || t.getAttribute && t.getAttribute(r)) && o.setAttribute(r, i); n.head.appendChild(o).parentNode.removeChild(o) } function w(e) { return null == e ? e + "" : "object" == typeof e || "function" == typeof e ? n[o.call(e)] || "object" : typeof e } var f = "3.4.1", k = function (e, t) { return new k.fn.init(e, t) }, p = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; function d(e) { var t = !!e && "length" in e && e.length, n = w(e); return !m(e) && !x(e) && ("array" === n || 0 === t || "number" == typeof t && 0 < t && t - 1 in e) } k.fn = k.prototype = { jquery: f, constructor: k, length: 0, toArray: function () { return s.call(this) }, get: function (e) { return null == e ? s.call(this) : e < 0 ? this[e + this.length] : this[e] }, pushStack: function (e) { var t = k.merge(this.constructor(), e); return t.prevObject = this, t }, each: function (e) { return k.each(this, e) }, map: function (n) { return this.pushStack(k.map(this, function (e, t) { return n.call(e, t, e) })) }, slice: function () { return this.pushStack(s.apply(this, arguments)) }, first: function () { return this.eq(0) }, last: function () { return this.eq(-1) }, eq: function (e) { var t = this.length, n = +e + (e < 0 ? t : 0); return this.pushStack(0 <= n && n < t ? [this[n]] : []) }, end: function () { return this.prevObject || this.constructor() }, push: u, sort: t.sort, splice: t.splice }, k.extend = k.fn.extend = function () { var e, t, n, r, i, o, a = arguments[0] || {}, s = 1, u = arguments.length, l = !1; for ("boolean" == typeof a && (l = a, a = arguments[s] || {}, s++), "object" == typeof a || m(a) || (a = {}), s === u && (a = this, s--); s < u; s++)if (null != (e = arguments[s])) for (t in e) r = e[t], "__proto__" !== t && a !== r && (l && r && (k.isPlainObject(r) || (i = Array.isArray(r))) ? (n = a[t], o = i && !Array.isArray(n) ? [] : i || k.isPlainObject(n) ? n : {}, i = !1, a[t] = k.extend(l, o, r)) : void 0 !== r && (a[t] = r)); return a }, k.extend({ expando: "jQuery" + (f + Math.random()).replace(/\D/g, ""), isReady: !0, error: function (e) { throw new Error(e) }, noop: function () { }, isPlainObject: function (e) { var t, n; return !(!e || "[object Object]" !== o.call(e)) && (!(t = r(e)) || "function" == typeof (n = v.call(t, "constructor") && t.constructor) && a.call(n) === l) }, isEmptyObject: function (e) { var t; for (t in e) return !1; return !0 }, globalEval: function (e, t) { b(e, { nonce: t && t.nonce }) }, each: function (e, t) { var n, r = 0; if (d(e)) { for (n = e.length; r < n; r++)if (!1 === t.call(e[r], r, e[r])) break } else for (r in e) if (!1 === t.call(e[r], r, e[r])) break; return e }, trim: function (e) { return null == e ? "" : (e + "").replace(p, "") }, makeArray: function (e, t) { var n = t || []; return null != e && (d(Object(e)) ? k.merge(n, "string" == typeof e ? [e] : e) : u.call(n, e)), n }, inArray: function (e, t, n) { return null == t ? -1 : i.call(t, e, n) }, merge: function (e, t) { for (var n = +t.length, r = 0, i = e.length; r < n; r++)e[i++] = t[r]; return e.length = i, e }, grep: function (e, t, n) { for (var r = [], i = 0, o = e.length, a = !n; i < o; i++)!t(e[i], i) !== a && r.push(e[i]); return r }, map: function (e, t, n) { var r, i, o = 0, a = []; if (d(e)) for (r = e.length; o < r; o++)null != (i = t(e[o], o, n)) && a.push(i); else for (o in e) null != (i = t(e[o], o, n)) && a.push(i); return g.apply([], a) }, guid: 1, support: y }), "function" == typeof Symbol && (k.fn[Symbol.iterator] = t[Symbol.iterator]), k.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "), function (e, t) { n["[object " + t + "]"] = t.toLowerCase() }); var h = function (n) { var e, d, b, o, i, h, f, g, w, u, l, T, C, a, E, v, s, c, y, k = "sizzle" + 1 * new Date, m = n.document, S = 0, r = 0, p = ue(), x = ue(), N = ue(), A = ue(), D = function (e, t) { return e === t && (l = !0), 0 }, j = {}.hasOwnProperty, t = [], q = t.pop, L = t.push, H = t.push, O = t.slice, P = function (e, t) { for (var n = 0, r = e.length; n < r; n++)if (e[n] === t) return n; return -1 }, R = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped", M = "[\\x20\\t\\r\\n\\f]", I = "(?:\\\\.|[\\w-]|[^\0-\\xa0])+", W = "\\[" + M + "*(" + I + ")(?:" + M + "*([*^$|!~]?=)" + M + "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + I + "))|)" + M + "*\\]", $ = ":(" + I + ")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|" + W + ")*)|.*)\\)|)", F = new RegExp(M + "+", "g"), B = new RegExp("^" + M + "+|((?:^|[^\\\\])(?:\\\\.)*)" + M + "+$", "g"), _ = new RegExp("^" + M + "*," + M + "*"), z = new RegExp("^" + M + "*([>+~]|" + M + ")" + M + "*"), U = new RegExp(M + "|>"), X = new RegExp($), V = new RegExp("^" + I + "$"), G = { ID: new RegExp("^#(" + I + ")"), CLASS: new RegExp("^\\.(" + I + ")"), TAG: new RegExp("^(" + I + "|[*])"), ATTR: new RegExp("^" + W), PSEUDO: new RegExp("^" + $), CHILD: new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + M + "*(even|odd|(([+-]|)(\\d*)n|)" + M + "*(?:([+-]|)" + M + "*(\\d+)|))" + M + "*\\)|)", "i"), bool: new RegExp("^(?:" + R + ")$", "i"), needsContext: new RegExp("^" + M + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + M + "*((?:-\\d)?\\d*)" + M + "*\\)|)(?=[^-]|$)", "i") }, Y = /HTML$/i, Q = /^(?:input|select|textarea|button)$/i, J = /^h\d$/i, K = /^[^{]+\{\s*\[native \w/, Z = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, ee = /[+~]/, te = new RegExp("\\\\([\\da-f]{1,6}" + M + "?|(" + M + ")|.)", "ig"), ne = function (e, t, n) { var r = "0x" + t - 65536; return r != r || n ? t : r < 0 ? String.fromCharCode(r + 65536) : String.fromCharCode(r >> 10 | 55296, 1023 & r | 56320) }, re = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g, ie = function (e, t) { return t ? "\0" === e ? "\ufffd" : e.slice(0, -1) + "\\" + e.charCodeAt(e.length - 1).toString(16) + " " : "\\" + e }, oe = function () { T() }, ae = be(function (e) { return !0 === e.disabled && "fieldset" === e.nodeName.toLowerCase() }, { dir: "parentNode", next: "legend" }); try { H.apply(t = O.call(m.childNodes), m.childNodes), t[m.childNodes.length].nodeType } catch (e) { H = { apply: t.length ? function (e, t) { L.apply(e, O.call(t)) } : function (e, t) { var n = e.length, r = 0; while (e[n++] = t[r++]); e.length = n - 1 } } } function se(t, e, n, r) { var i, o, a, s, u, l, c, f = e && e.ownerDocument, p = e ? e.nodeType : 9; if (n = n || [], "string" != typeof t || !t || 1 !== p && 9 !== p && 11 !== p) return n; if (!r && ((e ? e.ownerDocument || e : m) !== C && T(e), e = e || C, E)) { if (11 !== p && (u = Z.exec(t))) if (i = u[1]) { if (9 === p) { if (!(a = e.getElementById(i))) return n; if (a.id === i) return n.push(a), n } else if (f && (a = f.getElementById(i)) && y(e, a) && a.id === i) return n.push(a), n } else { if (u[2]) return H.apply(n, e.getElementsByTagName(t)), n; if ((i = u[3]) && d.getElementsByClassName && e.getElementsByClassName) return H.apply(n, e.getElementsByClassName(i)), n } if (d.qsa && !A[t + " "] && (!v || !v.test(t)) && (1 !== p || "object" !== e.nodeName.toLowerCase())) { if (c = t, f = e, 1 === p && U.test(t)) { (s = e.getAttribute("id")) ? s = s.replace(re, ie) : e.setAttribute("id", s = k), o = (l = h(t)).length; while (o--) l[o] = "#" + s + " " + xe(l[o]); c = l.join(","), f = ee.test(t) && ye(e.parentNode) || e } try { return H.apply(n, f.querySelectorAll(c)), n } catch (e) { A(t, !0) } finally { s === k && e.removeAttribute("id") } } } return g(t.replace(B, "$1"), e, n, r) } function ue() { var r = []; return function e(t, n) { return r.push(t + " ") > b.cacheLength && delete e[r.shift()], e[t + " "] = n } } function le(e) { return e[k] = !0, e } function ce(e) { var t = C.createElement("fieldset"); try { return !!e(t) } catch (e) { return !1 } finally { t.parentNode && t.parentNode.removeChild(t), t = null } } function fe(e, t) { var n = e.split("|"), r = n.length; while (r--) b.attrHandle[n[r]] = t } function pe(e, t) { var n = t && e, r = n && 1 === e.nodeType && 1 === t.nodeType && e.sourceIndex - t.sourceIndex; if (r) return r; if (n) while (n = n.nextSibling) if (n === t) return -1; return e ? 1 : -1 } function de(t) { return function (e) { return "input" === e.nodeName.toLowerCase() && e.type === t } } function he(n) { return function (e) { var t = e.nodeName.toLowerCase(); return ("input" === t || "button" === t) && e.type === n } } function ge(t) { return function (e) { return "form" in e ? e.parentNode && !1 === e.disabled ? "label" in e ? "label" in e.parentNode ? e.parentNode.disabled === t : e.disabled === t : e.isDisabled === t || e.isDisabled !== !t && ae(e) === t : e.disabled === t : "label" in e && e.disabled === t } } function ve(a) { return le(function (o) { return o = +o, le(function (e, t) { var n, r = a([], e.length, o), i = r.length; while (i--) e[n = r[i]] && (e[n] = !(t[n] = e[n])) }) }) } function ye(e) { return e && "undefined" != typeof e.getElementsByTagName && e } for (e in d = se.support = {}, i = se.isXML = function (e) { var t = e.namespaceURI, n = (e.ownerDocument || e).documentElement; return !Y.test(t || n && n.nodeName || "HTML") }, T = se.setDocument = function (e) { var t, n, r = e ? e.ownerDocument || e : m; return r !== C && 9 === r.nodeType && r.documentElement && (a = (C = r).documentElement, E = !i(C), m !== C && (n = C.defaultView) && n.top !== n && (n.addEventListener ? n.addEventListener("unload", oe, !1) : n.attachEvent && n.attachEvent("onunload", oe)), d.attributes = ce(function (e) { return e.className = "i", !e.getAttribute("className") }), d.getElementsByTagName = ce(function (e) { return e.appendChild(C.createComment("")), !e.getElementsByTagName("*").length }), d.getElementsByClassName = K.test(C.getElementsByClassName), d.getById = ce(function (e) { return a.appendChild(e).id = k, !C.getElementsByName || !C.getElementsByName(k).length }), d.getById ? (b.filter.ID = function (e) { var t = e.replace(te, ne); return function (e) { return e.getAttribute("id") === t } }, b.find.ID = function (e, t) { if ("undefined" != typeof t.getElementById && E) { var n = t.getElementById(e); return n ? [n] : [] } }) : (b.filter.ID = function (e) { var n = e.replace(te, ne); return function (e) { var t = "undefined" != typeof e.getAttributeNode && e.getAttributeNode("id"); return t && t.value === n } }, b.find.ID = function (e, t) { if ("undefined" != typeof t.getElementById && E) { var n, r, i, o = t.getElementById(e); if (o) { if ((n = o.getAttributeNode("id")) && n.value === e) return [o]; i = t.getElementsByName(e), r = 0; while (o = i[r++]) if ((n = o.getAttributeNode("id")) && n.value === e) return [o] } return [] } }), b.find.TAG = d.getElementsByTagName ? function (e, t) { return "undefined" != typeof t.getElementsByTagName ? t.getElementsByTagName(e) : d.qsa ? t.querySelectorAll(e) : void 0 } : function (e, t) { var n, r = [], i = 0, o = t.getElementsByTagName(e); if ("*" === e) { while (n = o[i++]) 1 === n.nodeType && r.push(n); return r } return o }, b.find.CLASS = d.getElementsByClassName && function (e, t) { if ("undefined" != typeof t.getElementsByClassName && E) return t.getElementsByClassName(e) }, s = [], v = [], (d.qsa = K.test(C.querySelectorAll)) && (ce(function (e) { a.appendChild(e).innerHTML = "", e.querySelectorAll("[msallowcapture^='']").length && v.push("[*^$]=" + M + "*(?:''|\"\")"), e.querySelectorAll("[selected]").length || v.push("\\[" + M + "*(?:value|" + R + ")"), e.querySelectorAll("[id~=" + k + "-]").length || v.push("~="), e.querySelectorAll(":checked").length || v.push(":checked"), e.querySelectorAll("a#" + k + "+*").length || v.push(".#.+[+~]") }), ce(function (e) { e.innerHTML = ""; var t = C.createElement("input"); t.setAttribute("type", "hidden"), e.appendChild(t).setAttribute("name", "D"), e.querySelectorAll("[name=d]").length && v.push("name" + M + "*[*^$|!~]?="), 2 !== e.querySelectorAll(":enabled").length && v.push(":enabled", ":disabled"), a.appendChild(e).disabled = !0, 2 !== e.querySelectorAll(":disabled").length && v.push(":enabled", ":disabled"), e.querySelectorAll("*,:x"), v.push(",.*:") })), (d.matchesSelector = K.test(c = a.matches || a.webkitMatchesSelector || a.mozMatchesSelector || a.oMatchesSelector || a.msMatchesSelector)) && ce(function (e) { d.disconnectedMatch = c.call(e, "*"), c.call(e, "[s!='']:x"), s.push("!=", $) }), v = v.length && new RegExp(v.join("|")), s = s.length && new RegExp(s.join("|")), t = K.test(a.compareDocumentPosition), y = t || K.test(a.contains) ? function (e, t) { var n = 9 === e.nodeType ? e.documentElement : e, r = t && t.parentNode; return e === r || !(!r || 1 !== r.nodeType || !(n.contains ? n.contains(r) : e.compareDocumentPosition && 16 & e.compareDocumentPosition(r))) } : function (e, t) { if (t) while (t = t.parentNode) if (t === e) return !0; return !1 }, D = t ? function (e, t) { if (e === t) return l = !0, 0; var n = !e.compareDocumentPosition - !t.compareDocumentPosition; return n || (1 & (n = (e.ownerDocument || e) === (t.ownerDocument || t) ? e.compareDocumentPosition(t) : 1) || !d.sortDetached && t.compareDocumentPosition(e) === n ? e === C || e.ownerDocument === m && y(m, e) ? -1 : t === C || t.ownerDocument === m && y(m, t) ? 1 : u ? P(u, e) - P(u, t) : 0 : 4 & n ? -1 : 1) } : function (e, t) { if (e === t) return l = !0, 0; var n, r = 0, i = e.parentNode, o = t.parentNode, a = [e], s = [t]; if (!i || !o) return e === C ? -1 : t === C ? 1 : i ? -1 : o ? 1 : u ? P(u, e) - P(u, t) : 0; if (i === o) return pe(e, t); n = e; while (n = n.parentNode) a.unshift(n); n = t; while (n = n.parentNode) s.unshift(n); while (a[r] === s[r]) r++; return r ? pe(a[r], s[r]) : a[r] === m ? -1 : s[r] === m ? 1 : 0 }), C }, se.matches = function (e, t) { return se(e, null, null, t) }, se.matchesSelector = function (e, t) { if ((e.ownerDocument || e) !== C && T(e), d.matchesSelector && E && !A[t + " "] && (!s || !s.test(t)) && (!v || !v.test(t))) try { var n = c.call(e, t); if (n || d.disconnectedMatch || e.document && 11 !== e.document.nodeType) return n } catch (e) { A(t, !0) } return 0 < se(t, C, null, [e]).length }, se.contains = function (e, t) { return (e.ownerDocument || e) !== C && T(e), y(e, t) }, se.attr = function (e, t) { (e.ownerDocument || e) !== C && T(e); var n = b.attrHandle[t.toLowerCase()], r = n && j.call(b.attrHandle, t.toLowerCase()) ? n(e, t, !E) : void 0; return void 0 !== r ? r : d.attributes || !E ? e.getAttribute(t) : (r = e.getAttributeNode(t)) && r.specified ? r.value : null }, se.escape = function (e) { return (e + "").replace(re, ie) }, se.error = function (e) { throw new Error("Syntax error, unrecognized expression: " + e) }, se.uniqueSort = function (e) { var t, n = [], r = 0, i = 0; if (l = !d.detectDuplicates, u = !d.sortStable && e.slice(0), e.sort(D), l) { while (t = e[i++]) t === e[i] && (r = n.push(i)); while (r--) e.splice(n[r], 1) } return u = null, e }, o = se.getText = function (e) { var t, n = "", r = 0, i = e.nodeType; if (i) { if (1 === i || 9 === i || 11 === i) { if ("string" == typeof e.textContent) return e.textContent; for (e = e.firstChild; e; e = e.nextSibling)n += o(e) } else if (3 === i || 4 === i) return e.nodeValue } else while (t = e[r++]) n += o(t); return n }, (b = se.selectors = { cacheLength: 50, createPseudo: le, match: G, attrHandle: {}, find: {}, relative: { ">": { dir: "parentNode", first: !0 }, " ": { dir: "parentNode" }, "+": { dir: "previousSibling", first: !0 }, "~": { dir: "previousSibling" } }, preFilter: { ATTR: function (e) { return e[1] = e[1].replace(te, ne), e[3] = (e[3] || e[4] || e[5] || "").replace(te, ne), "~=" === e[2] && (e[3] = " " + e[3] + " "), e.slice(0, 4) }, CHILD: function (e) { return e[1] = e[1].toLowerCase(), "nth" === e[1].slice(0, 3) ? (e[3] || se.error(e[0]), e[4] = +(e[4] ? e[5] + (e[6] || 1) : 2 * ("even" === e[3] || "odd" === e[3])), e[5] = +(e[7] + e[8] || "odd" === e[3])) : e[3] && se.error(e[0]), e }, PSEUDO: function (e) { var t, n = !e[6] && e[2]; return G.CHILD.test(e[0]) ? null : (e[3] ? e[2] = e[4] || e[5] || "" : n && X.test(n) && (t = h(n, !0)) && (t = n.indexOf(")", n.length - t) - n.length) && (e[0] = e[0].slice(0, t), e[2] = n.slice(0, t)), e.slice(0, 3)) } }, filter: { TAG: function (e) { var t = e.replace(te, ne).toLowerCase(); return "*" === e ? function () { return !0 } : function (e) { return e.nodeName && e.nodeName.toLowerCase() === t } }, CLASS: function (e) { var t = p[e + " "]; return t || (t = new RegExp("(^|" + M + ")" + e + "(" + M + "|$)")) && p(e, function (e) { return t.test("string" == typeof e.className && e.className || "undefined" != typeof e.getAttribute && e.getAttribute("class") || "") }) }, ATTR: function (n, r, i) { return function (e) { var t = se.attr(e, n); return null == t ? "!=" === r : !r || (t += "", "=" === r ? t === i : "!=" === r ? t !== i : "^=" === r ? i && 0 === t.indexOf(i) : "*=" === r ? i && -1 < t.indexOf(i) : "$=" === r ? i && t.slice(-i.length) === i : "~=" === r ? -1 < (" " + t.replace(F, " ") + " ").indexOf(i) : "|=" === r && (t === i || t.slice(0, i.length + 1) === i + "-")) } }, CHILD: function (h, e, t, g, v) { var y = "nth" !== h.slice(0, 3), m = "last" !== h.slice(-4), x = "of-type" === e; return 1 === g && 0 === v ? function (e) { return !!e.parentNode } : function (e, t, n) { var r, i, o, a, s, u, l = y !== m ? "nextSibling" : "previousSibling", c = e.parentNode, f = x && e.nodeName.toLowerCase(), p = !n && !x, d = !1; if (c) { if (y) { while (l) { a = e; while (a = a[l]) if (x ? a.nodeName.toLowerCase() === f : 1 === a.nodeType) return !1; u = l = "only" === h && !u && "nextSibling" } return !0 } if (u = [m ? c.firstChild : c.lastChild], m && p) { d = (s = (r = (i = (o = (a = c)[k] || (a[k] = {}))[a.uniqueID] || (o[a.uniqueID] = {}))[h] || [])[0] === S && r[1]) && r[2], a = s && c.childNodes[s]; while (a = ++s && a && a[l] || (d = s = 0) || u.pop()) if (1 === a.nodeType && ++d && a === e) { i[h] = [S, s, d]; break } } else if (p && (d = s = (r = (i = (o = (a = e)[k] || (a[k] = {}))[a.uniqueID] || (o[a.uniqueID] = {}))[h] || [])[0] === S && r[1]), !1 === d) while (a = ++s && a && a[l] || (d = s = 0) || u.pop()) if ((x ? a.nodeName.toLowerCase() === f : 1 === a.nodeType) && ++d && (p && ((i = (o = a[k] || (a[k] = {}))[a.uniqueID] || (o[a.uniqueID] = {}))[h] = [S, d]), a === e)) break; return (d -= v) === g || d % g == 0 && 0 <= d / g } } }, PSEUDO: function (e, o) { var t, a = b.pseudos[e] || b.setFilters[e.toLowerCase()] || se.error("unsupported pseudo: " + e); return a[k] ? a(o) : 1 < a.length ? (t = [e, e, "", o], b.setFilters.hasOwnProperty(e.toLowerCase()) ? le(function (e, t) { var n, r = a(e, o), i = r.length; while (i--) e[n = P(e, r[i])] = !(t[n] = r[i]) }) : function (e) { return a(e, 0, t) }) : a } }, pseudos: { not: le(function (e) { var r = [], i = [], s = f(e.replace(B, "$1")); return s[k] ? le(function (e, t, n, r) { var i, o = s(e, null, r, []), a = e.length; while (a--) (i = o[a]) && (e[a] = !(t[a] = i)) }) : function (e, t, n) { return r[0] = e, s(r, null, n, i), r[0] = null, !i.pop() } }), has: le(function (t) { return function (e) { return 0 < se(t, e).length } }), contains: le(function (t) { return t = t.replace(te, ne), function (e) { return -1 < (e.textContent || o(e)).indexOf(t) } }), lang: le(function (n) { return V.test(n || "") || se.error("unsupported lang: " + n), n = n.replace(te, ne).toLowerCase(), function (e) { var t; do { if (t = E ? e.lang : e.getAttribute("xml:lang") || e.getAttribute("lang")) return (t = t.toLowerCase()) === n || 0 === t.indexOf(n + "-") } while ((e = e.parentNode) && 1 === e.nodeType); return !1 } }), target: function (e) { var t = n.location && n.location.hash; return t && t.slice(1) === e.id }, root: function (e) { return e === a }, focus: function (e) { return e === C.activeElement && (!C.hasFocus || C.hasFocus()) && !!(e.type || e.href || ~e.tabIndex) }, enabled: ge(!1), disabled: ge(!0), checked: function (e) { var t = e.nodeName.toLowerCase(); return "input" === t && !!e.checked || "option" === t && !!e.selected }, selected: function (e) { return e.parentNode && e.parentNode.selectedIndex, !0 === e.selected }, empty: function (e) { for (e = e.firstChild; e; e = e.nextSibling)if (e.nodeType < 6) return !1; return !0 }, parent: function (e) { return !b.pseudos.empty(e) }, header: function (e) { return J.test(e.nodeName) }, input: function (e) { return Q.test(e.nodeName) }, button: function (e) { var t = e.nodeName.toLowerCase(); return "input" === t && "button" === e.type || "button" === t }, text: function (e) { var t; return "input" === e.nodeName.toLowerCase() && "text" === e.type && (null == (t = e.getAttribute("type")) || "text" === t.toLowerCase()) }, first: ve(function () { return [0] }), last: ve(function (e, t) { return [t - 1] }), eq: ve(function (e, t, n) { return [n < 0 ? n + t : n] }), even: ve(function (e, t) { for (var n = 0; n < t; n += 2)e.push(n); return e }), odd: ve(function (e, t) { for (var n = 1; n < t; n += 2)e.push(n); return e }), lt: ve(function (e, t, n) { for (var r = n < 0 ? n + t : t < n ? t : n; 0 <= --r;)e.push(r); return e }), gt: ve(function (e, t, n) { for (var r = n < 0 ? n + t : n; ++r < t;)e.push(r); return e }) } }).pseudos.nth = b.pseudos.eq, { radio: !0, checkbox: !0, file: !0, password: !0, image: !0 }) b.pseudos[e] = de(e); for (e in { submit: !0, reset: !0 }) b.pseudos[e] = he(e); function me() { } function xe(e) { for (var t = 0, n = e.length, r = ""; t < n; t++)r += e[t].value; return r } function be(s, e, t) { var u = e.dir, l = e.next, c = l || u, f = t && "parentNode" === c, p = r++; return e.first ? function (e, t, n) { while (e = e[u]) if (1 === e.nodeType || f) return s(e, t, n); return !1 } : function (e, t, n) { var r, i, o, a = [S, p]; if (n) { while (e = e[u]) if ((1 === e.nodeType || f) && s(e, t, n)) return !0 } else while (e = e[u]) if (1 === e.nodeType || f) if (i = (o = e[k] || (e[k] = {}))[e.uniqueID] || (o[e.uniqueID] = {}), l && l === e.nodeName.toLowerCase()) e = e[u] || e; else { if ((r = i[c]) && r[0] === S && r[1] === p) return a[2] = r[2]; if ((i[c] = a)[2] = s(e, t, n)) return !0 } return !1 } } function we(i) { return 1 < i.length ? function (e, t, n) { var r = i.length; while (r--) if (!i[r](e, t, n)) return !1; return !0 } : i[0] } function Te(e, t, n, r, i) { for (var o, a = [], s = 0, u = e.length, l = null != t; s < u; s++)(o = e[s]) && (n && !n(o, r, i) || (a.push(o), l && t.push(s))); return a } function Ce(d, h, g, v, y, e) { return v && !v[k] && (v = Ce(v)), y && !y[k] && (y = Ce(y, e)), le(function (e, t, n, r) { var i, o, a, s = [], u = [], l = t.length, c = e || function (e, t, n) { for (var r = 0, i = t.length; r < i; r++)se(e, t[r], n); return n }(h || "*", n.nodeType ? [n] : n, []), f = !d || !e && h ? c : Te(c, s, d, n, r), p = g ? y || (e ? d : l || v) ? [] : t : f; if (g && g(f, p, n, r), v) { i = Te(p, u), v(i, [], n, r), o = i.length; while (o--) (a = i[o]) && (p[u[o]] = !(f[u[o]] = a)) } if (e) { if (y || d) { if (y) { i = [], o = p.length; while (o--) (a = p[o]) && i.push(f[o] = a); y(null, p = [], i, r) } o = p.length; while (o--) (a = p[o]) && -1 < (i = y ? P(e, a) : s[o]) && (e[i] = !(t[i] = a)) } } else p = Te(p === t ? p.splice(l, p.length) : p), y ? y(null, t, p, r) : H.apply(t, p) }) } function Ee(e) { for (var i, t, n, r = e.length, o = b.relative[e[0].type], a = o || b.relative[" "], s = o ? 1 : 0, u = be(function (e) { return e === i }, a, !0), l = be(function (e) { return -1 < P(i, e) }, a, !0), c = [function (e, t, n) { var r = !o && (n || t !== w) || ((i = t).nodeType ? u(e, t, n) : l(e, t, n)); return i = null, r }]; s < r; s++)if (t = b.relative[e[s].type]) c = [be(we(c), t)]; else { if ((t = b.filter[e[s].type].apply(null, e[s].matches))[k]) { for (n = ++s; n < r; n++)if (b.relative[e[n].type]) break; return Ce(1 < s && we(c), 1 < s && xe(e.slice(0, s - 1).concat({ value: " " === e[s - 2].type ? "*" : "" })).replace(B, "$1"), t, s < n && Ee(e.slice(s, n)), n < r && Ee(e = e.slice(n)), n < r && xe(e)) } c.push(t) } return we(c) } return me.prototype = b.filters = b.pseudos, b.setFilters = new me, h = se.tokenize = function (e, t) { var n, r, i, o, a, s, u, l = x[e + " "]; if (l) return t ? 0 : l.slice(0); a = e, s = [], u = b.preFilter; while (a) { for (o in n && !(r = _.exec(a)) || (r && (a = a.slice(r[0].length) || a), s.push(i = [])), n = !1, (r = z.exec(a)) && (n = r.shift(), i.push({ value: n, type: r[0].replace(B, " ") }), a = a.slice(n.length)), b.filter) !(r = G[o].exec(a)) || u[o] && !(r = u[o](r)) || (n = r.shift(), i.push({ value: n, type: o, matches: r }), a = a.slice(n.length)); if (!n) break } return t ? a.length : a ? se.error(e) : x(e, s).slice(0) }, f = se.compile = function (e, t) { var n, v, y, m, x, r, i = [], o = [], a = N[e + " "]; if (!a) { t || (t = h(e)), n = t.length; while (n--) (a = Ee(t[n]))[k] ? i.push(a) : o.push(a); (a = N(e, (v = o, m = 0 < (y = i).length, x = 0 < v.length, r = function (e, t, n, r, i) { var o, a, s, u = 0, l = "0", c = e && [], f = [], p = w, d = e || x && b.find.TAG("*", i), h = S += null == p ? 1 : Math.random() || .1, g = d.length; for (i && (w = t === C || t || i); l !== g && null != (o = d[l]); l++) { if (x && o) { a = 0, t || o.ownerDocument === C || (T(o), n = !E); while (s = v[a++]) if (s(o, t || C, n)) { r.push(o); break } i && (S = h) } m && ((o = !s && o) && u-- , e && c.push(o)) } if (u += l, m && l !== u) { a = 0; while (s = y[a++]) s(c, f, t, n); if (e) { if (0 < u) while (l--) c[l] || f[l] || (f[l] = q.call(r)); f = Te(f) } H.apply(r, f), i && !e && 0 < f.length && 1 < u + y.length && se.uniqueSort(r) } return i && (S = h, w = p), c }, m ? le(r) : r))).selector = e } return a }, g = se.select = function (e, t, n, r) { var i, o, a, s, u, l = "function" == typeof e && e, c = !r && h(e = l.selector || e); if (n = n || [], 1 === c.length) { if (2 < (o = c[0] = c[0].slice(0)).length && "ID" === (a = o[0]).type && 9 === t.nodeType && E && b.relative[o[1].type]) { if (!(t = (b.find.ID(a.matches[0].replace(te, ne), t) || [])[0])) return n; l && (t = t.parentNode), e = e.slice(o.shift().value.length) } i = G.needsContext.test(e) ? 0 : o.length; while (i--) { if (a = o[i], b.relative[s = a.type]) break; if ((u = b.find[s]) && (r = u(a.matches[0].replace(te, ne), ee.test(o[0].type) && ye(t.parentNode) || t))) { if (o.splice(i, 1), !(e = r.length && xe(o))) return H.apply(n, r), n; break } } } return (l || f(e, c))(r, t, !E, n, !t || ee.test(e) && ye(t.parentNode) || t), n }, d.sortStable = k.split("").sort(D).join("") === k, d.detectDuplicates = !!l, T(), d.sortDetached = ce(function (e) { return 1 & e.compareDocumentPosition(C.createElement("fieldset")) }), ce(function (e) { return e.innerHTML = "", "#" === e.firstChild.getAttribute("href") }) || fe("type|href|height|width", function (e, t, n) { if (!n) return e.getAttribute(t, "type" === t.toLowerCase() ? 1 : 2) }), d.attributes && ce(function (e) { return e.innerHTML = "", e.firstChild.setAttribute("value", ""), "" === e.firstChild.getAttribute("value") }) || fe("value", function (e, t, n) { if (!n && "input" === e.nodeName.toLowerCase()) return e.defaultValue }), ce(function (e) { return null == e.getAttribute("disabled") }) || fe(R, function (e, t, n) { var r; if (!n) return !0 === e[t] ? t.toLowerCase() : (r = e.getAttributeNode(t)) && r.specified ? r.value : null }), se }(C); k.find = h, k.expr = h.selectors, k.expr[":"] = k.expr.pseudos, k.uniqueSort = k.unique = h.uniqueSort, k.text = h.getText, k.isXMLDoc = h.isXML, k.contains = h.contains, k.escapeSelector = h.escape; var T = function (e, t, n) { var r = [], i = void 0 !== n; while ((e = e[t]) && 9 !== e.nodeType) if (1 === e.nodeType) { if (i && k(e).is(n)) break; r.push(e) } return r }, S = function (e, t) { for (var n = []; e; e = e.nextSibling)1 === e.nodeType && e !== t && n.push(e); return n }, N = k.expr.match.needsContext; function A(e, t) { return e.nodeName && e.nodeName.toLowerCase() === t.toLowerCase() } var D = /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i; function j(e, n, r) { return m(n) ? k.grep(e, function (e, t) { return !!n.call(e, t, e) !== r }) : n.nodeType ? k.grep(e, function (e) { return e === n !== r }) : "string" != typeof n ? k.grep(e, function (e) { return -1 < i.call(n, e) !== r }) : k.filter(n, e, r) } k.filter = function (e, t, n) { var r = t[0]; return n && (e = ":not(" + e + ")"), 1 === t.length && 1 === r.nodeType ? k.find.matchesSelector(r, e) ? [r] : [] : k.find.matches(e, k.grep(t, function (e) { return 1 === e.nodeType })) }, k.fn.extend({ find: function (e) { var t, n, r = this.length, i = this; if ("string" != typeof e) return this.pushStack(k(e).filter(function () { for (t = 0; t < r; t++)if (k.contains(i[t], this)) return !0 })); for (n = this.pushStack([]), t = 0; t < r; t++)k.find(e, i[t], n); return 1 < r ? k.uniqueSort(n) : n }, filter: function (e) { return this.pushStack(j(this, e || [], !1)) }, not: function (e) { return this.pushStack(j(this, e || [], !0)) }, is: function (e) { return !!j(this, "string" == typeof e && N.test(e) ? k(e) : e || [], !1).length } }); var q, L = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/; (k.fn.init = function (e, t, n) { var r, i; if (!e) return this; if (n = n || q, "string" == typeof e) { if (!(r = "<" === e[0] && ">" === e[e.length - 1] && 3 <= e.length ? [null, e, null] : L.exec(e)) || !r[1] && t) return !t || t.jquery ? (t || n).find(e) : this.constructor(t).find(e); if (r[1]) { if (t = t instanceof k ? t[0] : t, k.merge(this, k.parseHTML(r[1], t && t.nodeType ? t.ownerDocument || t : E, !0)), D.test(r[1]) && k.isPlainObject(t)) for (r in t) m(this[r]) ? this[r](t[r]) : this.attr(r, t[r]); return this } return (i = E.getElementById(r[2])) && (this[0] = i, this.length = 1), this } return e.nodeType ? (this[0] = e, this.length = 1, this) : m(e) ? void 0 !== n.ready ? n.ready(e) : e(k) : k.makeArray(e, this) }).prototype = k.fn, q = k(E); var H = /^(?:parents|prev(?:Until|All))/, O = { children: !0, contents: !0, next: !0, prev: !0 }; function P(e, t) { while ((e = e[t]) && 1 !== e.nodeType); return e } k.fn.extend({ has: function (e) { var t = k(e, this), n = t.length; return this.filter(function () { for (var e = 0; e < n; e++)if (k.contains(this, t[e])) return !0 }) }, closest: function (e, t) { var n, r = 0, i = this.length, o = [], a = "string" != typeof e && k(e); if (!N.test(e)) for (; r < i; r++)for (n = this[r]; n && n !== t; n = n.parentNode)if (n.nodeType < 11 && (a ? -1 < a.index(n) : 1 === n.nodeType && k.find.matchesSelector(n, e))) { o.push(n); break } return this.pushStack(1 < o.length ? k.uniqueSort(o) : o) }, index: function (e) { return e ? "string" == typeof e ? i.call(k(e), this[0]) : i.call(this, e.jquery ? e[0] : e) : this[0] && this[0].parentNode ? this.first().prevAll().length : -1 }, add: function (e, t) { return this.pushStack(k.uniqueSort(k.merge(this.get(), k(e, t)))) }, addBack: function (e) { return this.add(null == e ? this.prevObject : this.prevObject.filter(e)) } }), k.each({ parent: function (e) { var t = e.parentNode; return t && 11 !== t.nodeType ? t : null }, parents: function (e) { return T(e, "parentNode") }, parentsUntil: function (e, t, n) { return T(e, "parentNode", n) }, next: function (e) { return P(e, "nextSibling") }, prev: function (e) { return P(e, "previousSibling") }, nextAll: function (e) { return T(e, "nextSibling") }, prevAll: function (e) { return T(e, "previousSibling") }, nextUntil: function (e, t, n) { return T(e, "nextSibling", n) }, prevUntil: function (e, t, n) { return T(e, "previousSibling", n) }, siblings: function (e) { return S((e.parentNode || {}).firstChild, e) }, children: function (e) { return S(e.firstChild) }, contents: function (e) { return "undefined" != typeof e.contentDocument ? e.contentDocument : (A(e, "template") && (e = e.content || e), k.merge([], e.childNodes)) } }, function (r, i) { k.fn[r] = function (e, t) { var n = k.map(this, i, e); return "Until" !== r.slice(-5) && (t = e), t && "string" == typeof t && (n = k.filter(t, n)), 1 < this.length && (O[r] || k.uniqueSort(n), H.test(r) && n.reverse()), this.pushStack(n) } }); var R = /[^\x20\t\r\n\f]+/g; function M(e) { return e } function I(e) { throw e } function W(e, t, n, r) { var i; try { e && m(i = e.promise) ? i.call(e).done(t).fail(n) : e && m(i = e.then) ? i.call(e, t, n) : t.apply(void 0, [e].slice(r)) } catch (e) { n.apply(void 0, [e]) } } k.Callbacks = function (r) { var e, n; r = "string" == typeof r ? (e = r, n = {}, k.each(e.match(R) || [], function (e, t) { n[t] = !0 }), n) : k.extend({}, r); var i, t, o, a, s = [], u = [], l = -1, c = function () { for (a = a || r.once, o = i = !0; u.length; l = -1) { t = u.shift(); while (++l < s.length) !1 === s[l].apply(t[0], t[1]) && r.stopOnFalse && (l = s.length, t = !1) } r.memory || (t = !1), i = !1, a && (s = t ? [] : "") }, f = { add: function () { return s && (t && !i && (l = s.length - 1, u.push(t)), function n(e) { k.each(e, function (e, t) { m(t) ? r.unique && f.has(t) || s.push(t) : t && t.length && "string" !== w(t) && n(t) }) }(arguments), t && !i && c()), this }, remove: function () { return k.each(arguments, function (e, t) { var n; while (-1 < (n = k.inArray(t, s, n))) s.splice(n, 1), n <= l && l-- }), this }, has: function (e) { return e ? -1 < k.inArray(e, s) : 0 < s.length }, empty: function () { return s && (s = []), this }, disable: function () { return a = u = [], s = t = "", this }, disabled: function () { return !s }, lock: function () { return a = u = [], t || i || (s = t = ""), this }, locked: function () { return !!a }, fireWith: function (e, t) { return a || (t = [e, (t = t || []).slice ? t.slice() : t], u.push(t), i || c()), this }, fire: function () { return f.fireWith(this, arguments), this }, fired: function () { return !!o } }; return f }, k.extend({ Deferred: function (e) { var o = [["notify", "progress", k.Callbacks("memory"), k.Callbacks("memory"), 2], ["resolve", "done", k.Callbacks("once memory"), k.Callbacks("once memory"), 0, "resolved"], ["reject", "fail", k.Callbacks("once memory"), k.Callbacks("once memory"), 1, "rejected"]], i = "pending", a = { state: function () { return i }, always: function () { return s.done(arguments).fail(arguments), this }, "catch": function (e) { return a.then(null, e) }, pipe: function () { var i = arguments; return k.Deferred(function (r) { k.each(o, function (e, t) { var n = m(i[t[4]]) && i[t[4]]; s[t[1]](function () { var e = n && n.apply(this, arguments); e && m(e.promise) ? e.promise().progress(r.notify).done(r.resolve).fail(r.reject) : r[t[0] + "With"](this, n ? [e] : arguments) }) }), i = null }).promise() }, then: function (t, n, r) { var u = 0; function l(i, o, a, s) { return function () { var n = this, r = arguments, e = function () { var e, t; if (!(i < u)) { if ((e = a.apply(n, r)) === o.promise()) throw new TypeError("Thenable self-resolution"); t = e && ("object" == typeof e || "function" == typeof e) && e.then, m(t) ? s ? t.call(e, l(u, o, M, s), l(u, o, I, s)) : (u++ , t.call(e, l(u, o, M, s), l(u, o, I, s), l(u, o, M, o.notifyWith))) : (a !== M && (n = void 0, r = [e]), (s || o.resolveWith)(n, r)) } }, t = s ? e : function () { try { e() } catch (e) { k.Deferred.exceptionHook && k.Deferred.exceptionHook(e, t.stackTrace), u <= i + 1 && (a !== I && (n = void 0, r = [e]), o.rejectWith(n, r)) } }; i ? t() : (k.Deferred.getStackHook && (t.stackTrace = k.Deferred.getStackHook()), C.setTimeout(t)) } } return k.Deferred(function (e) { o[0][3].add(l(0, e, m(r) ? r : M, e.notifyWith)), o[1][3].add(l(0, e, m(t) ? t : M)), o[2][3].add(l(0, e, m(n) ? n : I)) }).promise() }, promise: function (e) { return null != e ? k.extend(e, a) : a } }, s = {}; return k.each(o, function (e, t) { var n = t[2], r = t[5]; a[t[1]] = n.add, r && n.add(function () { i = r }, o[3 - e][2].disable, o[3 - e][3].disable, o[0][2].lock, o[0][3].lock), n.add(t[3].fire), s[t[0]] = function () { return s[t[0] + "With"](this === s ? void 0 : this, arguments), this }, s[t[0] + "With"] = n.fireWith }), a.promise(s), e && e.call(s, s), s }, when: function (e) { var n = arguments.length, t = n, r = Array(t), i = s.call(arguments), o = k.Deferred(), a = function (t) { return function (e) { r[t] = this, i[t] = 1 < arguments.length ? s.call(arguments) : e, --n || o.resolveWith(r, i) } }; if (n <= 1 && (W(e, o.done(a(t)).resolve, o.reject, !n), "pending" === o.state() || m(i[t] && i[t].then))) return o.then(); while (t--) W(i[t], a(t), o.reject); return o.promise() } }); var $ = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/; k.Deferred.exceptionHook = function (e, t) { C.console && C.console.warn && e && $.test(e.name) && C.console.warn("jQuery.Deferred exception: " + e.message, e.stack, t) }, k.readyException = function (e) { C.setTimeout(function () { throw e }) }; var F = k.Deferred(); function B() { E.removeEventListener("DOMContentLoaded", B), C.removeEventListener("load", B), k.ready() } k.fn.ready = function (e) { return F.then(e)["catch"](function (e) { k.readyException(e) }), this }, k.extend({ isReady: !1, readyWait: 1, ready: function (e) { (!0 === e ? --k.readyWait : k.isReady) || (k.isReady = !0) !== e && 0 < --k.readyWait || F.resolveWith(E, [k]) } }), k.ready.then = F.then, "complete" === E.readyState || "loading" !== E.readyState && !E.documentElement.doScroll ? C.setTimeout(k.ready) : (E.addEventListener("DOMContentLoaded", B), C.addEventListener("load", B)); var _ = function (e, t, n, r, i, o, a) { var s = 0, u = e.length, l = null == n; if ("object" === w(n)) for (s in i = !0, n) _(e, t, s, n[s], !0, o, a); else if (void 0 !== r && (i = !0, m(r) || (a = !0), l && (a ? (t.call(e, r), t = null) : (l = t, t = function (e, t, n) { return l.call(k(e), n) })), t)) for (; s < u; s++)t(e[s], n, a ? r : r.call(e[s], s, t(e[s], n))); return i ? e : l ? t.call(e) : u ? t(e[0], n) : o }, z = /^-ms-/, U = /-([a-z])/g; function X(e, t) { return t.toUpperCase() } function V(e) { return e.replace(z, "ms-").replace(U, X) } var G = function (e) { return 1 === e.nodeType || 9 === e.nodeType || !+e.nodeType }; function Y() { this.expando = k.expando + Y.uid++ } Y.uid = 1, Y.prototype = { cache: function (e) { var t = e[this.expando]; return t || (t = {}, G(e) && (e.nodeType ? e[this.expando] = t : Object.defineProperty(e, this.expando, { value: t, configurable: !0 }))), t }, set: function (e, t, n) { var r, i = this.cache(e); if ("string" == typeof t) i[V(t)] = n; else for (r in t) i[V(r)] = t[r]; return i }, get: function (e, t) { return void 0 === t ? this.cache(e) : e[this.expando] && e[this.expando][V(t)] }, access: function (e, t, n) { return void 0 === t || t && "string" == typeof t && void 0 === n ? this.get(e, t) : (this.set(e, t, n), void 0 !== n ? n : t) }, remove: function (e, t) { var n, r = e[this.expando]; if (void 0 !== r) { if (void 0 !== t) { n = (t = Array.isArray(t) ? t.map(V) : (t = V(t)) in r ? [t] : t.match(R) || []).length; while (n--) delete r[t[n]] } (void 0 === t || k.isEmptyObject(r)) && (e.nodeType ? e[this.expando] = void 0 : delete e[this.expando]) } }, hasData: function (e) { var t = e[this.expando]; return void 0 !== t && !k.isEmptyObject(t) } }; var Q = new Y, J = new Y, K = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/, Z = /[A-Z]/g; function ee(e, t, n) { var r, i; if (void 0 === n && 1 === e.nodeType) if (r = "data-" + t.replace(Z, "-$&").toLowerCase(), "string" == typeof (n = e.getAttribute(r))) { try { n = "true" === (i = n) || "false" !== i && ("null" === i ? null : i === +i + "" ? +i : K.test(i) ? JSON.parse(i) : i) } catch (e) { } J.set(e, t, n) } else n = void 0; return n } k.extend({ hasData: function (e) { return J.hasData(e) || Q.hasData(e) }, data: function (e, t, n) { return J.access(e, t, n) }, removeData: function (e, t) { J.remove(e, t) }, _data: function (e, t, n) { return Q.access(e, t, n) }, _removeData: function (e, t) { Q.remove(e, t) } }), k.fn.extend({ data: function (n, e) { var t, r, i, o = this[0], a = o && o.attributes; if (void 0 === n) { if (this.length && (i = J.get(o), 1 === o.nodeType && !Q.get(o, "hasDataAttrs"))) { t = a.length; while (t--) a[t] && 0 === (r = a[t].name).indexOf("data-") && (r = V(r.slice(5)), ee(o, r, i[r])); Q.set(o, "hasDataAttrs", !0) } return i } return "object" == typeof n ? this.each(function () { J.set(this, n) }) : _(this, function (e) { var t; if (o && void 0 === e) return void 0 !== (t = J.get(o, n)) ? t : void 0 !== (t = ee(o, n)) ? t : void 0; this.each(function () { J.set(this, n, e) }) }, null, e, 1 < arguments.length, null, !0) }, removeData: function (e) { return this.each(function () { J.remove(this, e) }) } }), k.extend({ queue: function (e, t, n) { var r; if (e) return t = (t || "fx") + "queue", r = Q.get(e, t), n && (!r || Array.isArray(n) ? r = Q.access(e, t, k.makeArray(n)) : r.push(n)), r || [] }, dequeue: function (e, t) { t = t || "fx"; var n = k.queue(e, t), r = n.length, i = n.shift(), o = k._queueHooks(e, t); "inprogress" === i && (i = n.shift(), r--), i && ("fx" === t && n.unshift("inprogress"), delete o.stop, i.call(e, function () { k.dequeue(e, t) }, o)), !r && o && o.empty.fire() }, _queueHooks: function (e, t) { var n = t + "queueHooks"; return Q.get(e, n) || Q.access(e, n, { empty: k.Callbacks("once memory").add(function () { Q.remove(e, [t + "queue", n]) }) }) } }), k.fn.extend({ queue: function (t, n) { var e = 2; return "string" != typeof t && (n = t, t = "fx", e--), arguments.length < e ? k.queue(this[0], t) : void 0 === n ? this : this.each(function () { var e = k.queue(this, t, n); k._queueHooks(this, t), "fx" === t && "inprogress" !== e[0] && k.dequeue(this, t) }) }, dequeue: function (e) { return this.each(function () { k.dequeue(this, e) }) }, clearQueue: function (e) { return this.queue(e || "fx", []) }, promise: function (e, t) { var n, r = 1, i = k.Deferred(), o = this, a = this.length, s = function () { --r || i.resolveWith(o, [o]) }; "string" != typeof e && (t = e, e = void 0), e = e || "fx"; while (a--) (n = Q.get(o[a], e + "queueHooks")) && n.empty && (r++ , n.empty.add(s)); return s(), i.promise(t) } }); var te = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source, ne = new RegExp("^(?:([+-])=|)(" + te + ")([a-z%]*)$", "i"), re = ["Top", "Right", "Bottom", "Left"], ie = E.documentElement, oe = function (e) { return k.contains(e.ownerDocument, e) }, ae = { composed: !0 }; ie.getRootNode && (oe = function (e) { return k.contains(e.ownerDocument, e) || e.getRootNode(ae) === e.ownerDocument }); var se = function (e, t) { return "none" === (e = t || e).style.display || "" === e.style.display && oe(e) && "none" === k.css(e, "display") }, ue = function (e, t, n, r) { var i, o, a = {}; for (o in t) a[o] = e.style[o], e.style[o] = t[o]; for (o in i = n.apply(e, r || []), t) e.style[o] = a[o]; return i }; function le(e, t, n, r) { var i, o, a = 20, s = r ? function () { return r.cur() } : function () { return k.css(e, t, "") }, u = s(), l = n && n[3] || (k.cssNumber[t] ? "" : "px"), c = e.nodeType && (k.cssNumber[t] || "px" !== l && +u) && ne.exec(k.css(e, t)); if (c && c[3] !== l) { u /= 2, l = l || c[3], c = +u || 1; while (a--) k.style(e, t, c + l), (1 - o) * (1 - (o = s() / u || .5)) <= 0 && (a = 0), c /= o; c *= 2, k.style(e, t, c + l), n = n || [] } return n && (c = +c || +u || 0, i = n[1] ? c + (n[1] + 1) * n[2] : +n[2], r && (r.unit = l, r.start = c, r.end = i)), i } var ce = {}; function fe(e, t) { for (var n, r, i, o, a, s, u, l = [], c = 0, f = e.length; c < f; c++)(r = e[c]).style && (n = r.style.display, t ? ("none" === n && (l[c] = Q.get(r, "display") || null, l[c] || (r.style.display = "")), "" === r.style.display && se(r) && (l[c] = (u = a = o = void 0, a = (i = r).ownerDocument, s = i.nodeName, (u = ce[s]) || (o = a.body.appendChild(a.createElement(s)), u = k.css(o, "display"), o.parentNode.removeChild(o), "none" === u && (u = "block"), ce[s] = u)))) : "none" !== n && (l[c] = "none", Q.set(r, "display", n))); for (c = 0; c < f; c++)null != l[c] && (e[c].style.display = l[c]); return e } k.fn.extend({ show: function () { return fe(this, !0) }, hide: function () { return fe(this) }, toggle: function (e) { return "boolean" == typeof e ? e ? this.show() : this.hide() : this.each(function () { se(this) ? k(this).show() : k(this).hide() }) } }); var pe = /^(?:checkbox|radio)$/i, de = /<([a-z][^\/\0>\x20\t\r\n\f]*)/i, he = /^$|^module$|\/(?:java|ecma)script/i, ge = { option: [1, ""], thead: [1, "", "
"], col: [2, "", "
"], tr: [2, "", "
"], td: [3, "", "
"], _default: [0, "", ""] }; function ve(e, t) { var n; return n = "undefined" != typeof e.getElementsByTagName ? e.getElementsByTagName(t || "*") : "undefined" != typeof e.querySelectorAll ? e.querySelectorAll(t || "*") : [], void 0 === t || t && A(e, t) ? k.merge([e], n) : n } function ye(e, t) { for (var n = 0, r = e.length; n < r; n++)Q.set(e[n], "globalEval", !t || Q.get(t[n], "globalEval")) } ge.optgroup = ge.option, ge.tbody = ge.tfoot = ge.colgroup = ge.caption = ge.thead, ge.th = ge.td; var me, xe, be = /<|&#?\w+;/; function we(e, t, n, r, i) { for (var o, a, s, u, l, c, f = t.createDocumentFragment(), p = [], d = 0, h = e.length; d < h; d++)if ((o = e[d]) || 0 === o) if ("object" === w(o)) k.merge(p, o.nodeType ? [o] : o); else if (be.test(o)) { a = a || f.appendChild(t.createElement("div")), s = (de.exec(o) || ["", ""])[1].toLowerCase(), u = ge[s] || ge._default, a.innerHTML = u[1] + k.htmlPrefilter(o) + u[2], c = u[0]; while (c--) a = a.lastChild; k.merge(p, a.childNodes), (a = f.firstChild).textContent = "" } else p.push(t.createTextNode(o)); f.textContent = "", d = 0; while (o = p[d++]) if (r && -1 < k.inArray(o, r)) i && i.push(o); else if (l = oe(o), a = ve(f.appendChild(o), "script"), l && ye(a), n) { c = 0; while (o = a[c++]) he.test(o.type || "") && n.push(o) } return f } me = E.createDocumentFragment().appendChild(E.createElement("div")), (xe = E.createElement("input")).setAttribute("type", "radio"), xe.setAttribute("checked", "checked"), xe.setAttribute("name", "t"), me.appendChild(xe), y.checkClone = me.cloneNode(!0).cloneNode(!0).lastChild.checked, me.innerHTML = "", y.noCloneChecked = !!me.cloneNode(!0).lastChild.defaultValue; var Te = /^key/, Ce = /^(?:mouse|pointer|contextmenu|drag|drop)|click/, Ee = /^([^.]*)(?:\.(.+)|)/; function ke() { return !0 } function Se() { return !1 } function Ne(e, t) { return e === function () { try { return E.activeElement } catch (e) { } }() == ("focus" === t) } function Ae(e, t, n, r, i, o) { var a, s; if ("object" == typeof t) { for (s in "string" != typeof n && (r = r || n, n = void 0), t) Ae(e, s, n, r, t[s], o); return e } if (null == r && null == i ? (i = n, r = n = void 0) : null == i && ("string" == typeof n ? (i = r, r = void 0) : (i = r, r = n, n = void 0)), !1 === i) i = Se; else if (!i) return e; return 1 === o && (a = i, (i = function (e) { return k().off(e), a.apply(this, arguments) }).guid = a.guid || (a.guid = k.guid++)), e.each(function () { k.event.add(this, t, i, r, n) }) } function De(e, i, o) { o ? (Q.set(e, i, !1), k.event.add(e, i, { namespace: !1, handler: function (e) { var t, n, r = Q.get(this, i); if (1 & e.isTrigger && this[i]) { if (r.length) (k.event.special[i] || {}).delegateType && e.stopPropagation(); else if (r = s.call(arguments), Q.set(this, i, r), t = o(this, i), this[i](), r !== (n = Q.get(this, i)) || t ? Q.set(this, i, !1) : n = {}, r !== n) return e.stopImmediatePropagation(), e.preventDefault(), n.value } else r.length && (Q.set(this, i, { value: k.event.trigger(k.extend(r[0], k.Event.prototype), r.slice(1), this) }), e.stopImmediatePropagation()) } })) : void 0 === Q.get(e, i) && k.event.add(e, i, ke) } k.event = { global: {}, add: function (t, e, n, r, i) { var o, a, s, u, l, c, f, p, d, h, g, v = Q.get(t); if (v) { n.handler && (n = (o = n).handler, i = o.selector), i && k.find.matchesSelector(ie, i), n.guid || (n.guid = k.guid++), (u = v.events) || (u = v.events = {}), (a = v.handle) || (a = v.handle = function (e) { return "undefined" != typeof k && k.event.triggered !== e.type ? k.event.dispatch.apply(t, arguments) : void 0 }), l = (e = (e || "").match(R) || [""]).length; while (l--) d = g = (s = Ee.exec(e[l]) || [])[1], h = (s[2] || "").split(".").sort(), d && (f = k.event.special[d] || {}, d = (i ? f.delegateType : f.bindType) || d, f = k.event.special[d] || {}, c = k.extend({ type: d, origType: g, data: r, handler: n, guid: n.guid, selector: i, needsContext: i && k.expr.match.needsContext.test(i), namespace: h.join(".") }, o), (p = u[d]) || ((p = u[d] = []).delegateCount = 0, f.setup && !1 !== f.setup.call(t, r, h, a) || t.addEventListener && t.addEventListener(d, a)), f.add && (f.add.call(t, c), c.handler.guid || (c.handler.guid = n.guid)), i ? p.splice(p.delegateCount++, 0, c) : p.push(c), k.event.global[d] = !0) } }, remove: function (e, t, n, r, i) { var o, a, s, u, l, c, f, p, d, h, g, v = Q.hasData(e) && Q.get(e); if (v && (u = v.events)) { l = (t = (t || "").match(R) || [""]).length; while (l--) if (d = g = (s = Ee.exec(t[l]) || [])[1], h = (s[2] || "").split(".").sort(), d) { f = k.event.special[d] || {}, p = u[d = (r ? f.delegateType : f.bindType) || d] || [], s = s[2] && new RegExp("(^|\\.)" + h.join("\\.(?:.*\\.|)") + "(\\.|$)"), a = o = p.length; while (o--) c = p[o], !i && g !== c.origType || n && n.guid !== c.guid || s && !s.test(c.namespace) || r && r !== c.selector && ("**" !== r || !c.selector) || (p.splice(o, 1), c.selector && p.delegateCount-- , f.remove && f.remove.call(e, c)); a && !p.length && (f.teardown && !1 !== f.teardown.call(e, h, v.handle) || k.removeEvent(e, d, v.handle), delete u[d]) } else for (d in u) k.event.remove(e, d + t[l], n, r, !0); k.isEmptyObject(u) && Q.remove(e, "handle events") } }, dispatch: function (e) { var t, n, r, i, o, a, s = k.event.fix(e), u = new Array(arguments.length), l = (Q.get(this, "events") || {})[s.type] || [], c = k.event.special[s.type] || {}; for (u[0] = s, t = 1; t < arguments.length; t++)u[t] = arguments[t]; if (s.delegateTarget = this, !c.preDispatch || !1 !== c.preDispatch.call(this, s)) { a = k.event.handlers.call(this, s, l), t = 0; while ((i = a[t++]) && !s.isPropagationStopped()) { s.currentTarget = i.elem, n = 0; while ((o = i.handlers[n++]) && !s.isImmediatePropagationStopped()) s.rnamespace && !1 !== o.namespace && !s.rnamespace.test(o.namespace) || (s.handleObj = o, s.data = o.data, void 0 !== (r = ((k.event.special[o.origType] || {}).handle || o.handler).apply(i.elem, u)) && !1 === (s.result = r) && (s.preventDefault(), s.stopPropagation())) } return c.postDispatch && c.postDispatch.call(this, s), s.result } }, handlers: function (e, t) { var n, r, i, o, a, s = [], u = t.delegateCount, l = e.target; if (u && l.nodeType && !("click" === e.type && 1 <= e.button)) for (; l !== this; l = l.parentNode || this)if (1 === l.nodeType && ("click" !== e.type || !0 !== l.disabled)) { for (o = [], a = {}, n = 0; n < u; n++)void 0 === a[i = (r = t[n]).selector + " "] && (a[i] = r.needsContext ? -1 < k(i, this).index(l) : k.find(i, this, null, [l]).length), a[i] && o.push(r); o.length && s.push({ elem: l, handlers: o }) } return l = this, u < t.length && s.push({ elem: l, handlers: t.slice(u) }), s }, addProp: function (t, e) { Object.defineProperty(k.Event.prototype, t, { enumerable: !0, configurable: !0, get: m(e) ? function () { if (this.originalEvent) return e(this.originalEvent) } : function () { if (this.originalEvent) return this.originalEvent[t] }, set: function (e) { Object.defineProperty(this, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) } }) }, fix: function (e) { return e[k.expando] ? e : new k.Event(e) }, special: { load: { noBubble: !0 }, click: { setup: function (e) { var t = this || e; return pe.test(t.type) && t.click && A(t, "input") && De(t, "click", ke), !1 }, trigger: function (e) { var t = this || e; return pe.test(t.type) && t.click && A(t, "input") && De(t, "click"), !0 }, _default: function (e) { var t = e.target; return pe.test(t.type) && t.click && A(t, "input") && Q.get(t, "click") || A(t, "a") } }, beforeunload: { postDispatch: function (e) { void 0 !== e.result && e.originalEvent && (e.originalEvent.returnValue = e.result) } } } }, k.removeEvent = function (e, t, n) { e.removeEventListener && e.removeEventListener(t, n) }, k.Event = function (e, t) { if (!(this instanceof k.Event)) return new k.Event(e, t); e && e.type ? (this.originalEvent = e, this.type = e.type, this.isDefaultPrevented = e.defaultPrevented || void 0 === e.defaultPrevented && !1 === e.returnValue ? ke : Se, this.target = e.target && 3 === e.target.nodeType ? e.target.parentNode : e.target, this.currentTarget = e.currentTarget, this.relatedTarget = e.relatedTarget) : this.type = e, t && k.extend(this, t), this.timeStamp = e && e.timeStamp || Date.now(), this[k.expando] = !0 }, k.Event.prototype = { constructor: k.Event, isDefaultPrevented: Se, isPropagationStopped: Se, isImmediatePropagationStopped: Se, isSimulated: !1, preventDefault: function () { var e = this.originalEvent; this.isDefaultPrevented = ke, e && !this.isSimulated && e.preventDefault() }, stopPropagation: function () { var e = this.originalEvent; this.isPropagationStopped = ke, e && !this.isSimulated && e.stopPropagation() }, stopImmediatePropagation: function () { var e = this.originalEvent; this.isImmediatePropagationStopped = ke, e && !this.isSimulated && e.stopImmediatePropagation(), this.stopPropagation() } }, k.each({ altKey: !0, bubbles: !0, cancelable: !0, changedTouches: !0, ctrlKey: !0, detail: !0, eventPhase: !0, metaKey: !0, pageX: !0, pageY: !0, shiftKey: !0, view: !0, "char": !0, code: !0, charCode: !0, key: !0, keyCode: !0, button: !0, buttons: !0, clientX: !0, clientY: !0, offsetX: !0, offsetY: !0, pointerId: !0, pointerType: !0, screenX: !0, screenY: !0, targetTouches: !0, toElement: !0, touches: !0, which: function (e) { var t = e.button; return null == e.which && Te.test(e.type) ? null != e.charCode ? e.charCode : e.keyCode : !e.which && void 0 !== t && Ce.test(e.type) ? 1 & t ? 1 : 2 & t ? 3 : 4 & t ? 2 : 0 : e.which } }, k.event.addProp), k.each({ focus: "focusin", blur: "focusout" }, function (e, t) { k.event.special[e] = { setup: function () { return De(this, e, Ne), !1 }, trigger: function () { return De(this, e), !0 }, delegateType: t } }), k.each({ mouseenter: "mouseover", mouseleave: "mouseout", pointerenter: "pointerover", pointerleave: "pointerout" }, function (e, i) { k.event.special[e] = { delegateType: i, bindType: i, handle: function (e) { var t, n = e.relatedTarget, r = e.handleObj; return n && (n === this || k.contains(this, n)) || (e.type = r.origType, t = r.handler.apply(this, arguments), e.type = i), t } } }), k.fn.extend({ on: function (e, t, n, r) { return Ae(this, e, t, n, r) }, one: function (e, t, n, r) { return Ae(this, e, t, n, r, 1) }, off: function (e, t, n) { var r, i; if (e && e.preventDefault && e.handleObj) return r = e.handleObj, k(e.delegateTarget).off(r.namespace ? r.origType + "." + r.namespace : r.origType, r.selector, r.handler), this; if ("object" == typeof e) { for (i in e) this.off(i, t, e[i]); return this } return !1 !== t && "function" != typeof t || (n = t, t = void 0), !1 === n && (n = Se), this.each(function () { k.event.remove(this, e, n, t) }) } }); var je = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi, qe = /\s*$/g; function Oe(e, t) { return A(e, "table") && A(11 !== t.nodeType ? t : t.firstChild, "tr") && k(e).children("tbody")[0] || e } function Pe(e) { return e.type = (null !== e.getAttribute("type")) + "/" + e.type, e } function Re(e) { return "true/" === (e.type || "").slice(0, 5) ? e.type = e.type.slice(5) : e.removeAttribute("type"), e } function Me(e, t) { var n, r, i, o, a, s, u, l; if (1 === t.nodeType) { if (Q.hasData(e) && (o = Q.access(e), a = Q.set(t, o), l = o.events)) for (i in delete a.handle, a.events = {}, l) for (n = 0, r = l[i].length; n < r; n++)k.event.add(t, i, l[i][n]); J.hasData(e) && (s = J.access(e), u = k.extend({}, s), J.set(t, u)) } } function Ie(n, r, i, o) { r = g.apply([], r); var e, t, a, s, u, l, c = 0, f = n.length, p = f - 1, d = r[0], h = m(d); if (h || 1 < f && "string" == typeof d && !y.checkClone && Le.test(d)) return n.each(function (e) { var t = n.eq(e); h && (r[0] = d.call(this, e, t.html())), Ie(t, r, i, o) }); if (f && (t = (e = we(r, n[0].ownerDocument, !1, n, o)).firstChild, 1 === e.childNodes.length && (e = t), t || o)) { for (s = (a = k.map(ve(e, "script"), Pe)).length; c < f; c++)u = e, c !== p && (u = k.clone(u, !0, !0), s && k.merge(a, ve(u, "script"))), i.call(n[c], u, c); if (s) for (l = a[a.length - 1].ownerDocument, k.map(a, Re), c = 0; c < s; c++)u = a[c], he.test(u.type || "") && !Q.access(u, "globalEval") && k.contains(l, u) && (u.src && "module" !== (u.type || "").toLowerCase() ? k._evalUrl && !u.noModule && k._evalUrl(u.src, { nonce: u.nonce || u.getAttribute("nonce") }) : b(u.textContent.replace(He, ""), u, l)) } return n } function We(e, t, n) { for (var r, i = t ? k.filter(t, e) : e, o = 0; null != (r = i[o]); o++)n || 1 !== r.nodeType || k.cleanData(ve(r)), r.parentNode && (n && oe(r) && ye(ve(r, "script")), r.parentNode.removeChild(r)); return e } k.extend({ htmlPrefilter: function (e) { return e.replace(je, "<$1>") }, clone: function (e, t, n) { var r, i, o, a, s, u, l, c = e.cloneNode(!0), f = oe(e); if (!(y.noCloneChecked || 1 !== e.nodeType && 11 !== e.nodeType || k.isXMLDoc(e))) for (a = ve(c), r = 0, i = (o = ve(e)).length; r < i; r++)s = o[r], u = a[r], void 0, "input" === (l = u.nodeName.toLowerCase()) && pe.test(s.type) ? u.checked = s.checked : "input" !== l && "textarea" !== l || (u.defaultValue = s.defaultValue); if (t) if (n) for (o = o || ve(e), a = a || ve(c), r = 0, i = o.length; r < i; r++)Me(o[r], a[r]); else Me(e, c); return 0 < (a = ve(c, "script")).length && ye(a, !f && ve(e, "script")), c }, cleanData: function (e) { for (var t, n, r, i = k.event.special, o = 0; void 0 !== (n = e[o]); o++)if (G(n)) { if (t = n[Q.expando]) { if (t.events) for (r in t.events) i[r] ? k.event.remove(n, r) : k.removeEvent(n, r, t.handle); n[Q.expando] = void 0 } n[J.expando] && (n[J.expando] = void 0) } } }), k.fn.extend({ detach: function (e) { return We(this, e, !0) }, remove: function (e) { return We(this, e) }, text: function (e) { return _(this, function (e) { return void 0 === e ? k.text(this) : this.empty().each(function () { 1 !== this.nodeType && 11 !== this.nodeType && 9 !== this.nodeType || (this.textContent = e) }) }, null, e, arguments.length) }, append: function () { return Ie(this, arguments, function (e) { 1 !== this.nodeType && 11 !== this.nodeType && 9 !== this.nodeType || Oe(this, e).appendChild(e) }) }, prepend: function () { return Ie(this, arguments, function (e) { if (1 === this.nodeType || 11 === this.nodeType || 9 === this.nodeType) { var t = Oe(this, e); t.insertBefore(e, t.firstChild) } }) }, before: function () { return Ie(this, arguments, function (e) { this.parentNode && this.parentNode.insertBefore(e, this) }) }, after: function () { return Ie(this, arguments, function (e) { this.parentNode && this.parentNode.insertBefore(e, this.nextSibling) }) }, empty: function () { for (var e, t = 0; null != (e = this[t]); t++)1 === e.nodeType && (k.cleanData(ve(e, !1)), e.textContent = ""); return this }, clone: function (e, t) { return e = null != e && e, t = null == t ? e : t, this.map(function () { return k.clone(this, e, t) }) }, html: function (e) { return _(this, function (e) { var t = this[0] || {}, n = 0, r = this.length; if (void 0 === e && 1 === t.nodeType) return t.innerHTML; if ("string" == typeof e && !qe.test(e) && !ge[(de.exec(e) || ["", ""])[1].toLowerCase()]) { e = k.htmlPrefilter(e); try { for (; n < r; n++)1 === (t = this[n] || {}).nodeType && (k.cleanData(ve(t, !1)), t.innerHTML = e); t = 0 } catch (e) { } } t && this.empty().append(e) }, null, e, arguments.length) }, replaceWith: function () { var n = []; return Ie(this, arguments, function (e) { var t = this.parentNode; k.inArray(this, n) < 0 && (k.cleanData(ve(this)), t && t.replaceChild(e, this)) }, n) } }), k.each({ appendTo: "append", prependTo: "prepend", insertBefore: "before", insertAfter: "after", replaceAll: "replaceWith" }, function (e, a) { k.fn[e] = function (e) { for (var t, n = [], r = k(e), i = r.length - 1, o = 0; o <= i; o++)t = o === i ? this : this.clone(!0), k(r[o])[a](t), u.apply(n, t.get()); return this.pushStack(n) } }); var $e = new RegExp("^(" + te + ")(?!px)[a-z%]+$", "i"), Fe = function (e) { var t = e.ownerDocument.defaultView; return t && t.opener || (t = C), t.getComputedStyle(e) }, Be = new RegExp(re.join("|"), "i"); function _e(e, t, n) { var r, i, o, a, s = e.style; return (n = n || Fe(e)) && ("" !== (a = n.getPropertyValue(t) || n[t]) || oe(e) || (a = k.style(e, t)), !y.pixelBoxStyles() && $e.test(a) && Be.test(t) && (r = s.width, i = s.minWidth, o = s.maxWidth, s.minWidth = s.maxWidth = s.width = a, a = n.width, s.width = r, s.minWidth = i, s.maxWidth = o)), void 0 !== a ? a + "" : a } function ze(e, t) { return { get: function () { if (!e()) return (this.get = t).apply(this, arguments); delete this.get } } } !function () { function e() { if (u) { s.style.cssText = "position:absolute;left:-11111px;width:60px;margin-top:1px;padding:0;border:0", u.style.cssText = "position:relative;display:block;box-sizing:border-box;overflow:scroll;margin:auto;border:1px;padding:1px;width:60%;top:1%", ie.appendChild(s).appendChild(u); var e = C.getComputedStyle(u); n = "1%" !== e.top, a = 12 === t(e.marginLeft), u.style.right = "60%", o = 36 === t(e.right), r = 36 === t(e.width), u.style.position = "absolute", i = 12 === t(u.offsetWidth / 3), ie.removeChild(s), u = null } } function t(e) { return Math.round(parseFloat(e)) } var n, r, i, o, a, s = E.createElement("div"), u = E.createElement("div"); u.style && (u.style.backgroundClip = "content-box", u.cloneNode(!0).style.backgroundClip = "", y.clearCloneStyle = "content-box" === u.style.backgroundClip, k.extend(y, { boxSizingReliable: function () { return e(), r }, pixelBoxStyles: function () { return e(), o }, pixelPosition: function () { return e(), n }, reliableMarginLeft: function () { return e(), a }, scrollboxSize: function () { return e(), i } })) }(); var Ue = ["Webkit", "Moz", "ms"], Xe = E.createElement("div").style, Ve = {}; function Ge(e) { var t = k.cssProps[e] || Ve[e]; return t || (e in Xe ? e : Ve[e] = function (e) { var t = e[0].toUpperCase() + e.slice(1), n = Ue.length; while (n--) if ((e = Ue[n] + t) in Xe) return e }(e) || e) } var Ye = /^(none|table(?!-c[ea]).+)/, Qe = /^--/, Je = { position: "absolute", visibility: "hidden", display: "block" }, Ke = { letterSpacing: "0", fontWeight: "400" }; function Ze(e, t, n) { var r = ne.exec(t); return r ? Math.max(0, r[2] - (n || 0)) + (r[3] || "px") : t } function et(e, t, n, r, i, o) { var a = "width" === t ? 1 : 0, s = 0, u = 0; if (n === (r ? "border" : "content")) return 0; for (; a < 4; a += 2)"margin" === n && (u += k.css(e, n + re[a], !0, i)), r ? ("content" === n && (u -= k.css(e, "padding" + re[a], !0, i)), "margin" !== n && (u -= k.css(e, "border" + re[a] + "Width", !0, i))) : (u += k.css(e, "padding" + re[a], !0, i), "padding" !== n ? u += k.css(e, "border" + re[a] + "Width", !0, i) : s += k.css(e, "border" + re[a] + "Width", !0, i)); return !r && 0 <= o && (u += Math.max(0, Math.ceil(e["offset" + t[0].toUpperCase() + t.slice(1)] - o - u - s - .5)) || 0), u } function tt(e, t, n) { var r = Fe(e), i = (!y.boxSizingReliable() || n) && "border-box" === k.css(e, "boxSizing", !1, r), o = i, a = _e(e, t, r), s = "offset" + t[0].toUpperCase() + t.slice(1); if ($e.test(a)) { if (!n) return a; a = "auto" } return (!y.boxSizingReliable() && i || "auto" === a || !parseFloat(a) && "inline" === k.css(e, "display", !1, r)) && e.getClientRects().length && (i = "border-box" === k.css(e, "boxSizing", !1, r), (o = s in e) && (a = e[s])), (a = parseFloat(a) || 0) + et(e, t, n || (i ? "border" : "content"), o, r, a) + "px" } function nt(e, t, n, r, i) { return new nt.prototype.init(e, t, n, r, i) } k.extend({ cssHooks: { opacity: { get: function (e, t) { if (t) { var n = _e(e, "opacity"); return "" === n ? "1" : n } } } }, cssNumber: { animationIterationCount: !0, columnCount: !0, fillOpacity: !0, flexGrow: !0, flexShrink: !0, fontWeight: !0, gridArea: !0, gridColumn: !0, gridColumnEnd: !0, gridColumnStart: !0, gridRow: !0, gridRowEnd: !0, gridRowStart: !0, lineHeight: !0, opacity: !0, order: !0, orphans: !0, widows: !0, zIndex: !0, zoom: !0 }, cssProps: {}, style: function (e, t, n, r) { if (e && 3 !== e.nodeType && 8 !== e.nodeType && e.style) { var i, o, a, s = V(t), u = Qe.test(t), l = e.style; if (u || (t = Ge(s)), a = k.cssHooks[t] || k.cssHooks[s], void 0 === n) return a && "get" in a && void 0 !== (i = a.get(e, !1, r)) ? i : l[t]; "string" === (o = typeof n) && (i = ne.exec(n)) && i[1] && (n = le(e, t, i), o = "number"), null != n && n == n && ("number" !== o || u || (n += i && i[3] || (k.cssNumber[s] ? "" : "px")), y.clearCloneStyle || "" !== n || 0 !== t.indexOf("background") || (l[t] = "inherit"), a && "set" in a && void 0 === (n = a.set(e, n, r)) || (u ? l.setProperty(t, n) : l[t] = n)) } }, css: function (e, t, n, r) { var i, o, a, s = V(t); return Qe.test(t) || (t = Ge(s)), (a = k.cssHooks[t] || k.cssHooks[s]) && "get" in a && (i = a.get(e, !0, n)), void 0 === i && (i = _e(e, t, r)), "normal" === i && t in Ke && (i = Ke[t]), "" === n || n ? (o = parseFloat(i), !0 === n || isFinite(o) ? o || 0 : i) : i } }), k.each(["height", "width"], function (e, u) { k.cssHooks[u] = { get: function (e, t, n) { if (t) return !Ye.test(k.css(e, "display")) || e.getClientRects().length && e.getBoundingClientRect().width ? tt(e, u, n) : ue(e, Je, function () { return tt(e, u, n) }) }, set: function (e, t, n) { var r, i = Fe(e), o = !y.scrollboxSize() && "absolute" === i.position, a = (o || n) && "border-box" === k.css(e, "boxSizing", !1, i), s = n ? et(e, u, n, a, i) : 0; return a && o && (s -= Math.ceil(e["offset" + u[0].toUpperCase() + u.slice(1)] - parseFloat(i[u]) - et(e, u, "border", !1, i) - .5)), s && (r = ne.exec(t)) && "px" !== (r[3] || "px") && (e.style[u] = t, t = k.css(e, u)), Ze(0, t, s) } } }), k.cssHooks.marginLeft = ze(y.reliableMarginLeft, function (e, t) { if (t) return (parseFloat(_e(e, "marginLeft")) || e.getBoundingClientRect().left - ue(e, { marginLeft: 0 }, function () { return e.getBoundingClientRect().left })) + "px" }), k.each({ margin: "", padding: "", border: "Width" }, function (i, o) { k.cssHooks[i + o] = { expand: function (e) { for (var t = 0, n = {}, r = "string" == typeof e ? e.split(" ") : [e]; t < 4; t++)n[i + re[t] + o] = r[t] || r[t - 2] || r[0]; return n } }, "margin" !== i && (k.cssHooks[i + o].set = Ze) }), k.fn.extend({ css: function (e, t) { return _(this, function (e, t, n) { var r, i, o = {}, a = 0; if (Array.isArray(t)) { for (r = Fe(e), i = t.length; a < i; a++)o[t[a]] = k.css(e, t[a], !1, r); return o } return void 0 !== n ? k.style(e, t, n) : k.css(e, t) }, e, t, 1 < arguments.length) } }), ((k.Tween = nt).prototype = { constructor: nt, init: function (e, t, n, r, i, o) { this.elem = e, this.prop = n, this.easing = i || k.easing._default, this.options = t, this.start = this.now = this.cur(), this.end = r, this.unit = o || (k.cssNumber[n] ? "" : "px") }, cur: function () { var e = nt.propHooks[this.prop]; return e && e.get ? e.get(this) : nt.propHooks._default.get(this) }, run: function (e) { var t, n = nt.propHooks[this.prop]; return this.options.duration ? this.pos = t = k.easing[this.easing](e, this.options.duration * e, 0, 1, this.options.duration) : this.pos = t = e, this.now = (this.end - this.start) * t + this.start, this.options.step && this.options.step.call(this.elem, this.now, this), n && n.set ? n.set(this) : nt.propHooks._default.set(this), this } }).init.prototype = nt.prototype, (nt.propHooks = { _default: { get: function (e) { var t; return 1 !== e.elem.nodeType || null != e.elem[e.prop] && null == e.elem.style[e.prop] ? e.elem[e.prop] : (t = k.css(e.elem, e.prop, "")) && "auto" !== t ? t : 0 }, set: function (e) { k.fx.step[e.prop] ? k.fx.step[e.prop](e) : 1 !== e.elem.nodeType || !k.cssHooks[e.prop] && null == e.elem.style[Ge(e.prop)] ? e.elem[e.prop] = e.now : k.style(e.elem, e.prop, e.now + e.unit) } } }).scrollTop = nt.propHooks.scrollLeft = { set: function (e) { e.elem.nodeType && e.elem.parentNode && (e.elem[e.prop] = e.now) } }, k.easing = { linear: function (e) { return e }, swing: function (e) { return .5 - Math.cos(e * Math.PI) / 2 }, _default: "swing" }, k.fx = nt.prototype.init, k.fx.step = {}; var rt, it, ot, at, st = /^(?:toggle|show|hide)$/, ut = /queueHooks$/; function lt() { it && (!1 === E.hidden && C.requestAnimationFrame ? C.requestAnimationFrame(lt) : C.setTimeout(lt, k.fx.interval), k.fx.tick()) } function ct() { return C.setTimeout(function () { rt = void 0 }), rt = Date.now() } function ft(e, t) { var n, r = 0, i = { height: e }; for (t = t ? 1 : 0; r < 4; r += 2 - t)i["margin" + (n = re[r])] = i["padding" + n] = e; return t && (i.opacity = i.width = e), i } function pt(e, t, n) { for (var r, i = (dt.tweeners[t] || []).concat(dt.tweeners["*"]), o = 0, a = i.length; o < a; o++)if (r = i[o].call(n, t, e)) return r } function dt(o, e, t) { var n, a, r = 0, i = dt.prefilters.length, s = k.Deferred().always(function () { delete u.elem }), u = function () { if (a) return !1; for (var e = rt || ct(), t = Math.max(0, l.startTime + l.duration - e), n = 1 - (t / l.duration || 0), r = 0, i = l.tweens.length; r < i; r++)l.tweens[r].run(n); return s.notifyWith(o, [l, n, t]), n < 1 && i ? t : (i || s.notifyWith(o, [l, 1, 0]), s.resolveWith(o, [l]), !1) }, l = s.promise({ elem: o, props: k.extend({}, e), opts: k.extend(!0, { specialEasing: {}, easing: k.easing._default }, t), originalProperties: e, originalOptions: t, startTime: rt || ct(), duration: t.duration, tweens: [], createTween: function (e, t) { var n = k.Tween(o, l.opts, e, t, l.opts.specialEasing[e] || l.opts.easing); return l.tweens.push(n), n }, stop: function (e) { var t = 0, n = e ? l.tweens.length : 0; if (a) return this; for (a = !0; t < n; t++)l.tweens[t].run(1); return e ? (s.notifyWith(o, [l, 1, 0]), s.resolveWith(o, [l, e])) : s.rejectWith(o, [l, e]), this } }), c = l.props; for (!function (e, t) { var n, r, i, o, a; for (n in e) if (i = t[r = V(n)], o = e[n], Array.isArray(o) && (i = o[1], o = e[n] = o[0]), n !== r && (e[r] = o, delete e[n]), (a = k.cssHooks[r]) && "expand" in a) for (n in o = a.expand(o), delete e[r], o) n in e || (e[n] = o[n], t[n] = i); else t[r] = i }(c, l.opts.specialEasing); r < i; r++)if (n = dt.prefilters[r].call(l, o, c, l.opts)) return m(n.stop) && (k._queueHooks(l.elem, l.opts.queue).stop = n.stop.bind(n)), n; return k.map(c, pt, l), m(l.opts.start) && l.opts.start.call(o, l), l.progress(l.opts.progress).done(l.opts.done, l.opts.complete).fail(l.opts.fail).always(l.opts.always), k.fx.timer(k.extend(u, { elem: o, anim: l, queue: l.opts.queue })), l } k.Animation = k.extend(dt, { tweeners: { "*": [function (e, t) { var n = this.createTween(e, t); return le(n.elem, e, ne.exec(t), n), n }] }, tweener: function (e, t) { m(e) ? (t = e, e = ["*"]) : e = e.match(R); for (var n, r = 0, i = e.length; r < i; r++)n = e[r], dt.tweeners[n] = dt.tweeners[n] || [], dt.tweeners[n].unshift(t) }, prefilters: [function (e, t, n) { var r, i, o, a, s, u, l, c, f = "width" in t || "height" in t, p = this, d = {}, h = e.style, g = e.nodeType && se(e), v = Q.get(e, "fxshow"); for (r in n.queue || (null == (a = k._queueHooks(e, "fx")).unqueued && (a.unqueued = 0, s = a.empty.fire, a.empty.fire = function () { a.unqueued || s() }), a.unqueued++ , p.always(function () { p.always(function () { a.unqueued-- , k.queue(e, "fx").length || a.empty.fire() }) })), t) if (i = t[r], st.test(i)) { if (delete t[r], o = o || "toggle" === i, i === (g ? "hide" : "show")) { if ("show" !== i || !v || void 0 === v[r]) continue; g = !0 } d[r] = v && v[r] || k.style(e, r) } if ((u = !k.isEmptyObject(t)) || !k.isEmptyObject(d)) for (r in f && 1 === e.nodeType && (n.overflow = [h.overflow, h.overflowX, h.overflowY], null == (l = v && v.display) && (l = Q.get(e, "display")), "none" === (c = k.css(e, "display")) && (l ? c = l : (fe([e], !0), l = e.style.display || l, c = k.css(e, "display"), fe([e]))), ("inline" === c || "inline-block" === c && null != l) && "none" === k.css(e, "float") && (u || (p.done(function () { h.display = l }), null == l && (c = h.display, l = "none" === c ? "" : c)), h.display = "inline-block")), n.overflow && (h.overflow = "hidden", p.always(function () { h.overflow = n.overflow[0], h.overflowX = n.overflow[1], h.overflowY = n.overflow[2] })), u = !1, d) u || (v ? "hidden" in v && (g = v.hidden) : v = Q.access(e, "fxshow", { display: l }), o && (v.hidden = !g), g && fe([e], !0), p.done(function () { for (r in g || fe([e]), Q.remove(e, "fxshow"), d) k.style(e, r, d[r]) })), u = pt(g ? v[r] : 0, r, p), r in v || (v[r] = u.start, g && (u.end = u.start, u.start = 0)) }], prefilter: function (e, t) { t ? dt.prefilters.unshift(e) : dt.prefilters.push(e) } }), k.speed = function (e, t, n) { var r = e && "object" == typeof e ? k.extend({}, e) : { complete: n || !n && t || m(e) && e, duration: e, easing: n && t || t && !m(t) && t }; return k.fx.off ? r.duration = 0 : "number" != typeof r.duration && (r.duration in k.fx.speeds ? r.duration = k.fx.speeds[r.duration] : r.duration = k.fx.speeds._default), null != r.queue && !0 !== r.queue || (r.queue = "fx"), r.old = r.complete, r.complete = function () { m(r.old) && r.old.call(this), r.queue && k.dequeue(this, r.queue) }, r }, k.fn.extend({ fadeTo: function (e, t, n, r) { return this.filter(se).css("opacity", 0).show().end().animate({ opacity: t }, e, n, r) }, animate: function (t, e, n, r) { var i = k.isEmptyObject(t), o = k.speed(e, n, r), a = function () { var e = dt(this, k.extend({}, t), o); (i || Q.get(this, "finish")) && e.stop(!0) }; return a.finish = a, i || !1 === o.queue ? this.each(a) : this.queue(o.queue, a) }, stop: function (i, e, o) { var a = function (e) { var t = e.stop; delete e.stop, t(o) }; return "string" != typeof i && (o = e, e = i, i = void 0), e && !1 !== i && this.queue(i || "fx", []), this.each(function () { var e = !0, t = null != i && i + "queueHooks", n = k.timers, r = Q.get(this); if (t) r[t] && r[t].stop && a(r[t]); else for (t in r) r[t] && r[t].stop && ut.test(t) && a(r[t]); for (t = n.length; t--;)n[t].elem !== this || null != i && n[t].queue !== i || (n[t].anim.stop(o), e = !1, n.splice(t, 1)); !e && o || k.dequeue(this, i) }) }, finish: function (a) { return !1 !== a && (a = a || "fx"), this.each(function () { var e, t = Q.get(this), n = t[a + "queue"], r = t[a + "queueHooks"], i = k.timers, o = n ? n.length : 0; for (t.finish = !0, k.queue(this, a, []), r && r.stop && r.stop.call(this, !0), e = i.length; e--;)i[e].elem === this && i[e].queue === a && (i[e].anim.stop(!0), i.splice(e, 1)); for (e = 0; e < o; e++)n[e] && n[e].finish && n[e].finish.call(this); delete t.finish }) } }), k.each(["toggle", "show", "hide"], function (e, r) { var i = k.fn[r]; k.fn[r] = function (e, t, n) { return null == e || "boolean" == typeof e ? i.apply(this, arguments) : this.animate(ft(r, !0), e, t, n) } }), k.each({ slideDown: ft("show"), slideUp: ft("hide"), slideToggle: ft("toggle"), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } }, function (e, r) { k.fn[e] = function (e, t, n) { return this.animate(r, e, t, n) } }), k.timers = [], k.fx.tick = function () { var e, t = 0, n = k.timers; for (rt = Date.now(); t < n.length; t++)(e = n[t])() || n[t] !== e || n.splice(t--, 1); n.length || k.fx.stop(), rt = void 0 }, k.fx.timer = function (e) { k.timers.push(e), k.fx.start() }, k.fx.interval = 13, k.fx.start = function () { it || (it = !0, lt()) }, k.fx.stop = function () { it = null }, k.fx.speeds = { slow: 600, fast: 200, _default: 400 }, k.fn.delay = function (r, e) { return r = k.fx && k.fx.speeds[r] || r, e = e || "fx", this.queue(e, function (e, t) { var n = C.setTimeout(e, r); t.stop = function () { C.clearTimeout(n) } }) }, ot = E.createElement("input"), at = E.createElement("select").appendChild(E.createElement("option")), ot.type = "checkbox", y.checkOn = "" !== ot.value, y.optSelected = at.selected, (ot = E.createElement("input")).value = "t", ot.type = "radio", y.radioValue = "t" === ot.value; var ht, gt = k.expr.attrHandle; k.fn.extend({ attr: function (e, t) { return _(this, k.attr, e, t, 1 < arguments.length) }, removeAttr: function (e) { return this.each(function () { k.removeAttr(this, e) }) } }), k.extend({ attr: function (e, t, n) { var r, i, o = e.nodeType; if (3 !== o && 8 !== o && 2 !== o) return "undefined" == typeof e.getAttribute ? k.prop(e, t, n) : (1 === o && k.isXMLDoc(e) || (i = k.attrHooks[t.toLowerCase()] || (k.expr.match.bool.test(t) ? ht : void 0)), void 0 !== n ? null === n ? void k.removeAttr(e, t) : i && "set" in i && void 0 !== (r = i.set(e, n, t)) ? r : (e.setAttribute(t, n + ""), n) : i && "get" in i && null !== (r = i.get(e, t)) ? r : null == (r = k.find.attr(e, t)) ? void 0 : r) }, attrHooks: { type: { set: function (e, t) { if (!y.radioValue && "radio" === t && A(e, "input")) { var n = e.value; return e.setAttribute("type", t), n && (e.value = n), t } } } }, removeAttr: function (e, t) { var n, r = 0, i = t && t.match(R); if (i && 1 === e.nodeType) while (n = i[r++]) e.removeAttribute(n) } }), ht = { set: function (e, t, n) { return !1 === t ? k.removeAttr(e, n) : e.setAttribute(n, n), n } }, k.each(k.expr.match.bool.source.match(/\w+/g), function (e, t) { var a = gt[t] || k.find.attr; gt[t] = function (e, t, n) { var r, i, o = t.toLowerCase(); return n || (i = gt[o], gt[o] = r, r = null != a(e, t, n) ? o : null, gt[o] = i), r } }); var vt = /^(?:input|select|textarea|button)$/i, yt = /^(?:a|area)$/i; function mt(e) { return (e.match(R) || []).join(" ") } function xt(e) { return e.getAttribute && e.getAttribute("class") || "" } function bt(e) { return Array.isArray(e) ? e : "string" == typeof e && e.match(R) || [] } k.fn.extend({ prop: function (e, t) { return _(this, k.prop, e, t, 1 < arguments.length) }, removeProp: function (e) { return this.each(function () { delete this[k.propFix[e] || e] }) } }), k.extend({ prop: function (e, t, n) { var r, i, o = e.nodeType; if (3 !== o && 8 !== o && 2 !== o) return 1 === o && k.isXMLDoc(e) || (t = k.propFix[t] || t, i = k.propHooks[t]), void 0 !== n ? i && "set" in i && void 0 !== (r = i.set(e, n, t)) ? r : e[t] = n : i && "get" in i && null !== (r = i.get(e, t)) ? r : e[t] }, propHooks: { tabIndex: { get: function (e) { var t = k.find.attr(e, "tabindex"); return t ? parseInt(t, 10) : vt.test(e.nodeName) || yt.test(e.nodeName) && e.href ? 0 : -1 } } }, propFix: { "for": "htmlFor", "class": "className" } }), y.optSelected || (k.propHooks.selected = { get: function (e) { var t = e.parentNode; return t && t.parentNode && t.parentNode.selectedIndex, null }, set: function (e) { var t = e.parentNode; t && (t.selectedIndex, t.parentNode && t.parentNode.selectedIndex) } }), k.each(["tabIndex", "readOnly", "maxLength", "cellSpacing", "cellPadding", "rowSpan", "colSpan", "useMap", "frameBorder", "contentEditable"], function () { k.propFix[this.toLowerCase()] = this }), k.fn.extend({ addClass: function (t) { var e, n, r, i, o, a, s, u = 0; if (m(t)) return this.each(function (e) { k(this).addClass(t.call(this, e, xt(this))) }); if ((e = bt(t)).length) while (n = this[u++]) if (i = xt(n), r = 1 === n.nodeType && " " + mt(i) + " ") { a = 0; while (o = e[a++]) r.indexOf(" " + o + " ") < 0 && (r += o + " "); i !== (s = mt(r)) && n.setAttribute("class", s) } return this }, removeClass: function (t) { var e, n, r, i, o, a, s, u = 0; if (m(t)) return this.each(function (e) { k(this).removeClass(t.call(this, e, xt(this))) }); if (!arguments.length) return this.attr("class", ""); if ((e = bt(t)).length) while (n = this[u++]) if (i = xt(n), r = 1 === n.nodeType && " " + mt(i) + " ") { a = 0; while (o = e[a++]) while (-1 < r.indexOf(" " + o + " ")) r = r.replace(" " + o + " ", " "); i !== (s = mt(r)) && n.setAttribute("class", s) } return this }, toggleClass: function (i, t) { var o = typeof i, a = "string" === o || Array.isArray(i); return "boolean" == typeof t && a ? t ? this.addClass(i) : this.removeClass(i) : m(i) ? this.each(function (e) { k(this).toggleClass(i.call(this, e, xt(this), t), t) }) : this.each(function () { var e, t, n, r; if (a) { t = 0, n = k(this), r = bt(i); while (e = r[t++]) n.hasClass(e) ? n.removeClass(e) : n.addClass(e) } else void 0 !== i && "boolean" !== o || ((e = xt(this)) && Q.set(this, "__className__", e), this.setAttribute && this.setAttribute("class", e || !1 === i ? "" : Q.get(this, "__className__") || "")) }) }, hasClass: function (e) { var t, n, r = 0; t = " " + e + " "; while (n = this[r++]) if (1 === n.nodeType && -1 < (" " + mt(xt(n)) + " ").indexOf(t)) return !0; return !1 } }); var wt = /\r/g; k.fn.extend({ val: function (n) { var r, e, i, t = this[0]; return arguments.length ? (i = m(n), this.each(function (e) { var t; 1 === this.nodeType && (null == (t = i ? n.call(this, e, k(this).val()) : n) ? t = "" : "number" == typeof t ? t += "" : Array.isArray(t) && (t = k.map(t, function (e) { return null == e ? "" : e + "" })), (r = k.valHooks[this.type] || k.valHooks[this.nodeName.toLowerCase()]) && "set" in r && void 0 !== r.set(this, t, "value") || (this.value = t)) })) : t ? (r = k.valHooks[t.type] || k.valHooks[t.nodeName.toLowerCase()]) && "get" in r && void 0 !== (e = r.get(t, "value")) ? e : "string" == typeof (e = t.value) ? e.replace(wt, "") : null == e ? "" : e : void 0 } }), k.extend({ valHooks: { option: { get: function (e) { var t = k.find.attr(e, "value"); return null != t ? t : mt(k.text(e)) } }, select: { get: function (e) { var t, n, r, i = e.options, o = e.selectedIndex, a = "select-one" === e.type, s = a ? null : [], u = a ? o + 1 : i.length; for (r = o < 0 ? u : a ? o : 0; r < u; r++)if (((n = i[r]).selected || r === o) && !n.disabled && (!n.parentNode.disabled || !A(n.parentNode, "optgroup"))) { if (t = k(n).val(), a) return t; s.push(t) } return s }, set: function (e, t) { var n, r, i = e.options, o = k.makeArray(t), a = i.length; while (a--) ((r = i[a]).selected = -1 < k.inArray(k.valHooks.option.get(r), o)) && (n = !0); return n || (e.selectedIndex = -1), o } } } }), k.each(["radio", "checkbox"], function () { k.valHooks[this] = { set: function (e, t) { if (Array.isArray(t)) return e.checked = -1 < k.inArray(k(e).val(), t) } }, y.checkOn || (k.valHooks[this].get = function (e) { return null === e.getAttribute("value") ? "on" : e.value }) }), y.focusin = "onfocusin" in C; var Tt = /^(?:focusinfocus|focusoutblur)$/, Ct = function (e) { e.stopPropagation() }; k.extend(k.event, { trigger: function (e, t, n, r) { var i, o, a, s, u, l, c, f, p = [n || E], d = v.call(e, "type") ? e.type : e, h = v.call(e, "namespace") ? e.namespace.split(".") : []; if (o = f = a = n = n || E, 3 !== n.nodeType && 8 !== n.nodeType && !Tt.test(d + k.event.triggered) && (-1 < d.indexOf(".") && (d = (h = d.split(".")).shift(), h.sort()), u = d.indexOf(":") < 0 && "on" + d, (e = e[k.expando] ? e : new k.Event(d, "object" == typeof e && e)).isTrigger = r ? 2 : 3, e.namespace = h.join("."), e.rnamespace = e.namespace ? new RegExp("(^|\\.)" + h.join("\\.(?:.*\\.|)") + "(\\.|$)") : null, e.result = void 0, e.target || (e.target = n), t = null == t ? [e] : k.makeArray(t, [e]), c = k.event.special[d] || {}, r || !c.trigger || !1 !== c.trigger.apply(n, t))) { if (!r && !c.noBubble && !x(n)) { for (s = c.delegateType || d, Tt.test(s + d) || (o = o.parentNode); o; o = o.parentNode)p.push(o), a = o; a === (n.ownerDocument || E) && p.push(a.defaultView || a.parentWindow || C) } i = 0; while ((o = p[i++]) && !e.isPropagationStopped()) f = o, e.type = 1 < i ? s : c.bindType || d, (l = (Q.get(o, "events") || {})[e.type] && Q.get(o, "handle")) && l.apply(o, t), (l = u && o[u]) && l.apply && G(o) && (e.result = l.apply(o, t), !1 === e.result && e.preventDefault()); return e.type = d, r || e.isDefaultPrevented() || c._default && !1 !== c._default.apply(p.pop(), t) || !G(n) || u && m(n[d]) && !x(n) && ((a = n[u]) && (n[u] = null), k.event.triggered = d, e.isPropagationStopped() && f.addEventListener(d, Ct), n[d](), e.isPropagationStopped() && f.removeEventListener(d, Ct), k.event.triggered = void 0, a && (n[u] = a)), e.result } }, simulate: function (e, t, n) { var r = k.extend(new k.Event, n, { type: e, isSimulated: !0 }); k.event.trigger(r, null, t) } }), k.fn.extend({ trigger: function (e, t) { return this.each(function () { k.event.trigger(e, t, this) }) }, triggerHandler: function (e, t) { var n = this[0]; if (n) return k.event.trigger(e, t, n, !0) } }), y.focusin || k.each({ focus: "focusin", blur: "focusout" }, function (n, r) { var i = function (e) { k.event.simulate(r, e.target, k.event.fix(e)) }; k.event.special[r] = { setup: function () { var e = this.ownerDocument || this, t = Q.access(e, r); t || e.addEventListener(n, i, !0), Q.access(e, r, (t || 0) + 1) }, teardown: function () { var e = this.ownerDocument || this, t = Q.access(e, r) - 1; t ? Q.access(e, r, t) : (e.removeEventListener(n, i, !0), Q.remove(e, r)) } } }); var Et = C.location, kt = Date.now(), St = /\?/; k.parseXML = function (e) { var t; if (!e || "string" != typeof e) return null; try { t = (new C.DOMParser).parseFromString(e, "text/xml") } catch (e) { t = void 0 } return t && !t.getElementsByTagName("parsererror").length || k.error("Invalid XML: " + e), t }; var Nt = /\[\]$/, At = /\r?\n/g, Dt = /^(?:submit|button|image|reset|file)$/i, jt = /^(?:input|select|textarea|keygen)/i; function qt(n, e, r, i) { var t; if (Array.isArray(e)) k.each(e, function (e, t) { r || Nt.test(n) ? i(n, t) : qt(n + "[" + ("object" == typeof t && null != t ? e : "") + "]", t, r, i) }); else if (r || "object" !== w(e)) i(n, e); else for (t in e) qt(n + "[" + t + "]", e[t], r, i) } k.param = function (e, t) { var n, r = [], i = function (e, t) { var n = m(t) ? t() : t; r[r.length] = encodeURIComponent(e) + "=" + encodeURIComponent(null == n ? "" : n) }; if (null == e) return ""; if (Array.isArray(e) || e.jquery && !k.isPlainObject(e)) k.each(e, function () { i(this.name, this.value) }); else for (n in e) qt(n, e[n], t, i); return r.join("&") }, k.fn.extend({ serialize: function () { return k.param(this.serializeArray()) }, serializeArray: function () { return this.map(function () { var e = k.prop(this, "elements"); return e ? k.makeArray(e) : this }).filter(function () { var e = this.type; return this.name && !k(this).is(":disabled") && jt.test(this.nodeName) && !Dt.test(e) && (this.checked || !pe.test(e)) }).map(function (e, t) { var n = k(this).val(); return null == n ? null : Array.isArray(n) ? k.map(n, function (e) { return { name: t.name, value: e.replace(At, "\r\n") } }) : { name: t.name, value: n.replace(At, "\r\n") } }).get() } }); var Lt = /%20/g, Ht = /#.*$/, Ot = /([?&])_=[^&]*/, Pt = /^(.*?):[ \t]*([^\r\n]*)$/gm, Rt = /^(?:GET|HEAD)$/, Mt = /^\/\//, It = {}, Wt = {}, $t = "*/".concat("*"), Ft = E.createElement("a"); function Bt(o) { return function (e, t) { "string" != typeof e && (t = e, e = "*"); var n, r = 0, i = e.toLowerCase().match(R) || []; if (m(t)) while (n = i[r++]) "+" === n[0] ? (n = n.slice(1) || "*", (o[n] = o[n] || []).unshift(t)) : (o[n] = o[n] || []).push(t) } } function _t(t, i, o, a) { var s = {}, u = t === Wt; function l(e) { var r; return s[e] = !0, k.each(t[e] || [], function (e, t) { var n = t(i, o, a); return "string" != typeof n || u || s[n] ? u ? !(r = n) : void 0 : (i.dataTypes.unshift(n), l(n), !1) }), r } return l(i.dataTypes[0]) || !s["*"] && l("*") } function zt(e, t) { var n, r, i = k.ajaxSettings.flatOptions || {}; for (n in t) void 0 !== t[n] && ((i[n] ? e : r || (r = {}))[n] = t[n]); return r && k.extend(!0, e, r), e } Ft.href = Et.href, k.extend({ active: 0, lastModified: {}, etag: {}, ajaxSettings: { url: Et.href, type: "GET", isLocal: /^(?:about|app|app-storage|.+-extension|file|res|widget):$/.test(Et.protocol), global: !0, processData: !0, async: !0, contentType: "application/x-www-form-urlencoded; charset=UTF-8", accepts: { "*": $t, text: "text/plain", html: "text/html", xml: "application/xml, text/xml", json: "application/json, text/javascript" }, contents: { xml: /\bxml\b/, html: /\bhtml/, json: /\bjson\b/ }, responseFields: { xml: "responseXML", text: "responseText", json: "responseJSON" }, converters: { "* text": String, "text html": !0, "text json": JSON.parse, "text xml": k.parseXML }, flatOptions: { url: !0, context: !0 } }, ajaxSetup: function (e, t) { return t ? zt(zt(e, k.ajaxSettings), t) : zt(k.ajaxSettings, e) }, ajaxPrefilter: Bt(It), ajaxTransport: Bt(Wt), ajax: function (e, t) { "object" == typeof e && (t = e, e = void 0), t = t || {}; var c, f, p, n, d, r, h, g, i, o, v = k.ajaxSetup({}, t), y = v.context || v, m = v.context && (y.nodeType || y.jquery) ? k(y) : k.event, x = k.Deferred(), b = k.Callbacks("once memory"), w = v.statusCode || {}, a = {}, s = {}, u = "canceled", T = { readyState: 0, getResponseHeader: function (e) { var t; if (h) { if (!n) { n = {}; while (t = Pt.exec(p)) n[t[1].toLowerCase() + " "] = (n[t[1].toLowerCase() + " "] || []).concat(t[2]) } t = n[e.toLowerCase() + " "] } return null == t ? null : t.join(", ") }, getAllResponseHeaders: function () { return h ? p : null }, setRequestHeader: function (e, t) { return null == h && (e = s[e.toLowerCase()] = s[e.toLowerCase()] || e, a[e] = t), this }, overrideMimeType: function (e) { return null == h && (v.mimeType = e), this }, statusCode: function (e) { var t; if (e) if (h) T.always(e[T.status]); else for (t in e) w[t] = [w[t], e[t]]; return this }, abort: function (e) { var t = e || u; return c && c.abort(t), l(0, t), this } }; if (x.promise(T), v.url = ((e || v.url || Et.href) + "").replace(Mt, Et.protocol + "//"), v.type = t.method || t.type || v.method || v.type, v.dataTypes = (v.dataType || "*").toLowerCase().match(R) || [""], null == v.crossDomain) { r = E.createElement("a"); try { r.href = v.url, r.href = r.href, v.crossDomain = Ft.protocol + "//" + Ft.host != r.protocol + "//" + r.host } catch (e) { v.crossDomain = !0 } } if (v.data && v.processData && "string" != typeof v.data && (v.data = k.param(v.data, v.traditional)), _t(It, v, t, T), h) return T; for (i in (g = k.event && v.global) && 0 == k.active++ && k.event.trigger("ajaxStart"), v.type = v.type.toUpperCase(), v.hasContent = !Rt.test(v.type), f = v.url.replace(Ht, ""), v.hasContent ? v.data && v.processData && 0 === (v.contentType || "").indexOf("application/x-www-form-urlencoded") && (v.data = v.data.replace(Lt, "+")) : (o = v.url.slice(f.length), v.data && (v.processData || "string" == typeof v.data) && (f += (St.test(f) ? "&" : "?") + v.data, delete v.data), !1 === v.cache && (f = f.replace(Ot, "$1"), o = (St.test(f) ? "&" : "?") + "_=" + kt++ + o), v.url = f + o), v.ifModified && (k.lastModified[f] && T.setRequestHeader("If-Modified-Since", k.lastModified[f]), k.etag[f] && T.setRequestHeader("If-None-Match", k.etag[f])), (v.data && v.hasContent && !1 !== v.contentType || t.contentType) && T.setRequestHeader("Content-Type", v.contentType), T.setRequestHeader("Accept", v.dataTypes[0] && v.accepts[v.dataTypes[0]] ? v.accepts[v.dataTypes[0]] + ("*" !== v.dataTypes[0] ? ", " + $t + "; q=0.01" : "") : v.accepts["*"]), v.headers) T.setRequestHeader(i, v.headers[i]); if (v.beforeSend && (!1 === v.beforeSend.call(y, T, v) || h)) return T.abort(); if (u = "abort", b.add(v.complete), T.done(v.success), T.fail(v.error), c = _t(Wt, v, t, T)) { if (T.readyState = 1, g && m.trigger("ajaxSend", [T, v]), h) return T; v.async && 0 < v.timeout && (d = C.setTimeout(function () { T.abort("timeout") }, v.timeout)); try { h = !1, c.send(a, l) } catch (e) { if (h) throw e; l(-1, e) } } else l(-1, "No Transport"); function l(e, t, n, r) { var i, o, a, s, u, l = t; h || (h = !0, d && C.clearTimeout(d), c = void 0, p = r || "", T.readyState = 0 < e ? 4 : 0, i = 200 <= e && e < 300 || 304 === e, n && (s = function (e, t, n) { var r, i, o, a, s = e.contents, u = e.dataTypes; while ("*" === u[0]) u.shift(), void 0 === r && (r = e.mimeType || t.getResponseHeader("Content-Type")); if (r) for (i in s) if (s[i] && s[i].test(r)) { u.unshift(i); break } if (u[0] in n) o = u[0]; else { for (i in n) { if (!u[0] || e.converters[i + " " + u[0]]) { o = i; break } a || (a = i) } o = o || a } if (o) return o !== u[0] && u.unshift(o), n[o] }(v, T, n)), s = function (e, t, n, r) { var i, o, a, s, u, l = {}, c = e.dataTypes.slice(); if (c[1]) for (a in e.converters) l[a.toLowerCase()] = e.converters[a]; o = c.shift(); while (o) if (e.responseFields[o] && (n[e.responseFields[o]] = t), !u && r && e.dataFilter && (t = e.dataFilter(t, e.dataType)), u = o, o = c.shift()) if ("*" === o) o = u; else if ("*" !== u && u !== o) { if (!(a = l[u + " " + o] || l["* " + o])) for (i in l) if ((s = i.split(" "))[1] === o && (a = l[u + " " + s[0]] || l["* " + s[0]])) { !0 === a ? a = l[i] : !0 !== l[i] && (o = s[0], c.unshift(s[1])); break } if (!0 !== a) if (a && e["throws"]) t = a(t); else try { t = a(t) } catch (e) { return { state: "parsererror", error: a ? e : "No conversion from " + u + " to " + o } } } return { state: "success", data: t } }(v, s, T, i), i ? (v.ifModified && ((u = T.getResponseHeader("Last-Modified")) && (k.lastModified[f] = u), (u = T.getResponseHeader("etag")) && (k.etag[f] = u)), 204 === e || "HEAD" === v.type ? l = "nocontent" : 304 === e ? l = "notmodified" : (l = s.state, o = s.data, i = !(a = s.error))) : (a = l, !e && l || (l = "error", e < 0 && (e = 0))), T.status = e, T.statusText = (t || l) + "", i ? x.resolveWith(y, [o, l, T]) : x.rejectWith(y, [T, l, a]), T.statusCode(w), w = void 0, g && m.trigger(i ? "ajaxSuccess" : "ajaxError", [T, v, i ? o : a]), b.fireWith(y, [T, l]), g && (m.trigger("ajaxComplete", [T, v]), --k.active || k.event.trigger("ajaxStop"))) } return T }, getJSON: function (e, t, n) { return k.get(e, t, n, "json") }, getScript: function (e, t) { return k.get(e, void 0, t, "script") } }), k.each(["get", "post"], function (e, i) { k[i] = function (e, t, n, r) { return m(t) && (r = r || n, n = t, t = void 0), k.ajax(k.extend({ url: e, type: i, dataType: r, data: t, success: n }, k.isPlainObject(e) && e)) } }), k._evalUrl = function (e, t) { return k.ajax({ url: e, type: "GET", dataType: "script", cache: !0, async: !1, global: !1, converters: { "text script": function () { } }, dataFilter: function (e) { k.globalEval(e, t) } }) }, k.fn.extend({ wrapAll: function (e) { var t; return this[0] && (m(e) && (e = e.call(this[0])), t = k(e, this[0].ownerDocument).eq(0).clone(!0), this[0].parentNode && t.insertBefore(this[0]), t.map(function () { var e = this; while (e.firstElementChild) e = e.firstElementChild; return e }).append(this)), this }, wrapInner: function (n) { return m(n) ? this.each(function (e) { k(this).wrapInner(n.call(this, e)) }) : this.each(function () { var e = k(this), t = e.contents(); t.length ? t.wrapAll(n) : e.append(n) }) }, wrap: function (t) { var n = m(t); return this.each(function (e) { k(this).wrapAll(n ? t.call(this, e) : t) }) }, unwrap: function (e) { return this.parent(e).not("body").each(function () { k(this).replaceWith(this.childNodes) }), this } }), k.expr.pseudos.hidden = function (e) { return !k.expr.pseudos.visible(e) }, k.expr.pseudos.visible = function (e) { return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length) }, k.ajaxSettings.xhr = function () { try { return new C.XMLHttpRequest } catch (e) { } }; var Ut = { 0: 200, 1223: 204 }, Xt = k.ajaxSettings.xhr(); y.cors = !!Xt && "withCredentials" in Xt, y.ajax = Xt = !!Xt, k.ajaxTransport(function (i) { var o, a; if (y.cors || Xt && !i.crossDomain) return { send: function (e, t) { var n, r = i.xhr(); if (r.open(i.type, i.url, i.async, i.username, i.password), i.xhrFields) for (n in i.xhrFields) r[n] = i.xhrFields[n]; for (n in i.mimeType && r.overrideMimeType && r.overrideMimeType(i.mimeType), i.crossDomain || e["X-Requested-With"] || (e["X-Requested-With"] = "XMLHttpRequest"), e) r.setRequestHeader(n, e[n]); o = function (e) { return function () { o && (o = a = r.onload = r.onerror = r.onabort = r.ontimeout = r.onreadystatechange = null, "abort" === e ? r.abort() : "error" === e ? "number" != typeof r.status ? t(0, "error") : t(r.status, r.statusText) : t(Ut[r.status] || r.status, r.statusText, "text" !== (r.responseType || "text") || "string" != typeof r.responseText ? { binary: r.response } : { text: r.responseText }, r.getAllResponseHeaders())) } }, r.onload = o(), a = r.onerror = r.ontimeout = o("error"), void 0 !== r.onabort ? r.onabort = a : r.onreadystatechange = function () { 4 === r.readyState && C.setTimeout(function () { o && a() }) }, o = o("abort"); try { r.send(i.hasContent && i.data || null) } catch (e) { if (o) throw e } }, abort: function () { o && o() } } }), k.ajaxPrefilter(function (e) { e.crossDomain && (e.contents.script = !1) }), k.ajaxSetup({ accepts: { script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, contents: { script: /\b(?:java|ecma)script\b/ }, converters: { "text script": function (e) { return k.globalEval(e), e } } }), k.ajaxPrefilter("script", function (e) { void 0 === e.cache && (e.cache = !1), e.crossDomain && (e.type = "GET") }), k.ajaxTransport("script", function (n) { var r, i; if (n.crossDomain || n.scriptAttrs) return { send: function (e, t) { r = k(" + +EOF + +rm -rf build/ && sphinx-multiversion source build/html && cp -rf build/html/master/* build/html/ diff --git a/source/_templates/versions.html b/source/_templates/versions.html new file mode 100644 index 0000000..31a1257 --- /dev/null +++ b/source/_templates/versions.html @@ -0,0 +1,27 @@ +{%- if current_version %} +
+ + Other Versions + v: {{ current_version.name }} + + +
+ {%- if versions.tags %} +
+
Tags
+ {%- for item in versions.tags %} +
{{ item.name }}
+ {%- endfor %} +
+ {%- endif %} + {%- if versions.branches %} +
+
Branches
+ {%- for item in versions.branches %} +
{{ item.name }}
+ {%- endfor %} +
+ {%- endif %} +
+
+{%- endif %} diff --git a/source/conf.py b/source/conf.py index fdcb6f7..66e5159 100644 --- a/source/conf.py +++ b/source/conf.py @@ -28,7 +28,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['chinese_search','sphinx.ext.mathjax', 'sphinx_sitemap'] +extensions = ['chinese_search','sphinx.ext.mathjax', 'sphinx_sitemap', 'sphinx_multiversion'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -127,28 +127,25 @@ sys.path.append(os.path.abspath(_exts)) html_js_files = [ - 'js/readmore.js', + 'js/readmore.js', 'js/baidutongji.js', ] -# General configuration. -with open("/home/docs/checkouts/readthedocs.org/user_builds/pythoncodingtime/envs/latest/lib/python3.7/site-packages/sphinxcontrib/disqus.py", "r") as file: - content = file.read() - content=content.replace("sphinx.application", "sphinx.errors") - -with open("/home/docs/checkouts/readthedocs.org/user_builds/pythoncodingtime/envs/latest/lib/python3.7/site-packages/sphinxcontrib/disqus.py", "w") as file: - file.write(content) author = '王炳明' -copyright = '2020, Python编程时光' +copyright = '2020-2024, Python编程时光' exclude_patterns = ['_build'] -extensions = ['sphinxcontrib.disqus'] # Add to this list. master_doc = 'index' project = 'Python编程时光' -release = '1.0' -version = '1.0' # Options for extensions. -disqus_shortname = 'iswbm' # Add this line to conf.py. -html_baseurl = 'http://pythontime.iswbm.com' +html_baseurl = 'https://magic.iswbm.com' html_extra_path = ["robots.txt"] + +html_sidebars = { + '**': [ + 'versioning.html', + ], +} +smv_latest_version = 'master' +sitemap_url_scheme = "{link}" From 07ecd0ea6bc99c5d821c28fc560f551c0848d711 Mon Sep 17 00:00:00 2001 From: iswbm Date: Mon, 26 Jan 2026 22:12:53 +0800 Subject: [PATCH 226/227] update requirements.txt to python3.6.8 --- rebuild.sh | 2 +- requirements.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rebuild.sh b/rebuild.sh index 3ceedd8..319b303 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,4 +1,4 @@ -cat << EOF >/usr/local/lib/python3.10/site-packages/sphinx_rtd_theme/comments.html +cat << EOF >/usr/local/lib/python3.6/site-packages/sphinx_rtd_theme/comments.html