def add_node(env, ip_address, t_ip_address, username, password): # POST # https://18.232.246.131/mgmt/cm/shared/esmgmt/add-node # {"address":"35.173.117.194","bigIqUsername":"******","bigIqPassword":"******","httpPort":9200,"transportAddress":"10.1.1.230","transportPort":9300,"zone":"default"} # Returns something like # {"address":"35.173.117.194","transportAddress":"10.1.1.230","httpPort":"9200","transportPort":"9300","zone":"default","bigIqUsername":"******","bigIqPassword":"******","id":"0d043d33-7619-404b-b184-58aa5c8ef0cf","status":"STARTED","userReference":{"link":"https://localhost/mgmt/shared/authz/users/admin"},"identityReferences":[{"link":"https://localhost/mgmt/shared/authz/users/admin"}],"ownerMachineId":"1f7b1aa0-8fa6-498a-bae6-9c7bb9318435","taskWorkerGeneration":1,"generation":1,"lastUpdateMicros":1525977026342300,"kind":"cm:shared:esmgmt:add-node:esaddnodetaskstate","selfLink":"https://localhost/mgmt/cm/shared/esmgmt/add-node/0d043d33-7619-404b-b184-58aa5c8ef0cf"} node_res = util.req(env['base_url'] + "cm/shared/esmgmt/add-node", env['auth'], method="POST", json={ "address": ip_address, "bigIqUsername": username, "bigIqPassword": password, "httpPort": 9200, "transportAddress": t_ip_address, "transportPort": 9300, "zone": "default" }) # Won't reach this point w/o 200 OK return node_res.json()['id']
def poll_for_result(env, uuid): # Based on a the UUID returned from add_node poll this endpoint until something happens # GET # https://18.232.246.131/mgmt/cm/shared/esmgmt/add-node/0d043d33-7619-404b-b184-58aa5c8ef0cf # Returns something like this in progress # {"address":"35.173.117.194","bigIqPassword":"","bigIqUsername":"******","cluster":{"clusterName":"39d30597-4d09-419b-ad64-450e5ba01edf","primaryMachineId":"1f7b1aa0-8fa6-498a-bae6-9c7bb9318435","clusterIndexCollectionReference":{"link":"https://localhost/mgmt/cm/shared/esmgmt/cluster/3fa8567f-b10d-49d1-8e50-09d8741ada4e/indices","isSubcollection":true},"nodes":[{"machineId":"1f7b1aa0-8fa6-498a-bae6-9c7bb9318435","allowData":false,"allowMaster":true,"httpAddress":"127.0.0.1","httpPort":"9200","transportAddress":"10.1.1.169/24","transportPort":"9300","zone":"default","mlockall":false,"repo":"/var/config/rest/elasticsearch/data","generation":0,"lastUpdateMicros":0}],"numberOfDataNodes":0,"id":"3fa8567f-b10d-49d1-8e50-09d8741ada4e","generation":1,"lastUpdateMicros":1525976702076194,"kind":"cm:shared:esmgmt:cluster:esclusterinstancestate","selfLink":"https://localhost/mgmt/cm/shared/esmgmt/cluster/3fa8567f-b10d-49d1-8e50-09d8741ada4e"},"currentStep":"CHECK_DEVICE_STATUS_ADD","deviceReference":{"link":"https://localhost/mgmt/shared/resolver/device-groups/cm-esmgmt-logging-group/devices/f5258bfe-b583-439e-ab92-1d063e3366d1"},"deviceState":{"uuid":"f5258bfe-b583-439e-ab92-1d063e3366d1","deviceUri":"https://35.173.117.194:443","machineId":"f5258bfe-b583-439e-ab92-1d063e3366d1","state":"PENDING","address":"35.173.117.194","httpsPort":443,"properties":{"isLoggingNode":true},"groupName":"cm-esmgmt-logging-group","generation":1,"lastUpdateMicros":1525977026535394,"kind":"shared:resolver:device-groups:restdeviceresolverdevicestate","selfLink":"https://localhost/mgmt/shared/resolver/device-groups/cm-esmgmt-logging-group/devices/f5258bfe-b583-439e-ab92-1d063e3366d1"},"generation":5,"httpPort":"9200","id":"0d043d33-7619-404b-b184-58aa5c8ef0cf","identityReferences":[{"link":"https://localhost/mgmt/shared/authz/users/admin"}],"kind":"cm:shared:esmgmt:add-node:esaddnodetaskstate","lastUpdateMicros":1525977028708833,"ownerMachineId":"1f7b1aa0-8fa6-498a-bae6-9c7bb9318435","selfLink":"https://localhost/mgmt/cm/shared/esmgmt/add-node/0d043d33-7619-404b-b184-58aa5c8ef0cf","startDateTime":"2018-05-10T11:30:26.360-0700","status":"STARTED","transportAddress":"10.1.1.230","transportPort":"9300","userReference":{"link":"https://localhost/mgmt/shared/authz/users/admin"},"username":"******","zone":"default"} i = 0 while i < 120: add_node_res = util.req( env['base_url'] + "cm/shared/esmgmt/add-node/" + uuid, env['auth']) status = add_node_res.json()['status'] if status == "FINISHED": break elif status == "FAILED": print("") print("Node addition failed with:") print(add_node_res.json()['errorMessage']) sys.exit(1) util.print_partial(".") time.sleep(2) i += 2
def req(url, json=None, method="GET", auth=None, verify=True): return util.req(url, auth or AUTH, json=json, method=method, verify=verify)
def poll_pipeline(expected_status, key, auth): print("Waiting for " + expected_status) count = 0 while True: count += 1 res = util.req( "https://localhost/mgmt/shared/pipeline/manager/cm-device-licensing-pool-purchased-pool-licenses", auth, method="POST", json={ "multiStageQueryRequest": { "repeatLastStageUntilTerminated": False, "queryParamsList": [{ "description": "aggregation", "managedPipelineWorkerName": "aggregator-pipe", "jsonContext": { "resourceUriPathTail": "" }, "pipelineAction": "DATA_RETRIEVAL", "runStageInternally": False, "jsonOutput": { "items": [ "https://localhost/mgmt/cm/device/licensing/pool/purchased-pool/licenses", "https://localhost/mgmt/cm/device/licensing/pool/utility/licenses", "https://localhost/mgmt/cm/device/licensing/pool/volume/licenses", "https://localhost/mgmt/cm/device/licensing/pool/websafe/licenses", "https://localhost/mgmt/cm/device/licensing/pool/initial-activation?%24filter=((kind%20eq%20'cm%3Adevice%3Alicensing%3Apool%3Ainitial-activation%3Ainitialactivationworkeritemstate')%20and%20(status%20ne%20'READY'))", "https://localhost/mgmt/cm/device/licensing/pool/regkey/licenses" ] } }, { "description": "sort", "managedPipelineWorkerName": "sort-pipe", "jsonContext": { "sortParamsList": [{ "sortField": "name", "sortOrder": "ASCENDING" }] } }, { "description": "pagination", "managedPipelineWorkerName": "page-pipe", "jsonContext": { "skip": 0, "top": 150 }, "pipelineAction": "DATA_PROCESSING", "runStageInternally": False }] }, "getOnPostAndTerminate": True }) res = res.json() try: status = res["items"][0][key] except KeyError: status = None if count >= 120: print("Timed out waiting or status " + expected_status) sys.exit(1) if not res or not res["items"]: time.sleep(1) elif status == expected_status: return res elif status == "ACTIVATION_FAILED": print("Activation failed") sys.exit(1) else: time.sleep(1)
def deploy_application(ssg_id, node_ip, elb_name, elb_dns_name): util.req( "http://localhost:8100/cm/global/tasks/apply-template", None, method="POST", json={ "resources": { "ltm:virtual:90735960bf4b": [{ "parameters": { "name": "default_vs" }, "parametersToRemove": [], "subcollectionResources": { "profiles:78b1bcfdafad": [{ "parameters": {}, "parametersToRemove": [] }], "profiles:2f52acac9fde": [{ "parameters": {}, "parametersToRemove": [] }], "profiles:9448fe71611e": [{ "parameters": {}, "parametersToRemove": [] }] } }], "ltm:pool:8bc5b256f9d1": [{ "parameters": { "name": "pool_0" }, "parametersToRemove": [], "subcollectionResources": { "members:dec6d24dc625": [{ "parameters": { "port": "80", "nodeReference": { "link": "#/resources/ltm:node:c072248f8e6a/" + node_ip, "fullPath": "# " + node_ip } }, "parametersToRemove": [] }] } }], "ltm:node:c072248f8e6a": [{ "parameters": { "name": node_ip, "address": node_ip }, "parametersToRemove": [] }], "ltm:monitor:http:18765a198150": [{ "parameters": { "name": "monitor-http" }, "parametersToRemove": [] }], "ltm:profile:client-ssl:78b1bcfdafad": [{ "parameters": { "name": "clientssl" }, "parametersToRemove": [] }], "ltm:profile:http:2f52acac9fde": [{ "parameters": { "name": "profile_http" }, "parametersToRemove": [] }] }, "addAnalytics": True, "domains": [{ "domainName": elb_dns_name }], "configSetName": "apache-test-application", "ssgReference": { "link": "https://localhost/mgmt/cm/cloud/service-scaling-groups/" + ssg_id }, "awsLoadBalancer": { "name": elb_name, "description": "", "listeners": [{ "loadBalancerPort": 80, "loadBalancerProtocol": "TCP", "instancePort": 80, "instanceProtocol": "TCP" }, { "loadBalancerPort": 443, "loadBalancerProtocol": "TCP", "instancePort": 443, "instanceProtocol": "TCP" }] }, "subPath": "apache-test-application", "templateReference": { "link": "https://localhost/mgmt/cm/global/templates/10e8d657-ed1c-3cc9-962d-f291ef02512e" }, "mode": "CREATE" })
def get_ssg_reference(): return util.req("http://localhost:8100/cm/cloud/service-scaling-groups/", None).json()