smartdc by Ruby

12
ruby-smartdc Usage CLI and Program

description

ruby-smartdc Usage CLI

Transcript of smartdc by Ruby

Page 1: smartdc by Ruby

ruby-smartdc

Usage CLI and Program

Page 2: smartdc by Ruby

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...

Page 3: smartdc by Ruby

CLI

Page 4: smartdc by Ruby

Install and Setup•Install

$ gem install smartdcFetching: smartdc-0.3.0.gem (100%)Successfully installed smartdc-0.3.01 gem installed

•Setup$ sdc-setup https://api.z-cloud.jpversion:[~6.5] ~6.5Username (login): your namePassword: your passwordSuccessful configuration.

Page 5: smartdc by Ruby

Register to generate an SSH •Generate

$ ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsaGenerating 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"}

Page 6: smartdc by Ruby

Provision a new Machine• Help

$ sdc-createmachine -hUsage: 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, --helpDatasets(urn): sdc:sdc:centos6lvm:1.1.3 sdc:sdc:smartos64:1.4.7Packages(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"}

Page 7: smartdc by Ruby

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

Page 8: smartdc by Ruby

Delete the machine•Stop

$ sdc-stopmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8ftrue$ sdc-getmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f{"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f",... "state": "stopped",

•Delete$ sdc-deletemachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8ftrue$ sdc-getmachine 83c2902a-0093-4ce2-8abe-3b9dd6199d8f{"id": "83c2902a-0093-4ce2-8abe-3b9dd6199d8f",... "state": "deleted",

Page 9: smartdc by Ruby

Program

Page 10: smartdc by Ruby

require 'smartdc'config = { "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

Connect and Machine find

Page 11: smartdc by Ruby

Return type of the variable# Type of a variable to mash. (Default)client.request.return_variable = 'mash'puts client.datacenters.find

#=> #<Hashie::Mash example="example.com">

# Type of a variable to hash.client.request.return_variable = 'hash'puts client.datacenters.find

#=> {"example"=>"https://example.com"}

# Type of a variable to json.client.request.return_variable = 'json'puts client.datacenters.find

#=> {"example": "https://example.com"}

Page 12: smartdc by Ruby

End•RubyGems

https://rubygems.org/gems/smartdc

•GitHubhttps://github.com/ogom/ruby-smartdc

•API documentationhttp://apidocs.joyent.com/napi/cloudapi/