Beispiel #1
0
    def email_ga_user_report_to_contact(self, context, start_date, end_date,
                                        cloudshell_username, email_address,
                                        email_title):
        """		
		:type context ResourceCommandContext
		:param context: 
		:param test_name: 
		:return: 
		"""
        api = CloudShellAPISession(
            host=context.connectivity.server_address,
            port=context.connectivity.cloudshell_api_port,
            token_id=context.connectivity.admin_auth_token,
            domain="Global")
        admin_email = api.GetUserDetails("admin").Email
        smtp_resource = api.FindResources('Mail Server',
                                          'SMTP Server').Resources[0]
        smtp_resource_details = api.GetResourceDetails(smtp_resource.Name)
        smtp_attributes = {
            attribute.Name: attribute.Value if attribute.Type != "Password"
            else api.DecryptPassword(attribute.Value).Value
            for attribute in smtp_resource_details.ResourceAttributes
        }
        smtp_client = SMTPClient(smtp_attributes["User"],
                                 smtp_attributes["Password"],
                                 smtp_resource_details.Address,
                                 smtp_attributes["Port"])
        report_content = self.generate_ga_user_report(context, start_date,
                                                      end_date,
                                                      cloudshell_username)
        if report_content:
            current_timestamp = datetime.datetime.strftime(
                datetime.datetime.now(), "%m-%d_%H-%M")
            filename = "GA_Report_" + current_timestamp + ".csv"
            with open(filename, 'w') as csv_file:
                csv_file.write(report_content)
            smtp_client.send_email(",".join([email_address,
                                             admin_email]), email_title,
                                   "See attached user activity report", False,
                                   [filename])
            return "User activity report emailed successfully"
        else:
            smtp_client.send_email(
                ",".join([email_address, admin_email]), email_title,
                "No activity reported to date for this user", False)
class CloudShellAPIHandler():
    def __init__(self, cloudshell_data):
        self.session = CloudShellAPISession(
            host=cloudshell_data.get('host'),
            username=cloudshell_data.get('username'),
            password=cloudshell_data.get('password'),
            domain=cloudshell_data.get('domain'))

    def get_all_possible_values_for_attribute_on_resource(
            self, resource_model, attribute_name):
        attribute_values = []
        all_resources_from_model = self.session.FindResources(
            resourceModel=resource_model).Resources
        for resource in all_resources_from_model:
            resource_details = self.session.GetResourceDetails(resource.Name)
            attr_value = filter(lambda x: x.Name == attribute_name,
                                resource_details.ResourceAttributes)[0]
            if attr_value not in attribute_values:
                attribute_values.append(attr_value.Value)
        return attribute_values
Beispiel #3
0
connectivityContext = json.loads(parameter["qualiConnectivityContext"])

global_inputs = {in_param["parameterName"]:in_param["value"] for in_param in reservationContext["parameters"]["globalInputs"]}
first_name = global_inputs["First Name"]
last_name = global_inputs["Last Name"]
email = global_inputs["email"].lower()
company = global_inputs["Company Name"]
phone = global_inputs["Phone number"]
owner_email = global_inputs["Quali Owner"]

new_username = email

api = CloudShellAPISession(host=connectivityContext["serverAddress"], token_id=connectivityContext["adminAuthToken"], domain=reservationContext["domain"])

# Get SMTP Details from Resource
smtp_resource = api.FindResources('Mail Server', 'SMTP Server').Resources[0]
smtp_resource_details = api.GetResourceDetails(smtp_resource.Name)
smtp_attributes = {attribute.Name: attribute.Value if attribute.Type != "Password" else api.DecryptPassword(attribute.Value).Value for attribute in smtp_resource_details.ResourceAttributes}
smtp_client = SMTPClient(smtp_attributes["User"], smtp_attributes["Password"], smtp_resource_details.Address, smtp_attributes["Port"], "*****@*****.**")
admin_email = api.GetUserDetails("admin").Email

# Create Domain
api.WriteMessageToReservationOutput(reservationContext["id"], "1. Creating New Domain")
domain_name = '.'.join(new_username.split('.')[:-1]).replace('@', '-')

if domain_name in [domain.Name for domain in api.GetResourceDetails("AWS us-east-1", True).Domains]:
	id_suffix = 1
	while domain_name + str(id_suffix) in [domain.Name for domain in api.GetResourceDetails("AWS us-east-1", True).Domains]: 
		id_suffix += 1
	domain_name = domain_name + str(id_suffix)
	api.WriteMessageToReservationOutput(reservationContext["id"], "The requested domain already exists, appending {} to new domain name, please contact system admin at [email protected]".format(id_suffix))
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()
Beispiel #5
0
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(resourceFamily='Deployed App', showAllDomains=domain == 'Global').Resources
                           if resource.FullPath is not None and hasattr(api.GetResourceDetails(resource.FullPath).VmDetails, 'UID')]
    resources_to_delete.extend([resource for resource in api.FindResources(resourceFamily='Generic App Family', showAllDomains=domain == 'Global').Resources
                                if resource.FullPath is not None and hasattr(api.GetResourceDetails(resource.FullPath).VmDetails, 'UID')])
    resources_to_delete.extend([resource for resource in api.FindResources(resourceFamily='Virtual Machine', showAllDomains=domain == 'Global').Resources
                                if resource.FullPath is not None and hasattr(api.GetResourceDetails(resource.FullPath).VmDetails, 'UID')])
    resources_to_delete.extend([resource for resource in api.FindResources(resourceFamily='Web Applications', showAllDomains=domain == 'Global').Resources
                                if resource.FullPath is not None and hasattr(api.GetResourceDetails(resource.FullPath).VmDetails, 'UID')])
    for resource in resources_to_delete:
        if not dry_run:
            api.DeleteResource(resource.FullPath)
        print("Deleted resource {}".format(resource.FullPath))

    api.Logoff()
from cloudshell.api.cloudshell_api import CloudShellAPISession

# start session
api = CloudShellAPISession(host="localhost", username="******", password="******", domain="Global")

# find resources in DB - specify models / family / attributes etc
all_resources = api.FindResources(resourceModel="Putshell").Resources
print(f"resource count found: {len(all_resources)}")
Beispiel #7
0
from cloudshell.api.cloudshell_api import CloudShellAPISession

user = "******"
password = "******"
server = "localhost"

TARGET_MODEL = "<MY_MODEL>"

api = CloudShellAPISession(host=server,
                           username=user,
                           password=password,
                           domain="Global")

duts = api.FindResources(resourceModel=TARGET_MODEL).Resources
Beispiel #8
0
from cloudshell.api.cloudshell_api import CloudShellAPISession

user = "******"
password = "******"
server = "localhost"
domain = "Global"

api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)

target_resources = api.FindResources(resourceModel="Ftpserver").Resources
my_ftp = target_resources[0]
ftp_details = api.GetResourceDetails(resourceFullPath=my_ftp.Name)
attrs = ftp_details.ResourceAttributes
model = ftp_details.ResourceModelName
target_attr = "{}.Golden Configs Folder".format(model)
golden_configs_val = [attr for attr in attrs if attr.Name == target_attr][0].Value
pass