无法通过编程方式创建AZURE虚拟机

3
我们正在尝试使用Azure所提供的REST API,通过Java中的HTTPClient创建一个虚拟机。我们使用以下请求URL和XML,但是我们得到了“错误的请求”响应。 https://management.core.windows.net/{subscription-id}/services/hostedservices/{existing hoster service name}/deployments
<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Name>TestVMAnandP</Name>
  <Label>bXl2bQ==</Label>
  <RoleList>
    <Role>
      <RoleName>TestVMAnandP</RoleName>
      <RoleType>PersistentVMRole</RoleType>
      <ConfigurationSets>
        <ConfigurationSet>
          <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
          <HostName>TestVMAnandP</HostName>
          <UserName>root</UserName>
          <UserPassword>test</UserPassword>
        </ConfigurationSet>
      </ConfigurationSets>
      <DataVirtualHardDisks>
        <DataVirtualHardDisk>
          <Lun>10</Lun>
          <LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>
        </DataVirtualHardDisk>
      </DataVirtualHardDisks>
      <OSVirtualHardDisk>
        <SourceImageName>srini2-srini2-2012-08-23.vhd</SourceImageName>
        <MediaLink>http://sriniteststore.blob.core.windows.net/vhds/srini2-srini2-2012-08-23.vhd</MediaLink>
      </OSVirtualHardDisk>
      <RoleSize>ExtraSmall</RoleSize>
    </Role>
  </RoleList>
  <VirtualNetworkName>MyNetwork</VirtualNetworkName>
</Deployment>

如果我们尝试将服务名称与URL中的虚拟机名称相同,我们会收到404错误。我们已经尝试了网络上提供的大多数示例并替换了值,但是所有的尝试都给我们带来了400错误。如果我们能得到一些帮助,那就太好了。
错误信息:
我得到了两种不同类型的错误:
Error 1 : When i use new <service-name> inside the below URL .management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/                          -------------------------------------------------------------------   Response message--->Not Found---404
java.io.FileNotFoundException: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/anand/deployments
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
Caused by: java.io.FileNotFoundException: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/anand/deployments
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

Error 2 : when i use an existing available <service-name> in the below URL  management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/                                                   
Response message--->Bad Request---400
java.io.IOException: Server returned HTTP response code: 400 for URL: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/azurecogservice/deployments
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/azurecogservice/deployments
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

"---------------------有效的XML-------------------------------------------------------------

"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
    <Name>190bed4a</Name>
    <DeploymentSlot>Production</DeploymentSlot>
    <Label>190bed4a</Label>
    <RoleList>
        <Role>
            <RoleName>SuseOpenVm_rolec8fc</RoleName>
            <RoleType>PersistentVMRole</RoleType>
            <ConfigurationSets>
                <ConfigurationSet>
                    <ConfigurationSetType>LinuxProvisioningConfiguration
                    </ConfigurationSetType>
                    <HostName>SuseOpenVm_rolec8fc</HostName>
                    <UserName>anandsrinivasan</UserName>
                    <UserPassword>Cloud360</UserPassword>
                    <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
                </ConfigurationSet>
                <ConfigurationSet>
                    <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
                    <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
                    <InputEndpoints>
                        <InputEndpoint>
                            <LocalPort>22</LocalPort>
                            <Name>SSH</Name>
                            <Port>22</Port>
                            <Protocol>TCP</Protocol>
                        </InputEndpoint>
                    </InputEndpoints>
                </ConfigurationSet>
            </ConfigurationSets>
            <OSVirtualHardDisk>
                <MediaLink>https://portalvhdsvf842yxvkhbg4.blob.core.windows.net/vhds/190bed4a.vhd</MediaLink>
                <SourceImageName>SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd</SourceImageName>
            </OSVirtualHardDisk>
            <RoleSize>Small</RoleSize>
        </Role>
    </RoleList>
    <VirtualNetworkName>anand360NW</VirtualNetworkName>
</Deployment>
5个回答

2
每当我在REST API上遇到问题时,我首先尝试通过门户完成我想做的事情。在您的情况下,我尝试使用用户名root和密码test创建一个Linux VM(TestVMAnandP)。我立即注意到以下错误:
  • 不允许使用用户名“root”
  • 密码必须至少为8个字符
  • 密码应包含以下3项中的任意3项:
    • 小写字符
    • 大写字符
    • 数字
    • 特殊字符

感谢您的输入..我尝试了有效的用户名和密码..仍然收到相同的错误。 - Anand Srinivasan

1

我之前也在做同样的事情。

我建议你去Cloudify GitHub仓库查看我的Java REST客户端实现,它可以消费这个API。

https://github.com/CloudifySource/cloudify/blob/master/esc/src/main/java/org/cloudifysource/esc/driver/provisioning/azure/client/MicrosoftAzureRestClient.java

另一个很好的参考是微软提供的Node.js SDK。您可以浏览代码并查看您哪里出错了:

https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/serviceManagement/servicemanagementservice.js

希望能有所帮助


Eli,通过上述客户端程序的帮助,我能够找出我的XML中的问题。非常感谢您宝贵的帮助。 - Anand Srinivasan
很高兴能够帮助到您。也许您可以分享一下具体问题出在哪里?我猜这会对其他面临相同问题的人有所裨益。 - Eli Polonsky
Eli,我已经在我的问题部分更新了正确的XML。 - Anand Srinivasan

0

错误代码400/4xx表示请求存在问题。而404错误代码则明确表示“服务器未找到与给定URI匹配的任何内容”。所以,您能否验证OSVertualHardDisck中提供的信息是否正确。

<OSVirtualHardDisk>
        <SourceImageName>srini2-srini2-2012-08-23.vhd</SourceImageName>
        <MediaLink>http://sriniteststore.blob.core.windows.net/vhds/srini2-srini2-2012-08-23.vhd</MediaLink>
      </OSVirtualHardDisk>

更新

您正在尝试使用的服务是 http://msdn.microsoft.com/en-us/library/windowsazure/jj157194.aspx

您可以在这里查看错误代码的解释 http://msdn.microsoft.com/en-us/library/windowsazure/ee460801.aspx

可能只是目标 URL 无效或不符合服务器预期。


嗨,已经通过媒体链接进行了验证。但我仍然遇到相同的错误。我甚至尝试了其他可用的媒体链接和默认的操作系统虚拟磁盘选项。 - Anand Srinivasan
你能否发布一下从该服务获取的完整错误消息? - Vamsi Mohan Jayanti
嗨Jayanthi,我遇到了两个不同的错误。 错误1:当我在以下URL中使用new <service-name>时。https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/ - Anand Srinivasan
我认为你的评论被截断了。你能把它作为问题的更新发布吗?这样每个人都可以轻松地看到它。 - Vamsi Mohan Jayanti
错误1:当我在下面的URL中使用new <service-name>时。https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/ -------------------------------------------------------------------响应消息--->未找到---404 java.io.FileNotFoundException: https://management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/anand/deployments at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) - Anand Srinivasan
显示剩余3条评论

0

服务管理 API 文档混乱不堪。如果你成为了受害者,我一点也不会感到惊讶。你可以尝试的一件事是更改

的内容。

<LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>

元素到

<LogicalSizeInGB>50</LogicalSizeInGB>

在您的DataVirtualHardDisk元素下。

我建议这样做的原因是,如果您查看 获取数据磁盘 的文档 (http://msdn.microsoft.com/en-us/library/windowsazure/jj157180.aspx),它提到您会得到 LogicalDiskSizeInGB 作为响应元素之一,但是当您执行此函数时,您收到的元素是 LogicalSizeInGB。

再次强调,这只是一个直觉。你可以试试看。

更新

您可能想要做的另一件事是解析您收到的异常以获取更多细节。在 .Net 中,我们得到一个 WebException(抱歉,我很久没有用Java工作了),所以我通常读取该异常的响应,这将返回我一个带有更多细节的XML。


0

Anand,这个API有问题。我已经在流畅管理中实现了它,但不幸的是XML是有序的。

如果不精确,您可能会在400和500个HTTP异常之间循环。我建议使用powershell以详细模式编写VM创建,并让应用程序按照您看到的确切顺序使用XML,这样就可以解决问题了。

在接下来的几天里,我将在http://blog.elastacloud.com上发布一个Java服务管理客户端示例,该示例使用.publishsettings文件进行请求,这可能对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接