Module: Chef::Knife::EcBase
Defined Under Namespace
Classes: NoAdminFound
Class Method Summary collapse
Instance Method Summary collapse
- #configure_chef ⇒ Object
- #ensure_webui_key_exists! ⇒ Object
- #org_admin ⇒ Object
- #rest ⇒ Object
- #server ⇒ Object
- #set_client_config! ⇒ Object
- #set_dest_dir_from_args! ⇒ Object
- #set_skip_user_acl! ⇒ Object
- #user_acl_rest ⇒ Object
Class Method Details
.included(includer) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chef/knife/ec_base.rb', line 26 def self.included(includer) includer.class_eval do option :concurrency, :long => '--concurrency THREADS', :description => 'Maximum number of simultaneous requests to send (default: 10)' option :webui_key, :long => '--webui-key KEYPATH', :description => 'Path to the WebUI Key (default: /etc/opscode/webui_priv.pem)', :default => '/etc/opscode/webui_priv.pem' option :skip_useracl, :long => '--skip-useracl', :boolean => true, :default => false, :description => "Skip downloading/restoring User ACLs. This is required for EC 11.0.2 and lower" option :skip_version, :long => '--skip-version-check', :boolean => true, :default => false, :description => "Skip Chef Server version check. This will also skip any auto-configured options" option :org, :long => "--only-org ORG", :description => "Only download/restore objects in the named organization (default: all orgs)" option :sql_host, :long => '--sql-host HOSTNAME', :description => 'Postgresql database hostname (default: localhost)', :default => "localhost" option :sql_port, :long => '--sql-port PORT', :description => 'Postgresql database port (default: 5432)', :default => 5432 option :sql_user, :long => "--sql-user USERNAME", :description => 'User used to connect to the postgresql database.' option :sql_password, :long => "--sql-password PASSWORD", :description => 'Password used to connect to the postgresql database' option :with_user_sql, :long => '--with-user-sql', :description => 'Try direct data base access for user export/import. Required to properly handle passwords, keys, and USAGs' option :with_key_sql, :long => '--with-key-sql', :description => 'Try direct data base access for key table export/import. Required to properly handle rotated keys.' end attr_accessor :dest_dir def configure_chef super Chef::Config[:concurrency] = config[:concurrency].to_i if config[:concurrency] Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1 end def org_admin rest = Chef::REST.new(Chef::Config.chef_server_url) admin_users = rest.get_rest('groups/admins')['users'] org_members = rest.get_rest('users').map { |user| user['user']['username'] } admin_users.delete_if { |user| !org_members.include?(user) || user == 'pivotal' } if admin_users.empty? raise Chef::Knife::EcBase::NoAdminFound else admin_users[0] end end end |
Instance Method Details
#configure_chef ⇒ Object
84 85 86 87 88 |
# File 'lib/chef/knife/ec_base.rb', line 84 def configure_chef super Chef::Config[:concurrency] = config[:concurrency].to_i if config[:concurrency] Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1 end |
#ensure_webui_key_exists! ⇒ Object
145 146 147 148 149 150 |
# File 'lib/chef/knife/ec_base.rb', line 145 def ensure_webui_key_exists! if !File.exist?(config[:webui_key]) ui.error("Webui Key (#{config[:webui_key]}) does not exist.") exit 1 end end |
#org_admin ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/chef/knife/ec_base.rb', line 90 def org_admin rest = Chef::REST.new(Chef::Config.chef_server_url) admin_users = rest.get_rest('groups/admins')['users'] org_members = rest.get_rest('users').map { |user| user['user']['username'] } admin_users.delete_if { |user| !org_members.include?(user) || user == 'pivotal' } if admin_users.empty? raise Chef::Knife::EcBase::NoAdminFound else admin_users[0] end end |
#rest ⇒ Object
112 113 114 |
# File 'lib/chef/knife/ec_base.rb', line 112 def rest @rest ||= Chef::REST.new(server.root_url) end |
#server ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/chef/knife/ec_base.rb', line 103 def server @server ||= if Chef::Config.chef_server_root.nil? ui.warn("chef_server_root not found in knife configuration; using chef_server_url") Chef::Server.from_chef_server_url(Chef::Config.chef_server_url) else Chef::Server.new(Chef::Config.chef_server_root) end end |
#set_client_config! ⇒ Object
131 132 133 134 135 |
# File 'lib/chef/knife/ec_base.rb', line 131 def set_client_config! Chef::Config.custom_http_headers = (Chef::Config.custom_http_headers || {}).merge({'x-ops-request-source' => 'web'}) Chef::Config.node_name = 'pivotal' Chef::Config.client_key = config[:webui_key] end |
#set_dest_dir_from_args! ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/chef/knife/ec_base.rb', line 137 def set_dest_dir_from_args! if name_args.length <= 0 ui.error("Must specify backup directory as an argument.") exit 1 end @dest_dir = name_args[0] end |
#set_skip_user_acl! ⇒ Object
127 128 129 |
# File 'lib/chef/knife/ec_base.rb', line 127 def set_skip_user_acl! config[:skip_useracl] ||= !(server.supports_user_acls? || server.direct_account_access?) end |
#user_acl_rest ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chef/knife/ec_base.rb', line 116 def user_acl_rest @user_acl_rest ||= if config[:skip_version] rest elsif server.supports_user_acls? rest elsif server.direct_account_access? Chef::REST.new("http://127.0.0.1:9465") end end |