Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Latest commit

 

History

History
202 lines (139 loc) · 4.43 KB

examples.rest

File metadata and controls

202 lines (139 loc) · 4.43 KB

studio_napi Examples

SUSE Studio API client library for Node.js

Author: Roman Neuhauser
Contact: [email protected]
Copyright: This document is in the public domain.

All examples assume the following code:

assert = require 'assert'
expect = (require 'chai').expect
napilo = require 'studio_napi/lib/lo'

anapi = napilo.session admin:
  url: 'http://susestudio.com/api/v2/admin'
  user: 'rneuhauser'
  key: '69sNafUbAR'

unapi = napilo.session user:
  url: 'http://susestudio.com/api/v2/user'
  user: 'rneuhauser'
  key: '69sNafUbAR'
# GET /api/v2/admin/about

anapi GET '/about', (e, r) ->

  assert.ifError e, "/about failed: #{e}"

  for p in 'server_name environment git_revision'.split ' '
    (expect r).to.have.property p
# GET /api/v2/user/appliances/42

unapi GET '/appliances/:app', app: 42, (e, r) ->

  assert.ifError e, "/appliances/:app failed: #{e}"

  (expect r).to.have.property 'appliance'
# GET /api/v2/admin/health_check?runner_threshold=75

anapi GET '/health_check', runner_threshold: 75, (e, r) ->

  assert.ifError e, "/health_check failed: #{e}"

  for p in 'state kiwi_runners testdrive_runners disks'.split ' '
    (expect r).to.have.property p

All examples assume the following code:

assert = require 'assert'
expect = (require 'chai').expect
napihi = require 'studio_napi/lib/hi'

admin = napihi.session admin:
  url: 'http://susestudio.com/api/v2/admin'
  user: 'rneuhauser'
  key: '69sNafUbAR'

user = napihi.session user:
  url: 'http://susestudio.com/api/v2/user'
  user: 'rneuhauser'
  key: '69sNafUbAR'
admin.about (e, r) ->

  assert.ifError e, "/about failed: #{e}"

  for p in 'server_name environment git_revision'.split ' '
    (expect r).to.have.property p
admin.health_check, runner_threshold: 75, (e, r) ->

  assert.ifError e, "/health_check failed: #{e}"

  for p in 'state kiwi_runners testdrive_runners disks'.split ' '
    (expect r).to.have.property p
app = user.create appliance:
  named: 'my system'
  based_on: 'SLES11 SP2'

app.configure LVM:
  enabled: yes
  group: 'mighty-lvm'
  comprising:
    "/var": "800G"
    "/fuvar": "12T"

app.configure PostgreSQL: [
  { user: 'db_user', password: 'secret', databases: 'foo bar' }
  { user: 'db_admin', password: 'top-secret' }
]

app.toggle PostgreSQL: on
app.toggle MySQL: off

app.select runlevel: 3

app.add package:
  named: 'djbdns'
  from: 'My Repository'
  version: '1.2.3'

app.add pattern:
  named: 'development'
  from: 'His Repository'

app.add user:
  named: 'toor'
  id: 1000
  member_of: 'wheel'
  identified_by:
    password: 'secret'

app.select locale:
  language: 'POSIX'
  keyboard: 'English (US)'

app.configure network:
  hostname: 'thisbox'
  address: '1.2.3.4'
  netmask: '255.255.0.0'
  gateway: '1.2.1.1'
  resolvers: '1.3.1.53 1.3.2.53'

app.configure RAM: '1G'
app.configure disk: '3T'
app.configure swap: '8G'

app.toggle PAE: on
app.toggle Xen_DOM0: off

app.commit (e) ->
  assert.ifError e, "app.commit failed: #{e}"