Ridgeline 4.0 REST API Quick Start

Ridgeline 4.0 REST API Quick
Start
Copyright ©
Legal Notice
Extreme Networks, Inc., on behalf of or through its wholly-owned subsidiary, Enterasys Networks,
Inc., reserves the right to make changes in specifications and other information contained in this
document and its website without prior notice. The reader should in all cases consult
representatives of Extreme Networks to determine whether any such changes have been made.
The hardware, firmware, software or any specifications described or referred to in this document
are subject to change without notice.
Trademarks
Extreme Networks and the Extreme Networks logo are trademarks or registered trademarks of
Extreme Networks, Inc. in the United States and/or other countries.
All other names (including any product names) mentioned in this document are the property of
their respective owners and may be trademarks or registered trademarks of their respective
companies/owners.
For additional information on Extreme Networks trademarks, please see:
www.extremenetworks.com/company/legal/trademarks/
Support
For product support, including documentation, visit: www.extremenetworks.com/
documentation/
Table of Contents
Chapter 1: Introduction............................................................................................................. 4
Overview................................................................................................................................................................................... 4
Audience................................................................................................................................................................................... 4
What Is REST?........................................................................................................................................................................4
Advantages of REST over SOAP.................................................................................................................................. 4
Limitations................................................................................................................................................................................ 5
Chapter 2: What is Supported in REST?.................................................................................6
REST Support for Ridgeline 4.0 Devices.................................................................................................................. 6
REST Support for Ridgeline 4.0 Slots.........................................................................................................................7
REST Support for Ridgeline 4.0 Ports........................................................................................................................8
REST Support for Ridgeline 4.0 Topology...............................................................................................................8
REST Support for Ridgeline 4.0 ExtremeXOS Network Virtualization.................................................... 10
REST Support for Ridgeline 4.0 Identity Management..................................................................................... 11
Pagination Support.............................................................................................................................................................14
Filtering Support..................................................................................................................................................................14
Chapter 3: Authentication and Exceptions...........................................................................15
Authentication.......................................................................................................................................................................15
Exceptions...............................................................................................................................................................................15
Exception Information...................................................................................................................................................... 16
Chapter 4: Using the REST API...............................................................................................18
Using the REST API through a Browser...................................................................................................................18
Using REST API through a Simple Java Program............................................................................................... 19
Java Program........................................................................................................................................................................ 19
Code Example....................................................................................................................................................................... 21
Ridgeline 4.0 REST API Quick Start
3
1 Introduction
Overview
Audience
What Is REST?
Advantages of REST over SOAP
Limitations
Overview
This quick start is intended as a reference for the REST API, which allows a client application to query a
network management server running Ridgeline 4.0 or later. Extreme Networks REST XML API enables
reliable external device-to-device management communication. The API interface provides a
mechanism to communicate with Extreme Networks network management servers using XML
messages. Its standards-based REST/XML architecture makes it easy to integrate the network
infrastructure with higher-level application and business software. In this release, the interface may be
used to retrieve the network inventory (devices, slots, ports, and links).
Audience
This guide is intended for software developers using a programming interface to write applications for
Extreme Networks devices. It assumes a basic working knowledge of the following:
• Concepts and operation of XML API interfaces and web services
• Writing web services client code in Java
What Is REST?
REST (Representational State Transfer) is a set of constraints that when applied to the design of a
system creates a software architectural style that exploits the existing technology and protocols of the
web, including HTTP (Hypertext Transfer Protocol) and XML (Extensible Markup Language).
Advantages of REST over SOAP
Ridgeline 4.0 uses a new API REST instead of SOAP (Simple Object Access Protocol), which was the
API of previous releases. REST has the following advantages over SOAP:
•
•
REST facilitates the transaction between web servers by allowing loose coupling between different
services.
REST is less strongly typed than SOAP.
Ridgeline 4.0 REST API Quick Start
4
Introduction
•
Unlike SOAP, REST does not require XML parsing and does not require a message header to and
from a service provider, thus using less bandwidth.
Limitations
The following limitations apply to REST support in Ridgeline 4.0:
• Only HTTP GET operations are supported.
• HTTPS is not supported by the Ridgeline 4.0 web server.
• Field selection of entities is not supported.
• Embedded Boolean statements within query strings are not supported.
• Caching is not supported.
Ridgeline 4.0 REST API Quick Start
5
2 What is Supported in REST?
REST Support for Ridgeline 4.0 Devices
REST Support for Ridgeline 4.0 Slots
REST Support for Ridgeline 4.0 Ports
REST Support for Ridgeline 4.0 Topology
REST Support for Ridgeline 4.0 ExtremeXOS Network Virtualization
REST Support for Ridgeline 4.0 Identity Management
Pagination Support
Filtering Support
REST Support for Ridgeline 4.0 Devices
The following table shows the URIs to fetch (GET) specific device attributes and device collection
information. The next table lists the supported device attributes along with any supported filters
(usable as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 1: REST Support for Ridgeline 4.0 Devices
Resource
URI
Device
http://<IP address>:<port>/v1.0/ dataservice/inventory/device[.xml/.json]
Example: http://localhost:8080/v1.0/ dataservice/inventory/device.xml
Device collection
http:///<IP address>:<port>/v1.0/ dataservice/inventory/device/<id> [.xml/.json]
Example: http://10.120.90.12:8080/v1.0/ dataservice/inventory/device/1.json
Table 2: REST Supported Attributes for Devices
Attribute
Meaning
Name
User-assigned device name
IP
IPv4 address
IPv6
IPv6 address
MAC
System MAC address
Software
Software version
NetworkStatus
Reachable/not reachable
AlarmState
Critical, major, minor, none
Ridgeline 4.0 REST API Quick Start
Usable as Query String
Yes
Yes
6
What is Supported in REST?
Table 2: REST Supported Attributes for Devices (continued)
Attribute
Meaning
Usable as Query String
HWModel
Hardware model
ID
Internal ID of the device
Note
When you perform a GET on a device collection, the IDs retrieved can then be
used to retrieve individual devices using a specific device GET operation.
SerialNumber
Serial number of device
REST Support for Ridgeline 4.0 Slots
The following table shows the URIs to fetch (GET) specific slot attributes and slot collection
information. The next table lists the supported slot attributes along with any supported filters (usable
as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 3: REST Support for Ridgeline 4.0 Slots
Resource
URI
Slot
http:///<IP address>:<port>/v1.0/dataservice/ inventory/slot[.xml/.json]
Example: http://10.120.90.12:8080/v1.0/ dataservice/inventory/slot
Slot collection
http:///<IP address>:<port>/v1.0/dataservice/ inventory/slot/{id}[.xml/.json]
Example: http://10.120.90.12:8080/v1.0/ dataservice/inventory/slot/1
Table 4: REST Supported Attributes for Slots
Attribute
Meaning
Usable as Query String
ID
System-assigned ID
Note
When you perform a GET on a slot collection, the IDs retrieved can then
be used to retrieve individual slots using a specific slot GET operation.
SerialNumber
MAC
MAC address
HWModel
Hardware model present
HWModelConfigured
Configured hardware model
Position
Slot number or stack position
ParentID
ID of containing system
Ridgeline 4.0 REST API Quick Start
Yes
7
What is Supported in REST?
REST Support for Ridgeline 4.0 Ports
The following table shows the URIs to fetch (GET) specific port attributes and port collection
information. The next table lists the supported port attributes along with any supported filters (usable
as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 5: REST Support for Ridgeline 4.0 Ports
Resource
URI
Port
http:///<IP address>:<port>/v1.0/dataservice/ inventory/port[.xml/.json]
Example: http://10.120.90.12:8080/v1.0/ dataservice/inventory/port
Port collection
http:///<IP address>:<port>/v1.0/dataservice/ inventory/port/{id}[.xml/.json]
Example: http://10.120.90.12:8080/v1.0/ dataservice/inventory/port/1
Table 6: REST Supported Attributes for Ports
Attribute
Meaning
Usable as Query String
ID
System-assigned identifier
Note
When you perform a GET on a port collection, the IDs retrieved can then be used
to retrieve individual ports using a specific port GET operation.
DeviceIP
IP address of containing switch
Yes
ParentID
ID of the containing system
Yes
Name
Administratively assigned name of port
Number
Port number
Speed
Current operating speed
Duplex
Half, full
LinkState
Active, ready, not present
Type
Gigabit, GBIC
REST Support for Ridgeline 4.0 Topology
Short reference description.
Ridgeline 4.0 REST API Quick Start
8
What is Supported in REST?
The following table shows the URIs to fetch (GET) specific topology attributes and topology collection
information. The next table lists the supported topology attributes along with any supported filters
(usable as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 7: REST Support for Ridgeline 4.0 Topology
Resource
URI
Filters
Map link
http:///<IP address>:<port>/v1.0/dataservice/topology/link/
<linkId>
Map link collection
http:///<IP address>:<port>/v1.0/dataservice/topology/link/
MAC
IP
LinkSate
LinkType
DiscoveryProtocol
Device links with MAC http:///<IP address>:<port>/v1.0/dataservice/dataservice/
toplology/link?MAC=00:04:96:27:81:ae
Device links with IP
http:///<IP address>:<port>/v1.0/dataservice/dataservice/
toplology/link?IP=10.127.3.63
Table 8: REST Supported Attributes for Topology
Attribute
Meaning
ID
Unique ID
Usable as Query String
Note
When you perform a GET on a topology collection, the IDs retrieved can
then be used to retrieve individual topology entities using a specific
topology GET operation.
Discoverprotocol
Discovery protocol of the link
EndPointAId
ID of A end of link
EndPointBId
ID of B end of link
EndPointAPort
Port of A end of link
EndPointBPort
Port of B end of link
EndPointAMac
MAC address of A end of link
EndPointBMac
MAC address of B end of link
EndPointAAnnotation
Annotation of A end of link
EndPointBAnnotation
Annotation of B end of link
LinkState
State of the link
Yes
LinkType
Type of the link
Yes
Ridgeline 4.0 REST API Quick Start
Yes
9
What is Supported in REST?
REST Support for Ridgeline 4.0 ExtremeXOS Network
Virtualization
The following table shows the URIs to fetch (GET) specific XNV attributes and XNV collection
information. The subsequent tables list the supported XNV attributes along with any supported filters
(usable as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 9: REST Support for Ridgeline 4.0 XNV
Resource
URI
VPP
http:///<IP address>:<port>/v1.0/dataservice/xnv/vpp/<vppid>
VPP collection
http:///<IP address>:<port>/v1.0/dataservice/xnv/vpp
Policy
http:///<IP address>:<port>/v1.0/dataservice/xnv/policy/<policyid>
Policy collection
http:///<IP address>:<port>/v1.0/dataservice/xnv/policy
VM
http:///<IP address>:<port>/v1.0/dataservice/xnv/vm/<vmid>
VM collection
http:///<IP address>:<port>/v1.0/dataservice/xnv/vm
Table 10: REST Supported Attributes for VPPs
Attribute
Meaning
Usable as Query String
Name
Administratively assigned name
ID
Unique identifier of VPP
Note
When you perform a GET on a XNV collection, the IDs retrieved can then be
used to retrieve individual XNV entities using a specific XNV GET operation.
Description
Administratively assigned description
IngressPolicy
Ingress policy and priority
EgressPolicy
Egress policy and priority
Table 11: REST Supported Attributes for Policies
Attribute
Meaning
Name
Administratively assigned name
ID
Unique identifier of policy
Description
Administratively assigned
description
Rule (see the following table)
Name of ACL rule n (1 of more)
Ridgeline 4.0 REST API Quick Start
Usable as Query String
10
What is Supported in REST?
Table 12: REST Supported Attributes for Rules
Attribute
Meaning
Name
Administratively assigned rule
Match
Match condition
Action
Drop or forward
Modifier
Modifiers (byte-count<countername>, meter<meter-name>, etc.)
Usable as Query String
Table 13: REST Supported Attributes for VMs
Attribute
Meaning
Usable as Query String
Name
Name of the VM obtained from VMM
ID
System-assigned identifier
MAC
MAC address of the VNIC
Yes
IP Address
IPv4 address of the VNIC
Yes
VPP
VPP-assigned to this VM
PowerStatus
On, off, or suspended
Yes
DeviceIP
IP address of detecting device
Yes
DevicePort
Port number of detecting device
HostIP
Address of host
HostName
Name of host
DataCenter
Name of data center
REST Support for Ridgeline 4.0 Identity Management
The following table shows the URIs to fetch (GET) specific IDM attributes and IDM collection
information. The subsequent tables list the supported IDM attributes along with any supported filters
(usable as query string).
Note
If desired, you can filter a GET operation to return data that matches your designated criteria
using a query string (also referred as a filter). For more information about using query strings,
see Filtering Support on page 14.
Table 14: REST Support for Ridgeline 4.0 IDM
Resource
URI
Policy
http:///<IP address>:<port>/v1.0/dataservice/idm/policy/<policyid>
Policy collection
http:///<IP address>:<port>/v1.0/dataservice/idm/policy
IDM-enabled device
http:///<IP address>:<port>/v1.0/dataservice/idm/device/<deviceid>
Ridgeline 4.0 REST API Quick Start
11
What is Supported in REST?
Table 14: REST Support for Ridgeline 4.0 IDM (continued)
Resource
URI
IDM-enabled device collection
http:///<IP address>:<port>/v1.0/dataservice/idm/device
IDM port
http:///<IP address>:<port>/v1.0/dataservice/idm/port/<portid>
IDM port collection
http:///<IP address>:<port>/v1.0/dataservice/idm/port
Identity
http:///<IP address>:<port>/v1.0/dataservice/idm/identity/<iid>
Identities collection
http:///<IP address>:<port>/v1.0/dataservice/idm/identity
Role
http:///<IP address>:<port>/v1.0/dataservice/idm/roles/<roleid>
Role collection
http:///<IP address>:<port>/v1.0/dataservice/idm/roles
Table 15: REST Supported Attributes for Roles
Attribute
Meaning
Usable as Query String
Name
Administratively assigned name
ID
System-assigned identifier
Note
When you perform a GET on a IDM collection, the IDs retrieved can then be
used to retrieve individual IDM entities using a specific IDM GET operation.
Priority
Numeric priority (0–255) low to high
Status
Attached or not attached
Description
Human-readable description
Parent
Parent role name or none
Child-role
Name of child role
Match criteria
Match criteria
Table 16: REST Supported Attributes for Policies
Attribute
Meaning
Name
Administratively assigned name
ID
Unique identifier of policy
Description
Administratively assigned
description
Rule (see the following table)
Name of ACL rule n (1 or more)
Usable as Query String
Table 17: REST Supported Attributes for Rules
Attribute
Meaning
Name
Administratively assigned rule
Match
Match condition
Ridgeline 4.0 REST API Quick Start
Usable as Query String
12
What is Supported in REST?
Table 17: REST Supported Attributes for Rules (continued)
Attribute
Meaning
Action
Drop or forward
Modifier
Modifiers (byte-count<countername>, meter<meter-name>, etc.)
Usable as Query String
Table 18: REST Supported Attributes for Identities
Attribute
Meaning
Name
User ID, system-assigned name, or
MAC address
ID
System-assigned identifier
Role
Role assigned by IDM subsystem of
edge device
Logon
Date/time user was identified
MAC
MAC address
DeviceIP
Edge device IP address
IdentityIP
IP address of detected entity
AuthMethod
Method of authentication:
Kerboeros, RADIUS, etc.
IdentityType
Machine, human
Port
Port identifier on edge device
Usable as Query String
Table 19: REST Supported Attributes for Devices
Attribute
Meaning
DeviceIP
IP address of device with IDM
enabled
ID
System-assigned identifier
IDM-Enabled
True or false
RBM-Enabled
True or false
Port
Port configuration
Usable as Query String
DirectoryServer
BaseDN
UserName
Password
ACL-SourceType
MAC or IP
KerberosAgingTime
10..1024 (minutes)
KerberosForceAging
0..180 (minutes)
Ridgeline 4.0 REST API Quick Start
13
What is Supported in REST?
Table 20: REST Supported Attributes for Ports
Attribute
Meaning
DeviceIP
IP address of device containing port
ID
System-assigned identifier
PortRange
Port range specifications (1–32)
IDM-Enabled
True or false
RBM-Enabled
True or false
Usable as Query String
Pagination Support
Clients can request the numbers and starting point of the entities to a GET response using these two
parameters:
• Offset—indicates the beginning index
• Limit—indicates the total number of entities that the client can accept
Examples:
HTTP GET ridgeline.co.com:8081/v1.0/dataservice/inventory/devices?limit=50
(Retrieves the first 50 entries. Note that offset=1 is implied.)
HTTP GET ridgeline.co.com:8081/v1.0/dataservice/inventory/devices?
offset=50&limit=50
(Retrieves the next 50 entries.)
Filtering Support
Filtering allows you to separate desired data that matches your designated criteria from a larger data
set. URL GET retrievals can be filtered using query-string style filters that meet these conditions:
• Query strings can be combined together with an implied “AND”.
• A specific query string can appear only once in the URL.
The query string filtering format is: ?filter=value
Example:
A client can retrieve a list of devices that are down (or unreachable) using this URL:
HTTP GET ridgeline.co.com:8081/v1.0/dataservice/inventory/devices?status=down
Ridgeline 4.0 REST API Quick Start
14
3 Authentication and Exceptions
Authentication
Exceptions
Exception Information
Authentication
Clients must provide credentials to access the API; no anonymous access is allowed. The REST API uses
the authentication methods built-in to HTTP. Security credentials are validated by the existing
mechanism for Ridgeline users, permitting access for both locally defined users as well as those
authenticated via RADIUS authorization. There is no dedicated REST request to deliver the user’s
credentials to the server; the credentials are provided using basic auth-method.
Exceptions
The API service supports the following HTTP status codes.
Table 21: Supported HTTP Status Codes
HTTP Status Codes
Description
200 OK
The request was executed successfully (or suppress_errors=true).
400 Bad Request
The request is invalid.
This error code appears for a variety of reasons:
• The request format is invalid, specifying unsupported query
strings or invalid entity fields.
• The request is incomplete—missing required fields for an entity
creation.
• The request cannot be completed due to the exhaustion of an
internal resource.
• The request violates an internal limit (the maximum number of
entities that can be returned in a retrieval request or the
maximum number of entities that can be updated in a single
operation).
401 Unauthorized
The supplied authentication credentials are invalid for the request.
This error code appears for two reasons:
• The credentials are not present within the request.
• The credentials are invalid.
Ridgeline 4.0 REST API Quick Start
15
Authentication and Exceptions
Table 21: Supported HTTP Status Codes (continued)
HTTP Status Codes
Description
403 Forbidden
The request is valid, but cannot be executed at this time.
The server understands the request, and the request is valid, but the
server refuses to process it for one of the following reasons:
• The credentials represent a user who is not allowed to perform
the requested operation (a read-only user, for example, may not
have permission to create a new entity).
• A modification, creation, or deletion operation was attempted
against a read-only entity.
404 Not Found
The request references an unknown URL.
406 Not Acceptable Exception
When a client makes a request of a server, it indicates the type of
data it can accept. If a server is capable only of producing data that
the client will find unacceptable, it instead returns this exception.
408 Request Timeout
An internal service did not respond in a timely manner.
500 Internal Error
The API encountered an unexpected error (a database connection
failed, a service timed out, etc.).
503 Service Unavailable
The API service cannot process the request at this time (the service is
unavailable—it is initializing, for example).
Exception Information
Each errored response is accompanied by an exception message in the format requested by the client:
XML
<?xml version=”1.0” encoding=”UTF-8”?>
<rest-error>
<response-code>http response code number</response>
<specific-error>errcode</specific-error>
<specific-msg>human readable message</specific message>
</rest-error>
JSON
{
“response-code : “http response code number”
“specific-error”: “errcode”
“specific-msg” : “human readable message”
}
Note that this exception format contains redundant information (the HTTP response code). This can be
safely ignored by most clients. Adobe Flash, however, does not pass responses for anything other than
HTTP 200 OK. To support these clients, the API supports the error code suppression as a query string:
HTTP GET /v1.0/dataservice/inventory/devices?status=down&suppress_errors=true
Ridgeline 4.0 REST API Quick Start
16
Authentication and Exceptions
If this query string is supplied with a request, all responses report the HTTP status, 200 OK, allowing
clients to access the actual HTTP error code within the response object. The suppression of errors is not
enabled by default.
Ridgeline 4.0 REST API Quick Start
17
4 Using the REST API
Using the REST API through a Browser
Using REST API through a Simple Java Program
Java Program
Code Example
Using the REST API through a Browser
To use the REST API through a web browser:
1 Ensure that Ridgeline 4.0 is running.
2 Start a web browser, type the appropriate URL in the address bar, and then press ENTER.
3 If you are prompted for logon credentials, type the user name and password that you use to log on
to the Ridgeline client.
Note
The default user name and password is admin.
Figure 1: Sample Browser Output
Ridgeline 4.0 REST API Quick Start
18
Using the REST API
Using REST API through a Simple Java Program
To use the REST API through a simple Java program:
1
Ensure that Ridgeline 4.0 is running.
2 Compile the Java program (see Java Program on page 19).
3 Run the Java program.
The associated HTTP responses from running the Java program are stored in a file with the following
name format: DD_MM_YYYY_hh_mm_ss_Rest_Get.[xml/json]
Java Program
The following code is for a simple Java program that you can use to access the REST API.
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
java.io.BufferedWriter;
java.io.FileWriter;
java.io.IOException;
java.text.SimpleDateFormat;
java.util.Date;
org.apache.http.HttpEntity;
org.apache.http.HttpResponse;
org.apache.http.HttpStatus;
org.apache.http.StatusLine;
org.apache.http.auth.AuthScope;
org.apache.http.auth.UsernamePasswordCredentials;
org.apache.http.client.ClientProtocolException;
org.apache.http.client.methods.HttpGet;
org.apache.http.impl.client.DefaultHttpClient;
org.apache.http.util.EntityUtils;
public class RestHttpClient {
private static final String xmlExtension = ".xml";
private static final String jsonExtension = ".json";
private DefaultHttpClient client = new DefaultHttpClient();
private String Url = null;
private String hostName;
private int portNumber;
private String userName;
private String password;
public RestHttpClient(String Url, String hostName, int portNumber,
String userName, String password) {
if (Url == null || Url.equals(""))
throw new NullPointerException("Null URL");
this.Url = Url;
this.hostName = hostName;
this.portNumber = portNumber;
this.userName = userName;
this.password = password;
}
private String httpGet() {
HttpGet httpget = new HttpGet(this.Url);
String response = null;
client.getCredentialsProvider().setCredentials(
Ridgeline 4.0 REST API Quick Start
19
Using the REST API
new AuthScope(this.hostName, this.portNumber),
new UsernamePasswordCredentials(this.userName,
this.password));
try {
HttpResponse httpResponse = client.execute(httpget);
StatusLine status = httpResponse.getStatusLine();
if (status.getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
response = EntityUtils.toString(entity);
}
} else {
response = httpResponse.toString();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
httpget.releaseConnection();
}
return response;
}
private boolean isXML() {
boolean isXML = false;
if (this.Url.trim().endsWith(RestHttpClient.xmlExtension)) {
isXML = true;
}
return isXML;
}
private String getFileName() {
SimpleDateFormat formatter = new
SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");
StringBuilder fileName = new StringBuilder(formatter.format(new
Date()));
fileName.append("_Rest_Get");
fileName.append(isXML() ? RestHttpClient.xmlExtension
: RestHttpClient.jsonExtension);
return fileName.toString();
}
private void writeToFile() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(getFileName()));
String response = httpGet();
writer.write(response);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null)
writer.flush();
Ridgeline 4.0 REST API Quick Start
20
Using the REST API
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
RestHttpClient httpClient = new RestHttpClient(
"http://10.120.91.105:8080/v1.0/dataservice/inventory/
device.json",
"10.120.91.105", 8080, "admin", "admin");
httpClient.writeToFile();
}
}
Code Example
Application definition
package com.extremenetworks.library;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/dataservice")
public class RestfulServiceApplications extends Application
{
}
package com.extremenetwokrs.library;
import javax.xm.bind.annotation.XmlRootElement;
@XmlRootElement
pbulic class Device {
private String ip;
private String name;
public Device() {
}
public Device(String ipaddress, String name)
{
this.ip = ipaddress;
this.name = name;
}
public String getIp() {
return ip;
}
public void setIp(String ip){
this.ip = ip;
}
public String qetName() {
return name;
public void setName(String name) {
}
Ridgeline 4.0 REST API Quick Start
21
Using the REST API
}
package com.extremenetworks.library;
import java.util.List;
import
import
import
import
javax.we.rs.GET;
javax.we.rs.Path;
javax.we.rs.Produces;
javax.we.rs.QueryParam;
@Path("/devices")
@Produces("text/xml")
public interface DeviceManager{
@GET
@Path("/")
public List<Device> all();
//URL http://HOST:PORT/WEBCONTEXT/dataservice/device?ip=1.1.1.1
@GET
@Path("/device/{ip}")
public Device getDevice(@QueryParam("ip") int deviceId);
}
package com.extremenetworks.library;
import java.util.Arrays;
import java.util.List;
public class DeviceManagerBean implements DeviceManager
{
@Override
public List<Device> all() {
return Arrays.asList(new Device("l.1.1.1", "Device 1"),
new Device("2.2.2.2", "Device 2"));
}
@Override
public Device getDevice(int deviceId) {
return new Device("1.1.1.1", "Device 1");
}
}
Data URL : http://localhost:8080/extreme/dataservice/devices
Output in XML
-<collection>
-<device>
-<ip>1.1.1.1</ip>
<name>Device 1</name>
</device>
-<device>
<ip>2.2.2.2</ip>
<name>Device 2</name>
Ridgeline 4.0 REST API Quick Start
22
Using the REST API
</device>
</collection>
Output in JSON
[{"name":"Device 1", "ip":"1.1.1.1"},{"name":"Device 2","ip":"2.2.2.2"}]
Ridgeline 4.0 REST API Quick Start
23