CSR1000V와 Postman에서 REST-API

오랜만에 다시 시작하면 CLI가 개량되고 있었던 것과, 설정을 곧 잊기 때문에 자신용의 메모입니다. SSH 접속은 되어 있다고 전제. 매뉴얼이나 포럼 등에서는 cURL의 예가 많기 때문에 여기에서는 Postman의 예로 합니다.

공식은 이 근처.
설정
API 참조

IOS-version
CSR-1#show flash: | i .pkg
 17  289154944 Jan 31 2017 23:05:47 +00:00 /bootflash/csr1000v-mono-universalk9.03.16.05.S.155-3.S5-ext.SPA.pkg
CSR-1#
CSR-1#show version | i 15
Cisco IOS Software, CSR1000V Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.5(3)S5, RELEASE SOFTWARE (fc2)

설정



나온 당초보다 훨씬 깨끗했습니다.

IOS-config
transport-map type persistent webui https-webui
 secure-server
!
username cisco privilege 15 password 0 cisco
!
virtual-service csr_mgmt
 ip shared host-interface GigabitEthernet1
 activate
!
no ip http server
ip http authentication local
ip http secure-server
!         
transport type persistent webui input https-webui

REST-API 서비스 시작 및 옵션 설정.

IOS-rest
CSR-1(config)#remote-management 
CSR-1(cfg-remote-mgmt)#?
  default      Set a command to its defaults
  exit         exit remote management configuration submode
  no           Negate a command or set its defaults
  pnsc         Prime Network Services Controller and Policy Agent configuration
  restful-api  RESTful API

CSR-1(cfg-remote-mgmt)#rest
CSR-1(cfg-remote-mgmt)#restful-api ?
  autosave        Automatic configuration saving interval
  local-port      Local port for secure access to RESTful API
  single-session  Limit RESTful API to one session at a time
  <cr>

확인



IOS-show
CSR-1#show virtual-service detail 
Virtual service csr_mgmt detail
  State                 : Activated
  Package information
    Name                : iosxe-remote-mgmt.03.16.05.S.155-3.S5-ext.ova
    Path                : bootflash:/iosxe-remote-mgmt.03.16.05.S.155-3.S5-ext.ova
    Application
      Name              : csr_mgmt
      Installed version : 03.16.04
      Description       : CSR-MGMT
    Signing
      Key type          : Cisco development key
      Method            : SHA-1
    Licensing
      Name              : Not Available
      Version           : Not Available

  Detailed guest status

----------------------------------------------------------------------
Process               Status            Uptime           # of restarts
----------------------------------------------------------------------
nginx                  UP         0Y 0W 0D  1: 2: 2        0
climgr                 UP         0Y 0W 0D  1: 2: 2        0
restful_api            UP         0Y 0W 0D  1: 2: 2        0
fcgicpa                Down      
pnscag                 Down      
pnscdme                Down      
----------------------------------------------------------------------
Feature         Status                 Configuration
----------------------------------------------------------------------
Restful API   Disabled, UP             
PNSC          Disabled, Down

Network stats:
 eth0: RX  packets:1868, TX  packets:6
 eth1: RX  packets:185, TX  packets:139

Coredump file(s): lost+found

  Activated profile name: None
  Resource reservation
    Disk                : 756 MB
    Memory              : 512 MB
    CPU                 : 5% system CPU

  Attached devices
    Type              Name        Alias            
    ---------------------------------------------
    NIC               ieobc_1     ieobc            
    NIC               dp_1_33     net2             
    Disk              _rootfs                      
    Disk              /opt/var                     
    Disk              /opt/va...                   
    Serial/shell                  serial0          
    Serial/aux                    serial1          
    Serial/Syslog                 serial2          
    Serial/Trace                  serial3          
    Watchdog          watchdo...                   

  Network interfaces
    MAC address             Attached to interface           
    ------------------------------------------------------
    54:0E:00:0B:0C:02       ieobc_1                         
    00:50:56:A2:22:D3       VirtualPortGroup33              

  Guest interface
  ---
  Interface: eth1
  ip address: 10.71.130.57/21

  ---

  Guest routes
  ---
  Address/Mask                         Next Hop                          Intf.
-------------------------------------------------------------------------------

  ---

  Resource admission (without profile) : passed
    Disk space    : 756MB
    Memory        : 512MB 
    CPU           : 5% system CPU 
    VCPUs         : Not specified

POSTMAN에서 토큰 획득


  • 토큰 서비스 API에 POST
  • 기본 인증 (헤더는 자동 완성됩니다)
  • 헤더에 Accept Application/json 추가





  • 이제 실행하면 다음과 같이 token-id가 반환됩니다. 이후에는 이것을 X-Auth-Token으로 헤더에 넣으면 읽기/쓰기에 액세스할 수 있습니다.



    POSTMAN에서 인터페이스 정보를 얻는 예





    이상입니다.

    좋은 웹페이지 즐겨찾기