~rackspace-titan/nova/openstack-api-versioned-controllers

« back to all changes in this revision

Viewing changes to contrib/boto_v6/ec2/connection.py

  • Committer: Brian Waldon
  • Date: 2011-03-21 19:23:11 UTC
  • mfrom: (784.1.56 nova)
  • Revision ID: brian.waldon@rackspace.com-20110321192311-ck4k5i3m2q4tksfy
merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
@author: Nachi Ueno <ueno.nachi@lab.ntt.co.jp>
5
5
'''
6
6
import boto
 
7
import base64
7
8
import boto.ec2
8
9
from boto_v6.ec2.instance import  ReservationV6
 
10
from boto.ec2.securitygroup import SecurityGroup
9
11
 
10
12
 
11
13
class EC2ConnectionV6(boto.ec2.EC2Connection):
39
41
            self.build_filter_params(params, filters)
40
42
        return self.get_list('DescribeInstancesV6', params,
41
43
                             [('item', ReservationV6)])
 
44
 
 
45
    def run_instances(self, image_id, min_count=1, max_count=1,
 
46
                      key_name=None, security_groups=None,
 
47
                      user_data=None, addressing_type=None,
 
48
                      instance_type='m1.small', placement=None,
 
49
                      kernel_id=None, ramdisk_id=None,
 
50
                      monitoring_enabled=False, subnet_id=None,
 
51
                      block_device_map=None):
 
52
        """
 
53
        Runs an image on EC2.
 
54
 
 
55
        :type image_id: string
 
56
        :param image_id: The ID of the image to run
 
57
 
 
58
        :type min_count: int
 
59
        :param min_count: The minimum number of instances to launch
 
60
 
 
61
        :type max_count: int
 
62
        :param max_count: The maximum number of instances to launch
 
63
 
 
64
        :type key_name: string
 
65
        :param key_name: The name of the key pair with which to
 
66
                         launch instances
 
67
 
 
68
        :type security_groups: list of strings
 
69
        :param security_groups: The names of the security groups with
 
70
                                which to associate instances
 
71
 
 
72
        :type user_data: string
 
73
        :param user_data: The user data passed to the launched instances
 
74
 
 
75
        :type instance_type: string
 
76
        :param instance_type: The type of instance to run
 
77
                              (m1.small, m1.large, m1.xlarge)
 
78
 
 
79
        :type placement: string
 
80
        :param placement: The availability zone in which to launch
 
81
                          the instances
 
82
 
 
83
        :type kernel_id: string
 
84
        :param kernel_id: The ID of the kernel with which to
 
85
                          launch the instances
 
86
 
 
87
        :type ramdisk_id: string
 
88
        :param ramdisk_id: The ID of the RAM disk with which to
 
89
                           launch the instances
 
90
 
 
91
        :type monitoring_enabled: bool
 
92
        :param monitoring_enabled: Enable CloudWatch monitoring
 
93
                                   on the instance.
 
94
 
 
95
        :type subnet_id: string
 
96
        :param subnet_id: The subnet ID within which to launch
 
97
                          the instances for VPC.
 
98
 
 
99
        :type block_device_map:
 
100
            :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
 
101
        :param block_device_map: A BlockDeviceMapping data structure
 
102
                                 describing the EBS volumes associated
 
103
                                 with the Image.
 
104
 
 
105
        :rtype: Reservation
 
106
        :return: The :class:`boto.ec2.instance.ReservationV6`
 
107
                 associated with the request for machines
 
108
        """
 
109
        params = {'ImageId': image_id,
 
110
                  'MinCount': min_count,
 
111
                  'MaxCount': max_count}
 
112
        if key_name:
 
113
            params['KeyName'] = key_name
 
114
        if security_groups:
 
115
            l = []
 
116
            for group in security_groups:
 
117
                if isinstance(group, SecurityGroup):
 
118
                    l.append(group.name)
 
119
                else:
 
120
                    l.append(group)
 
121
            self.build_list_params(params, l, 'SecurityGroup')
 
122
        if user_data:
 
123
            params['UserData'] = base64.b64encode(user_data)
 
124
        if addressing_type:
 
125
            params['AddressingType'] = addressing_type
 
126
        if instance_type:
 
127
            params['InstanceType'] = instance_type
 
128
        if placement:
 
129
            params['Placement.AvailabilityZone'] = placement
 
130
        if kernel_id:
 
131
            params['KernelId'] = kernel_id
 
132
        if ramdisk_id:
 
133
            params['RamdiskId'] = ramdisk_id
 
134
        if monitoring_enabled:
 
135
            params['Monitoring.Enabled'] = 'true'
 
136
        if subnet_id:
 
137
            params['SubnetId'] = subnet_id
 
138
        if block_device_map:
 
139
            block_device_map.build_list_params(params)
 
140
        return self.get_object('RunInstances', params,
 
141
                               ReservationV6, verb='POST')