GithubHelp home page GithubHelp logo

isabella232 / node-zutil Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tritondatacenter/node-zutil

0.0 0.0 0.0 144 KB

A SunOS-specific wrapper over zone.h and libzonecfg.h APIs

License: MIT License

C 37.42% C++ 28.25% JavaScript 18.67% Python 1.01% Makefile 14.64%

node-zutil's Introduction

node-zutil is a small library specific to SunOS/Solaris/Illumos/SmartOS that provides a wrapper over all three APIs in zone.h and one from libzonecfg.h.

"libzonecfg" is not documented in illumos and hence (IIUC) considered "unstable". That's a significant reason why bindings for more of its API is not provided here.

Version 2 of this lib is a significant departure from earlier versions. See the changelog entry.

Usage

Assuming "5d4f7599-a991-6b35-dd44-d91936957a6b" is your current zone.

> var zutil = require('zutil')

From zone.h:

> id =  zutil.getzoneid()               // get your current zone numeric ID
403

> zonename = zutil.getzonenamebyid(id)  // get the zonename from a zone ID
'5d4f7599-a991-6b35-dd44-d91936957a6b'

> zutil.getzoneidbyname(zonename)
403

As a convenience, because working zone name is more common, this API is added by this module:

> zutil.getzonename()
'5d4f7599-a991-6b35-dd44-d91936957a6b'

From libzonecfg.h:

> zutil.getzonestate('5d4f7599-a991-6b35-dd44-d91936957a6b')
'running'

Install

npm install zutil

Reference

getzoneid()

Gets the integer zone ID for the current process. In the global zone the id is zero (0).

getzonenamebyid(<id>)

Gets the string zonename for the given zone id.

Parameters

  • id - Integer zone id.

Examples

> zutil.getzonenamebyid(403)
'5d4f7599-a991-6b35-dd44-d91936957a6b'

getzoneidbyname(<zonename>)

Gets the integer zone id from the zonename.

Parameters

  • zonename - String zone name. Typically on SmartOS this is 'global' or a UUID.

Examples

> zutil.getzoneidbyname('5d4f7599-a991-6b35-dd44-d91936957a6b')
403

getzonename()

A convenience function that gets the current zonename.

Examples

> zutil.getzonename()
'5d4f7599-a991-6b35-dd44-d91936957a6b'

getzonestate(<zonename>)

Gets the zone state string (e.g. "running", "configured") for the given zonename string. Throws an Error on any failure. If you are in a non-global zone, you may only get a successful result for the current zone. Other zones will appear to not exist.

At the time of writing the possible zone state strings in illumos are the ZONE_STATE_STR_... vars defined here plus "unknown".

As stated above, "libzonecfg" is undocumented. This function name is made up. It combines the C zone_get_state and zone_state_str functions.

Parameters

  • zonename - String zone name. Typically on SmartOS this is 'global' or a UUID.

Examples

> zutil.getzonestate('5d4f7599-a991-6b35-dd44-d91936957a6b')
'running'

> zutil.getzonestate('global')      # errors if no in the global zone
Error: could not get zone "global" state: No such zone configured
    at Error (native)
    ...

> zutil.getzonestate('nosuchzone')
Error: could not get zone "nosuchzone" state: No such zone configured
    at Error (native)
    ...

Development

npm install

Note: If you are running as root you will see this warning (see npm/npm#3497):

npm WARN lifecycle [email protected]~install: cannot run in wd [email protected] node-gyp rebuild (wd=...)

You then need to use:

npm install --unsafe-perm

License

MIT.

node-zutil's People

Contributors

trentm avatar mcavage avatar orlandov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.