l.c.b.Node(object) : class documentation

Part of libcloud.compute.base View Source View In Hierarchy

Known subclasses: libcloud.compute.drivers.gogrid.GoGridNode

Provide a common interface for handling nodes of all types.

The Node object provides the interface in libcloud through which we can manipulate nodes in different cloud providers in the same way. Node objects don't actually do much directly themselves, instead the node driver handles the connection to the node.

You don't normally create a node object yourself; instead you use a driver and then have that create the node for you.

>>> from libcloud.compute.drivers.dummy import DummyNodeDriver
>>> driver = DummyNodeDriver(0)
>>> node = driver.create_node()
>>> node.public_ip[0]
'127.0.0.3'
>>> node.name
'dummy-3'

You can also get nodes from the driver's list_node function.

>>> node = driver.list_nodes()[0]
>>> node.name
'dummy-1'

the node keeps a reference to its own driver which means that we can work on nodes from different providers without having to know which is which.

>>> driver = DummyNodeDriver(72)
>>> node2 = driver.create_node()
>>> node.driver.creds
0
>>> node2.driver.creds
72

Althrough Node objects can be subclassed, this isn't normally done. Instead, any driver specific information is stored in the "extra" proproperty of the node.

>>> node.extra
{'foo': 'bar'}
Method __init__ Undocumented
Method get_uuid Unique hash for this node
Method reboot Reboot this node
Method destroy Destroy this node
Method __repr__ Undocumented
def __init__(self, id, name, state, public_ip, private_ip, driver, extra=None): (source)
Undocumented
def get_uuid(self): (source)
Unique hash for this node
Returnsstring

The hash is a function of an SHA1 hash of the node's ID and its driver which means that it should be unique between all nodes. In some subclasses (e.g. GoGrid) there is no ID available so the public IP address is used. This means that, unlike a properly done system UUID, the same UUID may mean a different system install at a different time

>>> from libcloud.compute.drivers.dummy import DummyNodeDriver
>>> driver = DummyNodeDriver(0)
>>> node = driver.create_node()
>>> node.get_uuid()
'd3748461511d8b9b0e0bfa0d4d3383a619a2bb9f'

Note, for example, that this example will always produce the same UUID!

def reboot(self): (source)
Reboot this node
Returnsbool

This calls the node's driver and reboots the node

>>> from libcloud.compute.drivers.dummy import DummyNodeDriver
>>> driver = DummyNodeDriver(0)
>>> node = driver.create_node()
>>> from libcloud.compute.types import NodeState
>>> node.state == NodeState.RUNNING
True
>>> node.state == NodeState.REBOOTING
False
>>> node.reboot()
True
>>> node.state == NodeState.REBOOTING
True
def destroy(self): (source)
Destroy this node
Returnsbool

This calls the node's driver and destroys the node

>>> from libcloud.compute.drivers.dummy import DummyNodeDriver
>>> driver = DummyNodeDriver(0)
>>> from libcloud.compute.types import NodeState
>>> node = driver.create_node()
>>> node.state == NodeState.RUNNING
True
>>> node.destroy()
True
>>> node.state == NodeState.RUNNING
False
def __repr__(self): (source)
Undocumented
API Documentation for libcloud, generated by pydoctor at 2012-07-15 18:45:14.