Skip to content

Instantly share code, notes, and snippets.

View ezr-ondrej's full-sized avatar

Ondřej Ezr ezr-ondrej

View GitHub Profile
module Fog
module Vsphere
class Compute
class Real
def create_vm(attributes = {})
# NOW
# stufff goes here....
# AFTER
CreateVmRequest.new(connection).call(attributes)
end
@ezr-ondrej
ezr-ondrej / custom_component.js
Last active April 29, 2019 12:41
web_components.js
import React from 'react';
import { mountNode } from 'foremanReact/common/MountingService';
/**
* This tag can be used for mounting one react component from ComponentRegistry
* This way, we would decide to rewrite the mounter completely and we would make all components there to the custom tags.
*/
class ComponentInRegistryElement extends HTMLElement {
connectedCallback() {
const mountPoint = document.createElement('span');
@ezr-ondrej
ezr-ondrej / vmware.rb
Created May 13, 2019 09:44
Disable update of VM params from foreman
# app/models/compute_resources/foreman/model/vmware.rb
# ...
def supports_update?
true
end
# ... change to
def supports_update?
false
end
# ...
@ezr-ondrej
ezr-ondrej / run_dynflow.sh
Last active May 28, 2019 11:53
dynflow on ActiveJob example
# (re)create DB
DB=dynflow_example; dropdb -U postgres "$DB"; createdb -U postgres "$DB"
# install staff
sudo yum install redis
sudo systemctl enable --now redis
# set DB connection - expect dynflow user with dynflow password
export DB_CONN_STRING='postgres://dynflow:dynflow@/dynflow_example'
# start dynflow with web dashboard
bundle exec ruby ./examples/remote_executor.rb observer
# running dynflow dashboard on http://localhost:4567/dynflow
@ezr-ondrej
ezr-ondrej / get_condition.rb
Last active August 20, 2019 00:30
Parameters search
groups = ActiveRecord::Base.connection.select_all(GROUP_PARAMS_QUERY)
# this array is pretty huge - <number of hosts having the parameter matching name> * <type of parameters meeting the criteria>
parameters = ActiveRecord::Base.connection.select_all(PARAMS_QUERY)
matching_host_ids = []
parameters.group_by(&:first).each do |host_id, params|
valid = params.first
hostgroup_path = valid[<ancestry_position>] && valid[<ancestry_position>].split('/')
# select first matching group
grp_param = hostgroup_path && groups.detect{|group| hostgroup_path.include?(group[<id_position>].to_s)}
@ezr-ondrej
ezr-ondrej / sidekiq_dynflow.rb
Created September 27, 2019 08:31
Dynflow by sidekiq start
rails_root = Dir.pwd
app_file = File.expand_path('./config/application', rails_root)
require app_file
rails_env_file = File.expand_path('./config/environment.rb', rails_root)
require rails_env_file
# require 'dynflow/executors/sidekiq/core'
role = nil
<tr>
<td>
<%= f.text_field(:name, ... %>
</td>
<td>
<%= f.text_field(:value, ... %>
</td>
<td>
<%= link_to_remove_fields(_('Remove'), f) if f.object.new_record? %>
</td>
@ezr-ondrej
ezr-ondrej / package-lock.json
Last active April 22, 2020 11:08
Package lock compare
This file has been truncated, but you can view the full file.
{
"name": "TheForemanDevDeps",
"version": "2.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.8.3",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz",
"integrity": "sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g==",
# test/benchmark/audit_taxed_benchmark.rb
# Run by: bundle exec ruby -I"test" test/benchmark/audit_taxed_benchmark.rb
require 'test_helper'
class AuditTaxedTest < ActiveSupport::TestCase
setup do
org = FactoryBot.create(:organization)
2.times do |k|
loc = FactoryBot.create(:location)
50.times do
@ezr-ondrej
ezr-ondrej / load_facts.rb
Created May 3, 2021 14:17
load foreman facts
require 'json' #probably not necessary
file_json = JSON.parse('test/static_fixtures/facts/facts.json')
host = Host.find(host_id)
HostFactImporter.new(host).import_facts(file_json['facts'])