blob: 9cfe2347db7767245c11d5b00897c5b6a8d677a3 [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Attila Fazekasa23f5002012-10-23 19:32:45 +020018import urlparse
19
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020import boto
21from boto.ec2.regioninfo import RegionInfo
22from boto.s3.connection import OrdinaryCallingFormat
23
24from tempest.services.boto import BotoClientBase
25
Attila Fazekasa23f5002012-10-23 19:32:45 +020026
27class APIClientEC2(BotoClientBase):
28
29 def connect_method(self, *args, **kwargs):
30 return boto.connect_ec2(*args, **kwargs)
31
32 def __init__(self, config, *args, **kwargs):
33 super(APIClientEC2, self).__init__(config, *args, **kwargs)
34 aws_access = config.boto.aws_access
35 aws_secret = config.boto.aws_secret
36 purl = urlparse.urlparse(config.boto.ec2_url)
37
38 region = RegionInfo(name=config.boto.aws_region,
39 endpoint=purl.hostname)
40 port = purl.port
41 if port is None:
42 if purl.scheme is not "https":
43 port = 80
44 else:
45 port = 443
46 else:
47 port = int(port)
48 self.connection_data = {"aws_access_key_id": aws_access,
49 "aws_secret_access_key": aws_secret,
50 "is_secure": purl.scheme == "https",
51 "region": region,
52 "host": purl.hostname,
53 "port": port,
54 "path": purl.path}
55
56 ALLOWED_METHODS = set(('create_key_pair', 'get_key_pair',
57 'delete_key_pair', 'import_key_pair',
58 'get_all_key_pairs',
59 'create_image', 'get_image',
60 'register_image', 'deregister_image',
61 'get_all_images', 'get_image_attribute',
62 'modify_image_attribute', 'reset_image_attribute',
63 'get_all_kernels',
64 'create_volume', 'delete_volume',
65 'get_all_volume_status', 'get_all_volumes',
66 'get_volume_attribute', 'modify_volume_attribute'
67 'bundle_instance', 'cancel_spot_instance_requests',
68 'confirm_product_instanc',
69 'get_all_instance_status', 'get_all_instances',
70 'get_all_reserved_instances',
71 'get_all_spot_instance_requests',
72 'get_instance_attribute', 'monitor_instance',
73 'monitor_instances', 'unmonitor_instance',
74 'unmonitor_instances',
75 'purchase_reserved_instance_offering',
76 'reboot_instances', 'request_spot_instances',
77 'reset_instance_attribute', 'run_instances',
78 'start_instances', 'stop_instances',
79 'terminate_instances',
80 'attach_network_interface', 'attach_volume',
81 'detach_network_interface', 'detach_volume',
82 'get_console_output',
83 'delete_network_interface', 'create_subnet',
84 'create_network_interface', 'delete_subnet',
85 'get_all_network_interfaces',
86 'allocate_address', 'associate_address',
87 'disassociate_address', 'get_all_addresses',
88 'release_address',
89 'create_snapshot', 'delete_snapshot',
90 'get_all_snapshots', 'get_snapshot_attribute',
91 'modify_snapshot_attribute',
92 'reset_snapshot_attribute', 'trim_snapshots',
93 'get_all_regions', 'get_all_zones',
94 'get_all_security_groups', 'create_security_group',
95 'delete_security_group', 'authorize_security_group',
96 'authorize_security_group_egress',
97 'revoke_security_group',
98 'revoke_security_group_egress'))
99
100 def get_good_zone(self):
101 """
102 :rtype: BaseString
103 :return: Returns with the first available zone name
104 """
105 for zone in self.get_all_zones():
106 #NOTE(afazekas): zone.region_name was None
107 if (zone.state == "available" and
108 zone.region.name == self.connection_data["region"].name):
109 return zone.name
110 else:
111 raise IndexError("Don't have a good zone")
112
113
114class ObjectClientS3(BotoClientBase):
115
116 def connect_method(self, *args, **kwargs):
117 return boto.connect_s3(*args, **kwargs)
118
119 def __init__(self, config, *args, **kwargs):
120 super(ObjectClientS3, self).__init__(config, *args, **kwargs)
121 aws_access = config.boto.aws_access
122 aws_secret = config.boto.aws_secret
123 purl = urlparse.urlparse(config.boto.s3_url)
124 port = purl.port
125 if port is None:
126 if purl.scheme is not "https":
127 port = 80
128 else:
129 port = 443
130 else:
131 port = int(port)
132 self.connection_data = {"aws_access_key_id": aws_access,
133 "aws_secret_access_key": aws_secret,
134 "is_secure": purl.scheme == "https",
135 "host": purl.hostname,
136 "port": port,
137 "calling_format": OrdinaryCallingFormat()}
138
139 ALLOWED_METHODS = set(('create_bucket', 'delete_bucket', 'generate_url',
140 'get_all_buckets', 'get_bucket', 'delete_key',
141 'lookup'))