def get_domain_blueprints(domain): """ get blueprint data from api and send back as JSON to be consumed by AJAX request from client """ # simulate mock command time sleep(3) try: api = CloudShellAPISession(host=host, username=user, password=password, domain=domain) blueprints_data = api.GetDomainDetails(domain).Topologies except Exception as e: exc_msg = "Error occurred making cloudshell api call: {}".format( str(e)) response_data = {"msg": exc_msg, "code": 400} json_response_data = json.dumps(response_data) return Response(json_response_data, status=400, mimetype='application/json') blueprints_data_dicts = [obj.__dict__ for obj in blueprints_data] return jsonify(blueprints_data_dicts)
from cloudshell.api.cloudshell_api import CloudShellAPISession TARGET_RESOURCES = [ "mock_3/Port 4", "my Cisco Switch/Chassis 0/FastEthernet0-6" ] # api session details user = "******" password = "******" server = "localhost" api = CloudShellAPISession(host=server, username=user, password=password, domain="Global") domain_blueprints = api.GetDomainDetails("Global").Topologies pass
api.AddNewUser(username=new_username, password=generated_password, email=email, isActive=True) api.UpdateUsersLimitations([UserUpdateRequest(Username=email, MaxConcurrentReservations="2", MaxReservationDuration=str(4*60))]) # Create Group and add to domain api.WriteMessageToReservationOutput(reservationContext["id"], "3. Configuring new domain permissions") new_group_name = domain_name api.AddNewGroup(groupName=new_group_name, description="Regular Users Group for " + domain_name + " domain", groupRole="Regular") api.AddUsersToGroup(usernames=[new_username, owner_email], groupName=new_group_name) api.AddGroupsToDomain(domainName=domain_name, groupNames=[new_group_name]) # Import content api.WriteMessageToReservationOutput(reservationContext["id"], "4. Importing Content to new domain") api_root_url = 'http://{0}:{1}/Api'.format(connectivityContext["serverAddress"], connectivityContext["qualiAPIPort"]) blueprints_to_export = [blueprint.Name for blueprint in api.GetDomainDetails("Master").Topologies] blueprints_to_export_full_names = ["Master topologies\\" + blueprint for blueprint in blueprints_to_export] api.AddTopologiesToDomain(domain_name, blueprints_to_export_full_names) # TODO: Change hardcoded CP name to dynamically assumed name api.AddResourcesToDomain(domain_name, ["AWS us-east-1"]) login_result = requests.put(api_root_url + "/Auth/Login", {"token": connectivityContext["adminAuthToken"], "domain": "Master"}) master_domain_authcode = "Basic " + login_result.content[1:-1] export_result = requests.post(api_root_url + "/Package/ExportPackage", {"TopologyNames": blueprints_to_export}, headers={"Authorization": master_domain_authcode}) login_result = requests.put(api_root_url + "/Auth/Login", {"token": connectivityContext["adminAuthToken"], "domain": domain_name}) new_domain_authcode = "Basic " + login_result.content[1:-1] import_result = requests.post(api_root_url + "/Package/ImportPackage", headers={"Authorization": new_domain_authcode}, files={'QualiPackage': export_result.content}) topologies_in_new_domain = [blueprint.Name for blueprint in api.GetDomainDetails(domain_name).Topologies]
from cloudshell.api.cloudshell_api import CloudShellAPISession, AttributeNameValue from os import environ as parameter import json connectivity = json.loads(parameter["QUALICONNECTIVITYCONTEXT"]) reservationDetails = json.loads(parameter["RESERVATIONCONTEXT"]) resourceDetails = json.loads(parameter["RESOURCECONTEXT"]) domains_to_scan = parameter["domains"].split(',') dry_run = parameter["dry_run"] != "False" for domain in domains_to_scan: api = CloudShellAPISession(host=connectivity["serverAddress"], token_id=connectivity["adminAuthToken"], domain=domain) domain_details = api.GetDomainDetails(domain) resources_to_delete = [resource for resource in api.FindResources(attributeValues=[AttributeNameValue('Temp Resource', "Yes")], showAllDomains=domain == 'Global').Resources if resource.FullPath is not None] for resource in resources_to_delete: if not dry_run: api.DeleteResource(resource.FullPath) print("Deleted resource {}".format(resource.FullPath)) api.Logoff()
description="Regular Users Group for " + domain_name + " domain", groupRole="Regular") api.AddUsersToGroup(usernames=[new_username, owner_email], groupName=new_group_name) api.AddGroupsToDomain(domainName=domain_name, groupNames=[new_group_name]) # Import content api.WriteMessageToReservationOutput(reservationContext["id"], "Importing Content to new domain") api_root_url = 'http://{0}:{1}/Api'.format( connectivityContext["serverAddress"], connectivityContext["qualiAPIPort"]) blueprints_to_export = [ blueprint.Name for blueprint in api.GetDomainDetails("Lead Master").Topologies ] blueprints_to_export_full_names = [ "Lead Master topologies\\" + blueprint for blueprint in blueprints_to_export ] api.AddTopologiesToDomain(domain_name, blueprints_to_export_full_names) # TODO: Change hardcoded CP name to dynamically assumed name api.AddResourcesToDomain(domain_name, ["AWS us-east-1"]) login_result = requests.put(api_root_url + "/Auth/Login", { "token": connectivityContext["adminAuthToken"], "domain": "Lead Master" }) master_domain_authcode = "Basic " + login_result.content[1:-1]
from cloudshell.api.cloudshell_api import CloudShellAPISession # set domain values SOURCE_DOMAIN = "QA" TARGET_DOMAIN = "SE" # start session api = CloudShellAPISession(host="localhost", username="******", password="******", domain="Global") # find resources of target model domain_details = api.GetDomainDetails(domainName=TARGET_DOMAIN) resources = domain_details.Resources resource_names = [x.Name for x in resources] blueprints = domain_details.Topologies blueprint_names = [x.Name for x in blueprints] # add resources print(f"adding {len(resources)} resources") api.AddResourcesToDomain(domainName=TARGET_DOMAIN, resourcesNames=resource_names, includeDecendants=True) print("adding topologies") api.AddTopologiesToDomain(domainName=TARGET_DOMAIN, topologyNames=blueprint_names) print("script done")