1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from openstack import cloud as openstack
14
15# Initialize and turn on debug logging
16openstack.enable_logging(debug=True)
17
18for cloud_name, region_name, image, flavor in [
19        ('my-vexxhost', 'ca-ymq-1',
20         'Ubuntu 16.04.1 LTS [2017-03-03]', 'v1-standard-4'),
21        ('my-citycloud', 'Buf1',
22         'Ubuntu 16.04 Xenial Xerus', '4C-4GB-100GB'),
23        ('my-internap', 'ams01',
24         'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]:
25    # Initialize cloud
26    cloud = openstack.connect(
27        cloud=cloud_name, region_name=region_name)
28    cloud.delete_server('my-server', wait=True, delete_ips=True)
29
30    # Boot a server, wait for it to boot, and then do whatever is needed
31    # to get a public ip for it.
32    server = cloud.create_server(
33        'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
34    print(server.name)
35    print(server['name'])
36    cloud.pprint(server)
37    # Delete it - this is a demo
38    cloud.delete_server(server, wait=True, delete_ips=True)
39