Upload
simon-su
View
460
Download
0
Embed Size (px)
Citation preview
Outline
● About API, SDK, REST● SmartDataCenter CloudAPI
○ Connect CloudAPI○ Machine managements○ Machine create options○ Cloud Analysis
● After Class○ Create a machine with pre-install joomla○ Give your machine a domain
API and SDK
● Application Programming Interface○ Is a set of routines, protocols, and tools for
building software applications● Software Development Kit
○ Is typically a set of software development tools
System code
non-standard language API
SDKSpecific programming language
REST
● Representational State Transfer○ Resource○ URL(Uniform Resource Locator)○ method : POST, GET, PUT, DELETE
CloudAPI
What is CloudAPI?
CloudAPI
● We can use cloudapi to ….○ Provision new machines (both SmartMachines and
traditional Virtual Machines)○ Manage your account credentials○ Create custom analytics for monitoring your
inferastructure
Connect CloudAPI - curl
● curl: linux/unix command to view http(s) requests
● REST API - curl○ curl -sS -k
-H 'Accept:application/json' -H 'x-Api-version:~6.5' -u 'account:password' https://api.micloud.tw/charles/machines -X GET
Data input use JSON
Sepcify the API version
Sepcify the username and password info
API route for action
API route method
Connect CloudAPI - Command Line Interface(CLI)
● Command line interface(CLI) - node.js SDK○ Install node.js○ Install smartdc: npm install smartdc -g○ Upload your ssh key to key store and set env value
CloudAPI Version 6.5.x
Connect CloudAPI - Java SDK
● Provider: Muzee (http://www.muzee.net/)● Github: https://github.com/qrtt1/joyent.
cloudapi● Piece of code:
SmartDCClient client = new SmartDCClient( ":api-server:", ":user-account:", ":key-name:", new File(":private-key:"));Systme.out.println(client.listDatasets());
● Node.js - the core tech of MiCloud CloudAPI● Github: https://github.com/joyent/node-
smartdc● Documentation: http://apidocs.joyent.
com/cloudapi/● Installation:
$ npm install smartdc -g● Piece of Code
Connect CloudAPI - Node.js SDK
var smartdc = require('smartdc');var client = smartdc.createClient(...);client.listMachines(function(err, machines) { machines.forEach(function(m) { console.log('Machine: ' + JSON.stringify(m, null, 2)); });});
Management your cloud!
Initialize your environment
● Create your MiCloud account● Generate your own ssh key:
$ ssh-keygen -t rsa
Import Key to Key Store - The REST way / Use curl
● CreateKey (POST /:login/keys)● curl -sS -k -H 'Accept:application/json' \
https://api.micloud.tw/$account/keys -X POST \ -H 'x-Api-version:~6.5' \ -u '$account:$password' \ -F 'key=<$publickeyPATH' \ -F 'name=$keyname’
Use your credential
Use your key pathGive key a name
PS: We will skip “-H 'x-Api-version:~6.5' -u '$account:$password'“ in the following slides, and the “https://api.micloud.tw” will skip, too. In this example, the api will be: [POST] /:login/keys, and will have parameters “key” and “name” need to provide.
Import Key to Key Store - Use CLI
● smartdc ~6.5Use CLI command: sdc-setup
select “no” to import new key
select you key file path
do export like this...
● ListKeys (GET /:login/keys)● $ curl -sS -k -H 'Accept:application/json' \
-H 'x-Api-version:~6.5' \-u $AUTH https://api.micloud.tw/charles/keys -X GET
Check your Key Store - curl
Check your Key Store - CLI
$ sdc-listkeys
We assump user use Java & Node.js SDK already import key...
● Account● Regist Credit Card● SSH Key● Dataset:
The machine type, include OS or a service preloaded system
● Package:The size information of a machine, include CPU, memory, disk size...
● Alias/Name:The name of your machine
Before create machine
List the public dataset & packages
● $ sdc-listdatasetsListDatasets (GET /:login/datasets)
● $ sdc-listpackagesListPackages (GET /:login/packages)
● Tips: ○ use help to see more parameters
ex: sdc-listdatasets --help○ check the document for more help
List Datasets Example
List Packages Example
Machine Management API - List
List Machines● CLI:
sdc-listmachines● REST:
ListMachines (GET /:login/machines)Get Machine● CLI:
sdc-getmachine [machine uuid]● REST:
GetMachine (GET /:login/machines/:id)
List Machines under my account
Get the detail info of one machine
Machine Management API - Create
● CLI:sdc-createmachines \-dataset [dataset] \-package [package] [machine alias]
● REST: CreateMachine (POST /:login/machines)
Create a 512M SmartOSPlus64 machine
Machine Management API - Stop & Delete a Machine
● sdc-stopmachine [machine uuid]StopMachine (POST /:login/machines/:id?action=stop)
● sdc-deletemachine [machine uuid]DeleteMachine (DELETE /:login/machines/:id)
Advance Use of CloudAPI - Create a Machine with User-Script
sdc-createmachine \ --dataset "sdc:sdc:smartosplus64:3.0.7" \ --package "XS 512MB RAM (4CORE)" \ --script ./install.sh \ --tag hadoop-namenode=me
curl -k https://raw.github.com/peihsinsu/installer/master/smartos-standard64/install-joomla.sh | sh
The Script: ./install.sh
Specify a script file to let machine execute after boot
Cloud Analysis - Dtrace
Dtrace -- MiCloud繼承Joyent的雲端平台,提供有一個進階的服務監控方式,這是個非常進階的狀態監控系統,原生於Solaris Unix上,已有Mac與SmartOS的實作套件,亦可於MiCloud環境上直接使用。
Cloud Analysis - Instruments 1/3
$ sdc-describeanalytics
可使用的監控模組:此部份為所有監控項目的大略說明
欄位說明:此部份為每
種欄位的設定說明
Cloud Analysis - Instruments 2/3
型別說明:此部份說明於分析上定義的基本資料型態有哪些 ...
可用監控設定說明: 這個是主要監控要設定的參考值...
Cloud Analysis - Instruments 3/3
轉換說明:此部份可以透過IP轉換地理位置,來進階顯示於世界地圖上…
Cloud Analysis - Create Instrument
● 建立監控點
Cloud Analysis - Get instruments
● 取回監控值
監控的結果值,不過...這邊是整合的數值,尚未能顯示每台主機的個別值...
Cloud Analysis - Use decomposition
● 使用decomposition分類結果值
加入decomposition可以有效分類結果值...
Cloud Analysis - Get decomposition data
● 使用decomposition的取值結果
按照zonename做分類的監控數值...
Cloud Analysis - Use jsontool to format data
● use jsontool
透過jsontool,透過主機的uuid,直接取出某台主機的記憶體使用量...
END - Q&A