Class: Dcmgr::Cli::SecurityGroup
- Defined in:
- lib/dcmgr/cli/security_group.rb
Constant Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #apply(uuid) ⇒ Object
- #del(uuid) ⇒ Object
- #modify(uuid) ⇒ Object
- #remove(uuid) ⇒ Object
- #show(uuid = nil) ⇒ Object
Instance Method Details
#add ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/dcmgr/cli/security_group.rb', line 29 def add UnknownUUIDError.raise([:account_id]) if M::Account[[:account_id]].nil? fields = .dup fields[:rule] = read_rule_text puts super(M::SecurityGroup,fields) end |
#apply(uuid) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/dcmgr/cli/security_group.rb', line 89 def apply(uuid) group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid) instance = M::Instance[[:instance]] || UnknownUUIDError.raise([:instance]) Error.raise("Group #{uuid} is already applied to instance #{[:instance]}.",100) if group.instances.member?(instance) group.add_instance(instance) end |
#del(uuid) ⇒ Object
39 40 41 |
# File 'lib/dcmgr/cli/security_group.rb', line 39 def del(uuid) super(M::SecurityGroup,uuid) end |
#modify(uuid) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dcmgr/cli/security_group.rb', line 76 def modify(uuid) UnknownUUIDError.raise([:account_id]) if [:account_id] && M::Account[[:account_id]].nil? fields = .dup if [:rule] fields[:rule] = read_rule_text end super(M::SecurityGroup,uuid, fields) end |
#remove(uuid) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/dcmgr/cli/security_group.rb', line 98 def remove(uuid) group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid) instance = M::Instance[[:instance]] || UnknownUUIDError.raise([:instance]) Error.raise("Group #{uuid} is not applied to instance #{[:instance]}.",100) unless group.instances.member?(instance) group.remove_instance(instance) end |
#show(uuid = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dcmgr/cli/security_group.rb', line 44 def show(uuid=nil) if uuid group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid) puts ERB.new(<<__END, nil, '-').result(binding) Group UUID: <%= group.canonical_uuid %> Account id: <%= group.account_id %> <%- if group.description -%> Description: <%= group.description %> <%- end -%> <%- unless group.security_group_rules.empty? -%> Rules: <%- group.security_group_rules.each { |rule| -%> <%= rule.permission %> <%- } -%> <%- end -%> __END else puts ERB.new(<<__END, nil, '-').result(binding) <%- M::SecurityGroup.all { |row| -%> <%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.description %> <%- } -%> __END end end |