# -*- coding:utf-8 -*-
import boto
import boto.s3.connection
import paramiko
class Accountinfo():
"""
用法详见 http://docs.ceph.org.cn/man/8/radosgw-admin/
"""
def __init__(self):
self.hostname = '192.168.44.70'
self.port = 22
self.username = 'root'
self.passwd = '123456'
def new_connect(self):
try:
paramiko.util.log_to_file('paramiko.log')
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='192.168.44.70',port=22,username='root',password='123456')
return ssh
except Exception as e:
return 'error'
def user_manager(self,username,flag):
"""
为s3访问创建radosgw用户
flag: c -> create,d -> delete
"""
ssh = self.new_connect()
if not isinstance(ssh,str):
c_command = '/usr/bin/radosgw-admin user create --uid="%s" --display-name="%s"' % (username, username.title())
d_command = '/usr/bin/radosgw-admin user rm --uid="%s"' % (username)
if flag == 'c':
stdin, stdout, stderr = ssh.exec_command