@startuml

participant "System"
participant "LCM API"
participant "aws.py"
participant "common.py"
participant "utils.py"
participant "pf9 client"

note left
  title (*): /aws/clusters/{uuid}/platform_status
  description: retrives the status for the GIVEN cluster referenced by uuid
end note

System ->"LCM API" : Call '/aws/clusters'
note left
    Required inputs are:

    containers_subnet (string): subnet for pods
    services_subnet (string): subnet for service
    name (string): cluster name! Do we need to ask? Yes, I think so.
    region (string):
    keys_uuid (string): provider_uuid
    master_flavor (string): ?
    worker_flavor (string): ?
    num_masters: 0,
    num_workers: 0,
    availability_zone (string): US_EAST_1 etc
    vpc_id (string): VPC id,
    subnet_id (string): ?
    domain_id: "/hostedzone/Z2UI7MEFQ7QQJH",
    ssh_key (string):
end note

note right #Orange
    In case of cluster deployment on baremetal,
    we need different set of parameters. For e.g.
    we need list of authorized servers, tenant to
    be associated with cluster (thanks to the
    current limitation). Need to do little bit more
    here on PF9 side.
end note

"LCM API" -> "aws.py" : create_cluster(body, tenant='service', region, project)
activate "aws.py"
note left #Orange
    Using service tenant to create cluster, which is
    by a default choice.
end note

activate "utils.py"
"aws.py" -> "utils.py": get_pf9_client(tenant, region)
"utils.py" --> "aws.py": get_pf9_client(...)
deactivate "utils.py"

activate "common.py"
alt if region and project feeded
    "aws.py"->"common.py": get_cloud_provider_by_name(project, region)
else
    "aws.py"->"common.py": get_cloud_provider(provider_uuid)
end
    "common.py"-->"aws.py": returns provider

    "aws.py"->"common.py": get_region_by_name()
    "common.py"-->"aws.py": return region_obj
    "aws.py"->"common.py": get_flavors(region_obj, body)
    "common.py"-->"aws.py": get_flavors(...)

deactivate "common.py"

activate "utils.py"
"aws.py" -> "utils.py": validate_node_counts()
"utils.py" --> "aws.py":
"aws.py" -> "utils.py": validate container subnet
"utils.py" --> "aws.py":
"aws.py" -> "utils.py": validate service subnet
"utils.py" --> "aws.py":
"aws.py" -> "utils.py": retrieve VPC ID (from existing dict())
"utils.py" --> "aws.py":
"aws.py" -> "utils.py": pick VPC related attributes
"utils.py" --> "aws.py":
note over "utils.py"
   We do try to pick following attributes:
        - subnet (What is this, how is it relate to container or service subnet)
        - availability zone
        - domain_name
        - key pair
        - service_fqdn
        - external_dns
   Need to understand more in detail. What is it?
end note

alt
"utils.py" -> "pf9 client": create_aws_cluster(...)
else Exception occured
    "utils.py" -> "utils.py": return HTTP error
end

"utils.py" -> "common.py":  common.send_post_deploy_run_msg(cluster.uuid, region=region_obj.name)
note over  "utils.py"
    Creates a message and sends it to the uwsgi mule listener with the aim of
    creating a post deployment task for the cluster specified. If there is a
    failure to send the message raise a LcmException.
end note
"common.py" --> "utils.py":
deactivate "utils.py"

"aws.py" --> "LCM API": returns (cluster_id, HTTP status code 202)
deactivate "aws.py"
@enduml