Delete key pair and server for Compute example
Change-Id: Ic136296f3dec0327f95e246342819378834fd23c
This commit is contained in:
parent
b79c440389
commit
88255cfdad
@ -18,6 +18,7 @@ from examples.connect import IMAGE_NAME
|
|||||||
from examples.connect import KEYPAIR_NAME
|
from examples.connect import KEYPAIR_NAME
|
||||||
from examples.connect import NETWORK_NAME
|
from examples.connect import NETWORK_NAME
|
||||||
from examples.connect import PRIVATE_KEYPAIR_FILE
|
from examples.connect import PRIVATE_KEYPAIR_FILE
|
||||||
|
from examples.connect import SERVER_NAME
|
||||||
from examples.connect import SSH_DIR
|
from examples.connect import SSH_DIR
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -60,7 +61,7 @@ def create_server(conn):
|
|||||||
keypair = create_keypair(conn)
|
keypair = create_keypair(conn)
|
||||||
|
|
||||||
server = conn.compute.create_server(
|
server = conn.compute.create_server(
|
||||||
name='openstacksdk-example', image=image, flavor=flavor,
|
name=SERVER_NAME, image=image, flavor=flavor,
|
||||||
networks=[{"uuid": network.id}], key_name=keypair.name)
|
networks=[{"uuid": network.id}], key_name=keypair.name)
|
||||||
|
|
||||||
server = conn.compute.wait_for_server(server)
|
server = conn.compute.wait_for_server(server)
|
||||||
|
50
examples/compute/delete.py
Normal file
50
examples/compute/delete.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import errno
|
||||||
|
import os
|
||||||
|
|
||||||
|
from examples.connect import KEYPAIR_NAME
|
||||||
|
from examples.connect import PRIVATE_KEYPAIR_FILE
|
||||||
|
from examples.connect import SERVER_NAME
|
||||||
|
|
||||||
|
"""
|
||||||
|
Delete resources with the Compute service.
|
||||||
|
|
||||||
|
For a full guide see TODO(etoews):link to docs on developer.openstack.org
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def delete_keypair(conn):
|
||||||
|
print("Delete Key Pair:")
|
||||||
|
|
||||||
|
keypair = conn.compute.find_keypair(KEYPAIR_NAME)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.remove(PRIVATE_KEYPAIR_FILE)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
print(keypair)
|
||||||
|
|
||||||
|
conn.compute.delete_keypair(keypair)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_server(conn):
|
||||||
|
print("Delete Server:")
|
||||||
|
|
||||||
|
server = conn.compute.find_server(SERVER_NAME)
|
||||||
|
|
||||||
|
print(server)
|
||||||
|
|
||||||
|
conn.compute.delete_server(server)
|
@ -52,6 +52,7 @@ opts = Opts(cloud_name=TEST_CLOUD)
|
|||||||
occ = os_client_config.OpenStackConfig()
|
occ = os_client_config.OpenStackConfig()
|
||||||
cloud = occ.get_one_cloud(opts.cloud, argparse=opts)
|
cloud = occ.get_one_cloud(opts.cloud, argparse=opts)
|
||||||
|
|
||||||
|
SERVER_NAME = 'openstacksdk-example'
|
||||||
IMAGE_NAME = _get_resource_value('image_name', 'cirros-0.3.4-x86_64-uec')
|
IMAGE_NAME = _get_resource_value('image_name', 'cirros-0.3.4-x86_64-uec')
|
||||||
FLAVOR_NAME = _get_resource_value('flavor_name', 'm1.small')
|
FLAVOR_NAME = _get_resource_value('flavor_name', 'm1.small')
|
||||||
NETWORK_NAME = _get_resource_value('network_name', 'private')
|
NETWORK_NAME = _get_resource_value('network_name', 'private')
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from examples.compute import create
|
from examples.compute import create
|
||||||
|
from examples.compute import delete
|
||||||
from examples.compute import find as compute_find
|
from examples.compute import find as compute_find
|
||||||
from examples.compute import list as compute_list
|
from examples.compute import list as compute_list
|
||||||
from examples import connect
|
from examples import connect
|
||||||
@ -44,3 +45,6 @@ class TestCompute(unittest.TestCase):
|
|||||||
network_find.find_network(self.conn)
|
network_find.find_network(self.conn)
|
||||||
|
|
||||||
create.create_server(self.conn)
|
create.create_server(self.conn)
|
||||||
|
|
||||||
|
delete.delete_keypair(self.conn)
|
||||||
|
delete.delete_server(self.conn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user