deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [4/4] git commit: Client: Added support for metrics (DTACLOUD-543)
Date Tue, 16 Apr 2013 21:01:08 GMT
Client: Added support for metrics (DTACLOUD-543)


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/1ee23012
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/1ee23012
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/1ee23012

Branch: refs/heads/master
Commit: 1ee230122cb0e2072937103ddad7d8e8f846bb2b
Parents: 604e64e
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Apr 16 11:42:29 2013 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Apr 16 11:42:29 2013 +0200

----------------------------------------------------------------------
 client/lib/deltacloud/client/connection.rb     |    1 +
 client/lib/deltacloud/client/methods.rb        |    1 +
 client/lib/deltacloud/client/methods/metric.rb |   54 ++++++++++++++
 client/lib/deltacloud/client/models.rb         |    1 +
 client/lib/deltacloud/client/models/metric.rb  |   72 +++++++++++++++++++
 5 files changed, 129 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1ee23012/client/lib/deltacloud/client/connection.rb
----------------------------------------------------------------------
diff --git a/client/lib/deltacloud/client/connection.rb b/client/lib/deltacloud/client/connection.rb
index 5c98afd..60ff5ad 100644
--- a/client/lib/deltacloud/client/connection.rb
+++ b/client/lib/deltacloud/client/connection.rb
@@ -40,6 +40,7 @@ module Deltacloud::Client
     include Deltacloud::Client::Methods::StorageSnapshot
     include Deltacloud::Client::Methods::StorageVolume
     include Deltacloud::Client::Methods::LoadBalancer
+    include Deltacloud::Client::Methods::Metric
 
     def initialize(opts={})
       @request_driver = opts[:driver]

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1ee23012/client/lib/deltacloud/client/methods.rb
----------------------------------------------------------------------
diff --git a/client/lib/deltacloud/client/methods.rb b/client/lib/deltacloud/client/methods.rb
index 21df6dc..d58059d 100644
--- a/client/lib/deltacloud/client/methods.rb
+++ b/client/lib/deltacloud/client/methods.rb
@@ -30,3 +30,4 @@ require_relative './methods/realm'
 require_relative './methods/storage_volume'
 require_relative './methods/storage_snapshot'
 require_relative './methods/load_balancer'
+require_relative './methods/metric'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1ee23012/client/lib/deltacloud/client/methods/metric.rb
----------------------------------------------------------------------
diff --git a/client/lib/deltacloud/client/methods/metric.rb b/client/lib/deltacloud/client/methods/metric.rb
new file mode 100644
index 0000000..f269947
--- /dev/null
+++ b/client/lib/deltacloud/client/methods/metric.rb
@@ -0,0 +1,54 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+module Deltacloud::Client
+  module Methods
+    module Metric
+
+      # Retrieve list of all metric entities
+      #
+      # Filter options:
+      #
+      # - :id -> Filter entities using 'id' attribute
+      #
+      def metrics(filter_opts={})
+        from_collection :metrics,
+        connection.get(api_uri('metrics'), filter_opts)
+      end
+
+      # Retrieve the single metric entity
+      #
+      # - metric_id -> Metric entity to retrieve
+      #
+      def metric(metric_id)
+        from_resource :metric,
+          connection.get(api_uri("metrics/#{metric_id}"))
+      end
+
+      # Create a new metric
+      #
+      # - create_opts
+      #
+      # def create_metric(create_opts={})
+      #   must_support! :metrics
+      #    response = connection.post(api_uri('metrics')) do |request|
+      #     request.params = create_opts
+      #   end
+      #   model(:metric).convert(self, response.body)
+      # end
+
+    end
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1ee23012/client/lib/deltacloud/client/models.rb
----------------------------------------------------------------------
diff --git a/client/lib/deltacloud/client/models.rb b/client/lib/deltacloud/client/models.rb
index 67005e1..241d2f5 100644
--- a/client/lib/deltacloud/client/models.rb
+++ b/client/lib/deltacloud/client/models.rb
@@ -29,3 +29,4 @@ require_relative './models/realm'
 require_relative './models/storage_volume'
 require_relative './models/storage_snapshot'
 require_relative './models/load_balancer'
+require_relative './models/metric'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1ee23012/client/lib/deltacloud/client/models/metric.rb
----------------------------------------------------------------------
diff --git a/client/lib/deltacloud/client/models/metric.rb b/client/lib/deltacloud/client/models/metric.rb
new file mode 100644
index 0000000..31bec6b
--- /dev/null
+++ b/client/lib/deltacloud/client/models/metric.rb
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+module Deltacloud::Client
+  class Metric < Base
+
+    include Deltacloud::Client::Methods::Metric
+
+    # Inherited attributes: :_id, :name, :description
+
+    attr_reader :entity
+    attr_reader :properties
+
+    class Property
+
+      attr_reader :name, :samples
+
+      def initialize(name, samples=[])
+        @name = name
+        samples.each { |s| self << s }
+      end
+
+      def <<(values)
+        @samples ||= []
+        @samples << Sample.new(values)
+      end
+
+      class Sample
+        attr_reader :values
+
+        def initialize(values)
+          @values = values || []
+        end
+
+      end
+
+    end
+
+    # Metric model methods
+    #
+    # def reboot!
+    #   metric_reboot(_id)
+    # end
+
+    # Parse the Metric entity from XML body
+    #
+    # - xml_body -> Deltacloud API XML representation of the metric
+    #
+    def self.parse(xml_body)
+      {
+        :entity => xml_body.text_at(:entity),
+        :properties => xml_body.xpath('properties/*').map { |p|
+          Property.new(p.name, p.xpath('sample').map { |s|
+            s.xpath('property').map { |v| [v['name'], v['value']] }
+          })
+        }
+      }
+    end
+  end
+end


Mime
View raw message