Skip to content

Commit

Permalink
Allow optional instance type, AZ, secgroups for RightScale servers
Browse files Browse the repository at this point in the history
  • Loading branch information
fr33jc committed Feb 20, 2015
1 parent 24aa651 commit 1b1b3b9
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions bang/providers/rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,38 +231,50 @@ def define_server(
"""
log.info('Defining server %s...' % basename)
self.basename = basename

# required attributes
tpl = find_exact(
self.api.server_templates,
name=server_tpl,
revision=server_tpl_rev,
)
itype = find_exact(
self.cloud.instance_types,
name=instance_type,
)
datacenter = find_exact(
self.cloud.datacenters,
name=availability_zone,
)
# ... the rightscale and aws apis allow you to spin up a server without
# a key, but let's not. we already assume you need ssh for ansible.
sshkey = find_exact(
self.cloud.ssh_keys,
resource_uid=ssh_key_name,
)
secgroup_hrefs = [
find_exact(self.cloud.security_groups, name=n).href
for n in security_groups
]
data = {
'server[deployment_href]': self.deployment.href,
'server[instance][cloud_href]': self.cloud.href,
'server[instance][datacenter_href]': datacenter.href,
'server[instance][instance_type_href]': itype.href,
'server[instance][security_group_hrefs][]': secgroup_hrefs,
'server[instance][server_template_href]': tpl.href,
'server[instance][ssh_key_href]': sshkey.href,
'server[name]': basename,
}

# optional attributes (i.e. you can set these to '' in bang configs)
itype = find_exact(
self.cloud.instance_types,
name=instance_type,
)
if itype:
data['server[instance][instance_type_href]'] = itype.href

datacenter = find_exact(
self.cloud.datacenters,
name=availability_zone,
)
if datacenter:
data['server[instance][datacenter_href]'] = datacenter.href

secgroup_hrefs = []
for n in security_groups:
secgroup = find_exact(self.cloud.security_groups, name=n)
if secgroup:
secgroup_hrefs.append(secgroup.href)
if secgroup_hrefs:
data['server[instance][security_group_hrefs][]'] = secgroup_hrefs

if provider_extras:
# use a copy because the inbound provider_extras will be passed in again
# when calling create_server()
Expand Down

0 comments on commit 1b1b3b9

Please sign in to comment.