#!/usr/bin/env python # Delete a devstack VM. # Copyright (C) 2011 OpenStack LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # # See the License for the specific language governing permissions and # limitations under the License. from libcloud.compute.base import NodeImage, NodeSize, NodeLocation from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver import os, sys import getopt import time import vmdatabase CLOUD_SERVERS_DRIVER = os.environ.get('CLOUD_SERVERS_DRIVER','rackspace') CLOUD_SERVERS_USERNAME = os.environ['CLOUD_SERVERS_USERNAME'] CLOUD_SERVERS_API_KEY = os.environ['CLOUD_SERVERS_API_KEY'] node_uuid = sys.argv[1] db = vmdatabase.VMDatabase() machine = db.getMachine(node_uuid) if CLOUD_SERVERS_DRIVER == 'rackspace': Driver = get_driver(Provider.RACKSPACE) conn = Driver(CLOUD_SERVERS_USERNAME, CLOUD_SERVERS_API_KEY) node = [n for n in conn.list_nodes() if n.id==str(machine['id'])][0] node.destroy() db.delMachine(node_uuid)