LoginSignup
0
0

More than 1 year has passed since last update.

PythonでTMF638 & 639 REST APIを叩いてみる

Posted at

TMF638 & 639で仕様化された'Service'と'Resource'インベントリ情報をPythonで取ってくる

TMF638 と TMF639 とは

  • TM Forumで仕様化されている「サービス」と「リソース」の情報を関連システムとの間でやりとりするREST API
  • オペレータ/キャリアのOSS(Operational Support Systems)装置のNBI(Northband Interface)として実装されるもの
  • TMF638 : Service Inventory API
  • TMF639 : Resource Inventory Management API

システム構成

  • jsonの情報はTMF638 & 639 API Guideの内容を流用

モジュール

  • requests
  • json
import json
import time

import requests

url1 = "https://mycsp.com:8080/tmf-api/serviceInventory/v4/service/5351"
url2 = "http://mycsp.com:port/resourceInventoryManagement/resource/8044"

r1 = requests.get(url1)
r1.encoding = r1.apparent_encoding    #エンコードが分からない場合にこれを設定すると適切なエンコードが選択される
r1_json = r1.text

# 1秒間空ける
time.sleep(1)

r2 = requests.get(url2)
r2.encoding = r2.apparent_encoding    #エンコードが分からない場合にこれを設定すると適切なエンコードが選択される
r2_json = r2.text

# 取得したデータをjsonファイルとして保存
with open('res1.json', 'w', encoding='utf8') as f:
    f.write(r1_json)

with open('res2.json', 'w', encoding='utf8') as f:
    f.write(r2_json)

取得データ

res1.json
{
    "id": "5351",
    "href": "https://mycsp.com:8080/tmf-api/serviceInventory/v4/service/5351",
    "serviceType": "Cloud",
    "name": "vCPE serial 1355615",
    "description": "Instantiation of vCPE",
    "state": "Active",
    "category": "CFS",
    "isServiceEnabled": true,
    "hasStarted": true,
    "startMode": "1",
    "isStateful": true,
    "startDate": "2018-01-15T12:26:11.747Z",
    "serviceSpecification": {
        "id": "1212",
        "href": "https://mycsp.com:8080/tmf-api/serviceCatalogManagement/v4/serviceSpecification/1212",
        "name": "vCPE",
        "version": "1.0.0",
        "@referredType": "ServiceSpecification"
    },
    "feature": [
        {
            "id": "Feat1",
            "isEnabled": true,
            "name": "ElasticBandwith",
            "featureCharacteritic": [
                {
                    "name": "isCapped",
                    "value": true,
                    "id": "45gh-fg",
                    "valueType": "boolean"
                }
            ]
        }
    ],
    "serviceCharacteristic": [
        {
            "id": "452-gh6",
            "name": "vCPE",
            "valueType": "object",
            "value": {
                "@type": "JSONSpecification",
                "@schemaLocation": "http://my.schemas/vCPE.schema.json",
                "vCPE_IP": "193.218.236.21",
                "MaxTxRate": 300,
                "TransmitPower": "11 dBm",
                "maxTream": "OFF"
            }
        }
    ],
    "serviceRelationship": [
        {
            "relationshipType": "DependentOn",
            "ServiceRelationshipCharacteristic": [
                {
                    "id": "126",
                    "name": "CrossRef",
                    "value": "44-11-h",
                    "valueType": "string"
                }
            ],
            "service": {
                "href": "https://mycsp.com:8080/tmf-api/serviceInventory/v4/service/5645",
                "id": "5645",
                "@type": "ServiceRef",
                "@referredType": "Service"
            }
        }
    ],
    "supportingService": [
        {
            "href": "https://mycsp.com:8080/tmf-api/serviceInventory/v4/service/5885",
            "id": "5885",
            "@type": "ServiceRef",
            "@referredType": "Service"
        }
    ],
    "supportingResource": [
        {
            "id": "6161",
            "href": "https://mycsp.com:8080/tmf-api/resourceInventoryManagement/v4/resource/5351",
            "name": "GenInfra",
            "@referredType": "VirtualResource"
        },
        {
            "id": "7171",
            "href": "https://mycsp.com:8080/tmf-api/resourceInventoryManagement/v4/resource/7171",
            "name": "BNG_MUX",
            "value": "01 25 65",
            "@referredType": "VNF"
        }
    ],
    "relatedParty": [
        {
            "href": "https://mycsp.com:8080/tmf-api/partyManagement/v4/party/456",
            "id": "456",
            "name": "John Doe",
            "role": "user",
            "@referredType": "Individual"
        }
    ],
    "serviceOrderItem": [
        {
            "serviceOrderHref": "https://mycsp.com:8080/tmf-api/serviceOrder/v4/serviceOrder/42",
            "serviceOrderId": "42",
            "role": "initiator",
            "@referredType": "ServiceOrder",
            "itemId": "1",
            "itemAction": "add"
        },
        {
            "serviceOrderHref": "https://mycsp.com:8080/tmf-api/serviceOrder/v4/serviceOrder/896",
            "serviceOrderId": "896",
            "role": "activation",
            "@referredType": "ServiceOrder",
            "itemId": "4",
            "itemAction": "change"
        }
    ],
    "place": [
        {
            "href": "https://mycsp.com:8080/tmf-api/geographicAddressManagement/v4/geographicAddress/2435",
            "id": "2435",
            "name": "Customer primary location",
            "@referredType": "GeographicAddress",
            "role": "InstallationAddress"
        }
    ],
    "note": [
        {
            "author": "Harvey Poupon",
            "date": "2018-01-15T12:26:11.748Z",
            "text": "This service was installed automatically, no issues were noted in testing."
        }
    ],
    "@type": "Service",
    "@schemaLocation": "https://mycsp.com:8080/tmf-api/schema/Service/vCPE.schema.json"
}
res2.json
{
    "id": "8044",
    "href": "http://mycsp.com:port/resourceInventoryManagement/resource/8044",
    "description": "This is a MSISDN resource with the category Premium and with a reserved resourceStatus fororganisations.",
    "category": "Premium",
    "value": "0170112231",
    "endOperatingDate": "2022-07-04T08:00.000Z",
    "name": "MobileNumber xx",
    "administrativeState": "locked",
    "operationalState": "enable",
    "usageState": "active",
    "resourceStatus": "reserved",
    "relatedParty": [
        {
            "href": "https://mycsp.com:port/tmf-api/partyManagement/v4/individual/456",
            "id": "456",
            "name": "John Doe",
            "role": "user",
            "@referredType": "Individual"
        }
    ],
    "note": [
        {
            "text": "something about this resource"
        }
    ],
    "place": {
        "id": "9912",
        "href": "https://mycsp.com:port/geographicAddressManagement/v4/geographicAddress/9912",
        "@type": "PlaceRef",
        "@referredType": "GeographicAddress"
    },
    "resourceRelationship": [
        {
            "relationshipType": "contains",
            "resource": {
                "id": "44",
                "href": "http://mycsp.com:port/resourceInventoryManagement/resource/44"
            }
        }
    ],
    "resourceSpecification": {
        "id": "4",
        "href": " http://mycsp.com:port/resourceCatalogManagement/resourceSpecification/4",
        "@referredType": "LogicalResourceSpecification"
    },
    "startOperatingDate": "2020-03-04T00:00.000Z",
    "version": "business v2",
    "@type": "MSISDN",
    "@schemaLocation": "http://mycsp.com:port/MSISDN_Resource.schema.json",
    "@baseType": "Resource"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0