38
CloudAPI MiCloud Team: 振偉 / Simon Got the PPT - http://goo.gl/DZH2Zp

Cloud api之應用與實例

Embed Size (px)

Citation preview

Page 1: Cloud api之應用與實例

CloudAPIMiCloud Team: 振偉 / Simon

Got the PPT - http://goo.gl/DZH2Zp

Page 2: Cloud api之應用與實例

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

Page 3: Cloud api之應用與實例

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

Page 4: Cloud api之應用與實例

REST

● Representational State Transfer○ Resource○ URL(Uniform Resource Locator)○ method : POST, GET, PUT, DELETE

Page 5: Cloud api之應用與實例

CloudAPI

What is CloudAPI?

Page 6: Cloud api之應用與實例

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

Page 7: Cloud api之應用與實例

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

Page 8: Cloud api之應用與實例

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

Page 9: Cloud api之應用與實例

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());

Page 10: Cloud api之應用與實例

● 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)); });});

Page 11: Cloud api之應用與實例

Management your cloud!

Page 12: Cloud api之應用與實例

Initialize your environment

● Create your MiCloud account● Generate your own ssh key:

$ ssh-keygen -t rsa

Page 13: Cloud api之應用與實例

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.

Page 14: Cloud api之應用與實例

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

Page 15: Cloud api之應用與實例

● 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

Page 16: Cloud api之應用與實例

Check your Key Store - CLI

$ sdc-listkeys

Page 17: Cloud api之應用與實例

We assump user use Java & Node.js SDK already import key...

Page 18: Cloud api之應用與實例

● 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

Page 19: Cloud api之應用與實例

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

Page 20: Cloud api之應用與實例

List Datasets Example

Page 21: Cloud api之應用與實例

List Packages Example

Page 22: Cloud api之應用與實例

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)

Page 23: Cloud api之應用與實例

List Machines under my account

Page 24: Cloud api之應用與實例

Get the detail info of one machine

Page 25: Cloud api之應用與實例

Machine Management API - Create

● CLI:sdc-createmachines \-dataset [dataset] \-package [package] [machine alias]

● REST: CreateMachine (POST /:login/machines)

Page 26: Cloud api之應用與實例

Create a 512M SmartOSPlus64 machine

Page 27: Cloud api之應用與實例

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)

Page 28: Cloud api之應用與實例

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

Page 29: Cloud api之應用與實例

Cloud Analysis - Dtrace

Dtrace -- MiCloud繼承Joyent的雲端平台,提供有一個進階的服務監控方式,這是個非常進階的狀態監控系統,原生於Solaris Unix上,已有Mac與SmartOS的實作套件,亦可於MiCloud環境上直接使用。

Page 30: Cloud api之應用與實例

Cloud Analysis - Instruments 1/3

$ sdc-describeanalytics

可使用的監控模組:此部份為所有監控項目的大略說明

欄位說明:此部份為每

種欄位的設定說明

Page 31: Cloud api之應用與實例

Cloud Analysis - Instruments 2/3

型別說明:此部份說明於分析上定義的基本資料型態有哪些 ...

可用監控設定說明: 這個是主要監控要設定的參考值...

Page 32: Cloud api之應用與實例

Cloud Analysis - Instruments 3/3

轉換說明:此部份可以透過IP轉換地理位置,來進階顯示於世界地圖上…

Page 33: Cloud api之應用與實例

Cloud Analysis - Create Instrument

● 建立監控點

Page 34: Cloud api之應用與實例

Cloud Analysis - Get instruments

● 取回監控值

監控的結果值,不過...這邊是整合的數值,尚未能顯示每台主機的個別值...

Page 35: Cloud api之應用與實例

Cloud Analysis - Use decomposition

● 使用decomposition分類結果值

加入decomposition可以有效分類結果值...

Page 36: Cloud api之應用與實例

Cloud Analysis - Get decomposition data

● 使用decomposition的取值結果

按照zonename做分類的監控數值...

Page 37: Cloud api之應用與實例

Cloud Analysis - Use jsontool to format data

● use jsontool

透過jsontool,透過主機的uuid,直接取出某台主機的記憶體使用量...

Page 38: Cloud api之應用與實例

END - Q&A