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 ...
随机推荐
- js函数在frame中的相互的调用
框架编程概述一个HTML页面可以有一个或多个子框架,这些子框架以<iframe>来标记,用来显示一个独立的HTML页面.这里所讲的框架编程包括框架的自我控制以及框架之间的互相访问,例如从一 ...
- JVM 监控以及内存分析
1 内存分析1.1 jmap -histo 命令pid=`jps | awk '{if ($2 == "Jps") print $1}'`jmap -histo $pid > ...
- 移动端Vue回到顶部
html: <div class="totop" id="totop" @click="Top" v-show="totop ...
- Spring知识点总结(四)之SpringAOP基础
1. Spring aop中的基本概念 • 连接点(Joinpoint):在程序执行过程中某个特定的点,比如某方法调用的时候或者处理异常的时候.在Spring AOP中,一个连接 ...
- Spring技术内幕阅读笔记(一)
1.BeanFactory:实现ioc容器的最基本形式.String FACTORY_BEAN_PREFIX = "&";Object getBean(String var ...
- leetcode笔记(四)9. Palindrome Number
题目描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same ...
- Linux性能监控工具 gtop
给大家介绍一款性能监控工具,个人对比界面比top美观,常用指标比较清晰毕竟top上的指标不是每个人都能熟悉,也不是所有指标参数都需要看,对于新手也不便查找,好了说的再多先上图大家参观一下. 1.安装需 ...
- docker安装MySQL 8.0及初始化错误处理
Preface Several days ago,I've implement a docker environmnet,I'm gonna Install a MySQL 8. ...
- npm install 报错
今天准备在服务器上部署一下pm2,发现 npm install -g pm2 爆出了错误 error Unexpected end of JSON input while parsing near ...
- c# WebBrowser开发参考资料--杂七杂八
c# WebBrowser开发参考资料 http://hi.baidu.com/motiansen/blog/item/9e99a518233ca3b24aedbca9.html=========== ...