用于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 项目的一部分。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java修复XSS漏洞   引发异常的函数的Java字段初始化   属性名中带有变量的java调用bean属性   在Java中打印不可见字符的十六进制   Azure SDK for Java如何获取网络安全组状态?   带有Jython的python Eclipse不理解Java导入   java如何在一个大小为5的arraylist中存储5个不同arraylist的相同索引的值?   类公司中的java NullPointerException   hadoop将目录从本地系统复制到hdfs java代码   Java中带方法的多级枚举   执行进程时,java JavaFX不确定进度条   JPA中存在java外键约束问题,尽管存在“cascade all”   数字不应以0开头的数值的java正则表达式   java Beanio流处理xml平面文件中的内部元素列表   带struts2标记的字符串的java测试长度   java将用户输入的数字与随机生成的数字进行比较   java如何更改属性。store()分隔符符号从“=”到“:”?   java需要帮助获得2人游戏功能Tic Tac Toe   java应用程序在尝试创建AmazonSClient时崩溃