Class: VMC::KNIFE::DataServiceManifestApplier
- Inherits:
-
Object
- Object
- VMC::KNIFE::DataServiceManifestApplier
- Defined in:
- lib/vmc_knife/vmc_knife.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#current_services ⇒ Object
Returns the value of attribute current_services.
-
#current_services_info ⇒ Object
Returns the value of attribute current_services_info.
-
#data_service_json ⇒ Object
Returns the value of attribute data_service_json.
Instance Method Summary collapse
-
#__set_current(current, current_services = nil, current_services_info = nil) ⇒ Object
Only for testing: inject json.
- #current ⇒ Object
- #delete ⇒ Object
- #execute ⇒ Object
-
#initialize(data_service, client, current_services = nil, current_services_info = nil) ⇒ DataServiceManifestApplier
constructor
A new instance of DataServiceManifestApplier.
-
#service_hash ⇒ Object
Returns the service manifest for the vendor.
- #updates_pending ⇒ Object
Constructor Details
#initialize(data_service, client, current_services = nil, current_services_info = nil) ⇒ DataServiceManifestApplier
Returns a new instance of DataServiceManifestApplier.
585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/vmc_knife/vmc_knife.rb', line 585 def initialize(data_service,client,current_services=nil,current_services_info=nil) @client = client if data_service.kind_of? Hash @data_service_json = data_service elsif data_service.kind_of? DataService @data_service_json = data_service.wrapped else raise "Unexpected type of object to describe the data_service #{data_service}" end raise "Can't find the name of the data_service" if @data_service_json['name'].nil? end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
584 585 586 |
# File 'lib/vmc_knife/vmc_knife.rb', line 584 def client @client end |
#current_services ⇒ Object
Returns the value of attribute current_services.
584 585 586 |
# File 'lib/vmc_knife/vmc_knife.rb', line 584 def current_services @current_services end |
#current_services_info ⇒ Object
Returns the value of attribute current_services_info.
584 585 586 |
# File 'lib/vmc_knife/vmc_knife.rb', line 584 def current_services_info @current_services_info end |
#data_service_json ⇒ Object
Returns the value of attribute data_service_json.
584 585 586 |
# File 'lib/vmc_knife/vmc_knife.rb', line 584 def data_service_json @data_service_json end |
Instance Method Details
#__set_current(current, current_services = nil, current_services_info = nil) ⇒ Object
Only for testing: inject json
610 611 612 613 614 |
# File 'lib/vmc_knife/vmc_knife.rb', line 610 def __set_current(current,current_services=nil,current_services_info=nil) @current = current @current_services = current_services @current_services_info = current_services_info end |
#current ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/vmc_knife/vmc_knife.rb', line 596 def current() return @current unless @current.nil? @current_services ||= @client.services @current_services_info ||= @client.services_info @current_services.each do |service| if service[:name] == @data_service_json['name'] @current = service break end end @current ||= Hash.new # that would be a new service. end |
#delete ⇒ Object
627 628 629 630 631 632 633 |
# File 'lib/vmc_knife/vmc_knife.rb', line 627 def delete() if current().empty? puts "The service #{@data_service_json['name']} does not exist." if VMC::Cli::Config.trace else client.delete_service(@data_service_json['name']) end end |
#execute ⇒ Object
621 622 623 624 625 626 |
# File 'lib/vmc_knife/vmc_knife.rb', line 621 def execute() return unless updates_pending service_man = service_hash() puts "Calling client.create_service #{@data_service_json['vendor']}, #{@data_service_json['name']}" client.create_service @data_service_json['vendor'], @data_service_json['name'] end |
#service_hash ⇒ Object
Returns the service manifest for the vendor. If the service vendor ( = type) is not provided by this vcap install An exception is raised.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/vmc_knife/vmc_knife.rb', line 638 def service_hash() searched_vendor = @data_service_json['vendor'] current() # in the vmc.rb code there is a comment that says 'FIXME!' @current_services_info.each do |service_type, value| value.each do |vendor, version| version.each do |version_str, service_descr| if searched_vendor == service_descr[:vendor] return { "type" => service_descr[:type], "tier" => 'free', "vendor" => searched_vendor, "version" => version_str } end end end end raise "vcap does not provide a data-service which vendor is #{searched_vendor}" end |
#updates_pending ⇒ Object
615 616 617 618 619 620 |
# File 'lib/vmc_knife/vmc_knife.rb', line 615 def updates_pending() vendor = @data_service_json['vendor'] name = @data_service_json['name'] sh = service_hash() return "Create data-service #{name} vendor #{vendor}" if current().empty? end |