【问题标题】:Adding SSH keys to Softlayer JSON order for Bare metal为 Bare metal 添加 SSH 密钥到 Softlayer JSON 订单
【发布时间】:2016-11-08 04:13:42
【问题描述】:

我想知道如何将 softlayer 中的 ssh 密钥添加到 json 裸机订单中。通过GUI,它会在您点击提交之前添加到订单的末尾

想知道它是否只是:

productOrder = { "quantity": 1, "location": 1234, "packageId": 1234, "sshKeyIds": 1234, "hardware": [ ...

我做了一个 verifyOrder() 但不确定它是否正确

【问题讨论】:

    标签: ssh-keys ibm-cloud-infrastructure


    【解决方案1】:

    如果您使用的是:SoftLayer_Product_Order::placeOrder 方法,请看以下示例:

    """
    Order a new server with SSH Keys
    
    Important manual pages:
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
    http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
    http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
    http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
    
    License: http://sldn.softlayer.com/article/License
    Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    """
    import SoftLayer
    
    
    # Your SoftLayer API username and key.
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    
    productOrder = {
        'quantity': 1,
        'location': "DALLAS09",
        'packageId': 255,
        'hardware': [
                     {
                      'hostname': 'rcvtest-11',  # The hostname of the server you wish to order.
                      'domain': 'example.org'  # The domain name of the server you wish to order.
                      }
                     ],
        'prices': [
                   {'id': 50357},  
                   {'id': 50041},  
                   {'id': 876},  
                   {'id': 55},  
                   {'id': 57},  
                   {'id': 44988},  
                   {'id': 273},  
                   {'id': 21},  
                   {'id': 50387},  
                   {'id': 906},  
                   {'id': 58},  
                   {'id': 50397},  
                   {'id': 420},  
                   {'id': 418}  
                   ],
            'sshKeys': [{'sshKeyIds': [214147, 94206]}]
    
    }
    
    # Create a SoftLayer API client object
    client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
    
    try:
        """
        verifyOrder() will check your order for errors. Replace this with a call
        to placeOrder() when you're ready to order. Both calls return a receipt
        object that you can use for your records.
    
        Once your order is placed it'll go through SoftLayer's approval and
        provisioning process. When it's done you'll have a new
        SoftLayer_Hardware_Server object and server ready to use.
        """
        receipt = client['Product_Order'].verifyOrder(productOrder)
        print(receipt)
    except SoftLayer.SoftLayerAPIError as e:
        print("Unable to place a server order faultCode=%s, faultString=%s"
              % (e.faultCode, e.faultString))
        exit(1)
    

    希望对你有帮助,有任何疑问或cmets请告诉我

    【讨论】:

    • 谢谢,我之前试过这个,我在收据中得到了这个:"sshKeys": [{'sshKeyIds': []}], 在 sshKeys 部分,它什么也没显示,这就是我担心的原因
    • 通过 getSshKeys 函数验证,我知道我的 ssh 密钥/ID 是正确的
    • 我已成功定义并查看收据中的 ssh 密钥,您能否提供您尝试过的完整代码?如果您继续遇到此问题
    • from pprint import pprint as pp import SoftLayer list_keys = client['Account'].getSshKeys() pp(list_keys) 是我用来获取 ssh 密钥并使用 id 的。对于实际的 json 顺序,它基本上看起来像你的
    • 是的,这是获取 sshKeys 的方式,请问您能否提供您用于下订单的完整代码?
    【解决方案2】:

    你可以试试这个:

    http://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Hardware_Server/createObject.json 
    Method: POST
    Request body:
    
    {  
       "parameters":[  
          {  
             "hostname":"test",
             "domain":"softlayer.com",
             "processorCoreAmount":2,
             "memoryCapacity":2,
             "hourlyBillingFlag":true,
             "datacenter":{  
                "name":"dal05"
             },
             "operatingSystemReferenceCode":"UBUNTU_LATEST",
             "sshKeys":[
                { "id":21414 },
                { "id":9420 }
             ]
          }
       ]
    }
    

    其他评论链接: http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/createObject http://sldn.softlayer.com/reference/services/SoftLayer_Account/getSshKeys http://sldn.softlayer.com/reference/services/SoftLayer_Hardware/getCreateObjectOptions

    【讨论】:

      【解决方案3】:
      import SoftLayer
      import json
      from pprint import pprint as pp
      
      productOrder = {
          "quantity": 1,
          "location": 1441195,
          "packageId": 251,
          "sshKeyIds": 248873,
          "hardware": [
              {
                  "hostname": "db2oncloud-tshirt-plan-customer-#-letter-datacenter",
                  "primaryNetworkComponent": {
                      "networkVlan": {
                          "id": 1351859
                      }
                  },
                  "domain": "bluemix.net",
                  "primaryBackendNetworkComponent": {
                      "networkVlan": {
                          "id": 1351879
                      }
                  }
      
              }
          ],
          "prices": [
              {
                  "id": 50691,
                  "description": "Dual Intel Xeon E5-2620 v3 (12 Cores, 2.40 GHz)"
              },
              {
                  "id": 49437,
                  "description": "128 GB RAM"
              },
              {
                  "id": 49081,
                  "description": "Red Hat Enterprise Linux 7.x (64 bit) (per-processor licensing)"
              },
              {
                  "id": 35686,
                  "description": "10 Gbps Redundant Public & Private Network Uplinks"
              },
              {
                  "id": 34241,
                  "description": "Host Ping and TCP Service Monitoring"
              },
              {
                  "id": 34996,
                  "description": "Automated Reboot from Monitoring"
              },
              {
                  "id": 50359,
                  "description": "500 GB Bandwidth"
              },
              {
                  "id": 33483,
                  "description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account"
              },
              {
                  "id": 141833, # Disk0
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 141833, # Disk1
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 141833, # Disk2
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 141833, # Disk3
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 141833, # Disk4
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 141833, # Disk5
                  "description": "1.2 TB SSD (10 DWPD)"
              },
              {
                  "id": 50143, # Disk6
                  "description": "800 GB SSD (10 DWPD)"
              },
              {
                  "id": 50143, # Disk7
                  "description": "800 GB SSD (10 DWPD)"
              },
              {
                  "id": 141965,
                  "description": "DISK_CONTROLLER_RAID_10"
              },
              {
                  "id": 32500,
                  "description": "Email and Ticket"
              },
              {
                  "id": 35310,
                  "description": "Nessus Vulnerability Assessment & Reporting"
              },
              {
                  "id": 34807,
                  "description": "1 IP Address"
              },
              {
                  "id": 25014,
                  "description": "Reboot / KVM over IP"
              }
          ],
          "sshKeys": [
              {
                  "sshKeyIds":248873
              }
          ],
          "storageGroups": [
              {
                  "arraySize": 100,
                  "arrayTypeId": 5, # Raid 10
                  "hardDrives": [
                      0,
                      1,
                      2,
                      3,
                      4,
                      5
                  ],
                  "partitionTemplateId": 1, # Linux Basic
                  "partitions": [
                      {
                          "isGrow": True,
                          "name": "/ssd_disk1",
                          "size": 3501
                      }
                  ]
              },
              {
                  "arraySize": 800,
                  "arrayTypeId": 2, # Raid 1
                  "hardDrives": [
                      6,
                      7
                  ],
                  "partitions": [
                      {
                          "isGrow": True,
                          "name": "/ssd_disk2",
                          "side": 800
                      }
                  ]
              }
          ]
      }
      
      client = SoftLayer.Client(username=&apikey)
      
      order = client['Product_Order'].verifyOrder(productOrder)
      pp(order)
      

      【讨论】:

        【解决方案4】:

        试试下面的脚本:

        import SoftLayer
        import json
        from pprint import pprint as pp
        
        productOrder = {
            "quantity": 1,
            "location": 1441195,
            "packageId": 251,
            #"sshKeyIds": 248873,
            "hardware": [
                {
                    "hostname": "db2oncloud-tshirt-plan-customer-#-letter-datacenter",
                    "primaryNetworkComponent": {
                        "networkVlan": {
                            "id": 1351859
                        }
                    },
                    "domain": "bluemix.net",
                    "primaryBackendNetworkComponent": {
                        "networkVlan": {
                            "id": 1351879
                        }
                    }
        
                }
            ],
            "prices": [
                {
                    "id": 50691,
                    "description": "Dual Intel Xeon E5-2620 v3 (12 Cores, 2.40 GHz)"
                },
                {
                    "id": 49437,
                    "description": "128 GB RAM"
                },
                {
                    "id": 49081,
                    "description": "Red Hat Enterprise Linux 7.x (64 bit) (per-processor licensing)"
                },
                {
                    "id": 35686,
                    "description": "10 Gbps Redundant Public & Private Network Uplinks"
                },
                {
                    "id": 34241,
                    "description": "Host Ping and TCP Service Monitoring"
                },
                {
                    "id": 34996,
                    "description": "Automated Reboot from Monitoring"
                },
                {
                    "id": 50359,
                    "description": "500 GB Bandwidth"
                },
                {
                    "id": 33483,
                    "description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account"
                },
                {
                    "id": 141833, # Disk0
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 141833, # Disk1
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 141833, # Disk2
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 141833, # Disk3
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 141833, # Disk4
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 141833, # Disk5
                    "description": "1.2 TB SSD (10 DWPD)"
                },
                {
                    "id": 50143, # Disk6
                    "description": "800 GB SSD (10 DWPD)"
                },
                {
                    "id": 50143, # Disk7
                    "description": "800 GB SSD (10 DWPD)"
                },
                {
                    "id": 141965,
                    "description": "DISK_CONTROLLER_RAID_10"
                },
                {
                    "id": 32500,
                    "description": "Email and Ticket"
                },
                {
                    "id": 35310,
                    "description": "Nessus Vulnerability Assessment & Reporting"
                },
                {
                    "id": 34807,
                    "description": "1 IP Address"
                },
                {
                    "id": 25014,
                    "description": "Reboot / KVM over IP"
                }
            ],
            "sshKeys": [
                {
                    "sshKeyIds":[248873]
                }
            ],
            "storageGroups": [
                {
                    "arraySize": 100,
                    "arrayTypeId": 5, # Raid 10
                    "hardDrives": [
                        0,
                        1,
                        2,
                        3,
                        4,
                        5
                    ],
                    "partitionTemplateId": 1, # Linux Basic
                    "partitions": [
                        {
                            "isGrow": True,
                            "name": "/ssd_disk1",
                            "size": 3501
                        }
                    ]
                },
                {
                    "arraySize": 800,
                    "arrayTypeId": 2, # Raid 1
                    "hardDrives": [
                        6,
                        7
                    ],
                    "partitions": [
                        {
                            "isGrow": True,
                            "name": "/ssd_disk2",
                            "side": 800
                        }
                    ]
                }
            ]
        }
        
        #client = Client(username=USERNAME, api_key=API_KEY)
        client = SoftLayer.Client(username=&apikey)
        
        order = client['Product_Order'].verifyOrder(productOrder)
        pp(order)
        

        【讨论】:

        • 非常感谢鲁伯,你是最棒的!
        • 我看到我在价格中有 RAID 选项,但在 storageGroups 中有 2 个 RAID 设置,可以吗?
        • 您应该使用此价格:141945 - DISK_CONTROLLER_RAID 而不是:141965 - DISK_CONTROLLER_RAID_10,查看您的模板。查看您的模板,您正在为第一个 RAID (RAID 10) 配置分区,无法为第一个 RAID 设置自定义分区。要获取有关 RAID 配置的更多信息,请参阅:Ordering RAID Through API
        • 抱歉耽搁了,我正在查看您的模板中的 RAID 配置
        猜你喜欢
        • 1970-01-01
        • 2018-03-15
        • 1970-01-01
        • 2021-09-06
        • 2012-07-31
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 2018-03-21
        相关资源
        最近更新 更多