跳转到主要内容

Microsoft Azure Legacy Service Management Client Library for Python

项目描述

Microsoft Azure SDK for Python

这是Microsoft Azure服务管理旧版客户端库。

此捆绑包中的所有包都已与Python 2.7、3.3、3.4和3.5进行了测试。

有关较新的Azure资源管理(ARM)库,请参阅azure-mgmt

有关更完整的Azure库集合,请参阅azure捆绑包。

兼容性

重要:如果您有较早版本的azure包(版本 < 1.0),在安装此包之前应先卸载它。

您可以使用pip检查版本

pip freeze

如果您看到azure==0.11.0(或任何低于1.0的版本),请先卸载它

pip uninstall azure

功能

  • 云服务管理(虚拟机、虚拟机镜像、操作系统镜像)
  • 存储帐户管理
  • 调度器管理
  • 服务总线管理
  • 亲和组管理
  • 管理证书管理
  • Web应用(网站)管理

安装

下载包

要使用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

用法

身份验证

设置证书

您需要两个证书,一个用于服务器(.cer文件),一个用于客户端(.pem文件)。

使用Azure .PublishSettings证书

您可以下载您的Azure发布设置文件,并使用该文件中嵌入的证书创建客户端证书。服务器证书已经存在,因此您不需要上传。

为此,请下载您的发布设置,然后使用此代码创建.pem文件。

from azure.servicemanagement import get_certificate_from_publish_settings

subscription_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。

ServiceManagementService

初始化

要初始化管理服务,请传入您的订阅id和.pem文件的路径。

from azure.servicemanagement import ServiceManagementService
subscription_id = '00000000-0000-0000-0000-000000000000'
cert_file = 'mycert.pem'
sms = ServiceManagementService(subscription_id, cert_file)

列出可用位置

locations = sms.list_locations()
for location in locations:
    print(location.name)

创建存储服务

要创建存储服务,您需要一个服务名称(介于3到24个字符之间,且在Microsoft Azure中唯一),一个标签(最多100个字符,自动编码为base-64),以及一个位置或亲和组。

name = "mystorageservice"
desc = name
label = name
location = 'West US'

result = sms.create_storage_account(name, desc, label, location=location)
sms.wait_for_operation_status(result.request_id, timeout=30)

创建云服务

云服务也称为托管服务(来自Microsoft Azure的早期版本)。create_hosted_service方法允许您通过提供托管服务名称(在Microsoft Azure中必须唯一)、标签(自动编码为base-64)以及服务的位置或亲和组来创建新的托管服务。

name = "myhostedservice"
desc = name
label = name
location = 'West US'

result = sms.create_hosted_service(name, label, desc, location=location)
sms.wait_for_operation_status(result.request_id, timeout=30)

创建虚拟机

要创建虚拟机,您首先需要创建云服务。然后使用create_virtual_machine_deployment方法创建虚拟机部署。

from azure.servicemanagement import LinuxConfigurationSet, OSVirtualHardDisk

name = "myhostedservice"

# Name of an os image as returned by list_os_images
image_name = 'OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd'

# Destination storage account container/blob where the VM disk
# will be created
media_link = 'url_to_target_storage_blob_for_vm_hd'

# Linux VM configuration, you can use WindowsConfigurationSet
# for a Windows VM instead
linux_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)

需要帮助?

如果您在使用提供的代码时遇到问题,请务必查看Microsoft Azure Stack Overflow开发者论坛

贡献代码或提供反馈

如果您想成为本项目的积极贡献者,请按照Microsoft Azure项目贡献指南中提供的说明进行操作。

如果您在库中遇到任何错误,请在项目的问题部分提交问题。

了解更多

Microsoft Azure Python开发者中心

Impressions

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源代码分布

azure-servicemanagement-legacy-0.20.7.zip (86.9 kB 查看哈希值)

上传时间 源代码

构建分布

azure_servicemanagement_legacy-0.20.7-py2.py3-none-any.whl (75.8 kB 查看哈希值)

上传时间 Python 2 Python 3

支持