Пример #1
0
 def delete_local(self,local_path):
     """ Deletes a local svn repo 
     @param local_path: path to the repository 
     @return: boolean
     """
     if self.is_path(local_path):
         shell("rm -rf %s" % local_path,verbose=False)
         return True
     else:
         self.log.error("Not an svn repo %s" % (local_path))
         return False
Пример #2
0
 def bsdiff(self):
     '''
     Generate bsdiff origin file of self
     Generate bsdiff origin file to new file
     diff compare origin to new
     '''
     diffs = []
     for file_path in self.union:
         tag_origin = "%s%s" % ('origin',file_path.replace('/','.'))
         tag_new = "%s%s" % ('new',file_path.replace('/','.'))
         path_origin = "%s%s" % (self.origin,file_path)
         path_new = "%s%s" % (self.new,file_path)
         if self.is_symlink(path_new):
             print "slink: %s" % (path_new)
             self.slinks.append(path_new)
             pass
         if self.is_symlink(path_origin):
             print "slink: %s" % (path_origin)
             self.slinks.append(path_origin)
             pass
         self._bsdiff(path_origin, path_origin, tag_origin)
         self._bsdiff(path_origin, path_new, tag_new)
         cmd = "diff %s/%s %s/%s" % (self.path,tag_origin,self.path,tag_new)
         session = shell(cmd)
         output = session.get('stdout')
         if self.options.debug:
             print output
         if("differ\n" in output):
             print "Found: %s" % file_path
             diffs.append(file_path)
         else:
             print " Pass: %s" % file_path
     self._write(diffs)
     return diffs
Пример #3
0
def reset(options):
    ip = options.get('ip')
    user = options.get('user')
    password = options.get('password')
    cmd = 'ipmitool -I lanplus -H %s -U %s -P %s power reset' % (ip, user,
                                                                 password)
    session = shell(cmd)
    return session
Пример #4
0
def make_package(options):
    if options.docs:
        shell("cd %s/docs; sphinx-apidoc -f -o source/ ../isi_fog_py" %
              (package_path))
        shell("cd %s/docs; make html" % (package_path))
        shell("cd %s; tar -zcvf isi_fog_py.tar.gz ./isi_fog_py" %
              (package_path))
    shell("cd %s; dpkg-buildpackage -rfakeroot -Tclean" % (package_path))
    shell("cd %s; dpkg-buildpackage -b" % (package_path))
    server = options.server
    src = "%s/%s" % (artifact_path, options.build)
    dest = "/root"
    print "server: %s" % server
    print "   src: %s" % src
    print "  dest: %s" % dest
    rsync(server, src, dest, rsa_private="~/.ssh/id_rsa", option='push')
    ssh(server,
        "cd /root; gdebi %s -n" % (options.build),
        rsa_private="~/.ssh/id_rsa")
Пример #5
0
 def init_package(self,name):
     cwd = os.getcwd()
     os.chdir(self.package_base)
     machine_info = {}
     drone_pkg_path = "%s/%s.drone" % (self.package_base,name)
     drone_path     = "%s/%s" % (self.package_base,name)
     drone_yml_path = "%s/%s" % (drone_path,"drone.yml")
     drone_disk_path= "%s/%s.vdi" % (drone_path,name)
     if os.path.exists(drone_pkg_path):
         print "\nunpacking drone package..."
         shell("tar -zxvf %s" % (drone_pkg_path),shell=True)
     else:
         print 'Error drone package not found %s' % drone_pkg_path
         return False
     drn_yaml = None
     os.chdir(cwd)
     if os.path.exists(drone_yml_path):
         with open(drone_yml_path, 'r') as cfg:
             drn_yaml = yaml.load(cfg)
     else:
         print "Error unable to find drone.yml file in package %s" % drone_yml_path
         return False
         
     if os.path.exists(drone_disk_path):
         if drn_yaml:
             drn_yaml['memorySize']=int(drn_yaml.get('memorySize'))
             drn_yaml['OSTypeID']= drn_yaml.get('OSTypeID')
             drn_yaml['hard_disk_path']=drone_disk_path
             drn_yaml['network_adapter']=1
             drn_yaml['network_enabled']=True
             drn_yaml['network_connected']=True
             drn_yaml['guest_ssh_port']='22'
             drn_yaml['host_ssh_port']=str(self.new_ssh_port(2223))
             for k,v in drn_yaml.iteritems():
                 print "%s : %s" % (k,v)
             machine = Machine(drn_yaml)
             print "\nlaunching virtual machine %s..." % drn_yaml.get('name')
             print machine.create()
             shell("rm -rf %s" % (drone_path))
     else:
         print "Error unable to find drone disk file %s" % (drone_disk_path)
         return False
     return True
Пример #6
0
 def is_alive(self):
     """ Pings the remote to make sure its a valid address
     :return: boolean
     """
     session = shell('/usr/bin/env ping -c 1 %s' % (self.server),
                     strict=False,
                     verbose=False,
                     show_cmd=False)
     if session.get('code') == 0:
         return True
     return False
Пример #7
0
    def _set_ssh_config(self,
                        ssh_config,
                        git_host):
        """
        This turns off host verification

        :param ssh_config: path to <user>/.ssh/config
        :param git_host: example. github.west.isilon.com
        """
        if os.path.exists(ssh_config):
            with open(ssh_config, 'r') as file:
                config = file.read()
                if git_host not in config:
                    print "[Info] adding host @ %s" % (ssh_config)
                    cmd = ("sudo printf "
                           "'Host %s\\n\\tStrictHostKeyChecking no\\n' "
                           ">> %s") % (git_host, ssh_config)
                    shell(cmd, shell=True)
        else:
            print "[Info] Creating ssh config @ %s" % (ssh_config)
            cmd = ("sudo printf "
                   "'Host %s\\n\\tStrictHostKeyChecking no\\n' "
                   "> %s") % (git_host, ssh_config)
            shell(cmd, shell=True)
Пример #8
0
 def _bsdiff(self,base_a, base_b,tag='tag'):
     '''
     perform a bsdiff
     :param base_a: String, path to file a 
     :param base_b: String, path to file b
     :param tag: tag of file
     '''
     cmd = "cd %s; bsdiff %s %s %s" % (self.path,
                                       base_a,
                                       base_b,
                                       tag)
     if self.options.debug:
         print cmd
     session = shell(cmd)
     if self.options.debug:
         print session
     if session.get('code') > 0:
         print "Error: %s" % (base_a)
         self.errors.append(base_a)
     return session.get('stdout')
Пример #9
0
 def create_package(self,name,package_name):
     machine = self.get_machine(name)
     if machine:
         #package_base = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)).rsplit('/',1)[0],'packages')
         print "\n creating drone package..."
         package_dir  = "%s/%s" % (self.package_base,package_name)
         drone_cfg      = "%s/drone.yml" % (package_dir)
         machine_path = machine.settingsFilePath.rsplit('/',1)[0]
         disk_name    = None
         disk_path    = None
         if os.path.exists(package_dir):
             shell("rm -rf %s" % (package_dir))
         if not os.path.exists(package_dir):
             os.makedirs(package_dir)
         for file in os.listdir(machine_path): # find the disk
             if '.vdi' in file:
                 disk_name = file 
                 disk_path = "%s/%s" % (machine_path,disk_name)
         if not os.path.exists(disk_path):# make sure the disk exists
             print 'Unable to find disk file'
             return None
         src = disk_path
         package_name_disk = "%s.vdi" % package_name
         dst = "%s/%s" % (package_dir,package_name_disk)
         print "\ncloning disk..."
         try:
             clonehd_code = shell("VBoxManage clonehd '%s' '%s' --format VDI" % (src,dst),strict=True)
         except Exception as e:
             print str(e)
             print "\n --note Make sure the vm is off"
             os.sys.exit(1)
         #if not os.path.exists(dst):
         #    shutil.copyfile(src,dst) # copy the disk into package
         if not os.path.exists(drone_cfg):
             with open(drone_cfg,'w') as drone_file:
                 machine_info = self.get_machine_info(name)
                 machine_info['name']=package_name
                 yaml.dump(machine_info, drone_file,default_flow_style=False)
         output = shell("tar czf %s.drone -C %s/ %s" % (package_dir,self.package_base,package_name))
         if output.get('code')==0:
             shell("rm -rf %s" % (package_dir))
             print "\ndrone package created"
         else:
             print "Error creating drone package"