Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
* Generate plugin from template: https://github.com/theforeman/foreman_plugin_template
* Add introduction to README
  • Loading branch information
bastian-src committed Jan 20, 2023
0 parents commit ccc6333
Show file tree
Hide file tree
Showing 39 changed files with 1,254 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["@theforeman/foreman"],
"extends": ["plugin:@theforeman/foreman/core", "plugin:@theforeman/foreman/plugins"]
}
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
locale/*.mo
locale/*/*.edit.po
locale/*/*.po.time_stamp
locale/*/*.pox
node_modules
package-lock.json
Gemfile.lock
coverage
38 changes: 38 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-minitest

AllCops:
TargetRubyVersion: 2.5
TargetRailsVersion: 6.0
Exclude:
- 'node_modules/**/*'

Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
IndentationWidth: 2

Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/LineLength:
Enabled: 111 # TODO: discuss and set this

Rails:
Enabled: true

Style/Alias:
EnforcedStyle: prefer_alias_method

# Don't enforce documentation
Style/Documentation:
Enabled: false

# Don't enforce frozen string literals
Style/FrozenStringLiteralComment:
Enabled: false

# Support both ruby19 and hash_rockets
Style/HashSyntax:
Enabled: false
5 changes: 5 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"stylelint-config-standard",
],
}
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com

[foreman.foreman_resource_quota]
file_filter = locale/<lang>/foreman_resource_quota.edit.po
source_file = locale/foreman_resource_quota.pot
source_lang = en
type = PO
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
619 changes: 619 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Foreman Resource Quota

When several users share a compute resource or infrastructure, there is a concern that some users could use more than its fair share of resources. Resource quotas are a tool for administrators to address this concern. They limit access to the shared resource in order to guarantee a fair collaboration.

Talking about Foreman, multiple users or groups usually share a fixed number of resources (limitation of compute resources like RAM, disk storage, and CPU power). As of now, a user cannot be limited when allocating resources. They can create hosts with as many resources as they want. This could lead to over-usage or unequal balancing of resources under the users. In order to prevent this, we want to introduce a new plugin: Foreman Resource Quota.

This plugin introduces the configuration of quotas. A quota limits specific resources and can be applied to a user or a user group. If a user belongs to a user group, the group’s quota is automatically applied to the user as well.

A user is hindered from deploying new hosts, if the new host would exceed the corresponding quota limits. In case, a user belongs to multiple user group with quota, the user can determine which quota new hosts belong to.

## Installation

See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
for how to install Foreman plugins

## Usage

*Usage here*

## TODO

*Todo list here*

## Contributing

Fork and send a Pull Request. Thanks!

## Copyright

Copyright (c) *year* *your name*

This program 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.

This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

47 changes: 47 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ForemanPluginTemplate'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)

Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

task default: :test

begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue => _
puts 'Rubocop not loaded.'
end

task :default do
Rake::Task['rubocop'].execute
end
Empty file added app/controllers/.gitkeep
Empty file.
Empty file added app/helpers/.gitkeep
Empty file.
Empty file added app/mailers/.gitkeep
Empty file.
Empty file added app/models/.gitkeep
Empty file.
Empty file added app/views/.gitkeep
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@theforeman/builder/babel'],
};
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ForemanPluginTemplate::Engine.routes.draw do
get 'new_action', to: 'example#new_action', as: 'new_action'
get 'plugin_template_description', to: 'example#react_template_page_description'
get 'welcome', to: '/react#index', as: 'welcome'
end

Foreman::Application.routes.draw do
mount ForemanPluginTemplate::Engine, at: '/foreman_resource_quota'
end
20 changes: 20 additions & 0 deletions foreman_resource_quota.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require File.expand_path('../lib/foreman_resource_quota/version', __FILE__)

Gem::Specification.new do |s|
s.name = 'foreman_resource_quota'
s.version = ForemanPluginTemplate::VERSION
s.metadata = { "is_foreman_plugin" => "true" }
s.license = 'GPL-3.0'
s.authors = ['TODO: Your name']
s.email = ['TODO: Your email']
s.homepage = 'TODO'
s.summary = 'TODO: Summary of ForemanPluginTemplate.'
# also update locale/gemspec.rb
s.description = 'TODO: Description of ForemanPluginTemplate.'

s.files = Dir['{app,config,db,lib,locale,webpack}/**/*'] + ['LICENSE', 'Rakefile', 'README.md', 'package.json']
s.test_files = Dir['test/**/*'] + Dir['webpack/**/__tests__/*.js']

s.add_development_dependency 'rubocop'
s.add_development_dependency 'rdoc'
end
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { foremanLocation, foremanRelativePath } = require('@theforeman/find-foreman')
const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const foremanFull = foremanLocation();
const foremanReactFull = foremanRelativePath(foremanReactRelative);

// Jest configuration
module.exports = {
testURL: 'http://localhost/',
setupFiles: [
'./webpack/test_setup.js',
],
setupFilesAfterEnv: [
'./webpack/global_test_setup.js',
'@testing-library/jest-dom'
],
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/foreman/',
'<rootDir>/.+fixtures.+',
'<rootDir>/engines',
],
moduleDirectories: [
`${foremanFull}/node_modules`,
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
'node_modules',
'webpack/test-utils',
],
modulePathIgnorePatterns: [
'<rootDir>/foreman/',
],
moduleNameMapper: {
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^foremanReact(.*)$': `${foremanReactFull}/$1`,
},
};
60 changes: 60 additions & 0 deletions locale/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Makefile for PO merging and MO generation. More info in the README.
#
# make all-mo (default) - generate MO files
# make check - check translations using translate-tool
# make tx-update - download and merge translations from Transifex
# make clean - clean everything
#
DOMAIN = foreman_resource_quota
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
POTFILE = $(DOMAIN).pot
MOFILE = $(DOMAIN).mo
POFILES = $(shell find . -name '$(DOMAIN).po')
MOFILES = $(patsubst %.po,%.mo,$(POFILES))
POXFILES = $(patsubst %.po,%.pox,$(POFILES))
EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))

%.mo: %.po
mkdir -p $(shell dirname $@)/LC_MESSAGES
msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<

# Generate MO files from PO files
all-mo: $(MOFILES)

# Check for malformed strings
%.pox: %.po
msgfmt -c $<
pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
-t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
cat $@
! grep -q msgid $@

%.edit.po:
touch $@

check: $(POXFILES)

# Unify duplicate translations
uniq-po:
for f in $(shell find ./ -name "*.po") ; do \
msguniq $$f -o $$f ; \
done

tx-pull: $(EDITFILES)
tx pull -f
for f in $(EDITFILES) ; do \
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
done

tx-update: tx-pull
@echo
@echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
@echo

mo-files: $(MOFILES)
git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
git commit -m "i18n - pulling from tx"
@echo
@echo Changes commited!
@echo
19 changes: 19 additions & 0 deletions locale/foreman_resource_quota.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# foreman_resource_quota
#
# This file is distributed under the same license as foreman_resource_quota.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: version 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
"PO-Revision-Date: 2014-08-20 08:46+0100\n"
"Last-Translator: Foreman Team <[email protected]>\n"
"Language-Team: Foreman Team <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

2 changes: 2 additions & 0 deletions locale/gemspec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Matches foreman_resource_quota.gemspec
_('TODO: Description of ForemanPluginTemplate.')
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "foreman_resource_quota",
"version": "1.0.0",
"description": "DESCRIPTION",
"main": "index.js",
"scripts": {
"lint": "tfm-lint --plugin -d /webpack",
"test": "tfm-test --config jest.config.js",
"test:watch": "tfm-test --plugin --watchAll",
"test:current": "tfm-test --plugin --watch",
"publish-coverage": "tfm-publish-coverage",
"stories": "tfm-stories --plugin",
"stories:build": "tfm-build-stories --plugin",
"create-react-component": "yo react-domain"
},
"repository": {
"type": "git",
"url": "git+https://github.com/theforeman/foreman_resource_quota.git"
},
"bugs": {
"url": "http://projects.theforeman.org/projects/foreman_resource_quota/issues"
},
"peerDependencies": {
"@theforeman/vendor": ">= 6.0.0"
},
"dependencies": {
"react-intl": "^2.8.0"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@sheerun/mutationobserver-shim": "^0.3.3",
"@theforeman/builder": "^6.0.0",
"@theforeman/eslint-plugin-foreman": "6.0.0",
"@theforeman/find-foreman": "^4.8.0",
"@theforeman/stories": "^7.0.0",
"@theforeman/test": "^8.0.0",
"@theforeman/vendor-dev": "^6.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.7.2",
"prettier": "^1.19.1",
"stylelint-config-standard": "^18.0.0",
"stylelint": "^9.3.0"
}
}
Loading

0 comments on commit ccc6333

Please sign in to comment.