Skip to content

Instantly share code, notes, and snippets.

@kordless
Last active August 29, 2015 14:21
Show Gist options
  • Save kordless/9dbac7af840e8ded1fc3 to your computer and use it in GitHub Desktop.
Save kordless/9dbac7af840e8ded1fc3 to your computer and use it in GitHub Desktop.
StackMonkey Quick and Dirty APIs

Utter.io API Reference

This is a quick and dirty documenation of the utter.io API calls used request and provision an instance anonymously with Bitcoin on the Intercloud. The system currently supports provisioning OpenStack backed instances via StackMonkey's website.

Instance Asks

A list of available instances for sale can be retrieved by doing a GET on the /api/v1/instances/ endpoint (truncated for brevity):

curl -sS \
-X GET \
https://www.stackmonkey.com/api/v1/instances/

{
  "response": "success",
  "result": {
    "remote_ip": "2601:9:e00:113c:a8f3:28aa:4f42:afac",
    "instances": [
      {
        "created": "2015-01-30 23:05:05.711020",
        "updated": "2015-05-15 03:50:07.681180",
        "name": "smi-pjzdvq8z",
        "address": "1L9amYThtb6jpkqoj2sGahRVAyixjL8AA3",
        "vpus": 1,
        "memory": 1024,
        "disk": 20,
        "egress": 0,
        "ingress": 0,
        "ask": 120,
        "appliance": {
          "name": "Auro Calgary",
          "gravatar_url": "https://www.gravatar.com/avatar/fbe1c266126bf48fd4c9616566d6c198",
          "location": [51.0171,-114.0812]
        }
      },
      {
        "created": "2015-01-30 23:05:05.843170",
        "updated": "2015-05-15 03:50:07.735200",
        "name": "smi-5l14t5z8",
        "address": "1N5PgwBE8zFrZdJftNa6k3mf6B2cVBtHp4",
        "vpus": 1,
        "memory": 1024,
        "disk": 20,
        "egress": 0,
        "ingress": 0,
        "ask": 120,
        "appliance": {
          "name": "Auro Calgary",
          "gravatar_url": "https://www.gravatar.com/avatar/fbe1c266126bf48fd4c9616566d6c198",
          "location": [51.0171,-114.0812]
        }
      }
    ]
  }
}

Note: Instances have to be bid on to be purchased. This list is here to allow a market to form around flavors and ask pricing.

Flavor List

To get a list of flavors, do a GET on the /api/v1/flavors/ endpoint:

curl -sS \
-X GET \
https://www.stackmonkey.com/api/v1/flavors/

{
  "items": [
    {
      "network_up": 0,
      "description": "1024MB RAM, 1 VPUs, 30GB Disk, Unlimited Ingress\/Egress",
      "launches": 0,
      "rate": 50,
      "network_down": 0,
      "hot": 2,
      "flags": 1,
      "memory": 1024,
      "ask": 0,
      "disk": 30,
      "active": true,
      "vpus": 1,
      "name": "m1024.v1.d30.e0.i0"
    },
    {
      "network_up": 0,
      "description": "2048MB RAM, 1 VPUs, 20GB Disk, Unlimited Ingress\/Egress",
      "launches": 0,
      "rate": 10,
      "network_down": 0,
      "hot": 2,
      "flags": 1,
      "memory": 2048,
      "ask": 0,
      "disk": 20,
      "active": true,
      "vpus": 1,
      "name": "m2048.v1.d20.e0.i0"
    }
  ]
}

Create a Wisp

Once you find an instance flavor you want to use, you can create a wisp template that will be used to boot the instance. Do a POST to the /api/v1/wisp/ endpoint:

curl -sS \
-X POST \
-H "Content-Type: application/json" \
--data @stackstorm.json \
https://www.stackmonkey.com/api/v1/wisp/

{
  "response": "success",
  "result": {
    "wisp": {
      "name": "anonymous",
      "dynamic_image_url": "http:\/\/cloud-images.ubuntu.com\/trusty\/current\/trusty-server-cloudimg-amd64-disk1.img",
      "token": "r5qvgp2nk100iedp",
      "id": "5678053736841216"
    }
  }
}

Copy the wisp id for use in creating a bid.

Create a New Bid

After you create the wisp template, you can ask for an instance bid. Do a POST to the /api/v1/bids/ endpoint with the wisp id and the flavor in a JSON object:

curl -sS \
-X POST \
-H "Content-Type: application/json" \
--data '{"flavor":"m2048.v2.d30.e0.i0","wisp_id":5678053736841216}' \
https://www.stackmonkey.com/api/v1/bids/

{
  "response": "success",
  "result": {
    "message": "A new instance bid has been created.",
    "bid": {
      "created": "2015-05-15 04:24:51.580080",
      "updated": "2015-05-15 04:24:51.869010",
      "name": "smr-ksgy5FRO",
      "remote_ip": "2601:9:e00:113c:a8f3:28aa:4f42:afac",
      "flavor": {
        "name": "m2048.v2.d30.e0.i0",
        "id": "5638703112257536"
      },
      "wisp": {
        "name": "anonymous",
        "id": "5678053736841216"
      },
      "address": "1ByA7nNCppnnmaHhYAwesVfoq8TEAQEjgz",
      "ask": "200",
      "token": "1CL48lyT7VsQaOpp"
    }
  }
}

You'll have 5 minutes to make a payment to the address value. After 5 minutes, the bid will expire and you'll need to create a new bid. Note: It is possible to change the bid amount in the POST, but the system doesn't support accepting bids off ask prices...yet.

You may view the address QR code by using the following URL:

https://blockchain.info/address/<address>

Alternately, you may create a QR code of your own by using the following string format:

bitcoin:<address>?amount=<amount>

Here's an example using Google's charting engine:

The URL for that image is as follows, with URL encoding:

https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=bitcoin%3A1ByA7nNCppnnmaHhYAwesVfoq8TEAQEjgz%3Famount%3D.001%3D&choe=UTF-8

Bid Status

Request a bid's status by doing a GET to the /api/v1/bids/<token>/ endpoint. If the bid is waiting to be filled, you'll see something like this:

curl -sS \
https://www.stackmonkey.com/api/v1/bids/1CL48lyT7VsQaOpp/

{
  "response": "success",
  "result": {
    "message": "Reservation found by token.",
    "bid": {
      "created": "2015-05-15 04:24:51.580080",
      "updated": "2015-05-15 04:24:51.869010",
      "name": "smr-ksgy5FRO",
      "remote_ip": "2601:9:e00:113c:a8f3:28aa:4f42:afac",
      "flavor": {
        "name": "m2048.v2.d30.e0.i0",
        "id": "5638703112257536"
      },
      "wisp": {
        "name": "anonymous",
        "id": "5678053736841216"
      },
      "address": "None",
      "ask": "",
      "token": "rK9L1aZHSkpw3O5G"
    }
  }
}

If the bid has been filled, you'll get the instance response instead:

curl -sS \
https://www.stackmonkey.com/api/v1/bids/1CL48lyT7VsQaOpp/

{
  "response": "success",
  "result": {
    "message": "Instance found by token.",
    "instance":
      {
        "created": "2015-03-03 18:53:16.601450",
        "updated": "2015-05-15 04:47:19.579160",
        "name": "smi-a4scvofb",
        "ipv4_private_address": "10.10.123.134",
        "ipv4_address": "15.125.123.38",
        "ipv6_address": "None",
        "address": "1ByA7nNCppnnmaHhYAwesVfoq8TEAQEjgz",
        "vpus": 2,
        "memory": 2048,
        "disk": 30,
        "network": ,
        "ask": 200,
        "appliance": {
          "name": "HP Helion Las Vegas",
          "location": [36.1741883571,-115.155944824]
        }
      }
  }
}

If the bid has expired, you'll get this:

{
  "response": "error",
  "result": {
    "message": "No resources found by token."
  }
}

Instance Status

You can request an instance's status by doing a GET to the /api/v1/instance/<instance_name>/ endpoint:

curl -sS \
https://www.stackmonkey.com/api/v1/instances/smi-a4scvofb/

Note: This method is currently broken in production on StackMonkey, and will be fixed shortly. You may use the /api/v1/bids/<token> endpoint to query for the instance's IPs, and link to the following URL, which will show logs, location, etc.:

https://www.stackmonkey.com/instances/1CL48lyT7VsQaOpp/

The End.

{
"ssh_key":"<ssh_key>",
"post_creation":"#cloud-init\nhostname: stackstorm-demo\nmanage_etc_hosts: true\nruncmd:\n- [ wget, 'http://goo.gl/nGvmgH', -O, /tmp/install.sh]\n- chmod 755 /tmp/install.sh\n- /tmp/install.sh",
"dynamic_image_url":"http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img",
"image_disk_format":"qcow2",
"image_container_format":"bare"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment