Class: Fog::Compute::QingCloud::SecurityGroup
Instance Method Summary
collapse
#changing?, inherited, #wait_for
Instance Method Details
#add_rule(attrs) ⇒ Object
20
21
22
23
24
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 20
def add_rule(attrs)
requires :id
attrs['group_id'] = id
service.security_group_rules.new(attrs).save
end
|
#add_rules(rules, auto_apply = true) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 26
def add_rules(rules, auto_apply = true)
requires :id
args = {}
rules.each_with_index { |r, i|
args.merge! service.security_group_rules.new(r).to_query(i + 1)
}
service.add_security_group_rules(id, args)
service.apply_security_group(id) if auto_apply
true
end
|
#apply ⇒ Object
58
59
60
61
62
63
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 58
def apply
requires :id
service.apply_security_group(id)
merge_attributes('is_applied' => 1)
true
end
|
#delete_rules(rule_id) ⇒ Object
Also known as:
delete_rule
52
53
54
55
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 52
def delete_rules(rule_id)
service.delete_security_group_rules(rule_id)
true
end
|
#destroy ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 65
def destroy
requires_one :group_id
service.delete_security_groups(group_id)
true
rescue Fog::QingCloud::Errors::PermissionDenied => e
raise e unless e.message =~ /has already been deleted/i
true
end
|
#egress_rules ⇒ Object
42
43
44
45
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 42
def egress_rules
requires :id
rules(:egress)
end
|
#ingress_rules ⇒ Object
37
38
39
40
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 37
def ingress_rules
requires :id
rules(:ingress)
end
|
#rules(direction = nil) ⇒ Object
47
48
49
50
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 47
def rules(direction = nil)
requires :id
service.security_group_rules.all('group-id' => id, 'direction' => direction)
end
|
#save ⇒ Object
Create a security group
>> g = QingCloud.security_groups.new(:name => "some_name", :description => "something")
>> g.save
Returns:
True or an exception depending on the result. Keep in mind that this creates a new security group. As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing group.
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/fog/qingcloud/models/compute/security_group.rb', line 85
def save
if persisted?
modify_attributes(name, description)
else
data = service.create_security_group(name).body
merge_attributes('id' => data['security_group_id'])
reload
end
true
end
|