Search code examples
ssh-keysibm-cloud-infrastructure

Adding SSH keys to Softlayer JSON order for Bare metal


I was wondering how to add ssh keys that are within softlayer to be added to a json bare metal order. Through the GUI, it would be added at the end of the order before you click submit

wondering if it's just with:

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

I did a verifyOrder() but not sure if it's correct


Solution

  • If you are using: SoftLayer_Product_Order::placeOrder method, take a look the following example:

    """
    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)
    

    I hope it helps, let me know any doubt or comments