Class List Method List File List

# Class: ConnectionWorkflow

Inherits:
  SampleBase
  - Object
  - SampleBase
  - ConnectionWorkflow
  show all
Defined in:
  /build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb

## Constant Summary

TITLE =

      'vAPI Connection Workflow'

DESCRIPTION =

      <<EOL
      Demonstrates vAPI connection and service initialization callflow:
          Step 1: Setup the required URLs using the LookupServiceHelper utility.
          Step 2: Connect to the SSO URL and retrieve the SAML token.
          Step 3: Use the SAML token to login to vAPI service endpoint.
      EOL

### Constants inherited from SampleBase

SampleBase::LOG_LEVELS

## Instance Attribute Summary (collapse)

- - (Object) session_id readonly

  sample config properties.

- - (Object) session_svc readonly

  sample config properties.

- - (Object) sso_url readonly

  sample config properties.

- - (Object) vapi_config readonly

  sample config properties.

- - (Object) vapi_url readonly

  sample config properties.

### Attributes inherited from SampleBase

#description, #log, #ls_ip, #ls_url, #mgmt_node_id, #mgmt_node_index, #mgmt_node_name, #multiple_mgmt_node, #option_parser, #options, #sso_password, #sso_username, #title, #use_supporters

## Instance Method Summary (collapse)

- - (Object) cleanup
- - (Object) execute
- - (ConnectionWorkflow) initialize constructor

  Constructs a new instance.

- - (Object) setup

### Methods inherited from SampleBase

#main

## Constructor Details

### - (`ConnectionWorkflow`) initialize

Constructs a new instance.

    30
    31
    32
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 30

    def initialize
        super(TITLE, DESCRIPTION, false)
    end

## Instance Attribute Details

### - (`Object`) session_id (readonly)

sample config properties

    27
    28
    29
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 27

    def session_id
      @session_id
    end

### - (`Object`) session_svc (readonly)

sample config properties

    27
    28
    29
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 27

    def session_svc
      @session_svc
    end

### - (`Object`) sso_url (readonly)

sample config properties

    27
    28
    29
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 27

    def sso_url
      @sso_url
    end

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

sample config properties

    27
    28
    29
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 27

    def vapi_config
      @vapi_config
    end

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

sample config properties

    27
    28
    29
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 27

    def vapi_url
      @vapi_url
    end

## Instance Method Details

### - (`Object`) cleanup

    75
    76
    77
    78
    79
    80
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 75

    def cleanup
        unless session_id.nil?
            log.info "Disconnect vAPI session ..."
            session_svc.delete()
        end
    end

### - (`Object`) execute

    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 57

    def execute
        log.info "Getting SSO token (#{sso_url})..."
        sso = SSO::Connection.new(sso_url).login(sso_username, sso_password)
        token = sso.request_bearer_token()
        vapi_config.set_security_context(
            VAPI::Security.create_saml_bearer_security_context(token.to_s))

        # Get the Session Service
        @session_svc = Com::Vmware::Cis::Session.new(vapi_config)

        log.info "Login to VAPI endpoint (#{vapi_url}) using token..."
        @session_id = session_svc.create()

        log.info "Got the Session Id: " + session_id
        vapi_config.set_security_context(
            VAPI::Security.create_session_security_context(session_id))
    end

### - (`Object`) setup

    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    # File '/build/mts/release/bora-4571906/vcsuite-sdks/ruby/samples/lib/sample/workflow/connection_workflow.rb', line 34

    def setup
        lookup_service_helper = LookupServiceHelper.new(self)
        Sample.log.info "Connecting to lookup service: #{lookup_service_helper.soap_url}"
        @sso_url = lookup_service_helper.find_sso_url()

        if mgmt_node_id
            @vapi_url = lookup_service_helper.find_vapi_url(mgmt_node_id)
            if vapi_url.nil?
                vapi_urls = lookup_service_helper.find_vapi_urls()
                report_error "management node with id (#{mgmt_node_id}) not found; try one of:\n#{vapi_urls}"
            end
        else
            vapi_urls = lookup_service_helper.find_vapi_urls()
            if mgmt_node_index < vapi_urls.values.size
                @vapi_url = vapi_urls.values[mgmt_node_index]
            else
                report_error "management node index (#{mgmt_node_index}) not valid; try an index < #{vapi_urls.size}"
            end
        end

        @vapi_config = VAPI::Bindings::VapiConfig.new(vapi_url)
    end