def delete_all_records(self, context): """ :param ResourceCommandContext context: :return: """ DNS_ATTRIBUTE = "DNS Name" logger = self._get_logger(context) logger.info("Starting delete all records") cs_api = CloudShellAPISession( host=context.connectivity.server_address, token_id=context.connectivity.admin_auth_token, domain="Global") reservation_details = cs_api.GetReservationDetails( context.reservation.reservation_id).ReservationDescription for resource in reservation_details.Resources: attribute_name = "{}.{}".format(resource.ResourceModelName, DNS_ATTRIBUTE) try: result = cs_api.GetAttributeValue(resource.Name, attribute_name).Value if result: try: self.delete_host_record(context, result) except Exception as e: logger.error( f"Error deleting record for '{result}'. error: {e}" ) except Exception as e: logger.info( f"Error getting DNS Attribute '{DNS_ATTRIBUTE}' on resource '{resource.Name}'. Error: {e}" )
from cloudshell.api.cloudshell_api import CloudShellAPISession user = "******" password = "******" server = "localhost" domain = "Global" api = CloudShellAPISession(host=server, username=user, password=password, domain=domain) MY_STRONG_PASSWORD = "******" # setting the password api.SetAttributeValue(resourceFullPath="mock1", attributeName="Putshell.Password", attributeValue=MY_STRONG_PASSWORD) # getting the encrypted password string from the resource encrypted_password_val = api.GetAttributeValue( resourceFullPath="mock1", attributeName="Putshell.Password").Value print("encrypted: " + encrypted_password_val) # to decrypt use api decrypted = api.DecryptPassword(encryptedString=encrypted_password_val).Value print("decrypted: " + decrypted)