Help us understand the problem. What is going on with this article?

IBM Cloud のDC/PoPの住所を一覧表示するスクリプト

追記

こちらからリストファイルをダウンロードできるようにしました。
http://ibm.biz/dcandpop

内容

Bluemix Infrastructure (旧SoftLayer) において、各データセンター/PoP(Point of Presence)の住所を、コマンドで一覧表示できるスクリプトをつくりました。

前提

以下の記事が理解できていることが前提です。
Bluemix Infrastructure (旧SoftLayer) のAPIについて、詳しく解説してあります。

ShinobiLayer: SoftLayer API 次の一歩: データ型オブジェクト(1) - Qiita

スクリプト(DC)

getDcLocationAddress.py
import SoftLayer
import json
from prettytable import PrettyTable

# account info
client = SoftLayer.create_client_from_env()

#objectmask
objectmask = """
    longName,
    name,
    locationAddress[
        address1,
        address2,
        city,
        country,
        postalCode,
        state
    ]

"""
dcs = client['Location'].getDatacenters(mask=objectmask)
#dcs_jsonstring = json.dumps(dcs,indent=4)
#print(dcs_jsonstring) 

table = PrettyTable([
    'Name',
    'Detail',
    'Country',
    'State',
    'PostalCode',
    'City',
    'Address1',
    'Address2'
])


for key in range(len(dcs)):
    if 'locationAddress' in dcs[key]:
        table.add_row([
            dcs[key]['name'],
            dcs[key]['longName'],
            dcs[key]['locationAddress'].get('country',""),
            dcs[key]['locationAddress'].get('state',""),
            dcs[key]['locationAddress'].get('postalCode',""),
            dcs[key]['locationAddress'].get('city',""),
            dcs[key]['locationAddress'].get('address1',""),
            dcs[key]['locationAddress'].get('address2',"")
        ])
    else:
        table.add_row([
            dcs[key]['name'],
            dcs[key]['longName'],
            dcs[key].get('locationAddress',""),
            dcs[key].get('locationAddress',""),
            dcs[key].get('locationAddress',""),
            dcs[key].get('locationAddress',""),
            dcs[key].get('locationAddress',""),
            dcs[key].get('locationAddress',"")
        ])

print len(dcs)
print table.get_string(sortby="Name")

スクリプト(PoP)

getPopLocationAddress.py
import SoftLayer
import json
from prettytable import PrettyTable

# account info
client = SoftLayer.create_client_from_env()

#objectmask
objectmask = """
    longName,
    name,
    locationAddress[
        address1,
        address2,
        city,
        country,
        postalCode,
        state
    ]

"""
pop = client['Location'].getpointOfPresence(mask=objectmask)
#pop_jsonstring = json.dumps(pop,indent=4)
#print(pop_jsonstring) 

table = PrettyTable([
    'Name',
    'Detail',
    'Country',
    'State',
    'PostalCode',
    'City',
    'Address1',
    'Address2'
])


for key2 in range(len(pop)):
    if 'locationAddress' in pop[key2]:
        table.add_row([
            pop[key2]['name'],
            pop[key2]['longName'],
            pop[key2]['locationAddress'].get('country',""),
            pop[key2]['locationAddress'].get('state',""),
            pop[key2]['locationAddress'].get('postalCode',""),
            pop[key2]['locationAddress'].get('city',""),
            pop[key2]['locationAddress'].get('address1',""),
            pop[key2]['locationAddress'].get('address2',"")
        ])
    else:
        table.add_row([
            pop[key2]['name'],
            pop[key2]['longName'],
            pop[key2].get('locationAddress',""),
            pop[key2].get('locationAddress',""),
            pop[key2].get('locationAddress',""),
            pop[key2].get('locationAddress',""),
            pop[key2].get('locationAddress',""),
            pop[key2].get('locationAddress',"")
        ])

print len(pop)
print table.get_string(sortby="Name")

実行結果の例(DC)

31
+-------+--------------+---------+-------+-----------------------------------+----------------+----------------------------------------------------------------------------------+-----------------------+
|  Name |    Detail    | Country | State |             PostalCode            |      City      |                                     Address1                                     |        Address2       |
+-------+--------------+---------+-------+-----------------------------------+----------------+----------------------------------------------------------------------------------+-----------------------+
| ams01 | Amsterdam 1  |    NL   |       |              1096 BK              |   Amsterdam    |                           Paul van Vlissingenstraat 16                           |                       |
| ams03 | Amsterdam 3  |    NL   |       |               1329BG              |     Almere     |                                    Flevoland                                     |    Rondebeltweg 62,   |
| che01 |  Chennai 1   |    IN   |       |               600053              |    Chennai     |                               226, Red Hills Road                                | Kallikuppam, Ambattur |
| dal01 |   Dallas 1   |    US   |   TX  |               75207               |     Dallas     |                              1950 Stemmons Freeway                               |       Suite 3048      |
| dal02 |   Dallas 2   |         |       |                                   |                |                                                                                  |                       |
| dal05 |   Dallas 5   |    US   |   TX  |               75244               |     Dallas     |                                 4849 Alpha Road                                  |                       |
| dal06 |   Dallas 6   |    US   |   TX  |               75207               |     Dallas     |                             1333 N. Stemmons Freeway                             |       Suite 110       |
| dal07 |   Dallas 7   |         |       |                                   |                |                                                                                  |                       |
| dal09 |   Dallas 9   |    US   |   TX  |               75081               |   Richardson   |                                 900 Quality Way                                  |                       |
| dal10 |  Dallas 10   |    US   |   TX  |               75063               |     Irving     |                               6431 Longhorn Drive                                |                       |
| fra02 | Frankfurt 2  |    DE   |       |               65936               |   Frankfurt    |                           Leonard - Heisswolf - Str 4.                           |                       |
| hkg02 | Hong Kong 2  |    HK   |       |                                   |   Hong Kong    | 33 Chun Choi Street, Tseung Kwan O Industrial Estate, New Territories, Hong Kong |                       |
| hou02 |  Houston 2   |    US   |   TX  |               77067               |    Houston     |                                855 Greens Parkway                                |       Suite 300       |
| lon02 |   London 2   |    GB   |       |              KT9 1SJ              |  Chessington   |                             Fountain Court, Cox Lane                             |   Suites 210 and 230  |
| mel01 | Melbourne 1  |    AU   |       |              VIC 3032             |   Melbourne    |                            72 Radnor Drive, Deer Park                            |                       |
| mex01 |   Mexico 1   |    MX   |       |                                   |   Querétaro   |                Km 2 200, Lateral Carretera Estatal 431 El Marques                |                       |
| mil01 |   Milan 1    |    IT   |       |               20010               |   CORNAREDO    |                                 VIA MONZORO 103                                  |                       |
| mon01 |  Montreal 1  |    CA   |   QC  |              J2C 7W2              | Drummondville  |                                2525 Rue Canadien                                 |                       |
| osl01 |    Oslo 1    |    NO   |       |                1900               |    Fetsund     |                                 Fet Næringspark                                 |      Heiaveien 9      |
| par01 |   Paris 1    |    FR   |       |               92582               |     Clichy     |                 Société par Actions Simplifiée Unipersonnelle                 |     7-9 rue Petit     |
| sao01 | Sao Paulo 1  |    BR   |       |              Km 67,7              |   Medeiros     |                          Rod Dom Gabriel Paulino Couto,                          |                       |
| sea01 |  Seattle 1   |    US   |   WA  |               98168               |    Tukwila     |                         3355 S. 120th Place, Suite# 331                          |                       |
| seo01 |   Seoul 1    |    KR   |       |            Gyeonggi-do            |  Seongnam-si   |                            46, Pangyo-ro 255beon-gil                             |       Bundang-gu      |
| sjc01 |  San Jose 1  |    US   |   CA  |               95054               |  Santa Clara   |                            3105 Alfred St, Suite 331                             |                       |
| sjc03 |  San Jose 3  |    US   |   CA  |               95054               |  Santa Clara   |                              1100 Space Park Drive                               |                       |
| sng01 | Singapore 1  |    SG   |       |               139964              |  East Jurong   |                         29A International Business Park                          |                       |
| syd01 |   Sydney 1   |    AU   |       | Ultimo, NSW 2007 Sydney Australia |     Ultimo     |                                273 Pymont Street                                 |                       |
| tok02 |   Tokyo 2    |    JP   |       |              135-0061             | Koto-ku, Tokyo |                                  6-2-12 Toyosu                                   |                       |
| tor01 |  Toronto 1   |    CA   |   ON  |              L3R 4B6              |    Markham     |                                    Suite 130                                     |       371 Gough       |
| wdc01 | Washington 1 |    US   |   VA  |               20151               |   Chantilly    |                           4030 Lafayette Center Drive                            |       Suite 331       |
| wdc04 | Washington 4 |    US   |   VA  |               20147               |    Ashburn     |                           44060 Digital Loudoun Plaza                            |                       |
+-------+--------------+---------+-------+-----------------------------------+----------------+----------------------------------------------------------------------------------+-----------------------+

実行結果の例(PoP)

30
+-------+---------------+---------+-------+-------------+---------------------+--------------------------------------------------------------------------------------+-------------------+
|  Name |     Detail    | Country | State |  PostalCode |         City        |                                       Address1                                       |      Address2     |
+-------+---------------+---------+-------+-------------+---------------------+--------------------------------------------------------------------------------------+-------------------+
| ams02 |  Amsterdam 2  |    NL   |       |   1101 EB   |      Amsterdam      |                                  Larrderhoogtweg 57                                  |                   |
| atl01 |   Atlanta 1   |    US   |   GA  |    30303    |       Atlanta       |                                  56 Marietta Street                                  |     4th floor     |
| chi01 |   Chicago 1   |    US   |   IL  |    60616    |       Chicago       |                                     350 E Cermak                                     |                   |
| dal03 |    Dallas 3   |    US   |   TX  |    75027    |        Dallas       |                               1950 N. Stemmons Freeway                               |     Suite 1034    |
| dal04 |  Dallas 4 Pop |    US   |   TX  |    75201    |        Dallas       |                                   2323 Bryan St,                                     |                   |
| den01 |    Denver 1   |    US   |   CO  |    80202    |        Denver       |                              910 15th Street, Suite 751                              |                   |
| fra01 |  Frankfurt 1  |    DE   |       |   D-60314   |  Frankfurt am Main  |                               Hanauer Landstrasse 302                                |                   |
| hkg01 |  Hong Kong 1  |    HK   |       |             |       Chai Wan      |                                29F, 399 Chai Wan Road                                |                   |
| lax01 | Los Angeles 1 |    US   |   CA  |    90717    |     Los Angeles     |                                  624 S. Grand Ave.                                   |                   |
| lon01 |    London 1   |    GB   |       |   E14 9GE   |        London       |                             6/7 Harbour Exchange Square                              |                   |
| mel02 |  Melbourne 2  |    AU   |       |     3207    |       Victoria      |                                  820 Lorimer Street                                  |   Port Melbourne  |
| mia01 |    Miami 1    |    US   |   FL  |    33132    |        Miami        |                                   50 NE 9th Street                                   |                   |
| mil02 |    Milan 2    |    IT   |       |    20153    |        Milan        |                          Building D, Caldera Business Park                           |  Via Caldera, 21  |
| mon02 |   Montreal 2  |    CA   |   QC  |    H3B3A7   |       Montreal      |                   1155 University Street, Montreal, QC H3B3A7, CA                    |                   |
| nyc01 |   New York 1  |    US   |   NY  |    10011    |       New York      |                                     111 8th Ave                                      |     14th Floor    |
| osl02 |    Norway 2   |    NO   |       |    0520     |         Oslo        |                             Hans Møller Gassmanssvei 9                              | 0520 Oslo, Norway |
| pal01 |  Palo Alto 1  |    US   |   CA  |    94301    |      PALO ALTO      |                        2nd Floor, 529 Bryant Street Palo Alto                        |                   |
| par02 |    Paris 2    |    FR   |       |             |     Saint Denis     |                               114 rue Ambroise Croizat                               |                   |
| per01 |    Perth 01   |    AU   |       |             |  Western Australia  |                                  6008 Shenton Park                                   |                   |
| per01 |    Perth 1    |         |       |             |                     |                                                                                      |                   |
| sao02 |  Sao Paulo 02 |    BR   |       |  06455-000  |      São Pulo      |                         Al. Araguaia, 3641 Tamboré Barueri                          |                   |
| sea02 |   Seattle 2   |    US   |   WA  |    98121    |       Seattle       |                                    2001 6th Ave.                                     |     Suite 3000    |
| seo02 |    Seoul 2    |    KR   |       | Gyeonggi-do |      Yatap-dong     |                           3F Hostway IDC, 343-1 Yatap-dong                           |                   |
| sjc02 |   San Jose 2  |    US   |   CA  |    95119    |       San Jose      |                                  11 Great Oaks Blvd                                  |                   |
| sng02 |   Singapore   |    SG   |       |    139964   |      Singapore      | 4th Floor, 20 Ayer Rajah Crescent Industrial Park Suite: L4B, Ayer Rajah, 139964, SG |                   |
| sto01 |  Stockholm 01 |         |       |             |                     |                                                                                      |                   |
| syd02 |    Sydney 2   |    AU   |       |     2015    |        Sydney       |                                     47 Bourke Rd                                     |                   |
| tok01 |    Tokyo 1    |    JP   |       |   140-0002  | Shinagawa-ku, Tokyo |                               3-8-21 Higashi-Shinagawa                               |                   |
| tor02 |   Toronto 2   |    CA   |   ON  |   M5J 2N1   |       Toronto       |                             6th Floor, 151 Front Street                              |                   |
| wdc02 |  Washington 2 |    US   |   VA  |    20147    |       Ashburn       |                                    21715 Filigree                                    |                   |
+-------+---------------+---------+-------+-------------+---------------------+--------------------------------------------------------------------------------------+-------------------+
khayama
このサイトにおける掲載内容はあくまで私自身の見解であり、必ずしも私の所属団体・企業における立場、戦略、意見を代表するものではありません。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした