1# Licensed to the Apache Software Foundation (ASF) under one or more
2# contributor license agreements.  See the NOTICE file distributed with
3# this work for additional information regarding copyright ownership.
4# The ASF licenses this file to You under the Apache License, Version 2.0
5# (the "License"); you may not use this file except in compliance with
6# the License.  You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from libcloud.compute.types import Provider
17from libcloud.compute.providers import get_driver
18
19from libcloud.compute.drivers.ec2 import EC2NodeDriver
20from libcloud.compute.drivers.rackspace import RackspaceNodeDriver
21
22from typing import Type, cast
23
24EC2 = get_driver(Provider.EC2)
25Rackspace = get_driver(Provider.RACKSPACE)
26
27drivers = [EC2('access key id', 'secret key', region='us-east-1'),
28           Rackspace('username', 'api key', region='iad')]
29
30nodes = []
31for driver in drivers:
32    nodes.extend(driver.list_nodes())
33
34print(nodes)
35# [ <Node: provider=Amazon, status=RUNNING, name=bob, ip=1.2.3.4.5>,
36# <Node: provider=Rackspace, status=REBOOT, name=korine, ip=6.7.8.9.10>, ... ]
37
38# grab the node named "test"
39node = [n for n in nodes if n.name == 'test'][0]
40
41# reboot "test"
42node.reboot()
43