Class List Method List File List

# Class: ServiceManager

Inherits:
  Object
  - Object
  - ServiceManager
  show all
Defined in:
  /build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb

## Overview

Manages all the services on a management node.

## Instance Attribute Summary (collapse)

- - (Object) instance_name readonly

  Returns the value of attribute instance_name.

- - (Object) node_id readonly

  Returns the value of attribute node_id.

- - (Object) psc readonly

  Returns the value of attribute psc.

- - (Object) vapi_config readonly

  Returns the value of attribute vapi_config.

- - (Object) vapi_session readonly

  Returns the value of attribute vapi_session.

- - (Object) vapi_session_id readonly

  Returns the value of attribute vapi_session_id.

- - (Object) vapi_url readonly

  Returns the value of attribute vapi_url.

- - (Object) vim_content readonly

  Returns the value of attribute vim_content.

- - (Object) vim_sc readonly

  Returns the value of attribute vim_sc.

- - (Object) vim_url readonly

  Returns the value of attribute vim_url.

- - (Object) vim_uuid readonly

  Returns the value of attribute vim_uuid.

## Class Method Summary (collapse)

- + (Object) disconnect
- + (Object) get_instance(psc, node_id)

## Instance Method Summary (collapse)

- - (Object) connect
- - (Object) disconnect
- - (ServiceManager) initialize(node_id, psc) constructor

  Constructs a new instance.

## Constructor Details

### - (`ServiceManager`) initialize(node_id, psc)

Constructs a new instance.

    53
    54
    55
    56
    57
    58
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 53

    def initialize(node_id, psc)
        @node_id = node_id
        @psc = psc
        raise 'Node id is required' if node_id.nil?
        raise 'Platform Service Controller is required' if psc.nil?
    end

## Instance Attribute Details

### - (`Object`) instance_name (readonly)

Returns the value of attribute instance_name

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def instance_name
      @instance_name
    end

### - (`Object`) node_id (readonly)

Returns the value of attribute node_id

    47
    48
    49
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 47

    def node_id
      @node_id
    end

### - (`Object`) psc (readonly)

Returns the value of attribute psc

    47
    48
    49
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 47

    def psc
      @psc
    end

### - (`Object`) vapi_config (readonly)

Returns the value of attribute vapi_config

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vapi_config
      @vapi_config
    end

### - (`Object`) vapi_session (readonly)

Returns the value of attribute vapi_session

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vapi_session
      @vapi_session
    end

### - (`Object`) vapi_session_id (readonly)

Returns the value of attribute vapi_session_id

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vapi_session_id
      @vapi_session_id
    end

### - (`Object`) vapi_url (readonly)

Returns the value of attribute vapi_url

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vapi_url
      @vapi_url
    end

### - (`Object`) vim_content (readonly)

Returns the value of attribute vim_content

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vim_content
      @vim_content
    end

### - (`Object`) vim_sc (readonly)

Returns the value of attribute vim_sc

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vim_sc
      @vim_sc
    end

### - (`Object`) vim_url (readonly)

Returns the value of attribute vim_url

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vim_url
      @vim_url
    end

### - (`Object`) vim_uuid (readonly)

Returns the value of attribute vim_uuid

    48
    49
    50
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 48

    def vim_uuid
      @vim_uuid
    end

## Class Method Details

### + (`Object`) disconnect

    35
    36
    37
    38
    39
    40
    41
    42
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 35

    def disconnect
        if @instances
            @instances.values.each { |sm|
                Sample.log.info "Disconnecting service manager for node id: #{sm.node_id}"
                sm.disconnect()
            }
        end
    end

### + (`Object`) get_instance(psc, node_id)

    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 22

    def get_instance(psc, node_id)
        @instances ||= {}

        Sample.log.info "Getting service manager for node id: #{node_id}"
        if @instances[node_id].nil?
            service_manager = ServiceManager.new(node_id, psc)
            Sample.log.info "Connecting service manager for node id: #{node_id}"
            service_manager.connect()
            @instances[node_id] = service_manager
        end
        return @instances[node_id]
    end

## Instance Method Details

### - (`Object`) connect

    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 60

    def connect
        @instance_name = psc.lookup_service_helper.
            get_mgmt_node_instance_name(node_id)

        # discover the service endpoints from the lookup service on the PSC
        @vapi_url = psc.lookup_service_helper.find_vapi_url(node_id)
        @vim_url = psc.lookup_service_helper.find_vim_url(node_id)
        raise 'VAPI URL is required (could not be looked up)' if vapi_url.nil?
        raise 'VIM URL is required (could not be looked up)' if vim_url.nil?

        # login to vAPI endpoint
        Sample.log.info "Connecting to vapi url: #{vapi_url}"
        @vapi_config = VAPI::Bindings::VapiConfig.new(vapi_url)
        vapi_config.set_security_context(psc.bearer_token_context)
        @vapi_session = Com::Vmware::Cis::Session.new(vapi_config)
        @vapi_session_id = vapi_session.create()
        vapi_config.set_security_context(
            VAPI::Security.create_session_security_context(vapi_session_id))

    =begin
        # pyvmomi
        # extract the host from the vim url
        vim_host = get_url_host(self.vim_url)
        raise 'VIM host is required (could not be looked up)' if vim_host.nil?

        @vim_sc = SmartConnect(host=vim_host,
                               user=self.psc.ssousername,
                               pwd=self.psc.ssopassword)
        #assert vim_sc is not None
        raise 'SmartConnect is required (could not be created)' if vim_sc.nil?

        # retrieve the service content
        @vim_content = vim_sc.RetrieveContent()
        assert vim_content is not None
        @vim_uuid = vim_content.about.instanceUuid
    =end
    end

### - (`Object`) disconnect

    98
    99
    100
    101
    102
    103
    104
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/framework/service_manager.rb', line 98

    def disconnect
        Sample.log.info "Disconnecting the session: #{vapi_session_id}"
        vapi_session.delete()
    =begin
        Disconnect(vim_sc)
    =end
    end