Class: JoyentUpdater

Inherits:
ProviderUpdater show all
Includes:
RegionArea
Defined in:
app/provider_updaters/joyent_updater.rb

Constant Summary

Constants included from RegionArea

RegionArea::UNKNOWN

Instance Method Summary collapse

Methods included from RegionArea

#extract_region_area

Methods inherited from ProviderUpdater

#extract_sla, load_providers, #logger, providers, update_providers

Constructor Details

#initializeJoyentUpdater

Returns a new instance of JoyentUpdater.


4
5
6
7
8
9
10
# File 'app/provider_updaters/joyent_updater.rb', line 4

def initialize
  super
  @prefixes = {
      'us' => 'US',
      'eu' => 'EU',
  }
end

Instance Method Details

#number_from(string) ⇒ Object (private)


87
88
89
# File 'app/provider_updaters/joyent_updater.rb', line 87

def number_from(string)
  Float(string.delete('^0-9.').to_d)
end

#performObject


12
13
14
15
16
# File 'app/provider_updaters/joyent_updater.rb', line 12

def perform
  update_provider
  update_compute_batch
  # update_storage
end

#update_computeObject (private)


35
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
# File 'app/provider_updaters/joyent_updater.rb', line 35

def update_compute
  provider = Provider.find_or_create_by(name: 'Joyent')
  uri = URI('https://www.joyent.com/pricing')
  doc = Nokogiri::HTML(open(uri))
  # there is no region info on the crawled pricing site, hence we hardcode it. Taken from https://docs.joyent.com/public-cloud/data-centers
  regions = ['us-east-1','us-east-2','us-east-3','us-east-3b','us-sw-1','us-west-1','eu-ams-1']
  kvm_div = doc.css('div#kvm')
  instances = kvm_div.css('div.instance')
  instances.each do |instance_element|

    if number_from(instance_element.css('li.spec.cpu').text) < 1
      next
    end
    regions.each do |region|
      resource_name = instance_element.css('li.spec.api').text

      resource = provider.resources.find_or_create_by(name: resource_name, region: region)
      resource.more_attributes['price_per_hour'] = number_from(instance_element.css('p.pph.s')[0].text)
      resource.more_attributes['price_per_month'] = number_from(instance_element.css('p.pph.s')[1].text)
      resource.more_attributes['cores'] = number_from(instance_element.css('li.spec.cpu').text)
      resource.more_attributes['mem_gb'] = number_from(instance_element.css('li.spec.ram').text)
      resource.more_attributes['disk_gb'] = number_from(instance_element.css('li.spec.disk').text)
      resource.resource_type = 'compute'
      resource.region_area = extract_region_area(region)
      resource.save!
    end
  end
end

#update_compute_batchObject (private)


29
30
31
32
33
# File 'app/provider_updaters/joyent_updater.rb', line 29

def update_compute_batch
  ActiveRecord::Base.transaction do
    update_compute
  end
end

#update_providerObject (private)


20
21
22
23
24
25
26
27
# File 'app/provider_updaters/joyent_updater.rb', line 20

def update_provider
  # NOTICE: Joyent has no 'actual' availability SLA, they claim 100%, but in reality it's around 0.9993, if you follow their example.
  # See here: https://www.joyent.com/about/policies/cloud-hosting-service-level-agreement

  provider = Provider.find_or_create_by(name: 'Joyent')
  provider.more_attributes['pricelist'] = {}
  provider.save!
end

#update_storageObject (private)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/provider_updaters/joyent_updater.rb', line 64

def update_storage
  provider = Provider.find_or_create_by(name: 'Joyent')
  uri = URI('https://www.joyent.com/pricing/manta')
  doc = Nokogiri::HTML(open(uri))

  rows = doc.css('tbody')[0].css('tr')
  rows.pop()

  # there is no region info on the crawled pricing site, hence we hardcode it. Taken from https://docs.joyent.com/public-cloud/data-centers
  regions = ['us-east-1','us-east-2','us-east-3','us-east-3b','us-sw-1','us-west-1','eu-ams-1']

  rows.each do |storage_element|
    regions.each do |region|
      resource_name = storage_element.css('td')[0].text
      resource = provider.resources.find_or_create_by(name: resource_name, region: region)
      resource.resource_type = 'storage'
      resource.region_area = extract_region_area(region)
      resource.more_attributes['price_per_month_gb'] = number_from(storage_element.css('td')[1].text)
      resource.save!
    end
  end
end