Module: OnlyofficeDigitaloceanWrapper::Getters

Included in:
DigitalOceanWrapper
Defined in:
lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb

Overview

Get image, droplet by metadata

Instance Method Summary collapse

Instance Method Details

#droplet_by_name(droplet_name) ⇒ DropletKit::Droplet

Get droplet by its name

Parameters:

  • droplet_name (String)

Returns:

  • (DropletKit::Droplet)

    droplet



18
19
20
21
22
23
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 18

def droplet_by_name(droplet_name)
  retry_exception do
    droplets = @client.droplets.all
    droplets.find { |x| x.name == droplet_name }
  end
end

#get_droplet_id_by_name(droplet_name) ⇒ nil, Integer

Return droplet id by it’s name

Parameters:

  • droplet_name (String)

    name of droplet

Returns:

  • (nil, Integer)

    id of droplet or nil is no one droplet found



52
53
54
55
56
57
58
59
60
61
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 52

def get_droplet_id_by_name(droplet_name)
  droplet = droplet_by_name(droplet_name)
  if droplet.nil?
    logger.info("get_droplet_id_by_name(#{droplet_name}): not found any droplets")
    nil
  else
    logger.info("get_droplet_id_by_name(#{droplet_name}): #{droplet.id}")
    droplet.id
  end
end

#get_droplet_ip_by_name(droplet_name) ⇒ String

Return droplet ip by it’s name

Parameters:

  • droplet_name (String)

    name of droplet

Returns:

  • (String)

    ip of droplet



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 66

def get_droplet_ip_by_name(droplet_name)
  droplet = droplet_by_name(droplet_name)
  if droplet.nil?
    logger.info("There is no created droplet with name: #{droplet_name}")
    return
  end
  retry_exception do
    ip = public_ip(droplet)
    logger.info("get_droplet_ip_by_name(#{droplet_name}): #{ip}")
    ip
  end
end

#get_droplet_status_by_name(droplet_name) ⇒ Symbol

Return droplet status by it’s name

Parameters:

  • droplet_name (String)

    name of droplet

Returns:

  • (Symbol)

    droplet status



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 82

def get_droplet_status_by_name(droplet_name)
  droplet = droplet_by_name(droplet_name)
  if droplet.nil?
    logger.info("get_droplet_status_by_name(#{droplet_name}): not found any droplets")
    nil
  else
    retry_exception do
      status = droplet.status
      status = :locked if droplet.locked
      logger.info("get_droplet_status_by_name(#{droplet_name}): #{status}")
      status
    end
  end
end

#get_image_id_by_name(image_name) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 6

def get_image_id_by_name(image_name)
  all_droplets = @client.images.all
  image = all_droplets.find { |x| x.name == image_name }
  raise DigitalOceanImageNotFound, image_name if image.nil?

  logger.info("get_image_id_by_name(#{image_name}): #{image.id}")
  image.id
end

#get_project_id_by_name(project_name) ⇒ nil, String

Get project id by name

Parameters:

  • project_name (String)

Returns:

  • (nil, String)

    id of current project or nil is no project found



38
39
40
41
42
43
44
45
46
47
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 38

def get_project_id_by_name(project_name)
  project = project_by_name(project_name)
  if project.nil?
    logger.info("get_project_id_by_name(#{project_name}): not found any projects")
    nil
  else
    logger.info("get_project_id_by_name(#{project_name}): #{project.id}")
    project.id
  end
end

#project_by_name(project_name) ⇒ DropletKit::Project

Get project by name

Parameters:

  • project_name (String)

Returns:

  • (DropletKit::Project)

    object representing a project



28
29
30
31
32
33
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb', line 28

def project_by_name(project_name)
  retry_exception do
    projects = @client.projects.all
    projects.find { |x| x.name == project_name }
  end
end