-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial code for endpoint/request.
- Loading branch information
Showing
4 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 compute 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::Compute::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |