chef / knife-azure

Chef knife plug-in for Microsoft Azure
https://github.com/chef/knife-azure
Apache License 2.0
72 stars 89 forks source link

Wrong xml format and value of Get-Deployment by using knife-azure to create a VM #236

Closed jackting73 closed 7 years ago

jackting73 commented 9 years ago

https://msdn.microsoft.com/en-us/library/azure/ee460804.aspx

We can get the right format and value of Azure REST api (Get-Deployment) if created the VM by Azure. By Powershell to get Ge-Deployment : righbypowershell By Azure JAVA SDK to get Get-Deployment : rightbyjava

However, we found it failed with wrong format and value if created by knife-azure. By Powershell to get Ge-Deployment : wrongbypowershell By Azure JAVA SDK to get Ge-Deployment : wrongbyjava

The wrong format of Get-Deployment create by knife-azure :

chris-test1Productionfed1879427af455898376c545a779d5fSuspendedhttp://chris-test1.cloudapp.net/PFNlcnZpY2VDb25maWd1cmF0aW9uIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL1NlcnZpY2VIb3N0aW5nLzIwMDgvMTAvU2VydmljZUNvbmZpZ3VyYXRpb24iPg0KICA8Um9sZSBuYW1lPSJjaHJpcy05NTItMiI+DQogICAgPEluc3RhbmNlcyBjb3VudD0iMSIgLz4NCiAgPC9Sb2xlPg0KPC9TZXJ2aWNlQ29uZmlndXJhdGlvbj4=chris-test1chris-test1StoppedDeallocatedStopped6904E4DFCC84CEBEFBB265E532BB25112987A9CC1chris-test1PersistentVMRoleNetworkConfiguration5986PowerShell5986tcpfalse3389Remote Desktop3389tcpfalseReadWritechris-test1-chris-test1-0-201505050830580485https://portalvhdsdqnt01flqwh9p.blob.core.windows.net/vhds/chris-test1-chris-test1-2015-05-05.vhda699494373c04fc0bc8f2bb1389d6106__Win2K8R2SP1-Datacenter-201504.01-en.us-127GB.vhdWindowsStandard_D1EAEA705B4F65B8A286B1CE95CF9DD58AA77FF553truefalsefalse2015-05-05T08:30:53Z2015-05-05T08:53:16Zchris-test1.g6.internal.cloudapp.net
Aliasgar16 commented 9 years ago

Hi @jackting73

From my side I tried to reproduce the error for two Azure VMs (one created through Azure portal and the other one created through 'knife azure server create' command) by making API calls for Get-Deployment operation but I got 200OK as the status, but I ran into the same error as you got when I gave incorrect value for field like DeploymentName. So, could you please provide me the command(s) that you invoked through Untitled1.ps1 file so that I can figure out the exact issue.

jackting73 commented 9 years ago

Hi @Aliasgar16

I follow this article to get the information : http://blogs.msdn.com/b/kaushal/archive/2015/06/02/azure-rest-api-amp-powershell-retrieve-cloud-service-configuration.aspx

My untitled1.ps1 file contents as below: (you should replace the subscription id and thumbprint with yours)

Request Headers required to invoke the GET DEPLOYMENT REST API

$method = "GET" $headerDate = '2014-05-01' $headers = @{"x-ms-version"="$headerDate"}

$cloudservice = "azurechefnode"

$deployment = "azurechefnode"

$cloudservice = "dnsbychefknife" $deployment = "chefknifenode00" $ContentType = "application/xml"

Retrieving the subscription ID

$subID = "your subscription id" $URI = "https://management.core.windows.net/$subID/services/hostedservices/$cloudservice/deployments/$deployment"

Retrieving the certificate from Local Store

$cert = (Get-ChildItem Cert:\CurrentUser\My | ?{$_.Thumbprint -eq "your thumbprint"}).GetRawCertData()

converting the raw cert data to BASE64

$body = "-----BEGIN CERTIFICATE-----n$([convert]::ToBase64String($cert))n-----END CERTIFICATE-----"

Retrieving the certificate ThumbPrint

$mgmtCertThumb = (Get-AzureSubscription -Current).Certificate.Thumbprint

Passing all the above parameters to Invoke-RestMethod cmdlet

$url = Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint "your thumbprint" -ContentType $ContentType

$url.Deployment

$url.Deployment.RoleList.Role.ResourceExtensionReferences.ResourceExtensionReference

Aliasgar16 commented 9 years ago

Hi @jackting73

Let me know your response on this.

Thanks

NimishaS commented 9 years ago

@jackting73 , could you please verify if things are working for you using the suggestions provided above?

jackting73 commented 9 years ago

Hi @Aliasgar16 ,

I follow your suggestion to create a VM by Azure which the DNS name and Deployment name are the same with "azurechefnode" then it works (I can get the slot and deployment names)

chefnodebyazure chefnodebyazure2

However, when I created a VM by knife which the DNS name and Deployment name are the same with "jackabcd" then it failed. (I tried to use base64-encoding, but still failed)

chefnodebyknife chefnodebyknife2

So, we guess it could be the response format which the VM was created by knife not the same with the spec on https://msdn.microsoft.com/en-us/library/azure/ee460804.aspx

Please help verify the xml response format or anything possible. Thanks.

Aliasgar16 commented 9 years ago

Hi @jackting73 ,

Thanks

Aliasgar16 commented 9 years ago

Hi @jackting73

Please find below the XML response when created VM through knife-azure:

INFO: calling post hostedservices/ali-knife/deployments synchronously 
DEBUG: <?xml version="1.0"?> 
<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
  <Name>ali-knife</Name> 
  <DeploymentSlot>Production</DeploymentSlot> 
  <Label>YWxpLWtuaWZl</Label> 
  <RoleList> 
    <Role i:type="PersistentVMRole"> 
      <RoleName>ali-knife</RoleName> 
      <OsVersion i:nil="true"/> 
      <RoleType>PersistentVMRole</RoleType> 
      <ConfigurationSets> 
  <ConfigurationSet i:type="WindowsProvisioningConfigurationSet"> 
    <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType> 
    <ComputerName>ali-knife</ComputerName> 
    <AdminPassword>****</AdminPassword> 
    <ResetPasswordOnFirstLogon>false</ResetPasswordOnFirstLogon> 
    <EnableAutomaticUpdates>false</EnableAutomaticUpdates> 
    <AdminUsername>azure</AdminUsername> 
  </ConfigurationSet> 
  <ConfigurationSet i:type="NetworkConfigurationSet"> 
    <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType> 
    <InputEndpoints/> 
  </ConfigurationSet> 
</ConfigurationSets> 
      <ResourceExtensionReferences> 
  <ResourceExtensionReference> 
    <ReferenceName>ChefClient</ReferenceName> 
    <Publisher>Chef.Bootstrap.WindowsAzure</Publisher> 
    <Name>ChefClient</Name> 
    <Version>1210.12</Version> 
    <ResourceExtensionParameterValues> 
      <ResourceExtensionParameterValue> 
        <Key>PublicParams</Key> 
        <Value>****</Value> 
        <Type>Public</Type> 
      </ResourceExtensionParameterValue> 
      <ResourceExtensionParameterValue> 
        <Key>PrivateParams</Key> 
        <Value>****</Value> 
        <Type>Private</Type> 
      </ResourceExtensionParameterValue> 
    </ResourceExtensionParameterValues> 
    <State>Enable</State> 
  </ResourceExtensionReference> 
</ResourceExtensionReferences> 
      <Label>YWxpLWtuaWZl</Label> 
      <OSVirtualHardDisk> 
  <DiskName>disk_1bc09bb7-246c-4f3c-a6a5-ca2cf32e6704</DiskName> 
  <MediaLink>http://aliknifekprdecgkbl.blob.core.windows.net/vhds/disk_1bc09bb7-246c-4f3c-a6a5-ca2cf32e6704.vhd</MediaLink> 
  <SourceImageName>bd507d3a70934695bc2128e3e5a255ba__RightImage-Windows-2012R2-x64-v14.2</SourceImageName> 
</OSVirtualHardDisk> 
      <RoleSize>Small</RoleSize> 
      <ProvisionGuestAgent>true</ProvisionGuestAgent> 
    </Role> 
  </RoleList> 
</Deployment>

Thanks

Vasu1105 commented 7 years ago

@jackting73 re-open if you are still facing this issue.