Skip to content

Commit

Permalink
add initial code for endpoint/request.
Browse files Browse the repository at this point in the history
  • Loading branch information
YWatchman committed Oct 26, 2022
1 parent d57cb3e commit 614b60b
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 0 deletions.
83 changes: 83 additions & 0 deletions lib/fog/proxmox/cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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 :get_resources

# 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
57 changes: 57 additions & 0 deletions lib/fog/proxmox/cluster/models/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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

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 :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(flatten)
end
end
end
end
end
39 changes: 39 additions & 0 deletions lib/fog/proxmox/cluster/models/resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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
self
end

def get(id)
all.find { |resource| resource.identity === id }
end
end
end
end
end
40 changes: 40 additions & 0 deletions lib/fog/proxmox/cluster/requests/get_resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 get_resources
request(
expects: [200],
method: 'GET',
path: 'cluster/resources'
)
end
end

# class Mock get_vnc request
class Mock
def get_resources; end
end
end
end
end

0 comments on commit 614b60b

Please sign in to comment.