docli 0.0.2.pre.alpha.pre.15 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +0,0 @@
1
- module Docli
2
- class Create < SubcommandBase
3
- def self.help(*args)
4
- super
5
- puts <<-INSTRUCTION
6
- Examples:
7
- docli create -f resources.yaml # Create resources from YAML file
8
-
9
- INSTRUCTION
10
- end
11
-
12
- method_option :filename, aliases: '-f', desc: 'Filename to use to create the resource'
13
-
14
- def initialize(args = [], local_options = {}, config = {})
15
- puts "`create droplet` called with options: #{options}" if Docli.debug?
16
- super
17
- if options[:filename]
18
- puts "create -f called with options: #{options}" if Docli.debug?
19
- config = YAML.load(File.open(options[:filename]))
20
- puts "YAML Loaded:"
21
- puts config
22
- exit
23
- end
24
- end
25
-
26
- desc 'droplet', 'Create a droplet'
27
- method_option :name , aliases: '-n', desc: 'droplet name (require for the hostname of droplets', required: true
28
- method_option :region , aliases: '-r', desc: 'droplet region', default: 'NYC1'
29
- method_option :size , aliases: '-s', desc: 'size of droplet, ex: 512mb, 1gb ...', default: '512mb'
30
- method_option :image , aliases: '-i', desc: 'mage name or image id', default: 'Ubuntu 16x04'
31
- method_option :user_data , aliases: '-u', desc: 'add command or cloud config on first boot'
32
- method_option :ipv6 , desc: 'turn on or off ipv6', type: :boolean, default: true
33
- method_option :private_networking, aliases: '-p', desc: 'turn on or off private networking', type: :boolean, lazy_default: true
34
- method_option :monitoring , aliases: '-m', desc: 'turn on or off monitoring', type: :boolean, lazy_default: true
35
- method_option :backups , aliases: '-b', desc: 'turn on or off auto backup', type: :boolean, lazy_default: true
36
- method_option :tags , aliases: '-t', desc: 'add tags', type: :array
37
-
38
- # method_options :volumes, :ssh_keys .... # TODO: consider to enable these options
39
-
40
- def droplet
41
- droplet_obj = DropletKit::Droplet.new(options)
42
- Docli.client.droplets.create(droplet_obj)
43
- tp(
44
- :id => droplet_obj.id,
45
- :name => droplet_obj.name,
46
- :region => droplet_obj.region.name,
47
- :size => droplet_obj.size,
48
- :status => droplet_obj.status
49
- )
50
- end
51
- end
52
- end
@@ -1,4 +0,0 @@
1
- module Docli
2
- class Delete < SubcommandBase
3
- end
4
- end
@@ -1,70 +0,0 @@
1
- module Docli
2
- class Get < SubcommandBase
3
- desc 'droplets', 'List droplets'
4
- method_option :tag_name, aliases: '-t', desc: 'filter by tag name', type: :string
5
- def droplets(droplet_id = nil)
6
- ## Sometime user confuse with `docli get droplet` and `docli get droplets`
7
- ## This enabled: docli get droplets DROPLET_ID
8
- ## IMPROVEMENT: Consider to enable or disable this feature
9
- return invoke :droplet if droplet_id
10
- ##
11
- puts "`get droplets` called with options: #{options}" if Docli.debug?
12
- droplet_objects = Docli.client.droplets.all(options.symbolize_keys)
13
- tp(
14
- droplet_objects.map do |drlet|
15
- {
16
- id: drlet.id,
17
- name: drlet.name,
18
- ipv4: drlet.networks.v4.find { |v| v.type == 'public' }.ip_address,
19
- region: drlet.region.slug,
20
- size: drlet.size_slug,
21
- status: Docli::Utils.colorize(drlet.status)
22
- }
23
- end
24
- )
25
- end
26
-
27
- desc 'account', 'Show account information'
28
- def account
29
- account = Cmd::Accounts.get_user_information
30
- puts 'Email: '.yellow + account.email.red
31
- puts 'Droplet Limit: '.yellow + account.droplet_limit.to_s.red
32
- puts 'Floating IP Limit: '.yellow + account.floating_ip_limit.to_s.red
33
- puts 'Verified: '.yellow + account.email_verified.to_s.red
34
- end
35
-
36
- desc 'blockstorages', 'List all block storage / volume'
37
- def blockstorages
38
- volumes = Cmd::Volumes.list_all_volumes.each.as_json
39
- tp (
40
- volumes.map do |vl|
41
- {
42
- id: vl['id'],
43
- name: vl['name'],
44
- region: vl['region']['name'],
45
- droplet_id: vl['droplet_ids'],
46
- size: vl['size_gigabytes'].to_s + " GB",
47
- created_at: vl['created_at']
48
- }
49
- end
50
- ), {:id => {:width => 100}}, :name, :region, {:droplet_id => {:width => 100}}, :size, :created_at
51
- end
52
-
53
- desc 'droplet', 'Show a droplet by id'
54
- def droplet(droplet_id)
55
- puts "`get droplet` called with params: #{droplet_id}, options: #{options}" if Docli.debug?
56
- drlet = Docli.client.droplets.find(id: droplet_id)
57
- puts "Droplet ID: #{drlet.id}"
58
- {
59
- name: drlet.name,
60
- ipv4: drlet.networks.v4.find { |v| v.type == 'public' }.ip_address,
61
- region: "#{drlet.region.name} (#{drlet.region.slug})",
62
- size: drlet.size_slug,
63
- status: drlet.status
64
- }.each do |k,v|
65
- puts "\t#{k}: #{v}"
66
- end
67
- end
68
-
69
- end
70
- end
@@ -1 +0,0 @@
1
- # User account information
@@ -1,10 +0,0 @@
1
- # List all domain on DO
2
-
3
- module Cmd
4
- class Domains
5
- def self.list_all_domains
6
- client = Cmd::Authen.client
7
- return client.domains.all
8
- end
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- module Docli
2
- class SubcommandBase < Thor
3
- def self.banner(command, namespace = nil, subcommand = false)
4
- "#{basename} #{subcommand_prefix} #{command.usage}"
5
- end
6
-
7
- def self.subcommand_prefix
8
- self.name.gsub(%r{.*::}, '').gsub(%r{^[A-Z]}) { |match| match[0].downcase }.gsub(%r{[A-Z]}) { |match| "-#{match[0].downcase}" }
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- module Docli
2
- module Utils
3
- class << self
4
- COLORIZE_MAPPING = {
5
- green: %w{active},
6
- red: %w{}
7
- }
8
- def colorize(text)
9
- color = COLORIZE_MAPPING.find { |color, values| values.include?(text) }
10
- color ? text.method(color[0]).call : text
11
- end
12
- end
13
- end
14
- end