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 ...
随机推荐
- intellig idea中jsp或html数据没有自动保存和更换字体
主题一:保存数据jsp intellig idea是自动保存数据的,看到没有保存 解决方案: 成功解决 主题二:更换字体: 或者快捷键Ctel+Alt+s 成功解决
- MVC学习二:Controller和View关系
控制器(Controller)主要是定义方法和加载视图(View) 1.控制器中的Action方法返回值的类型ActionResult,string 2.控制器中Action方法接收浏览器参数方式: ...
- C# 程序启动其他进程程序
1 启动一个独立进程,需要用到的命名空间是:using System.Diagnostics; 进程类是 Process ,进程的相关参数信息类是 ProcessStartInfo 2 等待启 ...
- Restframework框架总结及restful规范
1. django rest framework框架的作用? 帮助开发者可以快速开发出遵循restful规范的API 2. django rest framework框架都有哪些组件(10)? -版本 ...
- 有连接服务&无连接服务
面向连接的服务 通信双方在通信时要事先建立一条通信线路,其过程包括建立连接.使用链接.释放链接三个过程 如: TCP 电话 面向无连接的服务 通信双方不需要事先建立一条通信线路,而是把每个带有目的选址 ...
- js省市区级联选择联动
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta http-equiv="Con ...
- (暴力碾标算)NOIP模拟赛 宗教仪式
题意: 一个模式串,一个文本串,现定义最大失配值为k 求文本中最大失配值<=k的长度为len(模式串)的字串个数 失配值=当前字串中与模式串不同的字符个数 思路: 暴力,加一个跳出剪枝,居然过了 ...
- IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/app
web.xml初始化spring容器出错 org.springframework.beans.factory.BeanDefinitionStoreException: IOException par ...
- mysql——查询重复数据,及删除重复数据只保留一条数据
查询 text 表中,user_name字段值重复的数据及重复次数 select user_name,count(*) as count from text 删除 text 表中,重复出现的数据只保留 ...
- 01 shell编程规范与变量
前言: 大家对shell脚本应该都不算陌生了,如果突然问你什么是shell脚本?是干什么用的?由什么组成以及怎么使用?变量的概念是什么?作用范围是什么?变量间的算术运算怎么表示?你能很容易答出来吗 本 ...