2014-04-29 3 views
0

누구든지이 REST API 예제를 사용하여 C#에서 AWS sdk를 사용하지 않고 "설명하는 eucalyptus 인스턴스"를 도울 수 있습니까? 샘플 코드를 제공합니다. 이 코드는 aws에서 성공적으로 실행되지만 유칼립투스에서는 "404 찾을 수 없음"오류가 발생합니다.유칼립투스 REST API를 C에서 사용하는 방법 #

protected void Page_Load(object sender, EventArgs e) 
    { 
     EucaListInstance("xyx/services/Eucalyptus"); 
    } 

    private void ListEucaInstance(string inboundQueueUrl) 
    { 

     // Create a request for the URL.   
     string date = System.DateTime.UtcNow.ToString("s"); 
     string stringToSign = string.Format("DescribeInstances" + date); 
     string signature = CalculateEucaSignature(stringToSign, true); 

     StringBuilder sb = new StringBuilder(); 
     sb.Append(inboundQueueUrl); 
     sb.Append("?Action=DescribeInstances"); 
     sb.Append("&Version=2013-10-15"); 
     sb.AppendFormat("&AWSAccessKeyId={0}", m_EucaAccessKeyID); 
     sb.AppendFormat("&Expires={0}", date); 
     sb.AppendFormat("&Signature={0}", signature); 

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sb.ToString()); 
     HttpWebResponse response = null; 
     Stream dataStream = null; 
     StreamReader reader = null; 

     try 
     { 
      request.Credentials = CredentialCache.DefaultCredentials; 

      response = (HttpWebResponse)request.GetResponse(); 

      // Get the stream containing content returned by the server. 
      dataStream = response.GetResponseStream(); 

      // Open the stream using a StreamReader for easy access. 
      reader = new StreamReader(dataStream); 

     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
     } 
     finally 
     { 
      // Cleanup the streams and the response. 
      if (reader != null) 
       reader.Close(); 

      if (dataStream != null) 
       dataStream.Close(); 

      if (response != null) 
       response.Close(); 
     } 

    } 

    private string CalculateEucaSignature(string data, bool urlEncode) 
    { 
     ASCIIEncoding ae = new ASCIIEncoding(); 
     HMACSHA1 signature = new HMACSHA1(ae.GetBytes(m_EucaSecretKey)); 
     string retSignature = Convert.ToBase64String(signature.ComputeHash(ae.GetBytes(data.ToCharArray()))); 
     return urlEncode ? HttpUtility.UrlEncode(retSignature) : retSignature; 
    } 

답변

1

잘못된 URL로 요청을 보내면 404 오류가 발생합니다. 당신은 EC2_URL 값에 대한 귀하의 eucarc file 조사하여 배포에 사용할 수있는 URL을 찾을 수 있습니다

http://eucalyptus.your.domain.here.example.com:8773/services/Eucalyptus 

, 또는에 의해 : 나는 당신이 보통의 라인을 따라 것 올바른 URL로 전송되는 것을 확인 할 "euca-describe-services -T 유칼립투스" admin command 실행 (4.0 이후 버전에서는 "-T compute"를 사용합니다)

+0

URL을 먼저 작성해야합니다. 웹 브라우저에서 .. 웹 브라우저가 해당 URL을 사용하여 올바른 응답을 제공하면 해당 URL에 대한 코드에서 웹 요청을 작성하십시오. 그 API를 사용할 수 있습니다. –