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
-
#droplet_by_name(droplet_name) ⇒ DropletKit::Droplet
Get droplet by its name.
-
#get_droplet_id_by_name(droplet_name) ⇒ nil, Integer
Return droplet id by it’s name.
-
#get_droplet_ip_by_name(droplet_name) ⇒ String
Return droplet ip by it’s name.
-
#get_droplet_status_by_name(droplet_name) ⇒ Symbol
Return droplet status by it’s name.
- #get_image_id_by_name(image_name) ⇒ Object
-
#get_project_id_by_name(project_name) ⇒ nil, String
Get project id by name.
-
#project_by_name(project_name) ⇒ DropletKit::Project
Get project by name.
Instance Method Details
#droplet_by_name(droplet_name) ⇒ DropletKit::Droplet
Get droplet by its name
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
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
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
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
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
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 |