码迷,mamicode.com
首页 > 编程语言 > 详细

python 操作 azure 虚拟机

时间:2015-04-17 18:23:33      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:python   azure   

python 操作 azure 虚拟机

下载微软的 python SDK

pip install azure

但是默认的 azure 接口对国内的 azure 无效,修改Python27\Lib\site-packages\azure\__init__.py文件指向China Azure

源文件如下:

# Live ServiceClient URLs
BLOB_SERVICE_HOST_BASE = ‘.blob.core.windows.net‘
QUEUE_SERVICE_HOST_BASE = ‘.queue.core.windows.net‘
TABLE_SERVICE_HOST_BASE = ‘.table.core.windows.net‘
SERVICE_BUS_HOST_BASE = ‘.servicebus.windows.net‘
MANAGEMENT_HOST = ‘management.core.windows.net‘

修改为:

# Live ServiceClient URLs
BLOB_SERVICE_HOST_BASE = ‘.blob.core.chinacloudapi.cn‘
QUEUE_SERVICE_HOST_BASE = ‘.queue.core.chinacloudapi.cn‘
TABLE_SERVICE_HOST_BASE = ‘.table.core.chinacloudapi.cn‘
SERVICE_BUS_HOST_BASE = ‘.servicebus.chinacloudapi.cn‘
MANAGEMENT_HOST = ‘management.core.chinacloudapi.cn‘

启动和停止虚拟机

from azure.servicemanagement import *

subscription_id = ‘xxxxxxxx‘
# 订阅ID
certificate_path = ‘xxxxxxxx‘
# pem 证书路径

sms = ServiceManagementService(subscription_id, certificate_path)


sms.shutdown_role(‘orange‘, ‘oranged‘, ‘oranged‘, post_shutdown_action=‘Stopped‘)
sms.start_role(‘xxx‘, ‘xxx‘, ‘xxx‘)

LinuxMac命令行生成 azure 证书

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer

上传cer证书到控制台证书管理里面后,就可以在代码中操作azure了。

python 操作 azure 虚拟机

标签:python   azure   

原文地址:http://blog.csdn.net/smallfish1983/article/details/45098023

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!