Sha256: 8a39d90aba0c011ad132f9c3934f9b310e90336026cdad5d302524dee59bbd60

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# -*- encoding: utf-8 -*-
module Simplenet
  module Client
    class Interface < Base
      def initialize(url)
        @url     = url
        @fullurl = "#{url}/interfaces"
      end

      def create(hostname, mac)
        simplenet_post(@fullurl, {
          :hostname => hostname,
          :mac      => mac
        })
      end

      def attach_ip(uuid, ip)
        simplenet_post("#{@fullurl}/#{uuid}/ips", {
          :ip => ip
        })
      rescue Simplenet::Exception::EntityNotFoundError
        msg = "Ip not found on simplenet. Make sure Ip created already?"
        raise Simplenet::Exception::EntityNotFoundError.new(msg)
      end

      def detach_ip(uuid, ip)
        detach("ip", uuid, ip)
      end

      def attach_vlan(uuid, vlan_id)
        simplenet_post("#{@fullurl}/#{uuid}/vlans", {
          :id => vlan_id
        })
      rescue Simplenet::Exception::EntityNotFoundError
        msg = "Vlan not found on simplenet. Make sure Vlan created already?"
        raise Simplenet::Exception::EntityNotFoundError.new(msg)
      end

      def detach_vlan(uuid, vlan_name)
        detach("vlan", uuid, vlan_name)
      end

      private

      def detach(type, uuid, object)
        simplenet_delete("#{@fullurl}/#{uuid}/#{type}s/#{object}")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simplenet-client-0.2.0 ./lib/simplenet/client/interface.rb