def getImage(imageNo):
    dict = {}
    conn = MysqlConnector()
    imageTable = conn.getTable("IMAGE")
    image = conn.selectOne(imageTable.select(imageTable.c.IMAGE_NO==imageNo))
    if image is None:
        return dict

    platformTable = conn.getTable("PLATFORM")
    platform = conn.selectOne(platformTable.select(platformTable.c.PLATFORM_NO == image["PLATFORM_NO"]))

    dict = {}
    dict.update({"platformNo": image["PLATFORM_NO"]})
    dict.update({"os": image["OS"]})
    dict.update({"type": platform["PLATFORM_TYPE"]})
    if dict["type"] == "aws":
        awsImageTable = conn.getTable("IMAGE_AWS")
        awsImage = conn.selectOne(awsImageTable.select(awsImageTable.c.IMAGE_NO==imageNo))
        dict.update({"imageId": awsImage["IMAGE_ID"]})
        dict.update({"kernelId": awsImage["KERNEL_ID"]})
        dict.update({"ramdiskId": awsImage["RAMDISK_ID"]})
        dict.update({"instanceTypes": awsImage["INSTANCE_TYPES"]})
        if awsImage["EBS_IMAGE"] == 0 :
            dict.update({"ebsImage": "false"})
        else:
            dict.update({"ebsImage": "true"})

    elif dict["type"] == "vmware":
        vmwImageTable = conn.getTable("IMAGE_VMEARE")
        vmwImage = conn.selectOne(vmwImageTable.select(vmwImageTable.c.IMAGE_NO==imageNo))
        dict.update({"templateName": vmwImage["TEMPLATE_NAME"]})
        dict.update({"instanceTypes": vmwImage["INSTANCE_TYPES"]})
    elif dict["type"] == "nifty":
        niftyImageTable = conn.getTable("IMAGE_NIFTY")
        niftyImage = conn.selectOne(niftyImageTable.select(niftyImageTable.c.IMAGE_NO==imageNo))
        dict.update({"imageId": niftyImage["IMAGE_ID"]})
        dict.update({"instanceTypes": niftyImage["INSTANCE_TYPES"]})
    elif dict["type"] == "cloudstack":
        csImageTable = conn.getTable("IMAGE_CLOUDSTACK")
        csImage = conn.selectOne(csImageTable.select(csImageTable.c.IMAGE_NO==imageNo))
        dict.update({"templateId": csImage["TEMPLATE_ID"]})
        dict.update({"instanceTypes":  csImage["INSTANCE_TYPES"]})
    elif dict["type"] == "vcloud":
        vcImageTable = conn.getTable("IMAGE_VCLOUD")
        vcImage = conn.selectOne(vcImageTable.select(vcImageTable.c.IMAGE_NO==imageNo))
        dict.update({"templateName": vcImage["TEMPLATE_NAME"]})
        dict.update({"instanceTypes": vcImage["INSTANCE_TYPES"]})
    elif dict["type"] == "openstack":
        osImageTable = conn.getTable("IMAGE_OPENSTACK")
        osImage = conn.selectOne(osImageTable.select(osImageTable.c.IMAGE_NO==imageNo))
        dict.update({"imageId": osImage["IMAGE_ID"]})
        dict.update({"instanceTypes": osImage["INSTANCE_TYPES"]})

    return dict
예제 #2
0
def iaasSelect(user, platformNo, isLb = False):
    logger = IaasLogger()
    conn = MysqlConnector(user)

    '''プラットフォームを判断しユーザー情報を取得する
    '''
    platforminfo = getPlatformProperty(platformNo)
    platformType =  platforminfo["platformType"]
    platformName =  platforminfo["platformName"]

    logger.info(u"      Platform::No[%s]::種別[%s]::名称[%s]" % (str(platformNo), platformType, platformName))

    #ユーザー取得
    userTable = conn.getTable("USER")
    userinfo = conn.selectOne(userTable.select(userTable.c.USER_NO==user))


    iaasController = None
    if platformType == "aws":
        if platformName == "eucalyptus":
            return
        #EC2 およびユーカリ
        #AWS_CERTIFICATE 取得
        certificateTable = conn.getTable("AWS_CERTIFICATE")
        certificate = conn.selectOne(certificateTable.select(and_(certificateTable.c.USER_NO==user,  certificateTable.c.PLATFORM_NO==platformNo)))
        accessInfo = {"ACCESS_ID": str(certificate["AWS_ACCESS_ID"]), "SECRET_KEY": str(certificate["AWS_SECRET_KEY"]), "USER": user, "USER_NAME": userinfo["USERNAME"]}
        iaasController = EC2Controller(conn, accessInfo, platforminfo, isLb)
    elif platformType == "vmware":
        #vmware
        pass
    elif platformType == "nifty":
        #nifty
        pass
    elif platformType == "cloudstack":
        #CloudStack
        certificateTable = conn.getTable("CLOUDSTACK_CERTIFICATE")
        certificate = conn.selectOne(certificateTable.select(and_(certificateTable.c.ACCOUNT==user, certificateTable.c.PLATFORM_NO==platformNo)))
        accessInfo = {"ACCESS_ID": str(certificate["CLOUDSTACK_ACCESS_ID"]), "SECRET_KEY": str(certificate["CLOUDSTACK_SECRET_KEY"]), "USER": user, "USER_NAME": userinfo["USERNAME"]}
        iaasController = CloudStackController(conn, accessInfo, platforminfo)
    else:
        raise IaasException("PlatformError", platformNo)

    return iaasController
def getOpenStackInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformosTable = conn.getTable("PLATFORM_OPENSTACK")
    platformos = conn.selectOne(platformosTable.select(platformosTable.c.PLATFORM_NO == pltfmNo))
    if platformos is not None:
        dict.update({"URL": platformos["URL"]})
        dict.update({"TENANT_ID": platformos["TENANT_ID"]})
        dict.update({"TENANT_NM": platformos["TENANT_NM"]})

    return dict
def getOpenStackInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformosTable = conn.getTable("PLATFORM_OPENSTACK")
    platformos = conn.selectOne(
        platformosTable.select(platformosTable.c.PLATFORM_NO == pltfmNo))
    if platformos is not None:
        dict.update({"URL": platformos["URL"]})
        dict.update({"TENANT_ID": platformos["TENANT_ID"]})
        dict.update({"TENANT_NM": platformos["TENANT_NM"]})

    return dict
예제 #5
0
def getProxy():
    conn = MysqlConnector()
    proxyTable = conn.getTable("PROXY")
    proxyinfo = conn.selectOne(proxyTable.select())
    dict = {}
    if proxyinfo is not None:
        dict.update({"host": proxyinfo["HOST"]})
        dict.update({"port": proxyinfo["PORT"]})
        dict.update({"user": proxyinfo["USER"]})
        dict.update({"pass": proxyinfo["PASSWORD"]})

    return  dict
예제 #6
0
def getVCloudInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformcsTable = conn.getTable("PLATFORM_VCLOUD")
    platformcs = conn.selectOne(platformcsTable.select(platformcsTable.c.PLATFORM_NO == pltfmNo))
    if platformcs is not None:
        dict.update({"host": platformcs["HOST"]})
        dict.update({"path": platformcs["PATH"]})
        dict.update({"port": str(platformcs["PORT"])})
        dict.update({"secure": platformcs["SECURE"]})

    return dict
def getProxy():
    conn = MysqlConnector()
    proxyTable = conn.getTable("PROXY")
    proxyinfo = conn.selectOne(proxyTable.select())
    dict = {}
    if proxyinfo is not None:
        dict.update({"host": proxyinfo["HOST"]})
        dict.update({"port": proxyinfo["PORT"]})
        dict.update({"user": proxyinfo["USER"]})
        dict.update({"pass": proxyinfo["PASSWORD"]})

    return dict
def getVCloudInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformcsTable = conn.getTable("PLATFORM_VCLOUD")
    platformcs = conn.selectOne(platformcsTable.select(platformcsTable.c.PLATFORM_NO == pltfmNo))
    if platformcs is not None:
        dict.update({"host": platformcs["URL"]})
        dict.update({"org": platformcs["ORG_NAME"]})
        dict.update({"vdc": str(platformcs["VDC_NAME"])})
        dict.update({"secure": platformcs["SECURE"]})
        dict.update({"timeout": platformcs["TIMEOUT"]})
        dict.update({"defnetwork": platformcs["DEF_NETWORK"]})

    return dict
예제 #9
0
def getPlatformProperty(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformTable = conn.getTable("PLATFORM")
    platform = conn.selectOne(platformTable.select(platformTable.c.PLATFORM_NO == pltfmNo))
    if platform is not None:
        dict.update({"platformNo": str(platform["PLATFORM_NO"])})
        dict.update({"platformName": platform["PLATFORM_NAME"]})
        dict.update({"platformNameDisp": platform["PLATFORM_NAME_DISP"]})
        dict.update({"platformSimplenameDip": platform["PLATFORM_SIMPLENAME_DISP"]})
        dict.update({"internal": platform["INTERNAL"]})
        dict.update({"proxy": platform["PROXY"]})
        dict.update({"platformType": platform["PLATFORM_TYPE"]})
    return  dict
예제 #10
0
def getCloudStackInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformcsTable = conn.getTable("PLATFORM_CLOUDSTACK")
    platformcs = conn.selectOne(platformcsTable.select(platformcsTable.c.PLATFORM_NO == pltfmNo))
    if platformcs is not None:
        dict.update({"host": platformcs["HOST"]})
        dict.update({"path": platformcs["PATH"]})
        dict.update({"port": str(platformcs["PORT"])})
        dict.update({"secure": platformcs["SECURE"]})
        dict.update({"timeout": platformcs["TIMEOUT"]})
        dict.update({"device": platformcs["DEVICE_TYPE"]})
        dict.update({"hostid": platformcs["HOST_ID"]})

    return dict
예제 #11
0
def getVCloudInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformcsTable = conn.getTable("PLATFORM_VCLOUD")
    platformcs = conn.selectOne(
        platformcsTable.select(platformcsTable.c.PLATFORM_NO == pltfmNo))
    if platformcs is not None:
        dict.update({"host": platformcs["URL"]})
        dict.update({"org": platformcs["ORG_NAME"]})
        dict.update({"vdc": str(platformcs["VDC_NAME"])})
        dict.update({"secure": platformcs["SECURE"]})
        dict.update({"timeout": platformcs["TIMEOUT"]})
        dict.update({"defnetwork": platformcs["DEF_NETWORK"]})

    return dict
예제 #12
0
def getCloudStackInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformcsTable = conn.getTable("PLATFORM_CLOUDSTACK")
    platformcs = conn.selectOne(
        platformcsTable.select(platformcsTable.c.PLATFORM_NO == pltfmNo))
    if platformcs is not None:
        dict.update({"host": platformcs["HOST"]})
        dict.update({"path": platformcs["PATH"]})
        dict.update({"port": str(platformcs["PORT"])})
        dict.update({"secure": platformcs["SECURE"]})
        dict.update({"timeout": platformcs["TIMEOUT"]})
        dict.update({"device": platformcs["DEVICE_TYPE"]})
        dict.update({"hostid": platformcs["HOST_ID"]})

    return dict
예제 #13
0
def getPlatformProperty(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformTable = conn.getTable("PLATFORM")
    platform = conn.selectOne(
        platformTable.select(platformTable.c.PLATFORM_NO == pltfmNo))
    if platform is not None:
        dict.update({"platformNo": str(platform["PLATFORM_NO"])})
        dict.update({"platformName": platform["PLATFORM_NAME"]})
        dict.update({"platformNameDisp": platform["PLATFORM_NAME_DISP"]})
        dict.update(
            {"platformSimplenameDip": platform["PLATFORM_SIMPLENAME_DISP"]})
        dict.update({"internal": platform["INTERNAL"]})
        dict.update({"proxy": platform["PROXY"]})
        dict.update({"platformType": platform["PLATFORM_TYPE"]})
    return dict
예제 #14
0
def getAwsInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformawsTable = conn.getTable("PLATFORM_AWS")
    platformaws = conn.selectOne(platformawsTable.select(platformawsTable.c.PLATFORM_NO == pltfmNo))
    if platformaws is not None:
        dict.update({"host": platformaws["HOST"]})
        dict.update({"port": platformaws["PORT"]})
        dict.update({"secure": platformaws["SECURE"]})
        if platformaws["EUCA"] == 0 :
            dict.update({"euca": "false"})
        else:
            dict.update({"euca": "true"})

        if platformaws["VPC"] == 0 :
            dict.update({"vpc": "false"})
        else:
            dict.update({"vpc": "true"})
        dict.update({"zone": platformaws["AVAILABILITY_ZONE"]})
        dict.update({"region": platformaws["REGION"]})
    return dict
예제 #15
0
def getAwsInfo(pltfmNo):
    dict = {}
    conn = MysqlConnector()
    platformawsTable = conn.getTable("PLATFORM_AWS")
    platformaws = conn.selectOne(
        platformawsTable.select(platformawsTable.c.PLATFORM_NO == pltfmNo))
    if platformaws is not None:
        dict.update({"host": platformaws["HOST"]})
        dict.update({"port": platformaws["PORT"]})
        dict.update({"secure": platformaws["SECURE"]})
        if platformaws["EUCA"] == 0:
            dict.update({"euca": "false"})
        else:
            dict.update({"euca": "true"})

        if platformaws["VPC"] == 0:
            dict.update({"vpc": "false"})
        else:
            dict.update({"vpc": "true"})
        dict.update({"zone": platformaws["AVAILABILITY_ZONE"]})
        dict.update({"region": platformaws["REGION"]})
    return dict
예제 #16
0
def iaasSelect(user, platformNo, isLb=False):
    logger = IaasLogger()
    conn = MysqlConnector(user)
    '''プラットフォームを判断しユーザー情報を取得する
    '''
    platforminfo = getPlatformProperty(platformNo)
    platformType = platforminfo["platformType"]
    platformName = platforminfo["platformName"]

    logger.info(u"      Platform::No[%s]::種別[%s]::名称[%s]" %
                (str(platformNo), platformType, platformName))

    #ユーザー取得
    userTable = conn.getTable("USER")
    userinfo = conn.selectOne(userTable.select(userTable.c.USER_NO == user))

    iaasController = None
    if platformType == "aws":
        if platformName == "eucalyptus":
            return
        #EC2 およびユーカリ
        #AWS_CERTIFICATE 取得
        certificateTable = conn.getTable("AWS_CERTIFICATE")
        certificate = conn.selectOne(
            certificateTable.select(
                and_(certificateTable.c.USER_NO == user,
                     certificateTable.c.PLATFORM_NO == platformNo)))
        accessInfo = {
            "ACCESS_ID": str(certificate["AWS_ACCESS_ID"]),
            "SECRET_KEY": str(certificate["AWS_SECRET_KEY"]),
            "USER": user,
            "USER_NAME": userinfo["USERNAME"]
        }
        iaasController = EC2Controller(conn, accessInfo, platforminfo, isLb)
    elif platformType == "vmware":
        #vmware
        pass
    elif platformType == "nifty":
        #nifty
        pass
    elif platformType == "cloudstack":
        #CloudStack
        certificateTable = conn.getTable("CLOUDSTACK_CERTIFICATE")
        certificate = conn.selectOne(
            certificateTable.select(
                and_(certificateTable.c.ACCOUNT == user,
                     certificateTable.c.PLATFORM_NO == platformNo)))
        accessInfo = {
            "ACCESS_ID": str(certificate["CLOUDSTACK_ACCESS_ID"]),
            "SECRET_KEY": str(certificate["CLOUDSTACK_SECRET_KEY"]),
            "USER": user,
            "USER_NAME": userinfo["USERNAME"]
        }
        iaasController = CloudStackController(conn, accessInfo, platforminfo)
    elif platformType == "vcloud":
        #vCloud
        certificateTable = conn.getTable("VCLOUD_CERTIFICATE")
        certificate = conn.selectOne(
            certificateTable.select(
                and_(certificateTable.c.USER_NO == user,
                     certificateTable.c.PLATFORM_NO == platformNo)))
        accessInfo = {
            "ACCESS_ID": str(certificate["VCLOUD_ACCESS_ID"]),
            "SECRET_KEY": str(certificate["VCLOUD_SECRET_KEY"]),
            "USER": user,
            "USER_NAME": userinfo["USERNAME"]
        }
        iaasController = VCloudController(conn, accessInfo, platforminfo)
    elif platformType == "azure":
        #Azure
        certificateTable = conn.getTable("AZURE_CERTIFICATE")
        certificate = conn.selectOne(
            certificateTable.select(
                and_(certificateTable.c.USER_NO == user,
                     certificateTable.c.PLATFORM_NO == platformNo)))
        accessInfo = {
            "SUBSCRIPTION_ID": certificate["SUBSCRIPTION_ID"],
            "CERTIFICATE": certificate["CERTIFICATE"],
            "USER": user,
            "USER_NAME": userinfo["USERNAME"]
        }
        iaasController = AzureController(conn, accessInfo, platforminfo)
    elif platformType == "openstack":
        #OpenStack
        certificateTable = conn.getTable("OPENSTACK_CERTIFICATE")
        certificate = conn.selectOne(
            certificateTable.select(
                and_(certificateTable.c.USER_NO == user,
                     certificateTable.c.PLATFORM_NO == platformNo)))
        accessInfo = {
            "OS_ACCESS_ID": certificate["OS_ACCESS_ID"],
            "OS_SECRET_KEY": certificate["OS_SECRET_KEY"]
        }
        iaasController = OpenStackController(conn, accessInfo, platforminfo)
    else:
        raise IaasException("PlatformError", platformNo)

    return iaasController
 # (at your option) any later version.
 # 
 # PrimeCloud Controller(TM) is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU General Public License for more details.
 # 
 # You should have received a copy of the GNU General Public License
 # along with PrimeCloud Controller(TM). If not, see <http://www.gnu.org/licenses/>.
 # 
from iaasgw.db.mysqlConnector import MysqlConnector

if __name__ == '__main__':
    conn = MysqlConnector()
    #session = conn.getSession()
    table = conn.getTable("user")


    instanceId = "test"
    #AWS_INSTANCE 取得
    table = conn.getTable("AWS_INSTANCE")
    awsInstance = conn.selectOne(table.select(table.c.INSTANCE_NO==instanceId))

    #PCC_INSTANCE 取得
    table = conn.getTable("INSTANCE")
    pccInstance = conn.selectOne(table.select(table.c.INSTANCE_NO==instanceId))

    #イメージ取得   再考の余地あり


    print awsInstance
예제 #18
0
# (at your option) any later version.
#
# PrimeCloud Controller(TM) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PrimeCloud Controller(TM). If not, see <http://www.gnu.org/licenses/>.
#
from iaasgw.db.mysqlConnector import MysqlConnector

if __name__ == '__main__':
    conn = MysqlConnector()
    #session = conn.getSession()
    table = conn.getTable("user")

    instanceId = "test"
    #AWS_INSTANCE 取得
    table = conn.getTable("AWS_INSTANCE")
    awsInstance = conn.selectOne(
        table.select(table.c.INSTANCE_NO == instanceId))

    #PCC_INSTANCE 取得
    table = conn.getTable("INSTANCE")
    pccInstance = conn.selectOne(
        table.select(table.c.INSTANCE_NO == instanceId))

    #イメージ取得   再考の余地あり

    print awsInstance
예제 #19
0
def getImage(imageNo):
    dict = {}
    conn = MysqlConnector()
    imageTable = conn.getTable("IMAGE")
    image = conn.selectOne(imageTable.select(imageTable.c.IMAGE_NO == imageNo))
    if image is None:
        return dict

    platformTable = conn.getTable("PLATFORM")
    platform = conn.selectOne(
        platformTable.select(
            platformTable.c.PLATFORM_NO == image["PLATFORM_NO"]))

    dict = {}
    dict.update({"platformNo": image["PLATFORM_NO"]})
    dict.update({"os": image["OS"]})
    dict.update({"type": platform["PLATFORM_TYPE"]})
    if dict["type"] == "aws":
        awsImageTable = conn.getTable("IMAGE_AWS")
        awsImage = conn.selectOne(
            awsImageTable.select(awsImageTable.c.IMAGE_NO == imageNo))
        dict.update({"imageId": awsImage["IMAGE_ID"]})
        dict.update({"kernelId": awsImage["KERNEL_ID"]})
        dict.update({"ramdiskId": awsImage["RAMDISK_ID"]})
        dict.update({"instanceTypes": awsImage["INSTANCE_TYPES"]})
        if awsImage["EBS_IMAGE"] == 0:
            dict.update({"ebsImage": "false"})
        else:
            dict.update({"ebsImage": "true"})

    elif dict["type"] == "vmware":
        vmwImageTable = conn.getTable("IMAGE_VMEARE")
        vmwImage = conn.selectOne(
            vmwImageTable.select(vmwImageTable.c.IMAGE_NO == imageNo))
        dict.update({"templateName": vmwImage["TEMPLATE_NAME"]})
        dict.update({"instanceTypes": vmwImage["INSTANCE_TYPES"]})
    elif dict["type"] == "nifty":
        niftyImageTable = conn.getTable("IMAGE_NIFTY")
        niftyImage = conn.selectOne(
            niftyImageTable.select(niftyImageTable.c.IMAGE_NO == imageNo))
        dict.update({"imageId": niftyImage["IMAGE_ID"]})
        dict.update({"instanceTypes": niftyImage["INSTANCE_TYPES"]})
    elif dict["type"] == "cloudstack":
        csImageTable = conn.getTable("IMAGE_CLOUDSTACK")
        csImage = conn.selectOne(
            csImageTable.select(csImageTable.c.IMAGE_NO == imageNo))
        dict.update({"templateId": csImage["TEMPLATE_ID"]})
        dict.update({"instanceTypes": csImage["INSTANCE_TYPES"]})
    elif dict["type"] == "vcloud":
        vcImageTable = conn.getTable("IMAGE_VCLOUD")
        vcImage = conn.selectOne(
            vcImageTable.select(vcImageTable.c.IMAGE_NO == imageNo))
        dict.update({"templateName": vcImage["TEMPLATE_NAME"]})
        dict.update({"instanceTypes": vcImage["INSTANCE_TYPES"]})
    elif dict["type"] == "openstack":
        osImageTable = conn.getTable("IMAGE_OPENSTACK")
        osImage = conn.selectOne(
            osImageTable.select(osImageTable.c.IMAGE_NO == imageNo))
        dict.update({"imageId": osImage["IMAGE_ID"]})
        dict.update({"instanceTypes": osImage["INSTANCE_TYPES"]})

    return dict