2014-10-07 35 views
0

我已經在這個網站和谷歌搜索,但一直未能得到這個答案。如何使用純蟒蛇/ boto訪問EMR主私人IP地址

我的代碼從EC2實例運行,它使用boto創建和管理EMR集羣。 我可以使用這個框架來獲取flow_id(或者cluster_id,不知道哪個是正確的名稱),它以「j-」開頭並且具有固定數量的字符來標識集羣。

使用框架,我可以建立電子病歷或EC2連接,但對我的生活,我不能做以下使用博託:

aws emr --list-clusters --cluster-id=j-ASDFGHJKL | json '["instances"].[0].["privateipaddress"] 

**以上是有點欣喜之餘,我不記得了json格式和json命令是什麼或者它想要什麼參數,但是cli。

我pprint.pprint()編輯和檢查與inspect.getmembers()的連接,獲得連接到特定的cluster_id,但我還沒有看到這個字段/ var /屬性有或沒有方法調用。

我一直在向上和向下亞馬遜和博託,他們如何做它像 here

def test_list_instances(self): #line 317 
     ... 
     self.assertEqual(response.instances[0].privateipaddress , '10.0.0.60') 
     ... 

附:我試過this,但python抱怨說「實例」屬性不可迭代,數組可訪問(我忘記了「var [0]」的命名),還有其他我嘗試過的東西,包括檢查。 順便說一句,我可以從這裏訪問publicDNSaddress,以及許多其他的東西,只是不是私人IP ...

請告訴我,如果我搞亂了某處,我可以找到答案,我使用一個醜陋的修復通過使用子進程!

回答

0

檢查博託版本使用 pip show boto 我的猜測是您使用版本2.24或更早,因爲這版本並沒有解析實例的信息看https://github.com/boto/boto/blob/2.24.0/tests/unit/emr/test_connection.py#L117 相比 https://github.com/boto/boto/blob/2.25.0/tests/unit/emr/test_connection.py#L313

如果您博託的版本升級到2.25或更新版本,您可以執行以下操作:

from boto.emr.connection import EmrConnection 

conn = EmrConnection(<your aws key>, <your aws secret key>) 
jobid = 'j-XXXXXXXXXXXXXX' # your job id 
response = conn.list_instances(jobid) 

for instance in response.instances: 
    print instance.privateipaddress