Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwang committed Oct 10, 2015
2 parents 969b541 + 9017a14 commit d984a36
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
19 changes: 14 additions & 5 deletions cloudbridge/providers/aws/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,20 @@ def mac_address(self):
'mac_address not implemented by this provider')

@property
def security_group_ids(self):
"""
Get the security group IDs associated with this instance.
"""
return self._ec2_instance.groups
def security_groups(self):
"""
Get the security groups associated with this instance.
"""
# boto instance.groups field returns a ``Group`` object so need to
# convert that into a ``SecurityGroup`` object before creating a
# cloudbridge SecurityGroup object
security_groups = []
names = []
for group in self._ec2_instance.groups:
names.append(group.name)
security_groups = self.provider.security.security_groups.get(names)
return [AWSSecurityGroup(self.provider, group)
for group in security_groups]

@property
def key_pair_name(self):
Expand Down
10 changes: 5 additions & 5 deletions cloudbridge/providers/interfaces/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ def mac_address(self):
'Instance.mac_address not implemented by this provider')

@property
def security_group_ids(self):
def security_groups(self):
"""
Get the security group IDs associated with this instance.
Get the security groups associated with this instance.
:rtype: list
:return: A list of security group IDs associated with this instance.
:rtype: list or :class:``SecurityGroup`` objects
:return: A list of SecurityGroup objects associated with this instance.
"""
raise NotImplementedError(
'Instance.security_group_ids not implemented by this provider')
'Instance.security_groups not implemented by this provider')

@property
def key_pair_name(self):
Expand Down
14 changes: 9 additions & 5 deletions cloudbridge/providers/openstack/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,16 @@ def mac_address(self):
'mac_address not implemented by this provider')

@property
def security_group_ids(self):
def security_groups(self):
"""
Get the security group IDs associated with this instance.
Get the security groups associated with this instance.
"""
return [BaseSecurityGroup(group.id, group.name, group.description)
for group in self._os_instance.security_groups]
security_groups = []
for group in self._os_instance.security_groups:
security_groups.append(self.provider.nova.security_groups.find(
name=group.get('name')))
return [OpenStackSecurityGroup(self.provider, group)
for group in security_groups]

@property
def key_pair_name(self):
Expand Down Expand Up @@ -295,7 +299,7 @@ def refresh(self):
self._os_instance.status = 'unknown'

def __repr__(self):
return "<CB-OSInstance: {0}({1})>".format(self.name, self.instance_id)
return "<CB-OSInstance: {0} ({1})>".format(self.name, self.instance_id)


class OpenStackRegion(Region):
Expand Down

0 comments on commit d984a36

Please sign in to comment.