Class: Storazzo::Media::Storazzo::Media::GcsBucket
- Inherits:
-
AbstractRicDisk
- Object
- AbstractRicDisk
- Storazzo::Media::Storazzo::Media::GcsBucket
- Extended by:
- Common
- Defined in:
- lib/storazzo/media/gcs_bucket.rb
Constant Summary
Constants included from Colors
Instance Attribute Summary collapse
-
#project_id ⇒ Object
Returns the value of attribute project_id.
Attributes inherited from AbstractRicDisk
Class Method Summary collapse
-
.list_all ⇒ Object
(config = nil).
-
.list_all_with_type ⇒ Object
(config = nil).
- .list_available_buckets(_opts = {}) ⇒ Object
Instance Method Summary collapse
- #_autodetect_project_id ⇒ Object
-
#initialize(local_mount, project_id = nil) ⇒ GcsBucket
constructor
A new instance of GcsBucket.
Methods included from Common
bug, deb, err, fatal, if_deb?, linux?, mac?, ppp, pverbose, warn
Methods included from Colors
#azure, #blue, #deb2, #gray, #green, #orange, #pgreen, #pred, #purple, #pwhite, #pyellow, #red, #white, #yellow
Methods inherited from AbstractRicDisk
DirFactory, abstract_class_mandatory_methods, #check_implemented_correctly, default_stats_filename, #get_local_mountpoint, #parse, #parse_block_storage_folder, #stats_file_smart_fullpath, #stats_filename_default_fullpath, super_duper_list_all_with_type, #to_s, #to_verbose_s, #unique_id, #validate, #writeable?
Constructor Details
#initialize(local_mount, project_id = nil) ⇒ GcsBucket
Returns a new instance of GcsBucket.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 15 def initialize(local_mount, project_id = nil) deb '[Storazzo::Media::GcsBucket] initialize' @local_mountpoint = File.(local_mount) @description = "MountPoint in '#{local_mount}' pointing at TODO with mount options = TODO" project_id ||= _autodetect_project_id @project_id = project_id raise 'Sorry local mount doesnt exist!' unless File.exist?(@local_mountpoint) @wr = writeable? # File.writable?(stats_filename_default_fullpath) # .writeable? stats_file_smart_fullpath begin super(local_mount) rescue StandardError "SUPER_ERROR(#{local_mount}): #{$ERROR_INFO}" end end |
Instance Attribute Details
#project_id ⇒ Object
Returns the value of attribute project_id.
13 14 15 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 13 def project_id @project_id end |
Class Method Details
.list_all ⇒ Object
(config = nil)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 37 def self.list_all # get lisrts from Config singletone # puts " self.list_all: loading config " config ||= Storazzo::RicDiskConfig.instance # # ).get_config config.load # in case I need to load it for the first time # puts config['Config']['AdditionalMountDirs'] # puts "TODO see config: #{config}" # [42, 43] # deb config.get_local_folders # TODO pverbose true, "TODO(ricc): also add gsutil ls. For that please use the new 'list_all_with_type' (Id refactor it but Im afraid of leaving bad code dangling so before a proper refactor lets implement both side by side" config.get_bucket_paths end |
.list_all_with_type ⇒ Object
(config = nil)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 54 def self.list_all_with_type deb 'GCS::list_all_with_type() -- pull config' config ||= Storazzo::RicDiskConfig.instance config.load # in case I need to load it for the first time # puts "GCS::list_all_with_type() -- TODO(ricc): also add gsutil ls" # getFromConfig deb "I'm now returning a 'complex' array to tell the caller what kind of element they're getting, eg: GCS from Config Yaml, vs GCS from gsutil ls " list_from_config_with_type = config.get_bucket_paths.map do |path| [:config_gcs_bucket, path] end ret_list = list_from_config_with_type if config.gcs_enabled? # should be if GCS enabled :) project_id # so I concatenate Apples with Bananas with names # ret_list += list_available_buckets(config.project_id).map { |path| ret_list += list_available_buckets.map do |path| [:gsutil_ls_gcs_bucket, path] end else deb 'list_all_with_type(): empty project id. Skipping' end ret_list end |
.list_available_buckets(_opts = {}) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 78 def self.list_available_buckets(_opts = {}) # project_id = opts.fetch :project_id, nil # list_of_buckets = `gsutil ls --project '#{project_id}'`.chomp.split("\n") list_of_buckets = `gsutil ls`.chomp.split("\n") deb "list_of_buckets: #{list_of_buckets}" list_of_buckets end |
Instance Method Details
#_autodetect_project_id ⇒ Object
32 33 34 |
# File 'lib/storazzo/media/gcs_bucket.rb', line 32 def _autodetect_project_id 'todo-my-project-id-123' # TODO: fix end |