コード例 #1
0
    def __init__(self, conn, accessInfo, platforminfo, isLb=False):
        self.conn = conn
        self.accessInfo = accessInfo
        self.client = AzureIaasClient(platforminfo, accessInfo["USER_NAME"],
                                      accessInfo["SUBSCRIPTION_ID"],
                                      accessInfo["CERTIFICATE"], self.conn)

        #コントローラ作成
        self.instancecontroller = azureInstanceController(
            platforminfo, self.client, self.conn)
        self.volumecontroller = azureVolumeController(platforminfo,
                                                      self.client, self.conn)
        self.othercontroller = azureOtherController(platforminfo, self.client,
                                                    self.conn)
    def __init__(self, conn, accessInfo, platforminfo, isLb = False):
        self.conn = conn
        self.accessInfo = accessInfo
        self.client = AzureIaasClient(platforminfo, accessInfo["USER_NAME"], accessInfo["SUBSCRIPTION_ID"], accessInfo["CERTIFICATE"], self.conn)

        #コントローラ作成
        self.instancecontroller = azureInstanceController(platforminfo, self.client, self.conn)
        self.volumecontroller   = azureVolumeController(platforminfo, self.client, self.conn)
        self.othercontroller    = azureOtherController(platforminfo, self.client, self.conn)
class AzureController(IaasController):

    logger = IaasLogger()

    conn = None
    accessInfo = None

    client = None
    instancecontroller = None
    volumecontroller = None
    othercontroller = None

    def __init__(self, conn, accessInfo, platforminfo, isLb = False):
        self.conn = conn
        self.accessInfo = accessInfo
        self.client = AzureIaasClient(platforminfo, accessInfo["USER_NAME"], accessInfo["SUBSCRIPTION_ID"], accessInfo["CERTIFICATE"], self.conn)

        #コントローラ作成
        self.instancecontroller = azureInstanceController(platforminfo, self.client, self.conn)
        self.volumecontroller   = azureVolumeController(platforminfo, self.client, self.conn)
        self.othercontroller    = azureOtherController(platforminfo, self.client, self.conn)

    def __del__(self):
        self.conn.rollback()
        self.conn.close()

    def startInstance(self, instanceNo):
        try:
            self.instancecontroller.startInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def stopInstance(self, instanceNo):
        try:
            self.instancecontroller.stopInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def terminateInstance(self, instanceNo):
        try:
            self.instancecontroller.terminateInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def startVolume(self, instanceNo, volumeNo):
        try:
            self.volumecontroller.startVolume(instanceNo, volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def stopVolume(self, instanceNo, volumeNo):
        try:
            self.volumecontroller.stopVolume(instanceNo, volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def deleteVolume(self, volumeNo):
        try:
            self.volumecontroller.deleteVolume(volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise
        return True


    # ユーティリティ
    def generateEnvironment(self, platformNo):
        try:
            self.othercontroller.createCloudServiceFor(platformNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise
        try:
            self.othercontroller.createStorageAccountFor(platformNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def describeAzureSubnets(self, networkName):
        networks = self.client.listVirtualNetworkSites()
        rtString = ''
        for network in networks:
            if network.name != networkName:
                continue

            for subnet in network.subnets:
                if rtString != '':
                    rtString = rtString + "##"

                #とりあえず必要な情報のみ返します
                rtString = rtString + subnet.name + '#' + subnet.address_prefix

        self.conn.commit()
        return "RESULT:" + rtString
コード例 #4
0
class AzureController(IaasController):

    logger = IaasLogger()

    conn = None
    accessInfo = None

    client = None
    instancecontroller = None
    volumecontroller = None
    othercontroller = None

    def __init__(self, conn, accessInfo, platforminfo, isLb=False):
        self.conn = conn
        self.accessInfo = accessInfo
        self.client = AzureIaasClient(platforminfo, accessInfo["USER_NAME"],
                                      accessInfo["SUBSCRIPTION_ID"],
                                      accessInfo["CERTIFICATE"], self.conn)

        #コントローラ作成
        self.instancecontroller = azureInstanceController(
            platforminfo, self.client, self.conn)
        self.volumecontroller = azureVolumeController(platforminfo,
                                                      self.client, self.conn)
        self.othercontroller = azureOtherController(platforminfo, self.client,
                                                    self.conn)

    def __del__(self):
        self.conn.rollback()
        self.conn.close()

    def startInstance(self, instanceNo):
        try:
            self.instancecontroller.startInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def stopInstance(self, instanceNo):
        try:
            self.instancecontroller.stopInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def terminateInstance(self, instanceNo):
        try:
            self.instancecontroller.terminateInstance(instanceNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def startVolume(self, instanceNo, volumeNo):
        try:
            self.volumecontroller.startVolume(instanceNo, volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def stopVolume(self, instanceNo, volumeNo):
        try:
            self.volumecontroller.stopVolume(instanceNo, volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def deleteVolume(self, volumeNo):
        try:
            self.volumecontroller.deleteVolume(volumeNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise
        return True

    # ユーティリティ
    def generateEnvironment(self, platformNo):
        try:
            self.othercontroller.createCloudServiceFor(platformNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise
        try:
            self.othercontroller.createStorageAccountFor(platformNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            raise

        self.conn.commit()
        return True

    def describeAzureSubnets(self, networkName):
        networks = self.client.listVirtualNetworkSites()
        rtString = ''
        for network in networks:
            if network.name != networkName:
                continue

            for subnet in network.subnets:
                if rtString != '':
                    rtString = rtString + "##"

                #とりあえず必要な情報のみ返します
                rtString = rtString + subnet.name + '#' + subnet.address_prefix

        self.conn.commit()
        return "RESULT:" + rtString