amazon-web-servicesamazon-ec2cloudlibcloud

Is it possible to start / stop a node via libcloud


I'm trying to find a way to stop or start a node (device, instance) via libcloud and I cannot find a method for this. Could this basic functionality be missing? I'm now looking for working against EC2, but may need to work against other providers as well. Thanks in advance!


Solution

  • To stop a running node given that instance ID is known for a given region.

    cls = get_driver(Provider.EC2_AP_NORTHEAST)
    driver = cls(access_key, secret_key)
    nodes = driver.list_nodes()
    node_id = "i-xyz"        
    inst = [i for i in nodes if i.id == node_id][0]
    driver.ex_stop_node(inst)
    

    To start a stopped node.

    cls = get_driver(Provider.EC2_AP_NORTHEAST)
    driver = cls(access_key, secret_key)
    nodes = driver.list_nodes()
    node_id = "i-xyz"        
    inst = [i for i in nodes if i.id == node_id][0]
    driver.ex_start_node(inst)