java-无法以编程方式创建AZURE VM

我们正在尝试使用Azure公开的REST API通过Java中的HTTPClient创建虚拟机.我们正在使用以下请求URL和XML,但正在收到“错误请求”响应.

https://management.core.windows.net/ {subscription-id} /服务/ hostedservices / {现有主机服务名称} /部署

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

解决方法:

我前一段时间一直在做同样的事情.

我建议您在Cloudify GitHub存储库中查看使用此API的Java REST客户端的实现:

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

另一个很好的参考是我的Microsoft提供的node.js sdk.您可以浏览代码,看看哪里出错了:

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

希望能帮助到你

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐