smartdc by Ruby

615 views

Published on

ruby-smartdc Usage CLI

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
615
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

smartdc by Ruby

  1. 1. ruby-smartdc Usage CLI and Program
  2. 2. Get Started with SmartDataCenter•Create Account •Get a username and password.•Customers http://www.joyent.com/customers/ ‣ http://www.joyentcloud.com/ ‣ http://z-cloud.jp/ ‣ etc...
  3. 3. CLI
  4. 4. Install and Setup•Install $ gem install smartdc Fetching: smartdc-0.3.0.gem (100%) Successfully installed smartdc-0.3.0 1 gem installed•Setup $ sdc-setup https://api.z-cloud.jp version:[~6.5] ~6.5 Username (login): your name Password: your password Successful configuration.
  5. 5. Register to generate an SSH•Generate $ ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa Generating public/private rsa key pair. ...•Register $ sdc-createkey your-key ~/.ssh/id_rsa.pub { "name": "your-key", "key": "ssh-rsa ...", "created": "2011-11-06T12:43:24+00:00", "updated": "2011-11-06T12:43:24+00:00" }
  6. 6. Provision a new Machine• Help $ sdc-createmachine -h Usage: sdc-createmachine [options] -n, --name NAME friendly name for this machine. -e, --dataset URN dataset URN. -p, --package NAME Name of the package to use on provisioning. -h, --help Datasets(urn): sdc:sdc:centos6lvm:1.1.3 sdc:sdc:smartos64:1.4.7 Packages(name): Small_1GB Medium_2GB Medium_4GB Large_8GB• Create $ sdc-createmachine -n your-machine -e sdc:sdc:smartos64:1.4.7 -p Medium_2GB {"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f", "name": "your-machine", "type": "smartmachine", "state": "provisioning", "dataset": "sdc:sdc:smartos64:1.4.7", "ips": ["210.152.137.65"], "memory": 2048, "disk": 61440, "metadata": {}, "created": "2011-11-06T13:02:09+00:00", "updated": "2011-11-06T13:02:10+00:00"}
  7. 7. State of the machine•Get $ sdc-getmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f {"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f", "name": "your-machine", "type": "smartmachine", "state": "running", "dataset": "sdc:sdc:smartos64:1.4.7", "ips": ["210.152.137.65"], "memory": 2048, "disk": 61440, "metadata": {}, "created": "2011-11-06T13:02:42+00:00", "updated": "2011-11-06T13:02:42+00:00"}
  8. 8. Delete the machine• Stop $ sdc-stopmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f true $ sdc-getmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f {"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f", ... "state": "stopped",• Delete $ sdc-deletemachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f true $ sdc-getmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f {"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f", ... "state": "deleted",
  9. 9. Program
  10. 10. Connect and Machine findrequire smartdcconfig = { "url" => "https://example.com/", "version" => "~6.5", "username" => "auth_user","password" => "auth_pass"}client = Smartdc.new(config)machines = client.machines.findmachines.each do |machine| puts "machines id: #{machine.id}, state: #{machine.state}" machine = client.machines(machine.id) puts Start the machine. machine.start puts "machine id: #{machine.read.id}, state: #{machine.read.state}"end
  11. 11. Return type of the variable# Type of a variable to mash. (Default)client.request.return_variable = mashputs client.datacenters.find #=> #<Hashie::Mash example="example.com"># Type of a variable to hash.client.request.return_variable = hashputs client.datacenters.find #=> {"example"=>"https://example.com"}# Type of a variable to json.client.request.return_variable = jsonputs client.datacenters.find #=> {"example": "https://example.com"}
  12. 12. End•RubyGems https://rubygems.org/gems/smartdc•GitHub https://github.com/ogom/ruby-smartdc•API documentation http://apidocs.joyent.com/napi/cloudapi/

×