Client: Added support for metrics (DTACLOUD-543)
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 @@
     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]
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/storage_volume'
 require_relative './methods/storage_snapshot'
 require_relative './methods/load_balancer'
+require_relative './methods/metric'
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
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/storage_volume'
 require_relative './models/storage_snapshot'
 require_relative './models/load_balancer'
+require_relative './models/metric'
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