The emergence of cloud computing can help enterprises reduce their hardware and software investment and save their own operation and maintenance costs, thus more and more enterprises deploy their applications into the cloud. Generally, components of enterprise applications are resided in virtual machines and then hosted by physical machines. In order to achieve the efficiency and utilization of physical machines, reasonable virtual machines placement becomes very important. In this paper we propose a scheme of resource allocation model for virtual machines placement and investigate it with convex optimization approach. We also present a heuristic algorithm to achieve the optimal resource allocation and discuss its equilibrium and stability by applying the asymptotic stability of the continuous dynamic system of Lyapunov stability theory. Finally, we give some numerical examples to illustrate the performance of the resource allocation scheme and confirm its convergence with a certain number of iterations.