class Fog::Compute::Azure::Server

Public Instance Methods

destroy() click to toggle source
# 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() click to toggle source

helper functions for more common fog names

# File lib/fog/azure/models/compute/server.rb, line 57
def external_ip
  ipaddress
end
machine_type() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 77
def machine_type
  vm_size
end
name() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 65
def name
  vm_name
end
public_ip_address() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 61
def public_ip_address
  ipaddress
end
ready?() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 81
def ready?
  state == "Running"
end
reboot() click to toggle source
# 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() click to toggle source
# 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 storage_account_name.nil?
    service.storage_accounts.each do |sa|
      if sa.location == location
        self.storage_account_name = 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 => 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 69
def state
  deployment_status
end
username() click to toggle source
# File lib/fog/azure/models/compute/server.rb, line 73
def username
  vm_user
end