Sha256: 0e3418eb7735b83e17d365deb37e77d127e426031441aeb610857599c158dd75

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Hyperkit

  class Client

    # Methods for the networks API
    #
    # @see Hyperkit::Client
    # @see https://github.com/lxc/lxd/blob/master/specs/rest-api.md
    module Networks

      # List of networks defined on the host
      #
      # @return [Array<String>] An array of networks defined on the host
      #
      # @example Get list of networks
      #   Hyperkit.networks #=> ["lo", "eth0", "lxcbr0"]
      def networks
        response = get(networks_path)
        response.metadata.map { |path| path.split('/').last }
      end

      # Get information on a network
      #
      # @return [Sawyer::Resource] Network information
      #
      # @example Get information about lxcbr0
      #   Hyperkit.network("lxcbr0") #=> {:name=>"lxcbr0", :type=>"bridge", :used_by=>[]}
      def network(name)
        get(network_path(name)).metadata
      end

      private

      def network_path(name)
        File.join(networks_path, name)
      end

      def networks_path
        "/1.0/networks"
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hyperkit-1.2.0 lib/hyperkit/client/networks.rb
hyperkit-1.1.0 lib/hyperkit/client/networks.rb
hyperkit-1.0.2 lib/hyperkit/client/networks.rb