Skip to content

Commit 614b60b

Browse files
committed
add initial code for endpoint/request.
1 parent d57cb3e commit 614b60b

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

lib/fog/proxmox/cluster.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright 2018 Tristan Robert
4+
5+
# This file is part of Fog::Proxmox.
6+
7+
# Fog::Proxmox is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# Fog::Proxmox is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
19+
20+
require 'fog/proxmox/core'
21+
22+
module Fog
23+
module Proxmox
24+
# Proxmox cluster service
25+
class Cluster < Fog::Service
26+
requires :proxmox_url, :proxmox_auth_method
27+
recognizes :proxmox_token, :proxmox_tokenid, :proxmox_userid, :persistent, :proxmox_username, :proxmox_password
28+
29+
# Models
30+
model_path 'fog/proxmox/cluster/models'
31+
model :resource
32+
collection :resources
33+
34+
# Requests
35+
request_path 'fog/proxmox/cluster/requests'
36+
37+
# Manage nodes cluster
38+
request :get_resources
39+
40+
# Mock class
41+
class Mock
42+
attr_reader :config
43+
44+
def initialize(options = {})
45+
@proxmox_uri = URI.parse(options[:proxmox_url])
46+
@proxmox_auth_method = options[:proxmox_auth_method]
47+
@proxmox_tokenid = options[:proxmox_tokenid]
48+
@proxmox_userid = options[:proxmox_userid]
49+
@proxmox_username = options[:proxmox_username]
50+
@proxmox_password = options[:proxmox_password]
51+
@proxmox_token = options[:proxmox_token]
52+
@proxmox_path = @proxmox_uri.path
53+
@config = options
54+
end
55+
end
56+
57+
# Real class
58+
class Real
59+
include Fog::Proxmox::Core
60+
61+
def self.not_found_class
62+
Fog::Proxmox::Cluster::NotFound
63+
end
64+
65+
def config
66+
self
67+
end
68+
69+
def config_service?
70+
true
71+
end
72+
73+
private
74+
75+
def configure(source)
76+
source.instance_variables.each do |v|
77+
instance_variable_set(v, source.instance_variable_get(v))
78+
end
79+
end
80+
end
81+
end
82+
end
83+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2018 Tristan Robert
2+
3+
# This file is part of Fog::Proxmox.
4+
5+
# Fog::Proxmox is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
10+
# Fog::Proxmox is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
15+
# You should have received a copy of the GNU General Public License
16+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17+
18+
# frozen_string_literal: true
19+
20+
module Fog
21+
module Proxmox
22+
class Cluster
23+
# class Disk model
24+
class Resource < Fog::Model
25+
identity :id
26+
27+
attribute :name
28+
attribute :type
29+
attribute :node
30+
31+
# generic
32+
attribute :maxdisk
33+
34+
# vm/lxc specific
35+
attribute :status
36+
attribute :uptime
37+
attribute :template
38+
# resources are written in bytes, proxmox displays gibibytes
39+
attribute :maxcpu
40+
attribute :maxmem
41+
42+
# storage specific
43+
attribute :content
44+
attribute :shared
45+
attribute :storage
46+
47+
def is_template?
48+
template === 1
49+
end
50+
51+
def to_s
52+
Fog::Proxmox::Hash.flatten(flatten)
53+
end
54+
end
55+
end
56+
end
57+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright 2018 Tristan Robert
4+
5+
# This file is part of Fog::Proxmox.
6+
7+
# Fog::Proxmox is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# Fog::Proxmox is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
19+
20+
require 'fog/proxmox/cluster/models/resource'
21+
22+
module Fog
23+
module Proxmox
24+
class Cluster
25+
# class Disks Collection of disk
26+
class Resources < Fog::Collection
27+
model Fog::Proxmox::Cluster::Resource
28+
29+
def all
30+
self
31+
end
32+
33+
def get(id)
34+
all.find { |resource| resource.identity === id }
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright 2018 Tristan Robert
4+
5+
# This file is part of Fog::Proxmox.
6+
7+
# Fog::Proxmox is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# Fog::Proxmox is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
19+
20+
module Fog
21+
module Proxmox
22+
class Cluster
23+
# class Real get_vnc request
24+
class Real
25+
def get_resources
26+
request(
27+
expects: [200],
28+
method: 'GET',
29+
path: 'cluster/resources'
30+
)
31+
end
32+
end
33+
34+
# class Mock get_vnc request
35+
class Mock
36+
def get_resources; end
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)