Statistics
| Branch: | Tag: | Revision:

one / src / cli / one_helper / onevmgroup_helper.rb @ 202b47e9

History | View | Annotate | Download (4.23 KB)

1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

    
17
require 'one_helper'
18

    
19
class OneVMGroupHelper < OpenNebulaHelper::OneHelper
20
    def self.rname
21
        "VM_GROUP"
22
    end
23

    
24
    def self.conf_file
25
        "onevmgroup.yaml"
26
    end
27

    
28
    def format_pool(options)
29
        config_file = self.class.table_conf
30

    
31
        table = CLIHelper::ShowTable.new(config_file, self) do
32
            column :ID, "ONE identifier for the VM Group", :size=>4 do |d|
33
                d["ID"]
34
            end
35

    
36
            column :NAME, "Name of the VM Group", :left, :size=>15 do |d|
37
                d["NAME"]
38
            end
39

    
40
            column :USER, "Username of the VM Group owner", :left,
41
                    :size=>15 do |d|
42
                helper.user_name(d, options)
43
            end
44

    
45
            column :GROUP, "Group of the VM Group", :left, :size=>15 do |d|
46
                helper.group_name(d, options)
47
            end
48

    
49
            column :ROLES, "Roles in the VM Group", :left, :size=>31 do |d|
50
                roles = d["ROLES"]["ROLE"]
51
                roles_names = ""
52

    
53
                if !roles.nil?
54
                    rnames = roles.collect { |i| i["NAME"] }
55
                    roles_names = rnames.join(", ") if !rnames.empty?
56
                end
57

    
58
                roles_names
59
            end
60

    
61
            default :ID, :USER, :GROUP, :NAME, :ROLES
62
        end
63

    
64
        table
65
    end
66

    
67
    private
68

    
69
    def factory(id=nil)
70
        if id
71
            OpenNebula::VMGroup.new_with_id(id, @client)
72
        else
73
            xml=OpenNebula::VMGroup.build_xml
74
            OpenNebula::VMGroup.new(xml, @client)
75
        end
76
    end
77

    
78
    def factory_pool(user_flag=-2)
79
        OpenNebula::VMGroupPool.new(@client, user_flag)
80
    end
81

    
82
    def format_resource(vmgroup, options = {})
83
        str="%-15s: %-20s"
84
        str_h1="%-80s"
85

    
86
        CLIHelper.print_header(
87
            str_h1 % "VM GROUP #{vmgroup['ID']} INFORMATION")
88
        puts str % ["ID", vmgroup.id.to_s]
89
        puts str % ["NAME", vmgroup.name]
90
        puts str % ["USER", vmgroup['UNAME']]
91
        puts str % ["GROUP", vmgroup['GNAME']]
92

    
93
        CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
94

    
95
        puts
96

    
97
        ["OWNER", "GROUP", "OTHER"].each { |e|
98
            mask = "---"
99
            mask[0] = "u" if vmgroup["PERMISSIONS/#{e}_U"] == "1"
100
            mask[1] = "m" if vmgroup["PERMISSIONS/#{e}_M"] == "1"
101
            mask[2] = "a" if vmgroup["PERMISSIONS/#{e}_A"] == "1"
102

    
103
            puts str % [e,  mask]
104
        }
105

    
106
        puts
107

    
108
        CLIHelper.print_header(str_h1 % "ROLES", false)
109

    
110
        if !vmgroup.to_hash['VM_GROUP']['ROLES']['ROLE'].nil?
111
            roles = [vmgroup.to_hash['VM_GROUP']['ROLES']['ROLE']].flatten
112
        end
113

    
114
        CLIHelper::ShowTable.new(nil, self) do
115
            column :ID, "", :left, :size=>4 do |d|
116
                d["ID"]
117
            end
118

    
119
            column :NAME, "", :left, :size=>16 do |d|
120
                d["NAME"]
121
            end
122

    
123
            column :VIRTUAL_MACHINES, "", :left, :size=>32 do |d|
124
                d["VMS"]
125
            end
126
        end.show(roles, {})
127

    
128
        puts
129

    
130
        CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
131
        puts vmgroup.template_str
132
    end
133
end