Class: Chef::ChefFS::FileSystem::ChefServerRootDir
- Inherits:
-
BaseFSDir
- Object
- BaseFSObject
- BaseFSDir
- Chef::ChefFS::FileSystem::ChefServerRootDir
- Defined in:
- lib/chef/chef_fs/file_system/chef_server_root_dir.rb
Overview
Represents the root of a Chef server (or organization), under which nodes, roles, cookbooks, etc. can be found.
Instance Attribute Summary collapse
-
#chef_private_key ⇒ Object
readonly
Returns the value of attribute chef_private_key.
-
#chef_server_url ⇒ Object
readonly
Returns the value of attribute chef_server_url.
-
#chef_username ⇒ Object
readonly
Returns the value of attribute chef_username.
-
#cookbook_version ⇒ Object
readonly
Returns the value of attribute cookbook_version.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#repo_mode ⇒ Object
readonly
Returns the value of attribute repo_mode.
-
#versioned_cookbooks ⇒ Object
readonly
Returns the value of attribute versioned_cookbooks.
Attributes inherited from BaseFSObject
Instance Method Summary collapse
- #api_path ⇒ Object
- #can_have_child?(name, is_dir) ⇒ Boolean
- #chef_rest ⇒ Object
- #children ⇒ Object
- #fs_description ⇒ Object
- #get_json(path) ⇒ Object
-
#initialize(root_name, chef_config, options = {}) ⇒ ChefServerRootDir
constructor
Create a new Chef server root.
- #org ⇒ Object
- #path_for_printing ⇒ Object
- #rest ⇒ Object
Methods inherited from BaseFSDir
Methods inherited from BaseFSObject
#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #read, #root, #write
Constructor Details
#initialize(root_name, chef_config, options = {}) ⇒ ChefServerRootDir
Create a new Chef server root.
Parameters
- root_name
-
A friendly name for the root, for printing–like “remote” or “chef_central”.
- chef_config
-
A hash with options that look suspiciously like Chef::Config, including the following keys:
- :chef_server_url
-
The URL to the Chef server or top of the organization
- :node_name
-
The username to authenticate to the Chef server with
- :client_key
-
The private key for the user for authentication
- :environment
-
The environment in which you are presently working
- :repo_mode
-
The repository mode, :hosted_everything, :everything or :static. This determines the set of subdirectories the Chef server will offer up.
- :versioned_cookbooks
-
whether or not to include versions in cookbook names
- options
-
Other options:
- :cookbook_version
-
when cookbooks are retrieved, grab this version for them.
- :freeze
-
freeze cookbooks on upload
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 68 def initialize(root_name, chef_config, = {}) super("", nil) @chef_server_url = chef_config[:chef_server_url] @chef_username = chef_config[:node_name] @chef_private_key = chef_config[:client_key] @environment = chef_config[:environment] @repo_mode = chef_config[:repo_mode] @versioned_cookbooks = chef_config[:versioned_cookbooks] @root_name = root_name @cookbook_version = [:cookbook_version] # Used in knife diff and download for server cookbook version end |
Instance Attribute Details
#chef_private_key ⇒ Object (readonly)
Returns the value of attribute chef_private_key.
82 83 84 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 82 def chef_private_key @chef_private_key end |
#chef_server_url ⇒ Object (readonly)
Returns the value of attribute chef_server_url.
80 81 82 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 80 def chef_server_url @chef_server_url end |
#chef_username ⇒ Object (readonly)
Returns the value of attribute chef_username.
81 82 83 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 81 def chef_username @chef_username end |
#cookbook_version ⇒ Object (readonly)
Returns the value of attribute cookbook_version.
85 86 87 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 85 def cookbook_version @cookbook_version end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
83 84 85 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 83 def environment @environment end |
#repo_mode ⇒ Object (readonly)
Returns the value of attribute repo_mode.
84 85 86 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 84 def repo_mode @repo_mode end |
#versioned_cookbooks ⇒ Object (readonly)
Returns the value of attribute versioned_cookbooks.
86 87 88 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 86 def versioned_cookbooks @versioned_cookbooks end |
Instance Method Details
#api_path ⇒ Object
104 105 106 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 104 def api_path "" end |
#can_have_child?(name, is_dir) ⇒ Boolean
112 113 114 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 112 def can_have_child?(name, is_dir) is_dir && children.any? { |child| child.name == name } end |
#chef_rest ⇒ Object
100 101 102 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 100 def chef_rest Chef::REST.new(chef_server_url, chef_username, chef_private_key) end |
#children ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 127 def children @children ||= begin result = [ CookbooksDir.new(self), DataBagsDir.new(self), EnvironmentsDir.new(self), RestListDir.new("roles", self, nil, Chef::ChefFS::DataHandler::RoleDataHandler.new) ] if repo_mode == 'hosted_everything' result += [ AclsDir.new(self), RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new), RestListDir.new("containers", self, nil, Chef::ChefFS::DataHandler::ContainerDataHandler.new), RestListDir.new("groups", self, nil, Chef::ChefFS::DataHandler::GroupDataHandler.new), NodesDir.new(self), OrgEntry.new("org.json", self), OrganizationMembersEntry.new("members.json", self), OrganizationInvitesEntry.new("invitations.json", self) ] elsif repo_mode != 'static' result += [ RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new), NodesDir.new(self), RestListDir.new("users", self, nil, Chef::ChefFS::DataHandler::UserDataHandler.new) ] end result.sort_by { |child| child.name } end end |
#fs_description ⇒ Object
88 89 90 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 88 def fs_description "Chef server at #{chef_server_url} (user #{chef_username}), repo_mode = #{repo_mode}" end |
#get_json(path) ⇒ Object
96 97 98 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 96 def get_json(path) Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key).get(path) end |
#org ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 116 def org @org ||= begin path = Pathname.new(URI.parse(chef_server_url).path).cleanpath if File.dirname(path) == '/organizations' File.basename(path) else nil end end end |
#path_for_printing ⇒ Object
108 109 110 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 108 def path_for_printing "#{@root_name}/" end |