Smart Knight
My Articles: From. 2009-3 To. 2012-3 http://blog.csdn.net/watson243671

2013年8月23日

how to use DevStack to launch a stack with Heat in Ubuntu 12.04 Desktop dist?
1. create a shell file in home dir ~/createStack .
cd ~
sudo apt
-get update || yum update -y
sudo apt
-get install -qqy git || yum install -y git
PASSWORD
=*
git clone https:
//github.com/openstack-dev/devstack.git
cd devstack
echo 
"ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng">localrc
echo 
"DATABASE_PASSWORD=$PASSWORD">>localrc
echo 
"RABBIT_PASSWORD=$PASSWORD">>localrc
echo 
"SERVICE_TOKEN=$PASSWORD">>localrc
echo 
"SERVICE_PASSWORD=$PASSWORD">>localrc
echo 
"ADMIN_PASSWORD=$PASSWORD">>localrc
echo 
"IMAGE_URLS+=\",http://fedorapeople.org/groups/heat/prebuilt-jeos-images/F17-x86_64-cfntools.qcow2\"">>localrc
echo "IMAGE_URLS+=\",http://fedorapeople.org/groups/heat/prebuilt-jeos-images/U10-x86_64-cfntools.qcow2\"">>localrc
echo "IMAGE_URLS+=\",http://download.cirros-cloud.net/0.3.1/cirros-0.3.1-x86_64-uec.tar.gz\"">>localrc
./stack.sh
2. chmod +x createStack.sh
3.run ~/createStack.sh
posted @ 2013-08-23 09:36 hailiang 阅读(203) | 评论 (0)编辑 收藏

2013年8月21日


decorators i: introduction to python decorators

'''
Created on Aug 212013

@author: hailiang
'''
class myDecorator(object):
    
    def __init__(self, f):
        print 
"1:inside myDecorator.__init__()"
        self.f 
= f  # Prove that function definition has completed
 
    def __call__(self, args
=None):
        print 
"3:inside myDecorator.__call__()"
        self.f(args)
 
@myDecorator
def aFunction(args
=None):
    print 
"4:inside aFunction()"
    print args
 
print 
"2:Finished decorating aFunction()"
 
aFunction()
print 
"another call"
aFunction(args
="I have value")

posted @ 2013-08-21 17:38 hailiang 阅读(365) | 评论 (0)编辑 收藏

2013年8月16日

Online Docs
http://docs.python.org/2.6/library/exceptions.html
The class hierarchy for built-in exceptions is:

BaseException
 
+-- SystemExit
 
+-- KeyboardInterrupt
 
+-- GeneratorExit
 
+-- Exception
      
+-- StopIteration
      
+-- StandardError
      
|    +-- BufferError
      
|    +-- ArithmeticError
      
|    |    +-- FloatingPointError
      
|    |    +-- OverflowError
      
|    |    +-- ZeroDivisionError
      
|    +-- AssertionError
      
|    +-- AttributeError
      
|    +-- EnvironmentError
      
|    |    +-- IOError
      
|    |    +-- OSError
      
|    |         +-- WindowsError (Windows)
      
|    |         +-- VMSError (VMS)
      
|    +-- EOFError
      
|    +-- ImportError
      
|    +-- LookupError
      
|    |    +-- IndexError
      
|    |    +-- KeyError
      
|    +-- MemoryError
      
|    +-- NameError
      
|    |    +-- UnboundLocalError
      
|    +-- ReferenceError
      
|    +-- RuntimeError
      
|    |    +-- NotImplementedError
      
|    +-- SyntaxError
      
|    |    +-- IndentationError
      
|    |         +-- TabError
      
|    +-- SystemError
      
|    +-- TypeError
      
|    +-- ValueError
      
|         +-- UnicodeError
      
|              +-- UnicodeDecodeError
      
|              +-- UnicodeEncodeError
      
|              +-- UnicodeTranslateError
      
+-- Warning
           
+-- DeprecationWarning
           
+-- PendingDeprecationWarning
           
+-- RuntimeWarning
           
+-- SyntaxWarning
           
+-- UserWarning
           
+-- FutureWarning
       
+-- ImportWarning
       
+-- UnicodeWarning
       
+-- BytesWarning
exception BaseException

The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that use Exception). If str() or unicode() is called on an instance of this class, the representation of the argument(s) to the instance are returned or the empty string when there were no arguments. All arguments are stored in args as a tuple.

New in version 2.5.

exception Exception

All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class.

Changed in version 2.5: Changed to inherit from BaseException.

'''
Created on Aug 152013
'''
class MyException(Exception):
#     
"""My documentation"""
class MyException(Exception):
    pass
class MyException(Exception):
#     def _get_message(self): 
#         
return self.args[0]
#     def _set_message(self, message): 
#         self._message 
= message
#     message 
= property(_get_message, _set_message)

try:
    raise MyException(
'description1''description2')
except MyException as my:
    print str(my)
    print unicode(my) 
    
try:
    raise MyException(u
'description1', u'description2')
except MyException as my:
    print str(my)  
    print unicode(my)  
   
posted @ 2013-08-16 10:23 hailiang 阅读(251) | 评论 (0)编辑 收藏

2013年8月15日

#! /bin/bash 
#######################
#
#######################

# constants

# functions

# main 

-"${BASH_SOURCE[0]}" -"${BASH_SOURCE[0]}" = "$0" ] || return
posted @ 2013-08-15 12:17 hailiang 阅读(266) | 评论 (0)编辑 收藏

2013年8月1日

import java.io.*;
import java.util.zip.*;

public class ZipHandler {
    
private ZipInputStream zipIn;
    
private ZipOutputStream zipOut;
    
private ZipEntry zipEntry;
    
private static int bufSize;
    
private byte[] buf;
    
private int readedBytes;

    
public ZipHandler() {
        
this(512);
    }

    
public ZipHandler(int bufSize) {
        
this.bufSize = bufSize;
        
this.buf = new byte[this.bufSize];
    }

    
public void doZip(String zipDirectory) {
        File file;
        File zipDir;

        zipDir 
= new File(zipDirectory);
        String zipFileName 
= zipDir.getName() + ".zip";

        
try {
            
this.zipOut = new ZipOutputStream(new BufferedOutputStream(
                    
new FileOutputStream(zipFileName)));
            handleDir(zipDir, 
this.zipOut);
            
this.zipOut.close();
        } 
catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    
private void handleDir(File dir, ZipOutputStream zipOut) throws IOException {
        FileInputStream fileIn;
        File[] files;

        files 
= dir.listFiles();

        
if (files.length == 0) {
            
this.zipOut.putNextEntry(new ZipEntry(dir.toString() + "/"));
            
this.zipOut.closeEntry();
        } 
else {
            
for (File fileName : files) {
                
if (fileName.isDirectory()) {
                    handleDir(fileName, 
this.zipOut);
                } 
else {
                    fileIn 
= new FileInputStream(fileName);
                    
this.zipOut.putNextEntry(new ZipEntry(fileName.toString()));

                    
while ((this.readedBytes = fileIn.read(this.buf)) > 0) {
                        
this.zipOut.write(this.buf, 0this.readedBytes);
                    }

                    
this.zipOut.closeEntry();
                }
            }
        }
    }

    
public void unZip(String unZipfileName) {
        FileOutputStream fileOut;
        File file;

        
try {
            
this.zipIn = new ZipInputStream(new BufferedInputStream(
                    
new FileInputStream(unZipfileName)));

            
while ((this.zipEntry = this.zipIn.getNextEntry()) != null) {
                file 
= new File(this.zipEntry.getName());

                
if (this.zipEntry.isDirectory()) {
                    file.mkdirs();
                } 
else {
                    File parent 
= file.getParentFile();
                    
if (!parent.exists()) {
                        parent.mkdirs();
                    }

                    fileOut 
= new FileOutputStream(file);
                    
while ((this.readedBytes = this.zipIn.read(this.buf)) > 0) {
                        fileOut.write(
this.buf, 0this.readedBytes);
                    }
                    fileOut.close();
                }
                
this.zipIn.closeEntry();
            }
        } 
catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    
public void setBufSize(int bufSize) {
        
this.bufSize = bufSize;
    }

    
public static void main(String[] args) throws Exception {
        String name 
= "";
        ZipHandler zip 
= new ZipHandler();

        zip.doZip(name);
//         zip.unZip(name);
    }
}
                        
posted @ 2013-08-01 10:26 hailiang| 编辑 收藏
仅列出标题  下一页