def refresh_components(self, sandbox):
        """
        :param Sandbox sandbox: 
        :return:
        """
        reservation_description = sandbox.automation_api.GetReservationDetails(
            reservationId=sandbox.id, disableCache=True).ReservationDescription

        self.resources = dict(
            (resource.Name, resource)
            for resource in reservation_description.Resources)
        self.services = dict((service.Alias, service)
                             for service in reservation_description.Services)

        if reservation_description.Apps is not None:
            for app in reservation_description.Apps:
                if (app.Name not in self.apps.keys()
                        and len(app.DeploymentPaths) > 0):
                    # to avoid bug in cloudshell-automation-api where an app named None returns even when
                    # there are no apps in the reservation
                    self.apps[app.Name] = App(app)

        if self.resources is not None:
            for resource_name, resource in self.resources.items():
                if isinstance(resource.AppDetails,
                              AppInfo):  # if deployed app but not static VM
                    if resource.AppDetails.AppName in self.apps:
                        self.apps[resource.AppDetails.
                                  AppName].set_deployed_app_resource(resource)
Ejemplo n.º 2
0
def configure_app(pri_type,api, reservation_id, logger,apps,parallel, appConfigurations=[]):

    if len(apps) == 0 :
        api.WriteMessageToReservationOutput(reservation_id, 'No {} app/s to configure'.format(pri_type))
        return

    logger.info('App configuration started ...')

    try:
        if not parallel:
            for app in apps:
                configuration_result = api.ConfigureApps(reservationId=reservation_id, printOutput=True,
                                                 appConfigurations=App(app).app_request.appConfiguration)
        else:
            app_configs=[]
            for app in apps:
                app_configs.append(App(app).app_request.appConfiguration)
            configuration_result = api.ConfigureApps(reservationId=reservation_id, printOutput=True, appConfigurations=app_configs)

        if not configuration_result.ResultItems:
            api.WriteMessageToReservationOutput(reservation_id, 'No {} app/s to configure'.format(pri_type))
            return

        failed_apps = []
        for conf_res in configuration_result.ResultItems:
            if conf_res.Success:
                message = "App '{0}' configured successfully".format(conf_res.AppName)
                logger.info(message)
            else:
                message = "App '{0}' configuration failed due to {1}".format(conf_res.AppName,
                                                                             conf_res.Error)
                logger.error(message)
                failed_apps.append(conf_res.AppName)

        if not failed_apps:
            api.WriteMessageToReservationOutput(reservationId=reservation_id, message=
            'Apps were configured successfully.')
        else:
            api.WriteMessageToReservationOutput(reservationId=reservation_id, message=
            'Apps: {0} configuration failed. See logs for more details'.format(
                ",".join(failed_apps)))
            raise Exception("Configuration of apps failed see logs.")
    except Exception as ex:
        logger.error("Error configuring apps. Error: {0}".format(str(ex)))
        raise

    return
Ejemplo n.º 3
0
    def __init__(self, resources, services, apps):
        self.apps = dict((app.Name, App(app)) for app in apps
                         if len(app.DeploymentPaths) > 0)  # avoid bug in
        # cloudshell-automation-api where an app named None returns even when there are no apps in the reservation
        """:type : dict[str, App]"""
        self.resources = {}
        """:type : dict[str, ReservedResourceInfo]"""
        self.services = dict((service.Alias, service) for service in services)
        """:type : dict[str, ServiceInstance]"""

        for resource in resources:
            if isinstance(
                    resource.VmDetails,
                    ResourceInfoVmDetails):  ##if deployed app or static VM
                self.apps[resource.Name] = App(None)
                self.apps[resource.Name].set_deployed_app_resource(resource)
            else:
                self.resources[resource.Name] = resource