Cloud api之應用與實例

796 views

Published on

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

No Downloads
Views
Total views
796
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Cloud api之應用與實例

  1. 1. CloudAPI MiCloud Team: 振偉 / Simon Got the PPT - http://goo.gl/DZH2Zp
  2. 2. 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
  3. 3. 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
  4. 4. REST ● Representational State Transfer ○ Resource ○ URL(Uniform Resource Locator) ○ method : POST, GET, PUT, DELETE
  5. 5. CloudAPI What is CloudAPI?
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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());
  10. 10. ● 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)); }); });
  11. 11. Management your cloud!
  12. 12. Initialize your environment ● Create your MiCloud account ● Generate your own ssh key: $ ssh-keygen -t rsa
  13. 13. 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 path Give 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.
  14. 14. Import Key to Key Store - Use CLI ● smartdc ~6.5 Use CLI command: sdc-setup select “no” to import new key select you key file path do export like this...
  15. 15. ● 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
  16. 16. Check your Key Store - CLI $ sdc-listkeys
  17. 17. We assump user use Java & Node.js SDK already import key...
  18. 18. ● 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
  19. 19. List the public dataset & packages ● $ sdc-listdatasets ListDatasets (GET /:login/datasets) ● $ sdc-listpackages ListPackages (GET /:login/packages) ● Tips: ○ use help to see more parameters ex: sdc-listdatasets --help ○ check the document for more help
  20. 20. List Datasets Example
  21. 21. List Packages Example
  22. 22. 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)
  23. 23. List Machines under my account
  24. 24. Get the detail info of one machine
  25. 25. Machine Management API - Create ● CLI: sdc-createmachines -dataset [dataset] -package [package] [machine alias] ● REST: CreateMachine (POST /:login/machines)
  26. 26. Create a 512M SmartOSPlus64 machine
  27. 27. 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)
  28. 28. 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
  29. 29. Cloud Analysis - Dtrace Dtrace -- MiCloud繼承 Joyent的雲端平台,提供 有一個進階的服務監控 方式,這是個非常進階 的狀態監控系統,原生 於Solaris Unix上,已有 Mac與SmartOS的實作 套件,亦可於MiCloud環 境上直接使用。
  30. 30. Cloud Analysis - Instruments 1/3 $ sdc-describeanalytics 可使用的監控模組:此 部份為所有監控項目的 大略說明 欄位說明:此部份為每 種欄位的設定說明
  31. 31. Cloud Analysis - Instruments 2/3 型別說明:此部份說明 於分析上定義的基本資 料型態有哪些... 可用監控設定說明: 這 個是主要監控要設定的 參考值...
  32. 32. Cloud Analysis - Instruments 3/3 轉換說明:此部份可以 透過IP轉換地理位置, 來進階顯示於世界地圖 上…
  33. 33. Cloud Analysis - Create Instrument ● 建立監控點
  34. 34. Cloud Analysis - Get instruments ● 取回監控值 監控的結果值,不過...這邊是整 合的數值,尚未能顯示每台主機 的個別值...
  35. 35. Cloud Analysis - Use decomposition ● 使用decomposition分類結果值 加入decomposition可以有 效分類結果值...
  36. 36. Cloud Analysis - Get decomposition data ● 使用decomposition的取值結果 按照zonename做分類的監控數 值...
  37. 37. Cloud Analysis - Use jsontool to format data ● use jsontool 透過jsontool,透過主機的uuid, 直接取出某台主機的記憶體使 用量...
  38. 38. END - Q&A

×