Class: Fog::Compute::Azure::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/azure/models/compute/server.rb

Instance Method Summary collapse

Instance Method Details

#destroy ⇒ Object



85
86
87
88
89
90
# File 'lib/fog/azure/models/compute/server.rb', line 85

def destroy
  requires :vm_name
  requires :cloud_service_name

  service.delete_virtual_machine(vm_name, cloud_service_name)
end

#external_ip ⇒ Object

helper functions for more common fog names



57
58
59
# File 'lib/fog/azure/models/compute/server.rb', line 57

def external_ip
  ipaddress
end

#machine_type ⇒ Object



77
78
79
# File 'lib/fog/azure/models/compute/server.rb', line 77

def machine_type
  vm_size
end

#name ⇒ Object



65
66
67
# File 'lib/fog/azure/models/compute/server.rb', line 65

def name
  vm_name
end

#public_ip_address ⇒ Object



61
62
63
# File 'lib/fog/azure/models/compute/server.rb', line 61

def public_ip_address
  ipaddress
end

#ready? ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/fog/azure/models/compute/server.rb', line 81

def ready?
  state == "Running"
end

#reboot ⇒ Object



92
93
94
95
96
97
# File 'lib/fog/azure/models/compute/server.rb', line 92

def reboot
  requires :vm_name
  requires :cloud_service_name

  service.reboot_server(vm_name, cloud_service_name)
end

#save ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fog/azure/models/compute/server.rb', line 113

def save
  requires :vm_name
  requires :vm_user
  requires :image
  requires_one :location, :affinity_group_name
  #requires :vm_size

  if ! private_key_file.nil? && certificate_file.nil?
    key = OpenSSL::PKey.read File.read(private_key_file)
    cert = OpenSSL::X509::Certificate.new
    cert.version = 2 # cf. RFC 5280 - to make it a "v3" certificate
    cert.serial = 1
    cert.subject = OpenSSL::X509::Name.parse "/CN=Fog"
    cert.issuer = cert.subject # root CA's are "self-signed"
    cert.public_key = key.public_key
    cert.not_before = Time.now
    cert.not_after = cert.not_before + 2 * 365 * 24 * 60 * 60 # 2 years validity
    ef = OpenSSL::X509::ExtensionFactory.new
    ef.subject_certificate = cert
    ef.issuer_certificate = cert
    cert.add_extension(ef.create_extension("basicConstraints","CA:TRUE",true))
    cert.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
    cert.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
    cert.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false))
    cert.sign(key, OpenSSL::Digest::SHA256.new)

    cert_file = Tempfile.new(["cert", ".pem"])
    cert_file.chmod(0600)
    cert_file.write(cert.to_pem)
    cert_file.close
    self.certificate_file = cert_file.path
  end

  if .nil?
    service.storage_accounts.each do |sa|
      if sa.location == location
        self. = sa.name
        break
      end
    end
  end

  if cloud_service_name.nil?
    self.cloud_service_name = vm_name
  end

  #API to start deployment
  params = {
    :vm_name => vm_name,
    :vm_user => vm_user,
    :image => image,
    :password => password,
    :location => location,
  }
  options = {
    :storage_account_name => ,
    :winrm_transport => winrm_transport,
    :cloud_service_name => cloud_service_name,
    :deployment_name => deployment_name,
    :tcp_endpoints => tcp_endpoints,
    :private_key_file => private_key_file,
    :certificate_file => certificate_file,
    :ssh_port => ssh_port,
    :vm_size => vm_size,
    :affinity_group_name => affinity_group_name,
    :virtual_network_name => virtual_network_name,
    :subnet_name => subnet_name,
    :availability_set_name => availability_set_name,
  }
  service.create_virtual_machine(params, options)
  cert_file.unlink unless cert_file.nil?
end

#shutdown ⇒ Object



99
100
101
102
103
104
# File 'lib/fog/azure/models/compute/server.rb', line 99

def shutdown
  requires :vm_name
  requires :cloud_service_name

  service.shutdown_server(vm_name, cloud_service_name)
end

#start ⇒ Object



106
107
108
109
110
111
# File 'lib/fog/azure/models/compute/server.rb', line 106

def start
  requires :vm_name
  requires :cloud_service_name

  service.start_server(vm_name, cloud_service_name)
end

#state ⇒ Object



69
70
71
# File 'lib/fog/azure/models/compute/server.rb', line 69

def state
  deployment_status
end

#username ⇒ Object



73
74
75
# File 'lib/fog/azure/models/compute/server.rb', line 73

def username
  vm_user
end