예제 #1
0
def destroy(key, secret, service, node_uuid):
  driver = getDriverInstance(service, key, secret)
  node = getNode(driver, node_uuid)
  if node is None:
    return False
  if node.state in [NodeState.RUNNING, NodeState.REBOOTING, NodeState.PENDING]:
    return node.destroy()
  else:
    return False
예제 #2
0
def start(key, secret, service, node_uuid):
  """Starts node"""
  driver = getDriverInstance(service, key, secret)
  node = getNode(driver, node_uuid)
  if node is None:
    return False
  if node.state in [0, 1]:
    return True
  elif node.state == 3:
    return node.reboot()
  else:
    return False
  return True
예제 #3
0
def getpubliciplist(key, secret, service, node_uuid):
  """Gets public ip(s), can wait for the first IP to appear"""
  public_ip_list = []
  for i in range(100):
    driver = getDriverInstance(service, key, secret)
    node = getNode(driver, node_uuid)
    if node.state not in [NodeState.RUNNING, NodeState.REBOOTING,
        NodeState.PENDING]:
      break
    if node.public_ip[0]:
      public_ip_list = node.public_ip
      break
    else:
      time.sleep(5)

  return dict(
    public_ip_list = public_ip_list
  )
예제 #4
0
def stop(key, secret, service, node_uuid, ssh_key=None):
  """Stops node"""
  driver = getDriverInstance(service, key, secret)
  node = getNode(driver, node_uuid)
  # Checks state
  if node.state not in [NodeState.RUNNING, NodeState.REBOOTING,
      NodeState.PENDING]:
    return False
  # Good state : connects
  if ssh_key is None:
    ssh_key = getprivatekey(key, secret, service, node_uuid)
  public_ip = node.public_ip[0]
  if not public_ip:
    raise Exception('Node is started but has no IP.')
  try:
    ssh = getSSHConnection(driver, public_ip, ssh_key)
    print('Stopping instance...')
    stdin, stdout, stderr = ssh.exec_command('halt')
  except SSHException, e:
    print('unable to stop')
    raise e