softlayer / softlayer-go

SoftLayer API Client for the Go Language
Apache License 2.0
53 stars 46 forks source link

When I buy a subnet, can I directly set the subnet tag. #180

Closed jiangbo202 closed 11 months ago

jiangbo202 commented 11 months ago

If I place an order for a subnet, I can only get the order ID and cannot know which subnet I just bought(I don't have a subnet ID and subnet IP)

May I ask if there is a solution?

allmightyspiff commented 11 months ago

Hello,

First, you can't tag subnets directly at the order time sadly.

If you are using the softlayer-go library directly, you will need to make an API call to SoftLayer_Account::getSubnets with the following mask/filter

mask =  "mask[id,gateway,cidr,billingItem[id,orderItem[id,order[id]]]]"
filter = {"subnets":{"billingItem":{"orderItem":{"order":{"id":{"operation":SUBNET_ID_GOES_HERE}}}}}}

If you are using ibmcloud cli, the following commands will work. ibmcloud.exe sl call-api SoftLayer_Account getSubnets --mask="mask[id,gateway,cidr,billingItem[id,orderItem[id,order[id]]]]" --filter='{"subnets":{"billingItem":{"orderItem":{"order":{"id":{"operation":SUBNET_ID_GOES_HERE}}}}}}'

For example...

$> ibmcloud.exe  sl subnet create private 16  3365607
This action will incur charges on your account. Continue?> y
OK
Order 110309487 was placed.

item                               cost
16 Portable Private IP Addresses   0.00
Total monthly cost                 0.00

$> ibmcloud.exe  sl call-api SoftLayer_Account getSubnets --mask="mask[id,gateway,cidr,billingItem[id,orderItem[id,order[id]]]]" --filter='{"subnets":{"billingItem":{"orderItem":{"order":{"id":{"operation":110309487}}}}}}'
[
        {
                "cidr": 28,
                "gateway": "10.127.202.209",
                "id": 1351417,  # Subnet ID
                "billingItem": {
                        "id": 1090093605,
                        "orderItem": {
                                "id": 1024577357,
                                "order": {
                                        "id": 110309487
                                }
                        }
                }
        }
]

A similar call would work for vlans.

$> ibmcloud.exe  sl vlan create --name "testPleaseCancelThis" -d par01 --vlan-type private
This action will incur charges on your account. Continue?> y
OK
The order 110308587 was placed.

$> ibmcloud.exe  sl call-api SoftLayer_Account getNetworkVlans --mask="mask[id,name,vlanNumber,billingItem[id,orderItem[id,order[id]]]]" --filter='{"networkVlans":{"billingItem":{"orderItem":{"order":{"id":{"operation":110308587}}}}}}'
[
        {
                "id": 3365607,
                "name": "testPleaseCancelThis",
                "vlanNumber": 795,
                "billingItem": {
                        "id": 1090095081,
                        "orderItem": {
                                "id": 1024576391,
                                "order": {
                                        "id": 110308587
                                }
                        }
                }
        }
]
jiangbo202 commented 11 months ago

It works very well. Thank you