Skip to content
Browse files

Fetching resource attributes from chef server.

  • Loading branch information...
1 parent 2690994 commit 355d18512120a8ca07825d190b9d512d0d154143 @iafonov committed
View
7 app/assets/javascripts/backbone/models/node.js.coffee
@@ -1,4 +1,11 @@
+class ChefConsole.Models.NodeAttributes extends Backbone.Model
+
class ChefConsole.Models.Node extends Backbone.Model
+ resourceAttributes: ->
+ attrs = new ChefConsole.Models.NodeAttributes()
+ attrs.urlRoot = 'nodes/' + @get("id") + '/attributes'
+ attrs.fetch()
+ attrs
class ChefConsole.Collections.NodesCollection extends Backbone.Collection
model: ChefConsole.Models.Node
View
2 app/assets/javascripts/backbone/views/nodes/show_view.js.coffee
@@ -4,5 +4,5 @@ class ChefConsole.Views.Nodes.ShowView extends Backbone.View
template: JST["backbone/templates/nodes/show"]
render: ->
- $(@el).html(@template(@model.toJSON() ))
+ $(@el).html(@template(@model.toJSON()))
return this
View
17 app/controllers/attributes_controller.rb
@@ -0,0 +1,17 @@
+class AttributesController < ApplicationController
+ respond_to :json
+
+ def show
+ respond_with resource.fetch
+ end
+
+private
+
+ def resource
+ @resource_cache ||= resource_class.find("shard2")
+ end
+
+ def resource_class
+ request.path.split("/")[1].singularize.camelize.constantize
+ end
+end
View
4 config/routes.rb
@@ -1,5 +1,7 @@
ChefConsole::Application.routes.draw do
- resources :nodes
+ resources :nodes do
+ resource :attributes
+ end
resources :clients
root :to => "application#index"
View
5 lib/chef/client.rb
@@ -23,9 +23,14 @@ def get(resource, id = "", params = {})
raise ClientError.new("Client runtime error. Chef server error")
end
+ JSON.create_id = nil
JSON.parse(result)
end
+ def fetch(url)
+ result = RestClient.get url, sign_headers(:get, :path => "/nodes/ci")
+ end
+
private
def sign_headers(http_method, request_params={})
View
12 lib/chef/resource.rb
@@ -11,12 +11,24 @@ def self.all
collection.sort{ |a, b| a.name <=> b.name }
end
+ def self.fetch(name)
+ client.get(resouce_path, name)
+ end
+
+ def self.find(resource_id)
+ all.select{ |resource| resource.name == resource_id }.first
+ end
+
def initialize(name, url)
@name = name
@id = name
@fetch_url = url
end
+ def fetch
+ self.class.fetch(name)
+ end
+
private
def self.resouce_path

0 comments on commit 355d185

Please sign in to comment.
Something went wrong with that request. Please try again.