Class: Asteroid::Server
- Inherits:
-
Object
- Object
- Asteroid::Server
- Defined in:
- lib/asteroid/server.rb
Instance Attribute Summary collapse
-
#configure_steps ⇒ Object
Returns the value of attribute configure_steps.
-
#instance_options ⇒ Object
Returns the value of attribute instance_options.
-
#name ⇒ Object
Returns the value of attribute name.
-
#scripts ⇒ Object
Returns the value of attribute scripts.
-
#ssh_key ⇒ Object
Returns the value of attribute ssh_key.
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #commands ⇒ Object
- #config ⇒ Object
- #create_instance! ⇒ Object
- #first_instance ⇒ Object
- #generate_instance_name ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #instance_config ⇒ Object
- #provider ⇒ Object
- #ssh_key_filename ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/asteroid/server.rb', line 36 def initialize( = {}) data = self.class.default_config data.deep_merge! # Merge environment data if env = data.delete(:environments) env = env[Asteroid.environment] || {} data.deep_merge! env end @name = data.delete(:name) @provider = if data[:provider] Provider.named data[:provider] else Config.providers.first end @instance_options = data.delete :instance_options || {} @commands = data.delete(:commands) || {} @ssh_key = KeyReference.new data.delete(:ssh_key) @config = data["config"] || { "admin_username" => "ubuntu", "ssh_port" => 1983 } @default_config = data["default_instance_config"] || { "login.username" => "root", "ssh.port" => "22" } end |
Instance Attribute Details
#configure_steps ⇒ Object
Returns the value of attribute configure_steps.
8 9 10 |
# File 'lib/asteroid/server.rb', line 8 def configure_steps @configure_steps end |
#instance_options ⇒ Object
Returns the value of attribute instance_options.
8 9 10 |
# File 'lib/asteroid/server.rb', line 8 def @instance_options end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/asteroid/server.rb', line 8 def name @name end |
#scripts ⇒ Object
Returns the value of attribute scripts.
8 9 10 |
# File 'lib/asteroid/server.rb', line 8 def scripts @scripts end |
#ssh_key ⇒ Object
Returns the value of attribute ssh_key.
8 9 10 |
# File 'lib/asteroid/server.rb', line 8 def ssh_key @ssh_key end |
Class Method Details
.all ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/asteroid/server.rb', line 14 def self.all Dir[Asteroid::Config.server_dir + '/**/*.yml'].delete_if do |g| File.basename(g) == "default.yml" end.map do |g| load g end end |
.default_config ⇒ Object
22 23 24 25 |
# File 'lib/asteroid/server.rb', line 22 def self.default_config data = YAML.load_file File.join(Asteroid::Config.server_dir, '/default.yml') || {} ActiveSupport::HashWithIndifferentAccess.new data end |
.load(filename) ⇒ Object
31 32 33 34 |
# File 'lib/asteroid/server.rb', line 31 def self.load(filename) data = YAML.load_file filename new data end |
.named(name) ⇒ Object
27 28 29 |
# File 'lib/asteroid/server.rb', line 27 def self.named(name) load Asteroid::Config.server_dir + "/#{name}.yml" end |
Instance Method Details
#[](k) ⇒ Object
80 81 82 |
# File 'lib/asteroid/server.rb', line 80 def [](k) config[k.to_s] end |
#commands ⇒ Object
76 77 78 |
# File 'lib/asteroid/server.rb', line 76 def commands @commands end |
#config ⇒ Object
84 85 86 |
# File 'lib/asteroid/server.rb', line 84 def config @config end |
#create_instance! ⇒ Object
117 118 119 |
# File 'lib/asteroid/server.rb', line 117 def create_instance! provider.create_instance(self) end |
#first_instance ⇒ Object
92 93 94 |
# File 'lib/asteroid/server.rb', line 92 def first_instance Asteroid::Instance.all_with_type(self.type).first end |
#generate_instance_name ⇒ Object
112 113 114 115 |
# File 'lib/asteroid/server.rb', line 112 def generate_instance_name namespace = Config.namespace ? "#{Config.namespace}:" : "" "#{namespace}#{self.name}-#{SecureRandom.hex(4)}" end |
#instance_config ⇒ Object
96 97 98 |
# File 'lib/asteroid/server.rb', line 96 def instance_config @default_config end |
#provider ⇒ Object
108 109 110 |
# File 'lib/asteroid/server.rb', line 108 def provider @provider end |
#ssh_key_filename ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/asteroid/server.rb', line 100 def ssh_key_filename if @ssh_key File.join Asteroid::Config.secret_key_dir, @ssh_key else nil end end |
#type ⇒ Object
88 89 90 |
# File 'lib/asteroid/server.rb', line 88 def type name.to_sym end |