2016-09-06 65 views

回答

0

您可以使用Azure资源管理器模板或Azure命令行界面(CLI)以编程方式创建DocumentDB帐户。有关详细信息,

0

@Amol欣德见DocumentDB Automation,尝试使用Azure的SDK为Python创建documentdb帐户。

作为参考,这里是我的示例代码。

from azure.common.credentials import ServicePrincipalCredentials 
from azure.mgmt.resource import ResourceManagementClient 

subscription_id = 'xxxx-xxxx-xxx-xxx-xxx' 
client_id = 'xxxx-xxxx-xxx-xxx-xxx' 
client_secret = 'XXXXXXXXXXXXXXXXXXXXx' 
tenant_id = 'xxxx-xxxx-xxx-xxx-xxx' 

credentials = ServicePrincipalCredentials(client_id = client_id, secret = client_secret, tenant = tenant_id) 

client = ResourceManagementClient(credentials, subscription_id) 

documentdb_params = { 
    'location': 'westus', 
    'properties': { 
     'name': 'myDocumentDb', 
     'databaseAccountOfferType': 'Standard' 
    } 
} 

client.resources.create_or_update('<your-resource-group>', 
            'Microsoft.DocumentDB', 
            '', 
            'databaseAccounts', 
            'myDocumentDb', 
            '2015-06-01', 
            documentdb_params) 

而你可以参考Azure SDK document

希望它有帮助。

+0

感谢您的更新。 为上述代码我得到这个错误: {“错误”:{“代码”:“InvalidRequestContent”,“消息”:“请求内容是无效的,不能被反序列化:“错误转换值\‘{\’位置\ “:\” westus \ “\ ”属性\“:{\ ”名称\“:\ ”myDocumentDb \“,\ ”databaseAccountOfferType \“:\ ”标准\“}} \” 键入“Microsoft.WindowsAzure .ResourceStack.Frontdoor.Data.Definitions.ResourceDefinition'。Path''} –

+0

这不是我的工作,但我已经使用下面的其余API来创建它,并且API对我来说工作正常 “/ subscriptions/ /resourceGroups//providers/Microsoft.DocumentDB/databaseAccounts/ “ 在头部,我们只需要把Azure的ARM认证令牌。 –