用于python的Microsoft azure旧服务管理客户端库
azure-servicemanagement-legac的Python项目详细描述
用于python的Microsoft azure sdk
这是Microsoft azure服务管理旧客户端库。
这个包中的所有包都已经用Python2.7、3.3、3.4和3.5进行了测试。
有关较新的azure资源管理(arm)库,请参见azure-mgmt。
有关更完整的azure库集,请参阅azure捆绑包包。
兼容性
important:如果你有早期版本的azure包 (版本<;1.0),您应该在安装此软件包之前卸载它。
您可以使用pip:
pip freeze
如果看到azure==0.11.0(或1.0以下的任何版本),请先卸载它:
pip uninstall azure
功能
- 云服务管理(虚拟机、虚拟机映像、操作系统映像)
- 存储帐户管理
- 调度程序管理
- 服务总线管理
- 慈善团体管理
- 管理证书管理
- 网络应用(网站)管理
安装
下载包
要通过python包索引(pypi)安装,请键入:
pip install azure-servicemanagement-legacy
下载源代码
要通过git获取sdk的源代码,请键入:
git clone https://github.com/Azure/azure-sdk-for-python.git cd azure-sdk-for-python cd azure-servicemanagement-legacy python setup.py install
用法
认证
设置证书
您需要两个证书,一个用于服务器(a.cer文件),另一个用于 客户机(一个.pem文件)。
使用azure.publishsettings证书
你可以下载你的azure发布设置文件并使用 嵌入到该文件中以创建客户端证书。服务器 证书已经存在,所以您不需要上传一个。
为此,请下载publish settings 然后使用此代码创建.pem文件。
fromazure.servicemanagementimportget_certificate_from_publish_settingssubscription_id=get_certificate_from_publish_settings(publish_settings_path='MyAccount.PublishSettings',path_to_write_certificate='mycert.pem',subscription_id='00000000-0000-0000-0000-000000000000',)
订阅ID参数是可选的。如果不止一个 订阅在发布设置中,将使用第一个。
使用openssl创建和上载新证书
要使用OpenSSL创建.pem文件,请执行以下操作:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
要创建.cer证书,请执行以下操作:
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer
创建证书后,需要上载.cer 通过的“设置”选项卡的“上载”操作将文件发送到Microsoft azure 是management portal。
服务管理服务
初始化
若要初始化管理服务,请传入订阅ID和 .pem文件的路径。
fromazure.servicemanagementimportServiceManagementServicesubscription_id='00000000-0000-0000-0000-000000000000'cert_file='mycert.pem'sms=ServiceManagementService(subscription_id,cert_file)
列出可用位置
locations=sms.list_locations()forlocationinlocations:print(location.name)
创建存储服务
要创建存储服务,您需要该服务的名称(介于3 和24个小写字符,在Microsoft azure中是唯一的),一个标签 (最多100个字符,自动编码为base-64),并且 位置或关联组。
name="mystorageservice"desc=namelabel=namelocation='West US'result=sms.create_storage_account(name,desc,label,location=location)sms.wait_for_operation_status(result.request_id,timeout=30)
创建云服务
云服务也称为托管服务(来自早期版本 微软的azure)。create_hosted_服务方法允许您 通过提供托管服务名称(它 在Microsoft azure中必须是唯一的),标签(自动编码为 base-64),以及位置或服务的关联组。
name="myhostedservice"desc=namelabel=namelocation='West US'result=sms.create_hosted_service(name,label,desc,location=location)sms.wait_for_operation_status(result.request_id,timeout=30)
创建虚拟机
要创建虚拟机,首先需要创建云服务。 然后使用 创建虚拟机部署方法。
fromazure.servicemanagementimportLinuxConfigurationSet,OSVirtualHardDiskname="myhostedservice"# Name of an os image as returned by list_os_imagesimage_name='OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd'# Destination storage account container/blob where the VM disk# will be createdmedia_link='url_to_target_storage_blob_for_vm_hd'# Linux VM configuration, you can use WindowsConfigurationSet# for a Windows VM insteadlinux_config=LinuxConfigurationSet('myhostname','myuser','mypassword',disable_ssh_password_authentication=True,)os_hd=OSVirtualHardDisk(image_name,media_link)result=sms.create_virtual_machine_deployment(service_name=name,deployment_name=name,deployment_slot='production',label=name,role_name=name,system_config=linux_config,os_virtual_hard_disk=os_hd,role_size='Small',)sms.wait_for_operation_status(result.request_id,timeout=600)
需要帮助吗?
如果你有微软的azure Developer Forums on Stack Overflow 提供的代码有问题。
贡献代码或提供反馈
如果你想成为这个项目的积极贡献者,请 按照Microsoft Azure Projects Contribution Guidelines中提供的说明操作。
如果您遇到库中的任何错误,请在 Issues 项目的一部分。