require "providers/abstract_provider_connector"
require "providers/static/static_provider_account"

module Provider
  class StaticConnector < AbstractProviderConnector
    PROVIDER = "static"

    def initialize config
      #self.certificate_path = config[:static_certificate]
#      self.ssh_key = config["static_ssh_key"]
      self.run_list = config[:static_integration_run_list] || []
      #@@mongo ||= MongoConnector.new(config[:mongo_db], config[:mongo_host], config[:mongo_port], config[:mongo_user], config[:mongo_password])
    end

    def configured?
      true
    end

    def name
      PROVIDER
    end

    def flavors
      []
    end

    def images filters
      []
    end

    def servers
      @@mongo.servers_find({:provider => PROVIDER}).map{|s| s.to_hash}
    end

    def create_default_server_name s
      "static-#{s.project}-#{s.environment}-#{Time.now.to_i}"
    end

    def create_server s, image, flavor, subnets, groups, out, options={}
      out << "Unsupported operation: ca not create server for provider 'static'"
      false
    end

    def delete_server s
      res = Devops::Executor::ServerExecutor.new(s, "").unbootstrap()
      m = "Static server with id '#{s.id}' and name '#{s.name}' "
      return m + (res.nil? ? "has been unbootstraped" : "can not be unbootstraped: #{res}")
    end

    def pause_server s
      nil
    end

    def unpause_server s
      nil
    end

  end
end
