The powerof Rest API - vcdx211.files.wordpress.com · Beyond REST API Rest API bestpractices Quiz...

Preview:

Citation preview

12-12-2017

© Atos

The power of Rest API

Olena Zhuk and Konrad Cłapa

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Who are we?▶ How to start your journey?▶ What is REST API?▶ VMware REST API?▶ Beyond REST API▶ Rest API best practices▶ Quiz with gifts▶ QA

Agenda

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Technical Engineer @ Atos IT Services▶ Private Cloud Lead Developer▶ olena.zhuk@atos.net

Who are we – Olena Zhuk

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Global Technical Architect @ Atos IT Services▶ Private Cloud Developer▶ Double VCDX #211▶ vcdx211.wordpress.com▶ @clapa_konrad

Who are we – Konrad Cłapa

How to start the journey?

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Watch this presentation▶ Bookmark code.vmware.com▶ Watch vBrownBags API zero to hero▶ Download Postman and play with your own lab and 3rd party APIs▶ Run Hands on Labs

6

How to start your journey?

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Change mindset▶ The power of REST API▶ When to use REST API

7

Key Takeaways

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Application Programming Interface▶ communication interface between computer programs which is built based on

REST architectural principles▶ HTTP network communication (most often)▶ mapping CRUD operations (most often)▶ stateless▶ pointing to further resources (should be, not always implemented correctly)▶ payload is NOT restricted to specific format

8

What is RESTful API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Used for transmission of data between systems that are platform independent

9

What is RESTful API – make it simple

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ POSTMAN▶ SoapUI▶ vRO▶ CURL▶ Powershell▶ Python▶ any programming language

10

How to use REST API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Endpoint (URI)▶ Resource/Entity▶ Method ▶ Header▶ Body

11

Rest API call

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ GET – retrieve an entity by URI▶ PUT – overwrite an entity▶ POST – append child entity to one identified by URI▶ DELETE – delete resource identified by URI

12

Rest API methods (headlights)

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 13

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 14

Common responses

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 15

REST API vs SOAP

SOAP RESTXML JSON, XML, BinaryAccess to services Access to resourcesStateful StatelessBuilt-in retry logic CachingComplex operations Simple actionsMore complicate to implement Easier in use and implementation

Authentication

16

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Basic – NSX– vRO

▶ Oauth 2.0– vSphere– vRA– vRO– vROPs

17

Authentication

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 18

Basic authentication

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 19

Oauth 2.0

vSphere 6.5 REST API

20

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Brand new!▶ Swagger API Explorer

21

vSphere 6.5 Rest API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

DEMO TIME!

22

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

https://code.vmware.com/apis/176/vro-resthttps://code.vmware.com/apis/39/vrealize-automation

23

vRA/vRO Rest API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 24

vRO REST API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 25

vRO REST API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 26

vRO REST API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 27

vRA REST API

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 28

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ https://docs.vmware.com/en/VMware-NSX-for-vSphere/6.3/nsx_63_api.pdf

29

NSX Rest API

Could that be donesimpler?

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Almost as powerful as Rest API▶ Easier to use▶ Not always up to date▶ Most popular modules:– PowerCLI– PowerVRA– PowerVRO– PowerNSX

Powershell modules

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

VMware PowerCLI is a command-line and scripting tool built on Windows PowerShell, and provides more than 600 cmdlets for managing and automating vSphere, vCloud, vRealize Operations Manager, vSAN, NSX-T, VMware Cloud on AWS, and VMware Horizon environments.

▶ Install▶ Connect-VIServer▶ Rule it all!

32

PowerCLIVMware Supported

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Open projects on Github▶ Mimics the way PowerCLI works

33

PowerXCreated by community

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Invoke-WebRequest and Invoke-RestMethod from Microsoft.PowerShell.Commands.Utility

34

PowerVROCommunity supported

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Powershell wrapperfor vRA REST API

▶ Popular module for vRA automation

35

PowerVRACommunity supported

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ Not only command-letes▶ Contains some analysis

tools▶ Includes operations from

Cross-vCenter NSX

36

PowerNSXComminuty supported+

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering 37

vRO Plugins

Best Practices

38

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

Best practices

▶ Map rest responses to your error handling▶ Use one method to deal with resource▶ Use http encoding for special characters▶ Be careful about case-sensitivity▶ Use one media type▶ Develop one method for response parsing and managing retrieved resources▶ Develop common wrapper for creating REST calls▶ Get resource before modifying it to avoid conflicts

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ https://code.vmware.com/web/dp/tool/vmware-powercli/6.5.4▶ https://vbrownbag.com/vbrownbag-technology-series/api-zero-to-hero/▶ https://github.com/jakkulabs/PowervRA▶ https://github.com/jakkulabs/PowervRO▶ https://powernsx.github.io/▶ https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/products/nsx/vmware-automating-

vsphere-with-powernsx.pdf

40

References

QUIZ

41

QA

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ What are 4 most often used REST API methods?

43

Question 1

| 12-12-2017 | BG, KC | © Atos Cloud Services | Engineering

▶ What are 2 authentication methods used by VMware products?

44

Question 2

Thank You!

Recommended