コード例 #1
0
ファイル: az_cmd.py プロジェクト: narayana1043/Bigdata
 def setup(self, cloud="cloud=chameleon"):
     
     self.cloud = cloud
     print "Ignore Error: \n Please define a key first, e.g.: cm key add --ssh <keyname> \n " \
           "-- If key has been successfully added into the database and uploaded into the cloud \n" \
           "Ignore Error: \n problem uploading key veera to cloud chameleon: Key pair 'veera' already exists.\n " \
           "******************************************************************************************************"
     result = Shell.cm("reset")
     print result
     result = Shell.cm("key add --ssh")
     print result
     result = Shell.cm("key", "upload")
     print result
     result = Shell.cm("default", self.cloud)
     print result
     result = Shell.cm("refresh", "on")
     print result
コード例 #2
0
ファイル: az.py プロジェクト: naveenkumar2703/Miscellaneous
    def do_delete(self, names):

        names = str(names).split(' ')
        for name in names:
            delete_machine = "delete " + name
            print delete_machine
            result = Shell.cm("vm", delete_machine)
            print result
コード例 #3
0
ファイル: az_cmd.py プロジェクト: narayana1043/Bigdata
    def do_boot(self, n):
    
        self.floating_ip_list = []
        self.static_ip_list = []
        try:
        
            for i in range(int(n)):
    
                print "Starting to boot Virtual Machine : ",i+1
                Shell.cm("vm", "boot --secgroup=naveen-def")
                fip_result = Shell.cm("vm", "ip assign")            # floating IP
                floating_ip = fip_result.split(' ')[-2][:-6]
                
                try:
                
                    IP(floating_ip)
                    # the below cmd is the "cm vm ip show" as ip is not getting updated automatically in the DB
                    Shell.cm("vm", "ip assign")
                    
                    while True:
                        
                        sip_result = Shell.cm("vm", "ip show")          # static IP
                        static_ip = sip_result.split("\n")[3].split(' ')[3]
                        if IP(static_ip):
                            
                            break
                    
                except:
                
                    print "floating IP error encountered"
                    print "Stopping to create further VMs"
                    break
    
                self.floating_ip_list.append(floating_ip)
                self.static_ip_list.append(static_ip)
        
        except ValueError:
            
            self.help_boot()

        if self.floating_ip_list == []:
            
            print "No VMs created"
        
        else:
            
            print "Returning IPs of VMs created"
            print "Floating IPs list    :",self.floating_ip_list
            print "Static IPs list      :",self.static_ip_list
            print "wirting IPs to respective files ..."
        
            HW = HostsWriter()
            HW.writeIPs(staticIPs=self.static_ip_list, floatingIPs=self.floating_ip_list)
            
            # starting ansible
            if os.path.exists(os.environ['HOME']+'/.ssh/known_hosts'):
                os.remove(os.environ['HOME']+'/.ssh/known_hosts')
                
            print "Running the ansible-playbook for zepplin"
            
            # taking password
            password = getpass.getpass("Enter ansible valut password: "******"Time taken to depoly ",n," virtual machines for zeppelin is ",totalDeployTime
            
            # writing logs
            tempDepLog = open('deployment_logs','w')
            tempDepLog.write(deployment_logs)
            tempDepLog.close()

            # checking logs
            deployment_logs_lines = deployment_logs.splitlines()

            wordList = []
            for line in deployment_logs_lines:
                words = line.split(' ')
                for word in words:
                    wordList.append(word)

            if "fatal" in wordList or '"Decryption' in wordList or "failed" in wordList or 'fatal:' in wordList:
                print "Check deployment logs for errors during deployment"
            else:
                print "Deployment Successful"
コード例 #4
0
ファイル: shell_commad.py プロジェクト: sohiljain/client
from cloudmesh_client.common.Shell import Shell

if __name__ == "__main__":
    Shell.cm()
コード例 #5
0
ファイル: az.py プロジェクト: naveenkumar2703/Miscellaneous
    def do_boot(self, n):

        self.floating_ip_list = []
        self.static_ip_list = []
        boot_start_time = time.time()
        try:
            for i in range(int(n)):
                floating_ip = None
                static_ip = None
                print "Starting to boot Virtual Machine : ", i + 1
                Shell.cm("vm", "boot --secgroup=naveen-def")
                if self.assignIp:
                    fip_result = Shell.cm("vm", "ip assign")  # floating IP
                    floating_ip = fip_result.split(' ')[-2][:-6]

                try:
                    if self.assignIp:
                        IP(floating_ip)
                        # the below cmd is the "cm vm ip show" as ip is not getting updated automatically in the DB
                        Shell.cm("vm", "ip assign")

                    n = 0
                    while n < 5 and i >= len(self.static_ip_list):
                        sip_info = Shell.cm("vm", "list")
                        lines = sip_info.split('\n')
                        for lin in lines:
                            if self.userId in lin:
                                items = lin.split('|')
                                static_ip = items[5].strip()
                                if '.' in static_ip and static_ip not in self.static_ip_list and static_ip != self.masterIp:
                                    self.static_ip_list.append(static_ip)
                                    break
                        print 'Sleeping for ' + str(
                            20 * (n + 1)) + ' seconds as ip not assigned'
                        time.sleep(20 * (n + 1))
                        n += 1
                        if n > 4:
                            raise Exception('Unable to assign ips')

                except Exception as e:
                    print e
                    print "floating IP error encountered"
                    print "Stopping to create further VMs"
                    break

                self.floating_ip_list.append(floating_ip)

        except ValueError:

            self.help_boot()

        if len(self.floating_ip_list) == 0 and self.assignIp:

            print "No VMs created"

        else:

            print "Returning IPs of VMs created"
            print "Floating IPs list    :", self.floating_ip_list
            print "Static IPs list      :", self.static_ip_list
            print "wirting IPs to respective files ..."
            print 'VM user :'******'HOME'] + '/.ssh/known_hosts'):
                os.remove(os.environ['HOME'] + '/.ssh/known_hosts')

            boot_time = boot_start_time - time.time()
            print 'Time taken to boot:' + str(boot_time)
            print "Commencing deployment for zepplin"
            # taking password
            password = getpass.getpass("Enter ansible valut password: "******"Running the ansible-playbook for zepplin"
            deployment_start_time = time.time()
            tempPassFile = open('.log.txt', 'w')
            tempPassFile.write(password)
            tempPassFile.close()
            startTime = time.time()
            if 'chameleon' in self.cloud:
                deployment_logs = os.popen(
                    'ansible-playbook Zeppelin.yml -i hosts --vault-password-file .log.txt'
                ).read()
            else:
                deployment_logs = os.popen(
                    'ansible-playbook Zeppelin_jetstream.yml -i hosts --vault-password-file .log.txt'
                ).read()

            os.remove('.log.txt')
            endTime = time.time()

            totalDeployTime = endTime - startTime
            print "Time taken to depoly ", n, " virtual machines for zeppelin is ", totalDeployTime

            # writing logs
            tempDepLog = open('deployment_logs', 'w')
            tempDepLog.write(deployment_logs)
            tempDepLog.close()

            # checking logs
            deployment_logs_lines = deployment_logs.splitlines()

            wordList = []
            for line in deployment_logs_lines:
                words = line.split(' ')
                for word in words:
                    wordList.append(word)

            if "fatal" in wordList or '"Decryption' in wordList or "failed" in wordList or 'fatal:' in wordList:
                print "Check deployment logs for errors during deployment"
            else:
                print "Deployment Successful"

            print "Time took for deployment is:" + str(time.time() -
                                                       deployment_start_time)