Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fog-proxmox.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler', '~> 2.1'
spec.add_development_dependency 'bundler-audit', '~> 0.6'
spec.add_development_dependency 'debase', '~> 0.2.2'
spec.add_development_dependency 'debase', '~> 0.2.5.beta1'
spec.add_development_dependency 'debride', '~> 1.8'
spec.add_development_dependency 'fasterer', '~> 0.3'
spec.add_development_dependency 'fastri', '~> 0.3'
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/proxmox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ module Proxmox
autoload :Core, 'fog/proxmox/core'
autoload :Errors, 'fog/proxmox/errors'
autoload :Identity, 'fog/proxmox/identity'
autoload :Cluster, 'fog/proxmox/cluster'
autoload :Compute, 'fog/proxmox/compute'
autoload :Storage, 'fog/proxmox/storage'
autoload :Network, 'fog/proxmox/network'

extend Fog::Provider

service(:identity, 'Identity')
service(:cluster, 'Cluster')
service(:compute, 'Compute')
service(:storage, 'Storage')
service(:network, 'Network')
Expand Down
84 changes: 84 additions & 0 deletions lib/fog/proxmox/cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

require 'fog/proxmox/core'

module Fog
module Proxmox
# Proxmox cluster service
class Cluster < Fog::Service
requires :proxmox_url, :proxmox_auth_method
recognizes :proxmox_token, :proxmox_tokenid, :proxmox_userid, :persistent, :proxmox_username, :proxmox_password

# Models
model_path 'fog/proxmox/cluster/models'
model :resource
collection :resources

# Requests
request_path 'fog/proxmox/cluster/requests'

# Manage nodes cluster
request :list_resources
request :get_nextid

# Mock class
class Mock
attr_reader :config

def initialize(options = {})
@proxmox_uri = URI.parse(options[:proxmox_url])
@proxmox_auth_method = options[:proxmox_auth_method]
@proxmox_tokenid = options[:proxmox_tokenid]
@proxmox_userid = options[:proxmox_userid]
@proxmox_username = options[:proxmox_username]
@proxmox_password = options[:proxmox_password]
@proxmox_token = options[:proxmox_token]
@proxmox_path = @proxmox_uri.path
@config = options
end
end

# Real class
class Real
include Fog::Proxmox::Core

def self.not_found_class
Fog::Proxmox::Cluster::NotFound
end

def config
self
end

def config_service?
true
end

private

def configure(source)
source.instance_variables.each do |v|
instance_variable_set(v, source.instance_variable_get(v))
end
end
end
end
end
end
61 changes: 61 additions & 0 deletions lib/fog/proxmox/cluster/models/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true
# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

# frozen_string_literal: true

require 'fog/proxmox/hash'

module Fog
module Proxmox
class Cluster
# class Disk model
class Resource < Fog::Model
identity :id

attribute :name
attribute :type
attribute :node

# generic
attribute :maxdisk

# vm/lxc specific
attribute :vmid
attribute :status
attribute :uptime
attribute :template
# resources are written in bytes, proxmox displays gibibytes
attribute :maxcpu
attribute :maxmem

# storage specific
attribute :content
attribute :shared
attribute :storage

def is_template?
template === 1
end

def to_s
Fog::Proxmox::Hash.flatten(attributes)
end
end
end
end
end
43 changes: 43 additions & 0 deletions lib/fog/proxmox/cluster/models/resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

require 'fog/proxmox/cluster/models/resource'

module Fog
module Proxmox
class Cluster
# class Disks Collection of disk
class Resources < Fog::Collection
model Fog::Proxmox::Cluster::Resource

def all
load service.list_resources
end

def get(id)
all.find { |resource| resource.identity === id }
end

def by_type(type)
all.select { |resource| resource.type === type }
end
end
end
end
end
46 changes: 46 additions & 0 deletions lib/fog/proxmox/cluster/requests/get_nextid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

module Fog
module Proxmox
class Cluster
# class Real get_nextid request
class Real
def get_nextid(vmid = nil)
query = "vmid=#{vmid}" unless vmid.nil?
request(
expects: [200],
method: 'GET',
path: 'cluster/nextid',
query: query || ''
)
end
end

# class Mock get_nextid request
class Mock
def get_nextid(vmid = nil)
return "4002" unless vmid

vmid.to_s
end
end
end
end
end
104 changes: 104 additions & 0 deletions lib/fog/proxmox/cluster/requests/list_resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Fog::Proxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.

module Fog
module Proxmox
class Cluster
# class Real get_vnc request
class Real
def list_resources(resource_type = '')
query = resource_type.blank? ? '' : "type=#{resource_type}"
request(
expects: [200],
method: 'GET',
path: 'cluster/resources',
query: query || ''
)
end

def list_qemu_resources
list_vm_resources.select { |vm| vm['type'] == 'qemu' }
end

def list_lxc_resources
list_vm_resources.select { |vm| vm['type'] == 'lxc' }
end

def list_vm_resources
list_resources('vm')
end

def list_storage_resources
list_resources('storage')
end
end

# class Mock get_vnc request
class Mock
def list_resources(resource_type)
case resource_type
when 'qemu'
list_qemu_resources
when 'lxc'
list_lxc_resources
when 'storage'
list_storage_resources
else
(list_qemu_resources + list_lxc_resources + list_storage_resources)
end
end

def list_qemu_resources
[
{
'node' => 'pve',
'type' => 'qemu',
'vmid' => '100'
}
]
end

def list_lxc_resources
[
{
'node' => 'pve',
'type' => 'lxc',
'vmid' => '101'
}
]
end

def list_storage_resources # rubocop:disable Metrics/MethodLength
[
{
'node' => 'pve',
'type' => 'storage',
'storage' => 'local'
},
{
'node' => 'pve',
'type' => 'storage',
'storage' => 'local'
}
]
end
end
end
end
end
8 changes: 0 additions & 8 deletions lib/fog/proxmox/compute/models/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Copyright 2018 Tristan Robert

# This file is part of Fog::Proxmox.

# Fog::Proxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand Down
Loading