resetroot_169route_python2(用于ubuntu12.04和14.04,centos系列)
#!/usr/bin/python import os
import json
import subprocess
from cloudinit.sources.DataSourceConfigDrive import find_candidate_devs, read_config_drive
from cloudinit.util import mount_cb
from six.moves.urllib.request import urlopen
from six.moves.urllib.parse import urlencode def shell(cmd):
sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = sp.communicate()
return out, err INSTANCE_ID_RUN_PATH = "/run/cloud-init/.instance-id" # Ensure /run/cloud-init/.instance-id not exists so we can reload DataSource from ConfigDrive.
if os.path.isfile(INSTANCE_ID_RUN_PATH):
os.unlink(INSTANCE_ID_RUN_PATH) # Before resetroot, We must ensure if 169.254.169.254 have gateway
gateways = []
for dev in find_candidate_devs():
results = mount_cb(dev, read_config_drive)
network_data = results.get("networkdata")
networks = network_data.get("networks",None)
found = dev
if found:
if not networks:
continue
for network in networks:
routes = network.get("routes", None)
if not routes:
continue
for route in routes:
gateway = route.get('gateway')
gateways.append(gateway)
break if gateways:
gateway = gateways[0]
cmd = "route add -host 169.254.169.254 gw %s" % gateway
out,err = shell(cmd) data = urlopen("http://169.254.169.254/openstack/latest/meta_data.json").read()
json_data = json.loads(data.decode("utf-8")) meta = json_data.get("meta")
if meta:
adminPass = meta.get("admin_pass")
if adminPass:
os.system("echo 'root:%s' | chpasswd" % adminPass)
params = urlencode({"delete":True})
f = urlopen("http://169.254.169.254/openstack/latest/password", params)
f.read()
resetroot_169route_python2(用于ubuntu12.04和14.04,centos系列)的更多相关文章
- ubuntu12.10升级至14.04
之前执行apt-get 不管是什么软件或apt-get update都会遇到fail to fetch http://us.archive.ubuntu.com quantal-updates/mai ...
- Ubuntu 16.04或14.04里下安装搜狗输入法(图文详解)(全网最简单)
不多说,直接上干货! 其实啊,很简单 分三步走 1.添加fcitx的键盘输入法系统,因为sogou是基于fcitx的,而系统默认的是iBus: 2.安装sogou输入法: 3.设置系统参数及一些注意点 ...
- 在Ubuntu12.0至14.04版本之间用Apache搭建网站运行环境
为了顺利安装各种软件,先更新下系统. apt-get update 安装Apache服务 apt-get install apache2 -y 安装php apt-get install php5 - ...
- 超简单让ubuntu开启wifi热点(亲测16.04与14.04可用)
今天教大家一个简单方法让ubuntu发散wifi热点给手机或者其他设备使用. 首先,创建一个普通的热点,点击右上角的网络,然后选择下拉菜单中的编辑连接,然后出现以下界面. 然后点击增加,连接类型选接W ...
- 【转】Windows 7下用VMware Workstation 10虚拟机安装 Ubuntu 14.04
一.软件下载 1.VMware Workstation v10.0.1虚拟机官方简体中文版下载(附永久KEY注册密钥) http://www.linuxidc.com/Linux/2012-11/73 ...
- Ubuntu 12.04 升级到14.04之后,pidgin-sipe 出现的问题: Trouble with the pidgin and self-signed SSL certificate
Once again, I run into trouble when upgrading my LinuxMint. In last few days, my Linux mint notifies ...
- Windows 多用户远程访问 Ubuntu 14.04桌面
使用X2Go实现多用户远程访问 Ubuntu 14.04桌面:VNC也可以,但是每次连接VNC就回新创建一个Seession,想要在下次远程登录的时候返回上次活动,需要记住开启的线程,这种繁琐的操作不 ...
- Ubuntu 14.04 禁用ipv6
参考: 关闭IPV6,ubuntu 14.04 Ubuntu 14.04 禁用ipv6 1.检查ipv6是否开启: cat /proc/sys/net/ipv6/conf/all/disable_ip ...
- Ubuntu 14.04 java环境安装配置(不是openJAVA)
两种配置方式 第一: 在 Ubuntu 中使用 PPA 安装 Java 8 ( 支持 Ubuntu 10.04 - Ubuntu 14.04 ): sudo add-apt-repository pp ...
随机推荐
- 【洛谷P2216】[HAOI2007]理想的正方形
理想的正方形 [题目描述] 一个a*b的矩阵,从中取一个n*n的子矩阵,使所选矩阵中的最大数与最小数的差最小. 思路: 二维的滑动窗口 对于每行:用一个单调队列维护,算出每个长度为n的区间的最大值和最 ...
- 【luogu P2023 [AHOI2009]维护序列】 题解
题目链接:https://www.luogu.org/problemnew/show/P2023 把P3373改一改直接粘过来就A #include <iostream> #include ...
- 数据库:DDL/DML/DCL/TCL基本概念
SQL(Structure Query Language)语言是数据库的核心语言 1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHERE 子句组成的查询块: ...
- Oracle 反向索引(反转建索引) 理解
一 反向索引 1.1 反向索引的定义 反向索引作为B-tree索引的一个分支,主要是在创建索引时,针对索引列的索引键值进行字节反转,进而实现分散存放到不同叶子节点块的目的. 1.2 反向索引针对的问题 ...
- c# 调用服务返回结果模板化
一般我们返回一个结果,主要有返回值,执行结果信息,所以定义一个类 public class QuestResult { /// <summary> /// 返回值 ...
- webpack中使用vue
1.安装vue cnpm i install -S 2.由于在 webpack 中,推荐使用 .vue 的文件模板文件定义组件 , 所以 ,需要安装 能解析这种文件的 loader cnpm i vu ...
- Eclipse工具查看依赖的JDK、Maven源码方法
一.Eclipse软件里查看JDK依赖源码 1.Window->Preferences->Java->Installed JREs 2.如图: 二.Eclipse软件里查看Maven ...
- lvs集群实现lvs-dr模型和lvs-nat模型
ipvsadm ipvsadm命令是lvs集群在应用层的管理工具,我们可以通过此ipvsadm来管理lvs的配置,其实现了集群服务管理:增.删.改,集群服务的RS管理:增.删.改以及查看集群状态. 管 ...
- MySQL innodb表使用表空间物理文件复制或迁移表
MySQL InnoDB引擎的表通过拷贝物理文件来进行单表或指定表的复制,可以想到多种方式,今天测试其中2种: 将innodb引擎的表修改为Myisam引擎,然后拷贝物理文件 直接拷贝innodb的表 ...
- php Laravel5.5 表单验证常用的验证规则,以及示例
namespace App\Http\Controllers; use App\Models\Users; use Illuminate\Support\Facades\Validator; use ...